
[Sponsors] 
June 9, 2018, 14:43 
UDF with differential equations

#1 
New Member
Edwin P
Join Date: Jun 2018
Posts: 13
Rep Power: 4 
Hi.
I am computing a source term of the energy equation in ANSYS Fluent. How to add a system of differential equations in a UDF? Each differential equation depends on time and temperature. In particular, I want to solve a set of differential equations based on the Arrhenious equation: dx1/dt=k1*exp(k2/(R*T)), dx2/dt=k3*exp(k4/R*T), where k1,k2,k3,k4 and R are constants. Thus, my source term is (dx1/dt+dx2/dt)*k5. I know that I could use DEFINE_SOURCE(name,c,t,dS,eqn). Any suggestion? Regards 

June 13, 2018, 23:05 

#2 
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 15 
Using the DEFINE_SOURCE macro is correct, and the temperature of each cell can be retrieved with C_T(c,t). See below for an example, and check the UDF guide for details. Was the second equation intentionally of a different form to the first, or was it supposed to follow the Arrhenius equation as well?
Code:
#define k1 1.0 #define k2 2.0 #define k3 3.0 #define k4 4.0 #define k5 5.0 #define R 6.0 DEFINE_SOURCE(arrhenious_source,c,t,dS,eqn) { real term1 = k1*exp(k2/(R*C_T(c,t))); real term2 = k3*exp(k4/(R*C_T(c,t))); real source = (term1+term2)*k5; dS[eqn] = 0.0; return source; } 

June 14, 2018, 10:53 
UDF with differential equations (Edited)

#3 
New Member
Edwin P
Join Date: Jun 2018
Posts: 13
Rep Power: 4 
Sorry, I forgot one term in each equation. The system of differential equations are as follow:
dx1/dt=x1*k1*exp(k2/(R*T)), dx2/dt=x2*k3*exp(k4/R*T), The source term is (dx1/dt+dx2/dt)*k5. As you can see, the dependt variables are x1 and x2. Thanks for your help 

June 14, 2018, 20:42 

#4 
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 15 
What are x1 and x2? Are they the spatial coordinates x and y? The centroid of cell volumes can be retrieved with the C_CENTROID macro.


June 14, 2018, 20:57 

#5 
New Member
Edwin P
Join Date: Jun 2018
Posts: 13
Rep Power: 4 
x1 and x2 are dimensionless concentrations (from 0 to 1). These variables represent chemical reactions. I am computing the transient increase of temperature due to these reactions.


June 14, 2018, 21:05 

#6 
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 15 
How are you modelling the concentrations? If you are using the species transport model in Fluent then the species mass fraction can be retrieved with the C_YI macro.


June 14, 2018, 21:22 

#7 
New Member
Edwin P
Join Date: Jun 2018
Posts: 13
Rep Power: 4 
I am not modelling the concentrations because of I need to know only the temperature. For this reason, I had been thinking to solve the system of equations and get automatically the temperature.
Thanks for your suggestion about using the species transport model. 

June 14, 2018, 21:34 

#8 
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 15 
Sounds like the concentrations are an important and coupled component of your model. For perspective: without modelling the concentrations and trying to calculate the temperature would be similar to finding the pressure distribution on an aerofoil without solving the momentum equations.
The userdefined scalar transport equation could be used instead of the inbuilt species model (both methods should work, the former has more flexibility but the latter would be easier to implement). 

June 15, 2018, 19:13 

#9 
New Member
Paul Lee
Join Date: Jun 2018
Location: Vancouver
Posts: 14
Rep Power: 4 
Can I use the builtin species transport model for ionic movement in aqueous electrolyte? From the density term it seems to be built for gases reaction of an IC engine.


June 15, 2018, 20:25 

#10 
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 15 
What equations are you trying to solve and do these equations have a similar form to the species transport model? Otherwise you could use the userdefined scalar transport equations for more flexibility.


June 15, 2018, 20:49 

#11 
New Member
Paul Lee
Join Date: Jun 2018
Location: Vancouver
Posts: 14
Rep Power: 4 
I'm solving charged ionic movement in a galvanic corrosion system using the nernst planck equation. I think that is what species transport model use as well. what prompt me to wonder if species transport model is suitable for aqueous system is the density property of the mixture material. I've been using the "volumeweightedmixing law" instead of the default "incompressibleidealgas" hopping that the solver will pick the "waterliquid" density that I entered as "selected species". I would have preferred if I could just entered a constant for the electrolyte density, but that is not an option. Perhaps I need to do this through UDF.
Have you used the species transport solver on aqueous system? How did that worked out? 

June 15, 2018, 21:21 

#12  
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 15 
Quote:
No. 

June 16, 2018, 07:45 

#13 
Senior Member
Join Date: Sep 2017
Posts: 224
Rep Power: 8 
Hi Paoching,
I have used species transport and reactions for aqueous systems, and there are no special problems. If you want a constant density, then define the same density for all the species, and then a weighted average in the mixture will always give the same answer. With the species model, your reactions have standard Arrhenius rate laws, so they are easy to set up. You may not need UDFs at all  and this will probably have benefits in terms of stability etc. Good luck! Ed 

June 16, 2018, 14:12 

#14 
New Member
Paul Lee
Join Date: Jun 2018
Location: Vancouver
Posts: 14
Rep Power: 4 
Thank you Ed


Tags 
differential equation, fluent, source terms, udf 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
udf for one dimensional linear motion based on force  maccheese  Fluent UDF and Scheme Programming  2  September 1, 2019 03:18 
Save output of udf in another udf!  JuanJoMex  FLUENT  0  February 8, 2018 13:43 
UDF Compilation Error  Loading Library  COMMON Problem! Help!  robtheslob  Fluent UDF and Scheme Programming  8  July 24, 2015 01:53 
How to extract Differential Equations Matrix Coeff  srodrb  OpenFOAM Programming & Development  4  October 30, 2012 04:14 
UDF in Differential form  Chin Fook  Fluent UDF and Scheme Programming  10  July 27, 2012 14:48 