Use DEFINE_ADJUST change boundary condition
dear all friends:
now,i have some trouble in solving question about how to change boundary condition.details as follow: boudary condition:heat flux q2=a1*qe^(1/3)[Twall2684qe*(a2+a3+a4*qe^(1/3))) qe is heat flux that Fluent compute itself.That is to say,i write a udf about boundary heat flux,and use macro DEFINE_ADJUST to modify boundary condition(heat flux) based on whether fabs((q2qe)/q2)<=0.05. it is my code: #include "udf.h" DEFINE_PROFILE(my_flux,thread,i) { face_t f; Thread*t0=THREAD_T0(thread); cell_t c0; real a1,a2,a3,a4,T,qe,q2,xw[ND_ND],xc[ND_ND],dx[ND_ND],dy; real flow_time,current_timestep; a1=3.27e4; a2=2.63e4; a3=2.08e6; a4=3.05987e5; flow_time=RP_Get_Real("flowtime"); current_timestep=CURRENT_TIMESTEP; if(flow_time<=current_timestep) { begin_f_loop(f,thread) { F_PROFILE(f,thread,i)=1000; }end_f_loop(f,thread) } else { begin_f_loop(f,thread) { c0=F_C0(f,thread); F_CENTROID(xw,f,thread); C_CENTROID(xc,c0,t0); NV_VV(dx,=,xc,,xw); dy=ND_MAG(dx[0],dx[1],dx[2]); qe=(0.6*C_LIQF(c0,t0)+2.24*(1C_LIQF(c0,t0)))*(F_T(f,thread)C_T(c0,t0))/dy;/*heat flux computed through fluent itself*/ q2=a1*pow(qe,1/3)*(F_T(f,thread)2684*qe*(a2+a3+a4*pow(qe,1/3)));/*gived boundary condition heat flux*/ if((fabs(q2qe)/q2)<=0.2)/*judge q2 and qe */ F_PROFILE(f,thread,i)=0.6*qe+0.4*q2; else if((fabs(q2qe)/q2)<=0.1) F_PROFILE(f,thread,i)=0.8*qe+0.2*q2; else F_PROFILE(f,thread,i)=q2; }end_f_loop(f,thread) } } temperature limited to 1.000000e+000 in 10000 cells on zone 2 in domain 1 iter continuity xvelocity yvelocity energy time/iter 62 2.3745e+09 4.9106e02 8.2004e02 5.1416e+19 0:00:06 18 temperature limited to 5.000000e+003 in 10000 cells on zone 2 in domain 1 63 3.2869e+08 6.5883e02 1.1955e01 4.4575e+25 0:00:08 17 temperature limited to 1.000000e+000 in 10000 cells on zone 2 in domain 1 64 2.5771e+09 5.0354e02 8.0179e02 3.3946e+22 0:00:06 16 temperature limited to 5.000000e+003 in 10000 cells on zone 2 in domain 1 65 2.6958e+08 8.3365e02 1.4457e01 3.2549e+28 0:00:05 15 Error: Floating point error: invalid number Error Object: () how to do that? I need your help, 
about my question ,i will tell more details as follows:
I want to simulate water solidification in a tank. I will give a boundary condition(heat flux) and this boundary heat flux qe=f(qe). 
This is my code about DEFINE_ADJUST,i want to write a program that can link DEFINE_ADJUST and DEFINE_PROFILE in order to realize change boundary condition.please help me!!!Big thanks!!!
DEFINE_ADJUST(my_adjust,d) { int ID=6; Thread*thread=Lookup_Thread(d,ID); cell_t c; cell_t c0; face_t f; Thread*t0=THREAD_T0(thread); real a1,a2,a3,a4,T,qe,q2,xw[ND_ND],xc[ND_ND],dx[ND_ND],dy; real flow_time,current_timestep; a1=3.27e4; a2=2.63e4; a3=2.08e6; a4=3.05987e5; if(!Data_Valid_P()) return; thread_loop_f(thread,d) { begin_f_loop(f,thread) { c0=F_C0(f,thread); F_CENTROID(xw,f,thread); C_CENTROID(xc,c0,t0); NV_VV(dx,=,xc,,xw); dy=ND_MAG(dx[0],dx[1],dx[2]); qe=(0.6*C_LIQF(c0,t0)+2.24*(1C_LIQF(c0,t0)))*(F_T(f,thread)C_T(c0,t0))/dy; q2=a1*pow(qe,1/3)*(F_T(f,thread)2684*qe*(a2+a3+a4*pow(qe,1/3))); if(fabs((q2qe)/q2)<=0.05) F_UDMI(f,thread,0)=q2; else F_UDMI(f,thread,1)=0.8*q2+0.2*qe; }end_f_loop(f,thread) } } 
Hi,
I'm wondering if you have solved the problem you posted a while ago, or got any ideas on how to solve it. I have a much similar problem in trying to change the boundary condition by using either DEFINE_ADJUST or DEFINE_PROFILE. Thank you very much. Regards, ljp 
hi
i'm not experienced with heat transfer and either i cant understand some parts of ur udf.but as i know: 1. c0 ,c1 r used when u wanna store/access to values of an interior faces and in boundary condition u dont need to do that and the values of the cell face is enoughg. [Thread*t0=THREAD_T0(thread); cell_t c0;] 2.i can tell u if the int ID=6 is ur desired boundary u dont need to use define_adjust and u can write both of them in DEFINE_PROFILE.nevertheles to link the adjust to profile, u need to define the number of memory that u use in your problem e.g if your boundary is subdevided into 20 parts and u need to define qe in all of them so u should change the no. of memory(define>user define>memory) in fluent to 20 and use this order :for(k=0;k<n_udm;k++),F_UDMI(f,t,k) and if u store the q2 in memory in define_adjust and u wanna use it in define_profile u need to access to memory or vise versa:e.g begin_f_loop(f,thread) { for(k=0;k<n_udm;k++) c0=F_C0(f,thread); F_CENTROID(xw,f,thread); C_CENTROID(xc,c0,t0); NV_VV(dx,=,xc,,xw); dy=ND_MAG(dx[0],dx[1],dx[2]); qe=(0.6*C_LIQF(c0,t0)+2.24*(1C_LIQF(c0,t0)))*(F_T(f,thread)C_T(c0,t0))/dy;/*heat flux computed through fluent itself*/ q2=F_UDMI(f,t,k); and the other lines. 
although u can use printf("name:%f\n",value) to show the values in graph window.it's very helpfull

I have no idea about my posted question ,i am confused.I feel it is very difficult.My boundary condition is a coupled condition.qe=f(qe).

Can you elaborate?
Quote:
Are you having difficulty setting up the boundary conditions? Do you want to know how to link your UDF to the problem? Is there a compile error? Do you need help with the math? 
Hi
Eventually I want to write a UDF for a pitching airfoil, which pitches up and down continuously. However I first want to learn about dynamic meshing in fluent, so I want to try the tutorial on fluent about cyl3d.msh, but I do not have this fiel, once I understand this I was going to write a code and try using the udf and dynamic meshing together, does anyone have cyl3d.msh? Thanks Or have you got a code for pitching an airfoil whilst oncoming flow is heading towards the airfoil? If I can have a look I will understand the process of writing this better 
Quote:
First,i suppose boundary heat fllux q=constant,through macro DEFINE_PROFILE(f,thread) pass q to Fluent, every interation,i will judge if fabs(q2qe)/qe<=0.05. if yes, continue to interate,if no, i want to change boundary heat flux as like q=02*qe+0.8*q2, then pass q to Fluent ,start a new interation,then judge again as above. Now, my problem is that i do not know how to write a UDF reallize this process.How to change boundary heat flux through DEFINE_ADJUST macro. 
Quote:

Quote:

anybody can help me,i need your help, I hope somebody can help me!! Big thanks!!

I believe I have a similar problem as you. I am trying to adjust a boundary condition each iteration based on the temperature of the faces along the boundary as calculated by the previous iteration. (e.g. the boundary condition is q=f(T), where yours is similar with q=f(q)). I was watching your thread for a solution, but it appears none have come.
I have found a means of fixing my problem that I will describe for you. My UDF contains both a DEFINE_PROFILE and a DEFINE_ADJUST macro. I use the DEFINE_PROFILE macro as the set boundary condition when setting up the problem. The macro not only sets the boundary flux for the first iteration, but also reads and outputs the zone_id number and the property_id number associated with that boundary condition. The DEFINE_ADJUST macro then reads the property_id and zone_id written in the DEFINE_PROFILE macro and looks up the appropriate thread pointer for the boundary of interest. Next, it loops through the boundary and reads the information needed to determine the new boundary flux (in my case it reads temperature, in your case, read whatever you need). Lastly it uses the F_PROFILE(f,t,i) macro to assign the new flux value, where 'i' is the property_id saved from the DEFINE_PROFILE macro earlier. I've simplified down the code I'm using to post here. Now it acts as if i'm starting with an initial flux of 190 [W/m^2K] then applying a heat flux to each face corresponding to a convection condition for a bulk fluid temperature of 375 [K] with a convection coefficient of 6 [W/m^2K]. Code:
q = 6 * ( 375  T ) Code:
#include "udf.h" 
my boundary heat flux is q=f(q).So,first of all ,i must assume boundary heat flux q=A(arbitrary constant).Fluent calculate itself after one timestep,judge q and f(q),if fabs([qf(q)]/q)<=5%,so Fluent enter next timestep calculation;If fabs([qf(q)]/q)>5%,so give boundary heat flux q1=0.7*q+0.3*f(q) to Fluent,Fluent calculate in the same timestep.
how to write UDF ?thanks 
Quote:
[CODE]#include "udf.h" FILE*fid;DEFINE_PROFILE(heat_flux,t,i) { face_t f; int zoneid=THREAD_ID(t); fid=fopen("fluxids","w"); fprintf(fid,"%d,%d\n",zoneid,i); fclose(fid); begin_f_loop(f,t) { F_PROFILE(f,t,i)=1000; }end_f_loop(f,t) }[DEFINE_ADJUST(flux_adjust,domain) { int iprop; int izone; Thread*thread=Lookup_Thread(domain,izone); Thread*t0=THREAD_T0(thread); cell_t c; cell_t c0; face_t f; real a1,a2,a3,a4,T,qe,q2,xw[ND_ND],xc[ND_ND],dx [ND_ND],dy; a1=3.27e4; a2=2.63e4; a3=2.08e6; a4=3.06e5; fid=fopen("fluxids","r"); fscanf(fid,"%d,%d",&izone,&iprop); fclose(fid); if(!Data_Valid_P()) return;thread_loop_f(thread,domain) { begin_f_loop(f,thread) { c0=F_C0(f,thread); F_CENTROID(xw,f,thread); C_CENTROID(xc,c0,t0); NV_VV(dx,=,xc,,xw); dy=ND_MAG(dx[0],dx[1],dx[2]); qe=(0.6*C_LIQF(c0,t0)+2.24*(1C_LIQF(c0,t0))) *(F_T(f,thread)C_T(c0,t0))/dy;/*water or ice heat flux*/ q2=a1*(pow(q2,1/3))*(268+4*fabs(q2)* (a2+a3+a4*fabs(pow(q2,1/3)))F_T(f,thread));/*heat pipe heat flux*/ if(fabs((q2qe)/q2)>=0.005) F_PROFILE(f,thread,iprop)=0.3*qe+0.7*q2; else F_PROFILE(f,thread,iprop)=0.5*qe+0.5*q2; }end_f_loop(f,thread) } } interpreted can succeed,but Fluent appear wrong information when it iterate. Updating solution at time levels N and N1. done. iter continuity xvelocity yvelocity energy time/iter Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: () Help me please 
Hi,first of all,thanks for your suggestion.
Now,i want to give you some deatils about my difficulties,so please give your email to me. I hopely want to abtain your help,thanks very much!!! My email is :liurengtong@163.com 
1 Attachment(s)
Hi
every one ,now i need your help . I give detail about my problem through a picture . 
I am able to do something similar with only DEFINE_PROFILE. At every time step, I check the value of a virtual thermocouple and adjust the heat flux to a radiant heater using a control law.
Here's my code for your reference. Note that there is another function called at the beginning that returns the location of the cells I'm using as my virtual thermocouples. Also, note that this same DEFINE_PROFILE is used to control 8 separate heater surfaces (4 actual surfaces and 4 shadow faces). Code:
DEFINE_PROFILE(heater_control,boundary_thread,i){ 
Hi
thank you for giving me some suggestion. I want to talk about my problem in detail ,so please give me your Email in order to discuss about it. My Email :liurengtong@163.com Thanks very much!!! 
All times are GMT 4. The time now is 15:29. 