UDF to Define Temperature Dependent Negative Heat Source
Hi,
I am trying to calculate the average temperature of interface at each iteration (since I am solving steady state problem) and based on the interface temperature I want to update my negative heat source value (Q_Source=(-constant*(T_Interface-T_Constant))/volume). First, I tried UDM to store interface temperature but didn't work. Then I tried to GLOBAL variable to avoid UDM, but again no luck. I am using ANSYS FLUENT 2019 R2. For both cases, I Interpreted the UDF and during the interpretetion, FLUENT didn't show any error. I have attached my written UDF below. Can someone please help me to fix the problem? Thanks in advance. /*********UDF with UDM**********/ #include "udf.h" /*********INTERFACE TEMPERATURE**************/ DEFINE_EXECUTE_AT_END(average_interface_temp_of_wi ndings_air) { Domain *d; face_t f; real temper = 0.0; real A[ND_ND]; real tsavg=0.0; real area = 0.0; real area_tot = 0.0; int ID = 10; /*this is the ID of the interface that I want to get the temperature from*/ Thread *t; d = Get_Domain(1); t = Lookup_Thread(d,ID); /*We are trying to calculate area weighted average temperature of a surface- as per the definition of area weighted average*/ begin_f_loop(f,t) { F_AREA(A,f,t); /*get face area which is a vector*/ area = NV_MAG(A);/*get magnitude of the face area*/ area_tot += area; /*calculate total area*/ temper = F_T(f,t); /*calculate face temperature*/ tsavg += temper*area; } end_f_loop(f,t) tsavg /= area_tot; printf("Average Interface Temperature = %g\n",tsavg); begin_f_loop(f,t) { F_UDMI(f,t,0) = tsavg; /* User Define Memory */ } end_f_loop(f,t) } /**********NEGATIVE HEAT SOURCE***************/ DEFINE_SOURCE(negative_heat_source,c,t,dS,eqn) { real source; face_t f; source = -5000.*(F_UDMI(f,t,0)-290.); /* For the time being, I have assumed an arbitrary constant for hA and T_Sat */ dS[eqn] = 0.; /* Need to double check. It can be -5000. as a resultant of the derivative of source term */ return source; } /******UDF with Global Variable***********/ #include "udf.h" /*********INTERFACE TEMPERATURE**************/ real tsavg=0; /* Defining Global Variable */ DEFINE_EXECUTE_AT_END(average_interface_temp) { Domain *d; face_t f; /*real tsavg=0;*/ real temper = 0.0; real A[ND_ND]; real area = 0.0; real area_tot = 0.0; int ID = 10; /*this is the ID of the interface that I want to get the temperature from*/ Thread *t; d = Get_Domain(1); t = Lookup_Thread(d,ID); /*We are trying to calculate area weighted average temperature of a surface- as per the definition of area weighted average*/ begin_f_loop(f,t) { F_AREA(A,f,t); /*get face area which is a vector*/ area = NV_MAG(A);/*get magnitude of the face area*/ area_tot += area; /*calculate total area*/ temper = F_T(f,t); /*calculate face temperature*/ tsavg += temper*area; } end_f_loop(f,t) tsavg /= area_tot; printf("Average Interface Temperature = %g\n",tsavg); } /**********NEGATIVE HEAT SOURCE***************/ DEFINE_SOURCE(heat_source,c,t,dS,eqn) { real source; source = -5000.*(tsavg-300.); /* For the time being, I have assumed an arbitrary constant for hA and T_Sat */ dS[eqn] = 0.; /* Need to double check. It can be -5000. as a resultant of the derivative of source term */ return source; } |
if you are using 2019R2 -> it means you run your code in parallel, but it was not considered
you have to modify your code: Ansys Fluent Customization manual -> Global Reduction Macros other problem Code:
DEFINE_SOURCE(negative_heat_source,c,t,dS,eqn) fix these issues first best regards |
All times are GMT -4. The time now is 08:42. |