|
[Sponsors] |
May 19, 2010, 02:17 |
Use DEFINE_ADJUST change boundary condition
|
#1 |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
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)[Twall-268-4qe*(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((q2-qe)/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.63e-4; a3=2.08e-6; a4=3.05987e-5; flow_time=RP_Get_Real("flow-time"); 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*(1-C_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)-268-4*qe*(a2+a3+a4*pow(qe,1/3)));/*gived boundary condition heat flux*/ if((fabs(q2-qe)/q2)<=0.2)/*judge q2 and qe */ F_PROFILE(f,thread,i)=0.6*qe+0.4*q2; else if((fabs(q2-qe)/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 x-velocity y-velocity energy time/iter 62 2.3745e+09 4.9106e-02 8.2004e-02 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.5883e-02 1.1955e-01 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.0354e-02 8.0179e-02 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.3365e-02 1.4457e-01 3.2549e+28 0:00:05 15 Error: Floating point error: invalid number Error Object: () how to do that? I need your help, |
|
May 23, 2010, 22:57 |
|
#2 |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
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). |
|
May 25, 2010, 22:02 |
|
#3 |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
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.63e-4; a3=2.08e-6; a4=3.05987e-5; 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*(1-C_LIQF(c0,t0)))*(F_T(f,thread)-C_T(c0,t0))/dy; q2=a1*pow(qe,-1/3)*(F_T(f,thread)-268-4*qe*(a2+a3+a4*pow(qe,1/3))); if(fabs((q2-qe)/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) } } |
|
June 22, 2010, 12:20 |
|
#4 |
New Member
Join Date: Apr 2010
Posts: 15
Rep Power: 16 |
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 |
|
June 22, 2010, 17:26 |
|
#5 |
New Member
omid
Join Date: Mar 2010
Posts: 17
Rep Power: 16 |
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*(1-C_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. Last edited by om1234; June 22, 2010 at 20:04. |
|
June 22, 2010, 17:32 |
|
#6 |
New Member
omid
Join Date: Mar 2010
Posts: 17
Rep Power: 16 |
although u can use printf("name:%f\n",value) to show the values in graph window.it's very helpfull
|
|
June 23, 2010, 04:56 |
|
#7 |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
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).
|
|
July 12, 2010, 12:53 |
Can you elaborate?
|
#8 | |
Member
Tim Diller
Join Date: Mar 2010
Location: Austin, TX
Posts: 32
Rep Power: 16 |
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? |
||
July 12, 2010, 13:18 |
|
#9 |
New Member
Dave Smith
Join Date: Jul 2010
Posts: 27
Rep Power: 16 |
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 |
|
July 12, 2010, 23:57 |
|
#10 | |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
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(q2-qe)/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. |
||
July 17, 2010, 23:26 |
|
#11 | |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
Quote:
|
||
July 29, 2010, 03:54 |
|
#12 |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
||
September 13, 2010, 05:12 |
|
#13 |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
anybody can help me,i need your help, I hope somebody can help me!! Big thanks!!
|
|
October 19, 2010, 20:29 |
|
#14 |
New Member
|
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^2-K] 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^2-K]. Code:
q = 6 * ( 375 - T ) Code:
#include "udf.h" FILE *fid; DEFINE_PROFILE(flux_setget,t,i) { face_t f; int zoneid = THREAD_ID(t); /* Write the property and thread id values for the flux condition to file */ fid = fopen("flux-ids", "w"); fprintf(fid, "%d, %d\n", zoneid, i); fclose(fid); /* Set initial profile values */ begin_f_loop(f,t) { F_PROFILE(f,t,i) = 190; } end_f_loop(f,t) } DEFINE_ADJUST(flux_adjuster, domain) { int iprop; int izone; real temp; real newflux; Thread *t; face_t f; /* Read in the property and thread id values stored by the BC UDF */ fid = fopen("flux-ids", "r"); fscanf(fid,"%d, %d", &izone, &iprop); fclose(fid); /* Get the thread pointer based on the obtained zone id */ t = Lookup_Thread(domain, izone); /* Read the needed data, then calculate and set the new flux values */ begin_f_loop(f,t) { temp = F_T(f,t); newflux = 6 * (375 - temp); F_PROFILE(f,t,iprop) = newflux; } end_f_loop(f,t) } |
|
November 16, 2010, 08:56 |
|
#15 |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
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([q-f(q)]/q)<=5%,so Fluent enter next timestep calculation;If fabs([q-f(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 |
|
November 23, 2010, 02:36 |
|
#16 | |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
Quote:
[CODE]#include "udf.h" FILE*fid;DEFINE_PROFILE(heat_flux,t,i) { face_t f; int zoneid=THREAD_ID(t); fid=fopen("flux-ids","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.63e-4; a3=2.08e-6; a4=3.06e-5; fid=fopen("flux-ids","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*(1-C_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((q2-qe)/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 N-1. done. iter continuity x-velocity y-velocity 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 |
||
November 28, 2010, 23:08 |
|
#17 |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
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 |
|
December 9, 2010, 23:01 |
|
#18 |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
Hi
every one ,now i need your help . I give detail about my problem through a picture . |
|
December 10, 2010, 11:23 |
|
#19 |
Member
Tim Diller
Join Date: Mar 2010
Location: Austin, TX
Posts: 32
Rep Power: 16 |
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){ /*i is the boundary property index, known to Fluent*/ face_t face_thread; int zone_ID = THREAD_ID(boundary_thread); int j=0; real flow_time = RP_Get_Real("flow-time"); real cell_temp; real error; real this_power; /* Set the temperature control measurement point and the index variable based on the value of zone_ID. */ if(power[0]<=0){init();} switch(zone_ID){ case FB_LEFT_ZONE: j=FB_LEFT; break; case FB_LEFT_SHADOW_ZONE: j=FB_LEFT_SHADOW; break; case BB_CENTER_LEFT_ZONE: j=BB_CENTER_LEFT; break; case BB_CENTER_LEFT_SHADOW_ZONE: j=BB_CENTER_LEFT_SHADOW; break; case BB_CENTER_RIGHT_ZONE: j=BB_CENTER_RIGHT; break; case BB_CENTER_RIGHT_SHADOW_ZONE: j=BB_CENTER_RIGHT_SHADOW; break; case FB_RIGHT_ZONE: j=FB_RIGHT; break; case FB_RIGHT_SHADOW_ZONE: j=FB_RIGHT_SHADOW; break; default: printf("\nDid not identify zone_ID."); break; } /*printf("\nDEFINE_PROFILE: flow time = %1.3e\t previous_time[%d] = %1.3e.",flow_time,j,previous_time[j]);*/ if (flow_time > previous_time[j] + 0.5){/*This prevents multiple control efforts per time step*/ /*Record the temperature of the virtual thermocouple*/ cell_temp = C_T(c[j],t[j]); /*Heater control algorithm is proportional with control variable epsilon*/ error = (set_temp[j]-cell_temp); printf("\n\tepsilon = %1.2e",error); epsilon[j][0] = epsilon [j][1]; epsilon[j][1] = epsilon [j][2]; epsilon[j][2] = error; u[j][0] = u[j][1]; u[j][1] = u[j][2]; u[j][2] = alpha * error; if(u[j][2] > 1){u[j][2]=1.0;} if(error>0){ heater_state[j] = power[j]*u[j][2]; } else{heater_state[j]=0;}/* Don't let the heater be a cold sink! */ printf("\nHeater power in zone %d set to %1.3e.",zone_ID,heater_state[j]); printf("\n\tcontrol variable is %1.2e.",u[j][2]); previous_time[j]=flow_time; this_power = heater_state[j]; begin_f_loop(face_thread,boundary_thread){ F_PROFILE(face_thread,boundary_thread,i)=this_power; } end_f_loop(f,thread) } } |
|
December 11, 2010, 00:34 |
|
#20 |
New Member
Rengtong Liu
Join Date: May 2010
Posts: 15
Rep Power: 16 |
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!!! |
|
Tags |
fluent, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Wind turbine simulation | Saturn | CFX | 60 | July 17, 2024 06:45 |
How to change boundary condition from command | fluent87 | FLUENT | 8 | September 11, 2019 14:27 |
Time dependant pressure boundary condition | yosuke1984 | OpenFOAM Verification & Validation | 3 | May 6, 2015 07:16 |
An error has occurred in cfx5solve: | volo87 | CFX | 5 | June 14, 2013 18:44 |
inlet velocity boundary condition | murali | CFX | 5 | August 3, 2012 09:56 |