Ansys Learning Forum › Forums › Discuss Simulation › Fluids › Melting and solidification process for different boundary condition& time period › Reply To: Melting and solidification process for different boundary condition& time period
Sir, I wrote a UDF regarding the above-stated problem, which is given below,
#include "udf.h"
real pcm_tavg;
real gc_tavg;
#define T_S 494 Â /*pcm solidus temperature*/
#define T_L 514 Â /*pcm liquidus temperature*/
#define h 10 /*heat transfer coefficient*/
#define T_amb 300 /*ambient temperature*/
/* CALCULATING THE PCM DOMAIN VOLUME WEIGHTED AVERAGE TEMPERATURE*/
DEFINE_EXECUTE_AT_END(pcm_domain_average_temperature)
{
statement
----------
pcm_tavg = -----;
}
/* CALCULATING THE GLASS COVER AREA WEIGHTED AVERAGE TEMPERATURE*/
DEFINE_EXECUTE_AT_END(glass_cover_average_temperature)
{
statement
----------
gc_tavg = -----;
}
/* APPLYING CHARGING AND DIS-CHARGING BOUNDARY CONDITION */
Â
DEFINE_PROFILE(bound_condition,thread,position)
{
  real x[ND_ND];
  real current_time = CURRENT_TIME;
  int current_time_step = N_TIME;
  real current_time_step_size = CURRENT_TIMESTEP;
  real total_time = current_time_step*current_time_step_size;
  current_time=0;
 #if !RP_HOST
    face_t face;
    while(current_time<=total_time)
    {
      begin_f_loop(face,thread)
      {
        if(pcm_tavg>=T_L)
        {
          Message("pcm completely melts, pcm_Tavg = %g\n",v_w_tavg);
          while(current_time<=total_time)
          {
            begin_f_loop(face,thread)
              {
                if(pcm_tavg<=T_S)
                {
                  Message("pcm completely solidifies, pcm_Tavg = %g\n",v_w_tavg);
                  break;
                }                  Â
                else
                {Â
                  F_CENTROID(x,face,thread);
                  F_PROFILE(face,thread,position) = h*(T_amb-gc_tavg);
                }
              }
            end_f_loop(face,thread)
            current_time = current_time + current_time_step_size;Â
          }          Â
        }
        else
        {
        F_CENTROID(x,face,thread);
        F_PROFILE(face,thread,position) = 20000;
        }
      }
      end_f_loop(face,thread)
      current_time = current_time + current_time_step_size;
    }
  #endif  Â
}
First, I calculated the PCM domain volume-weighted average temperature and area-weighted average temperature for the glass cover outer surface, respectively, using the UDF - DEFINE_EXECUTE_AT_END macros, as shown in the UDF above. These two UDFs work fine. Â
The change of boundary condition is done by using the DEFINE_PROFILE macro. Initially, the flux value applies as per the condition. But, the problem arises when the PCM average temperature exceeds the T_L; it doesn't enter the if condition statement of the 1st while statement; rather, it continues with the else statement. Can you please suggest why the if statement doesn't work?