CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Non-linear equation system (DEFINE_source) (https://www.cfd-online.com/Forums/fluent-udf/130188-non-linear-equation-system-define_source.html)

Laexzzz February 21, 2014 04:02

Non-linear equation system (DEFINE_source)
 
Hello!

I model system with 4 species.

I want to define source terms with UDF.

But my sources are described by the system of non-linear equation

S(1) = -2*k1*[1]
S(2) = -k2*[2][3] - k2*[2][4]
S(3) = +2*k1*[1]-k2*[2][3]
S(4) = -k3*[4][4] - k2*[2][4]

[1] - molar concentration of species 1 at the moment

So, sources affect each other.

I create UDF, but obviously it does not work correct

#include "udf.h"
#define kd0 1.58e+15
#define ki0 4.27e+7
#define kp0 4.27e+7
#define kt0 1.255e+9


DEFINE_SOURCE(InicSource,c,t,dS,eqn)
{
real InicSource;
real Dens = C_R(c,t);
real temp = C_T(c,t);
real kd = kd0*exp(-15501/temp);
real InicMC;

InicMC = (C_YI(c,t,1)*Dens) / 164;
InicSource = -kd*InicMC*164;
dS[eqn] = 0;
return InicSource;
}

DEFINE_SOURCE(styrene_source,c,t,dS,eqn)
{
real StyreneMC;
real Radicals1MC;
real LivradMC;
real Styrene_sourceMC;
real temp = C_T(c,t);
real Dens = C_R(c,t);
real styrene_source;
real kp = kp0*exp(-3910/temp);


StyreneMC = (C_YI(c,t,0)*Dens) / 104;
Radicals1MC =(C_YI(c,t,2)*Dens) / 82;
LivradMC = (C_YI(c,t,3)*Dens) / 100000;
Styrene_sourceMC = -kp*StyreneMC*Radicals1MC-kp*StyreneMC*LivradMC;
styrene_source = Styrene_sourceMC*104;
dS[eqn] = 0;
return styrene_source;
}

DEFINE_SOURCE(radicals1_source,c,t,dS,eqn)
{
real radicals1_source;
real temp = C_T(c,t);
real Dens = C_R(c,t);
real kd = kd0*exp(-15501/temp);
real ki = ki0*exp(-3910/temp);
real kp = kp0*exp(-3910/temp);
real StyreneMC1;
real InicMC1;
real radicals1MC1;
real radicals1MC_source;

StyreneMC1 = (C_YI(c,t,0)*Dens) / 104.12;
InicMC1 = (C_YI(c,t,1)*Dens) / 164;
radicals1MC1 = (C_YI(c,t,2)*Dens)/82;
radicals1MC_source = 2.0* kd*InicMC1-kp*radicals1MC1*StyreneMC1;
radicals1_source = radicals1MC_source*82;
dS[eqn] = 0;
return radicals1_source;
}

DEFINE_SOURCE(Livrad_source,c,t,dS,eqn)
{

real Livrad_source;
real temp = C_T(c,t);
real Dens = C_R(c,t);
real kd = kd0*exp(-15501/temp);
real ki = ki0*exp(-3910/temp);
real kp = kp0*exp(-3910/temp);
real kt = kt0*exp(-844/temp);
real StyreneMC2;
real radicals1MC2;
real LivradMC2;
real LivradMC_source;

StyreneMC2 = (C_YI(c,t,0)*Dens) / 104.12;
LivradMC2 = (C_YI(c,t,3)*Dens) / 100000;
LivradMC_source = -kt*LivradMC2*LivradMC2-kp*StyreneMC2*LivradMC2;
Livrad_source = LivradMC_source*100000;
dS[eqn] = 0;
return Livrad_source;
}

Sources can not be linearized

So, any ideas?

I want to solve that system and then set as sources S1, 2,3,4 values ​​obtained by the simultaneous solution of all equations

Laexzzz February 24, 2014 10:05

Pls, any ideas?

HyperNova February 11, 2015 06:39

hi , please forgive because i don have any idea , i just have a question,
what does dS[eqn] = 0; do in code ?
i want to introduce a source to epsilon equation for my model.
thank you very much

CeesH February 11, 2015 08:16

Hi

@ Hypernova; that's a source term linearization function which you can add for stability of the solver. Basically, the source term is outputted as
Code:

S = A + B*X
where A is the constant part which you typically calculate as a source, and B = dS/dX. The FLUENT UDF manual gives an example where S is a function of Vx, so you can add the derivative dS/dVx.

@ Laexzz; It seems to me there is no choice but to linearize your equation set. This happens automatically during iteration, for example S(2) is calculated while holding C(2),(3),(4) constant (alternatively, you can link the derivative as outlined above). Of course, your set of equations is still coupled and eventually the result should converge.

I don't think the problem with your set of equations is the linearization, but I'm afraid it's a stiff set of equations. The time constant of the first equation is much higher than all the other ones, and I am guessing this causes problems. What happens if you run your model for a simple configuration (so excluding any flow) in say, MATLAB? Do you get good, smooth results? Does ODE45 interation work at all or do you need a special stiff routine.

FLUENT should have some options to deal with stiff chemistry (I have no experience with that however), alternatively you may want to use a quasi-equilibrium assumption or so to deal with the fast reaction step.

HyperNova February 11, 2015 16:11

thank you very much for spending time to explain, i don know any thing on species topic otherwise i help you , but in near future i have to learn because i need it in my work , thank you very much


All times are GMT -4. The time now is 18:24.