# How to define a static aditional variable in CFX

 Register Blogs Members List Search Today's Posts Mark Forums Read

 January 21, 2018, 10:02 Recursive variable: how to define a static additional variable in CFX #1 Member   Join Date: Jun 2017 Posts: 40 Rep Power: 8 Hi, I am trying to define a static additional variable in CFX which only varies with time so the transport equation for this variable,B, will be like this: dB/dt = some function. So there is no advection or diffusion for this variable, and this variable will only be updated at the end of each time step, a trans_loop variable. Is there a way to do that in CFX? Thanks a lot in advance. Last edited by cardioCFD; January 21, 2018 at 11:34.

 January 21, 2018, 10:14 #2 Member   Join Date: Jun 2017 Posts: 40 Rep Power: 8 I have tried to do this using a trans_loop algebraic equation additional variable BOld, for previous time step, and another additional variable called B. B will be calculated by this CEL, B = BOld + (some function) * Time Step Size. And BOld = B But CFX gives an error that some variable depends on itself and stop.

 January 21, 2018, 17:03 #3 Super Moderator   Glenn Horrocks Join Date: Mar 2009 Location: Sydney, Australia Posts: 17,729 Rep Power: 143 How about: Define the variable as a diffusive additional variable. Set the diffusion to zero (or at least a very small number) so that stops diffusion. Then use a source term to do the dB/dt function. cardioCFD likes this.

January 21, 2018, 17:27
#4
Member

Join Date: Jun 2017
Posts: 40
Rep Power: 8
Quote:
 Originally Posted by ghorrocks How about: Define the variable as a diffusive additional variable. Set the diffusion to zero (or at least a very small number) so that stops diffusion. Then use a source term to do the dB/dt function.
Thanks a lot Glenn. Thats exactly how I have tried and am now waiting to see the results, will give an update on that.

But, in general, I do not have a positive experience with using source terms in CFX, usually have problems with convergences, and the results show wiggles overshoots and undershoots, although I use sourceB/max(B,1e-16) as source cofficient.

But I gave it a try, will update on that.

 January 21, 2018, 17:36 #5 Super Moderator   Glenn Horrocks Join Date: Mar 2009 Location: Sydney, Australia Posts: 17,729 Rep Power: 143 Have you read section 1.3.2.1.1 in the documentation on Source Coefficients? It explains that the source term coefficient should be set to dS/dB where S is your source term and B is the current local variable value. You seem to be applying S/B.

January 21, 2018, 18:43
#6
Member

Join Date: Jun 2017
Posts: 40
Rep Power: 8
Quote:
 Originally Posted by ghorrocks Have you read section 1.3.2.1.1 in the documentation on Source Coefficients? It explains that the source term coefficient should be set to dS/dB where S is your source term and B is the current local variable value. You seem to be applying S/B.
Thanks for reminding me of that Glenn, yes I have read that. But in this problem my source is not depending on B,
S= k*v1*v2*v3, where v1 v2 and v3 are three other variables and k is a constant. v3 is concentration of a specie in my reacting mixture, and I have a transport equation for that. B appears in the source term of v3 transport equation, so the relation between v3 and B is quite complete and I could not calculate the derivate dS/dB, that why I just used S/B. Thanks.

Any further comment is highly appreciated, Glenn.

 January 21, 2018, 18:54 #7 Super Moderator   Glenn Horrocks Join Date: Mar 2009 Location: Sydney, Australia Posts: 17,729 Rep Power: 143 S/B is completely wrong so I would not use that. If you don't know the exact gradient then estimate it. Choose typical values of any variables you don't know of v1, v2 and v3 and work out the gradient based on the estimates. An estimated gradient is usually close enough to allow convergence. Even better, set the source term coefficient to a CEL expression of the gradient of the complex function. This requires analytically working out the derivative which can be challenging but is the best approach if it can be done. cardioCFD likes this.

January 22, 2018, 04:17
#8
Member

Join Date: Jun 2017
Posts: 40
Rep Power: 8
Quote:
 Originally Posted by ghorrocks S/B is completely wrong so I would not use that. If you don't know the exact gradient then estimate it. Choose typical values of any variables you don't know of v1, v2 and v3 and work out the gradient based on the estimates. An estimated gradient is usually close enough to allow convergence. Even better, set the source term coefficient to a CEL expression of the gradient of the complex function. This requires analytically working out the derivative which can be challenging but is the best approach if it can be done.
Hi Glenn,

Thank you so much for the advice. Let me check the way I modified the source coefficient with you.

B and A are two chemical species.

A source, rate of production of A: S_A = dA/dt = f(A,B,some other variables)
B source, rate of production of B: S_B = dB/dt = k2*A

I want to calculate the B source coefficient:

source coeff B = dS_B/dB = k2*dA/dB

dA/dB means change in concentration of A divided by change in concentration of B, in other words dA/dB = (dA/dt) / (dB/dt).

Then dA/dB = S_A/S_B and the source coefficient would be k2*S_A/S_B

Is that right? Thanks.

 January 22, 2018, 04:58 #9 Super Moderator   Glenn Horrocks Join Date: Mar 2009 Location: Sydney, Australia Posts: 17,729 Rep Power: 143 That looks OK. cardioCFD likes this.