
[Sponsors] 
June 12, 2014, 23:11 
second derivation of temperature

#1 
New Member
Join Date: Jun 2014
Posts: 16
Rep Power: 4 
Hi,everyone!
I want to define a source term including the second derivation of temperature. I use the macros DEFINE_SOURCE and DEFINF_ADJUST. Here is the code: DEFINE_ADJUST(my_adjust,d) { Thread *t; cell_t c; if (! Data_Valid_P()) return; thread_loop_c(t,d) { begin_c_loop(c,t) { C_UDSI(c,t,1)=C_T_G(c,t)[0]; C_UDSI(c,t,2)=C_T_G(c,t)[1]; C_UDSI(c,t,3)=C_T_G(c,t)[2]; } end_c_loop(c,t) } } DEFINE_SOURCE(uds_source, c, t, dS, eqn) { real source; source=0.000143472*(C_UDSI_G(c,t,1)[0]+C_UDSI_G(c,t,2)[1]+C_UDSI_G(c,t,3)[2]); dS[eqn]=0; return source; } I use an interpreted udf. I've tried solve/set/expert temporary solver memory [yes], and iterated some steps before hooking DEFINE_ADJUST. After I hook DEFINE_ADJUST, it can calculate without any problems. But once I include the source term, I meet the error access_violation. Can you help me with some advice on my problem. I am looking forward to your reply. Thank you in advance. sunjian 

June 13, 2014, 03:43 

#2 
Senior Member
Join Date: Nov 2013
Posts: 933
Rep Power: 12 
Do you get the same error if you replace the line
Code:
source=0.000143472*(C_UDSI_G(c,t,1)[0]+C_UDSI_G(c,t,2)[1]+C_UDSI_G(c,t,3)[2]); Code:
source=0.000143472*(C_UDSI(c,t,1)[0]+C_UDSI(c,t,2)[1]+C_UDSI(c,t,3)[2]); Having this information might bring you one small step closer to the solution... 

June 13, 2014, 08:27 

#3 
New Member
Join Date: Jun 2014
Posts: 16
Rep Power: 4 
Hi, pakk. Thank you for your reply. I replace the line
CODE: source=0.000143472*(C_UDSI_G(c,t,1)[0]+C_UDSI_G(c,t,2)[1]+C_UDSI_G(c,t,3)[2]); with the following line CODE: source=0.000143472*(C_UDSI(c,t,1)+C_UDSI(c,t,2)+C_UDSI(c, t,3)); Then I get the same error. You said maybe the uds is not defined. But what can I do to solve this problem? Is there something wrong in DEFINE_ADJUST? 

June 13, 2014, 09:52 

#4 
Senior Member
Join Date: Nov 2013
Posts: 933
Rep Power: 12 
Try to plot the UDS. Is it zero on some parts of your domain? Then something is wrong in the adjustpart, maybe it did not hook to all cell zones.
Otherwise, I would have to think really hard. 

June 15, 2014, 05:23 

#5 
New Member
Join Date: Jun 2014
Posts: 16
Rep Power: 4 
Hi, pakk. It's very nice of you to reply. Thank you again.
I tried to iterated with hooking the adjustpart and without including UDS transport equation 0 (I need to obtain User Scalar 0 in this equation) because as long as I include UDS transport equation 0, I will get the error access_violation. And I found that User Scalar 1, User Scalar 2 and User Scalar 3 were mostly not zero, though in some parts they might be zero (most of the values were near zero). On this occasion, is something wrong in the adjustpart? 

June 18, 2014, 02:50 

#6 
New Member
Join Date: Jun 2014
Posts: 16
Rep Power: 4 
Hi,pakk.
I read a UDF showgrad.c in section Gradient(G) and Reconstruction Gradient(RG) Vector Macros in UDF Manual. I include the code below in my code. CODE: DEFINE_ON_DEMAND(showgrad) { Domain *domain; Thread *t; domain=Get_Domain(1); if (! Data_Valid_P()) return; Message0(" >>> entering showgrad: \n "); thread_loop_c(t, domain) { Message0("::::\n "); Message0(":::: Gradients :::: \n "); Message0("::::\n "); if (NNULLP(THREAD_STORAGE(t, SV_T_G))) { Message0("Gradient of T is available \n "); } if (NNULLP(T_STORAGE_R_NV(t,SV_UDSI_G(1)))) { Message0("Gradient of UDSI(1) is available \n "); } if (NNULLP(T_STORAGE_R_NV(t,SV_UDSI_G(2)))) { Message0("Gradient of UDSI(2) is available \n "); } if (NNULLP(T_STORAGE_R_NV(t,SV_UDSI_G(3)))) { Message0("Gradient of UDSI(3) is available \n "); } } } After the calculation with attaching the adjustpart and without attaching UDS transport equation 0, showgrad is executed and shows gradient of T, UDSI(1), UDSI(2) and UDSI(3) are available. So I think maybe the error happens in the source in UDS transport equation 0. Am I right? The source term is Laplacian of temperature as follows: source=a*(d2T/dX2+d2T/dY2+d2T/dZ2) My code is: DEFINE_SOURCE(uds_source, c, t, dS, eqn) { real source; source=0.000143472*(C_UDSI_G(c,t,1)[0]+C_UDSI_G(c,t,2)[1]+C_UDSI_G(c,t,3)[2]); dS[eqn]=0; return source; } But I can't find any problem here. Can you give some suggestions? I'm looking forward to you reply. Thank you. 

June 18, 2014, 03:16 

#7 
Senior Member
Join Date: Nov 2013
Posts: 933
Rep Power: 12 
Simplify your uds_source until it works. In that way you might identify in which step the problem occurs.
Some suggestions: Code:
DEFINE_SOURCE(uds_source, c, t, dS, eqn) { real source; source=0.000143472*(C_UDSI_G(c,t,1)[0]); dS[eqn]=0; return source; } Code:
DEFINE_SOURCE(uds_source, c, t, dS, eqn) { real source; source=0.000143472*(C_UDSI(c,t,1)[0]); dS[eqn]=0; return source; } Code:
DEFINE_SOURCE(uds_source, c, t, dS, eqn) { real source; source=0.000143472; dS[eqn]=0; return source; } 

June 19, 2014, 04:06 

#8 
New Member
Join Date: Jun 2014
Posts: 16
Rep Power: 4 
Hi, pakk. Thank you for your help!
I've found where the error happens. In my UDF, I also define a UDS flux for UDS transport equation 0. I want to obtain the flux that equals the negative product of density and velocity. I use the code below firstly: DEFINE_UDS_FLUX(A_flux, f, t, i) { real NV_VEC(vec), NV_VEC(A),dens,flux; F_AREA(A, f, t); dens=F_R(f,t); NV_DS(vec,=,F_U(f,t),F_V(f,t),F_W(f,t),*,dens); flux=NV_DOT(vec,A); return  flux; } The error access_violation always occurs. Then I try the code below: DEFINE_UDS_FLUX(A_flux, f, t, i) { return  F_FLUX(f,t); } It can iterate now. Both of the codes can be compiled without any error. Do you know what the mistake is in the first code? Best regards. 

June 19, 2014, 05:04 

#9 
Senior Member
Join Date: Nov 2013
Posts: 933
Rep Power: 12 
You should look at the example in the manual for DEFINE_UDS_FLUX. It has a comment about the density not being available for all BCs, and how to solve it. I don't know if this is causing the problem, but you could try it.


June 23, 2014, 05:32 

#10 
New Member
Join Date: Jun 2014
Posts: 16
Rep Power: 4 
Hi, pakk. I have another question about the outlet boundary condition. I simulate the heat transfer in duct. For the inlet, I set the velocityinlet condition and the user scalar 0 is set constant value 0. Here's no question. But for the fullydeveloped flow, I set the outflow condition and the BC should be (A*)inlet = (A*)outlet, where A is user scalar 0. For BC like this, how can I define it? I couldn't find a similar example in UDF manual. Could you help me with some clue? Thank you very much.


June 23, 2014, 05:55 

#11 
Senior Member
Join Date: Nov 2013
Posts: 933
Rep Power: 12 
Quote:


June 23, 2014, 10:25 

#12 
New Member
Join Date: Jun 2014
Posts: 16
Rep Power: 4 

July 18, 2014, 08:53 

#13 
New Member
Join Date: Jul 2014
Posts: 6
Rep Power: 4 
Hi everyone!!
I have a similar problem. I'm trying to calculate the laplacian of temperature field in order to introduce it into the source terme of energy equation. Here there is a simplification of my C code. DEFINE_ADJUST(adjust_gradient, domain) { Thread *t; cell_t c; if (! Data_Valid_P()) return; thread_loop_c (t,domain) { begin_c_loop (c,t) { C_UDSI(c,t,0)=C_T_RG(c,t)[0]; C_UDSI(c,t,1)=C_T_RG(c,t)[1]; C_UDSI(c,t,2)=C_T_RG(c,t)[2]; } end_c_loop (c,t) } } DEFINE_SOURCE(energy_source,c,t,ds,eqn) { real source; source=20*C_UDSI(c,t,0); C_UDMI(c,t,0)=C_UDSI(c,t,0); C_UDMI(c,t,1)=source; C_UDMI(c,t,2)=C_UDSI_G(c,t,0)[0]; /*some calculus for testing the data*/ C_UDMI(c,t,3)=1/C_UDSI_G(c,t,0)[0]; C_UDMI(c,t,4)=100*C_UDSI_G(c,t,0)[0]; ds[eqn]=0; return source; } The operations I make are:
SO I have 2 principal problems:
Is there someone who can help me, pleeease??? Thank you guys!!! Stefano 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Calculation of the Governing Equations  Mihail  CFX  7  September 7, 2014 06:27 
whats the cause of error?  immortality  OpenFOAM Running, Solving & CFD  11  April 22, 2014 12:32 
is internalField(U) equivalent to zeroGradient?  immortality  OpenFOAM Running, Solving & CFD  7  March 29, 2013 02:27 
Static Temperature / Opening Temperature  JulianP  CFX  6  March 23, 2013 17:03 
Is wall ajacent temperature equal to conservative temperature of the wall?  shenying0710  CFX  8  January 4, 2013 05:03 