|
[Sponsors] |
February 9, 2011, 04:29 |
how to get the derivative of scalar?
|
#1 |
New Member
tom pan
Join Date: Nov 2010
Posts: 14
Rep Power: 16 |
It seems like to need to get it using dn(x)/dx=(n(x+h)-n(x))/h
Please help me to get the values of n(x+h), n(x) and h. Thanks. |
|
February 9, 2011, 09:11 |
|
#2 |
Senior Member
|
Hi Tom,
you can refer to UDF help manual (DEFINE_ADJUST 2nd example). otherwise for specific x value over a face, you can use C0 and C1 values. Last edited by Amir; February 9, 2011 at 09:31. |
|
February 18, 2011, 04:47 |
|
#3 |
New Member
tom pan
Join Date: Nov 2010
Posts: 14
Rep Power: 16 |
Thank you, Amir.
I followed the Manual example and constructed my udf as below ================================================== ====== #include "udf.h" #define PI (3.1415926) real x[ND_ND]; face_t f; real diff; real Kn, rc, kb, rp, diffuse, dc, G; real source, source1,source2, B , As, dp, Tau, v, np, l, g, I, v0,a0, KnD,p; real kk,e, lumda; DEFINE_DIFFUSIVITY(diffusivityN,c,t,i) { C_CENTROID(x,c,t) return C_R(c,t)*C_T(c,t); } DEFINE_SOURCE(N_source,c,t,dS,eqn) { C_CENTROID(x,c,t) v=sqrt(8.*kb*C_UDSI(c,t,0)*C_T(c,t)/(PI*C_R(c,t)*C_UDSI(c,t,1))); KnD=4.*diffuse/v; p=1.; B=(1+KnD)/(1+2*KnD*(1+KnD)/p); source=C_UDSI(c,t,0); dS[eqn]=1.; return source; } DEFINE_SOURCE(V_source,c,t,dS,eqn) { C_CENTROID(x,c,t) source1=C_UDSI(c,t,3)/C_UDSI(c,t,0); dS[eqn]=1./C_UDSI(c,t,0); return source1; } DEFINE_ADJUST(adjust_fcn1,d) { Thread *t; cell_t c; real K_EL=1.0; if(!Data_Valid_P()) return; thread_loop_c(t,d) { if(FLUID_THREAD_P(t)) { begin_c_loop_all(c,t) { C_UDSI(c,t,2)+=K_EL*NV_MAG2(C_UDSI_G(c,t,0))*C_VOL UME(c,t); } end_c_loop_all(c,t) } } } DEFINE_ADJUST(adjust_fcn2,d) { Thread *t; cell_t c; real K_EL=1.0; if(!Data_Valid_P()) return; thread_loop_c(t,d) { if(FLUID_THREAD_P(t)) { begin_c_loop_all(c,t) { C_UDSI(c,t,3)+=K_EL*NV_MAG2(C_UDSI_G(c,t,3))*C_VOL UME(c,t); } end_c_loop_all(c,t) } } } ================================================== ==== It was compiled successfully but couldn't calculate. The error message is below: ============================================== 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: 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: #f ================================================ Is there something wrong in my UDF? And in FLUENT, the number of user-defined scalar should be 2 or 4 in my case? |
|
February 19, 2011, 01:23 |
|
#5 |
New Member
tom pan
Join Date: Nov 2010
Posts: 14
Rep Power: 16 |
Thank you, Amir.
I will simplify and check my udf. I have another question here: In example2 for DEFINE_ADJUST, why "C_UDSI(c,t,1)+=K_EL*NV_MAG2(C_UDSI_G(c,t,0)*C_VOL UME(c,t));" can specifies a user-define scalar as a function of the gradient of another user-define scalar? |
|
February 19, 2011, 09:17 |
|
#6 |
Senior Member
|
Hi Tom,
yes, you can define a UDS as a function of another UDS or it's gradient components or magnitude. note that C_UDSI stores scalar but C_UDSI_G stores vector. as you see in second example the magnitude of UDS gradient was stored in another UDS. |
|
March 1, 2020, 06:51 |
|
#7 | |
Senior Member
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6 |
Quote:
do you know what is the T_derivatives function in udf?? |
||
March 2, 2020, 04:41 |
T_derivatives
|
#8 |
Senior Member
|
Mahdi, I have checked and I can confirm that T_derivatives calculates gradients for temperature field in the domain. Hence, you certainly do not need it in your case. Now, the reason why you are facing issue is something else.
I'd suggest you do two things. Issue following commands and then run for a few iterations. solve set expert and then select Yes where it asks to keep the memory from being freed. Second command is (use the brackets as well) (rpsetvar 'species/save-gradients? #t) Then check for the gradients of species in contour plots. If those are not there, then there is some issue with the case setup. If those exist, then remove all the commands in your UDF that you are using to free up the allocated space, i.e., commands with Free_. Then compile the UDF and check. Do note you have to compile it. Interpreted UDF will not work.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
March 2, 2020, 09:35 |
|
#9 | |
Senior Member
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6 |
Quote:
type this in TUI,(rpsetvar 'species/save-gradients? #t) solve/set/expert and yes to answer keep temporary...? define/models/ and yes to answer save gradients....? and it's modified code correspond your opinion DEFINE_ADJUST(gradient, domain) { Thread *t; Thread **pt; cell_t c; Domain *pDomain = DOMAIN_SUB_DOMAIN(domain,P_PHASE); real voidx, voidy, voidz=0.0; { Alloc_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_N ULL); Scalar_Reconstruction(pDomain, SV_VOF,-1,SV_VOF_RG,NULL); Scalar_Derivatives(pDomain,SV_VOF,-1,SV_VOF_G,SV_VOF_RG,Vof_Deriv_Accumulate); } mp_thread_loop_c (t,domain,pt) if (FLUID_THREAD_P(t)) { Thread *tp = pt[P_PHASE]; begin_c_loop (c,t) { C_UDMI(c,t,0) = C_VOF_G(c,tp)[0]*C_YI_G(c,tp,0)[0] + C_VOF_G(c,tp)[1]*C_YI_G(c,tp,0)[1] + C_VOF_G(c,tp)[2]*C_YI_G(c,tp,0)[2]; } end_c_loop (c,t) } Free_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NU LL); } and well compiling and initializing without error but for bottom calculation, in the 1st iteration FLUENT report message 'the f1 ..... could not be started' and automatically closed but a remarkable point!!! does it message is important(appear when case setup open)?? ************************************************** ************************** ************************************************** ************************** ** WARNING: Automatically switched to run in parallel -t1 mode. ** ** Detected non-parallelized UDF usage, enabling parallel usage. ** ** If you encounter any issues, please re-run with -t0 flag. ** ************************************************** ************************** ************************************************** ************************** |
||
March 2, 2020, 09:42 |
Udf
|
#10 |
Senior Member
|
The message in the end is of no value here; it only mentions new feature in Ansys Fluent that it can be run on 4 cores without HPC license.
What I meant by my previous post is not to use UDF. Just use the commands and run the simulation without the UDF. And then check the gradients reported in the Contours. If your final objective is only to get gradients and do some calculation with those, then you don't need a UDF.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
March 3, 2020, 06:19 |
|
#11 | |
Senior Member
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6 |
Quote:
one question this command "SV_Y_G" how to alter to get 1st species? is it right? SV_Y_0_G |
||
March 3, 2020, 06:39 |
Sv_y_g
|
#12 |
Senior Member
|
Putting the names in between will increase the variables. So, when the fields are related, vectors are used. Therefore, the SV_Y_G is used as it is and an integer identifier is used as
C_YI_G(c, t, 0)[0] The above function will return gradient of first species with respect to x-coordinate.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Fluent udf--spatial derivative of user-defined scalar | tas38 | Fluent UDF and Scheme Programming | 13 | October 26, 2020 22:05 |
dieselFoam problem!! trying to introduce a new heat transfer model | vivek070176 | OpenFOAM Programming & Development | 10 | December 24, 2014 00:48 |
derivative of scalar | lig | Main CFD Forum | 3 | December 26, 2010 05:02 |
the derivative of Scalar on time ? | owen | FLUENT | 0 | March 5, 2009 05:59 |
scalar and its derivative | sucker | Main CFD Forum | 1 | April 15, 2008 14:28 |