# second derivation of temperature

 Register Blogs Members List Search Today's Posts Mark Forums Read June 13, 2014, 00:11 second derivation of temperature #1 New Member   Join Date: Jun 2014 Posts: 16 Rep Power: 9 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); C_UDSI(c,t,2)=C_T_G(c,t); C_UDSI(c,t,3)=C_T_G(c,t); } end_c_loop(c,t) } } DEFINE_SOURCE(uds_source, c, t, dS, eqn) { real source; source=-0.000143472*(C_UDSI_G(c,t,1)+C_UDSI_G(c,t,2)+C_UDSI_G(c,t,3)); 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, 04:43 #2 Senior Member   Join Date: Nov 2013 Posts: 1,946 Rep Power: 24 Do you get the same error if you replace the line Code: `source=-0.000143472*(C_UDSI_G(c,t,1)+C_UDSI_G(c,t,2)+C_UDSI_G(c,t,3));` by the following line? Code: `source=-0.000143472*(C_UDSI(c,t,1)+C_UDSI(c,t,2)+C_UDSI(c,t,3));` If you get the same problems without the gradient, the problem is that the UDS is not defined; if you do not get the same problems, the problem is related to the gradient. Having this information might bring you one small step closer to the solution...   June 13, 2014, 09:27 #3 New Member   Join Date: Jun 2014 Posts: 16 Rep Power: 9 Hi, pakk. Thank you for your reply. I replace the line CODE: source=-0.000143472*(C_UDSI_G(c,t,1)+C_UDSI_G(c,t,2)+C_UDSI_G(c,t,3)); 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, 10:52 #4 Senior Member   Join Date: Nov 2013 Posts: 1,946 Rep Power: 24 Try to plot the UDS. Is it zero on some parts of your domain? Then something is wrong in the adjust-part, maybe it did not hook to all cell zones. Otherwise, I would have to think really hard.   June 15, 2014, 06:23 #5 New Member   Join Date: Jun 2014 Posts: 16 Rep Power: 9 Hi, pakk. It's very nice of you to reply. Thank you again. I tried to iterated with hooking the adjust-part 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 adjust-part?   June 18, 2014, 03:50 #6 New Member   Join Date: Jun 2014 Posts: 16 Rep Power: 9 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 show-grad: \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 adjust-part 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)+C_UDSI_G(c,t,2)+C_UDSI_G(c,t,3)); 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, 04:16 #7 Senior Member   Join Date: Nov 2013 Posts: 1,946 Rep Power: 24 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)); dS[eqn]=0; return source; }``` Code: ```DEFINE_SOURCE(uds_source, c, t, dS, eqn) { real source; source=-0.000143472*(C_UDSI(c,t,1)); 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, 05:06 #8 New Member   Join Date: Jun 2014 Posts: 16 Rep Power: 9 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, 06:04 #9 Senior Member   Join Date: Nov 2013 Posts: 1,946 Rep Power: 24 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, 06:32 #10 New Member   Join Date: Jun 2014 Posts: 16 Rep Power: 9 Hi, pakk. I have another question about the outlet boundary condition. I simulate the heat transfer in duct. For the inlet, I set the velocity-inlet condition and the user scalar 0 is set constant value 0. Here's no question. But for the fully-developed 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, 06:55 #11
Senior Member

Join Date: Nov 2013
Posts: 1,946
Rep Power: 24 Quote:
 Originally Posted by sunjian Hi, pakk. I have another question about the outlet boundary condition. I simulate the heat transfer in duct. For the inlet, I set the velocity-inlet condition and the user scalar 0 is set constant value 0. Here's no question. But for the fully-developed 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.
If A at the inlet is set at the constant value 0, then (A* )inlet=0, isn't it?   June 23, 2014, 11:25 #12 New Member   Join Date: Jun 2014 Posts: 16 Rep Power: 9 Yes, you are right. So I just need to define (A* )outlet = 0. Is it right? I'll have a try and see what I will get. Thank you very much.   July 18, 2014, 09:53 #13 New Member   Join Date: Jul 2014 Posts: 6 Rep Power: 9 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); C_UDSI(c,t,1)=C_T_RG(c,t); C_UDSI(c,t,2)=C_T_RG(c,t); } 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); /*some calculus for testing the data*/ C_UDMI(c,t,3)=1/C_UDSI_G(c,t,0); C_UDMI(c,t,4)=100*C_UDSI_G(c,t,0); ds[eqn]=0; return source; } The operations I make are:Add User Scalars and memory Inactivate UDS equations Tape solver/set/expert---> yes for "keep temporary solver memory ...." Launch the computation SO I have 2 principal problems:Sometimes, I receive a "segmentation fault" error message: this is due to the lines C_UDSI(c,t,0)=C_T_G(c,t); C_UDSI(c,t,1)=C_T_G(c,t); C_UDSI(c,t,2)=C_T_G(c,t); If I use C_T(c,t), there's no more problems...whyyy??; In this case, if I plot "Reconstruction dT/dx", Scalar 0 and Memory 0, they should coincide but there some little differences. Is there someone who can help me, pleeease??? Thank you guys!!! Stefano  Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules Similar Threads Thread Thread Starter Forum Replies Last Post immortality OpenFOAM Running, Solving & CFD 13 March 24, 2021 08:15 JulianP CFX 12 April 10, 2019 19:00 Mihail CFX 7 September 7, 2014 07:27 immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 02:27 shenying0710 CFX 8 January 4, 2013 05:03

All times are GMT -4. The time now is 17:22.