CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Question about the calculation of available amount of reactant based on cell content

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 25, 2021, 23:10
Default Question about the calculation of available amount of reactant based on cell content
  #1
Member
 
xingangzheng
Join Date: Jul 2009
Posts: 37
Rep Power: 16
ustbdynamic is on a distinguished road
Hi at all!

I am trying to find a way to calculate the available amount of reactant based on cell content in one calculation step. The purpose is used it to evaluate whether the available reactants are greater than the source terms in each cell.

The following code was found. But the calculation process is a little bit confused.
1) Here, the flux from C0 to the face is regarded as positive value, and the flux from C1 is just the opposite ; So the thread of C0 is used in the first 'if' stament, and C1 is used to the negative flux.
Is this right ? ( Or this is a kind of upwind format of flux)

2) the transient behavior is reflected by ' f_h2o * CURRENT_TIMESTEP '.
Is this reasonable?

m_h2o = C_VOLUME(c,t) * C_R(c,t) * C_YI(c,t,i);
c_face_loop(c,t,n)
{
f = C_FACE(c,t,n);
tf = C_FACE_THREAD(c,t,n);
/* At faces with out flow */
if(F_FLUX(f,tf) > 0.0)
{
f_h2o += F_FLUX(f,tf) * C_YI(c,t,i);
}
else
{
/* At faces with in flow */
t1 = F_C1_THREAD(f,tf);
c1 = F_C1(f,tf);
f_h2o += - F_FLUX(f,tf) * C_YI(c1,t1,i);
}
}
/* Available amount of h2o based on cell content in one calculation step */
dm_h2o = m_h2o + f_h2o * CURRENT_TIMESTEP;

3) If the above two is correct. Is the following modification appropriate


/* At faces with out flow */
if(F_FLUX(f,tf) > 0.0)
{
f_h2o += -F_FLUX(f,tf) * C_YI(c,t,i); /****here a minus sign is added to indicates outflow *****/
}
else
{
/* At faces with in flow */
t1 = F_C1_THREAD(f,tf);
c1 = F_C1(f,tf);
f_h2o += - F_FLUX(f,tf) * C_YI(c1,t1,i);
}
}

dm_h2o = m_h2o + f_h2o * CURRENT_TIMESTEP;

Thank you very much in advance.
ustbdynamic is offline   Reply With Quote

Old   April 26, 2021, 00:05
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
I don't understand your goal... Why is
Code:
m_h2o = C_VOLUME(c,t) * C_R(c,t) * C_YI(c,t,i);
not sufficient? Why do you calculate the flux into the cell, ate you trying to predict the next time step? The description does not mention that, or I fail to understand something.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 26, 2021, 00:25
Default
  #3
Member
 
xingangzheng
Join Date: Jul 2009
Posts: 37
Rep Power: 16
ustbdynamic is on a distinguished road
Thank you sir.

The background is as follows.
There are source terms caused by reaction or condensation. If the available amount of reactant in one cell is fewer than the mass sources calculated by formulas, then the available amount is used to replace the original calculated value.
If not, there will be an imbalance. The calculated mass sources are going to be added all the time, when Qavailable<Qsource.

There is another situation,when Qavailable=0, but the calculated Qsource may be added to another phases.


Quote:
Originally Posted by pakk View Post
I don't understand your goal... Why is
Code:
m_h2o = C_VOLUME(c,t) * C_R(c,t) * C_YI(c,t,i);
not sufficient? Why do you calculate the flux into the cell, ate you trying to predict the next time step? The description does not mention that, or I fail to understand something.
ustbdynamic is offline   Reply With Quote

Old   April 26, 2021, 00:36
Default
  #4
Member
 
xingangzheng
Join Date: Jul 2009
Posts: 37
Rep Power: 16
ustbdynamic is on a distinguished road
m_h2o = C_VOLUME(c,t) * C_R(c,t) * C_YI(c,t,i) is a static quantity.

For the transient behavior, the mass variation in a control volume may need to consider the flux. Because in one step time, the flux_in can increase the available quantity in a cell, and the flux_out can decrease the available quantity in a cell.

I don't know this description is right or wrong.



Quote:
Originally Posted by pakk View Post
I don't understand your goal... Why is
Code:
m_h2o = C_VOLUME(c,t) * C_R(c,t) * C_YI(c,t,i);
not sufficient? Why do you calculate the flux into the cell, ate you trying to predict the next time step? The description does not mention that, or I fail to understand something.
ustbdynamic is offline   Reply With Quote

Old   April 26, 2021, 01:57
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by ustbdynamic View Post
m_h2o = C_VOLUME(c,t) * C_R(c,t) * C_YI(c,t,i) is a static quantity.

For the transient behavior, the mass variation in a control volume may need to consider the flux. Because in one step time, the flux_in can increase the available quantity in a cell, and the flux_out can decrease the available quantity in a cell.

I don't know this description is right or wrong.
Hard to follow... Why is this a static quantity? density and mass fraction are not static.

Adding the flux gives you a reasonable prediction of the quantity at the next time step, which might be useful in some cases, but not in your case, as far as I can see.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 26, 2021, 02:42
Default
  #6
Member
 
xingangzheng
Join Date: Jul 2009
Posts: 37
Rep Power: 16
ustbdynamic is on a distinguished road
For example, using m_h2o = C_VOLUME(c,t) * C_R(c,t) * C_YI(c,t,i), you may obtain the available reactant is 5 kg. Within the calculation time step, the net flux into the cell may be 10 kg.
So the total available reactant is 15 kg.

The corresponding physical phenomenon can be the condensation process of water vapor. If the power of cold source is high, in one step time, it will condense the original vapor (5 kg),and then cause the vapor flux (10 kg) into the cell.

This is the original intention of it.

Now the first question seems to be whether it is necessary to consider the increment caused by flux in one step.




Quote:
Originally Posted by pakk View Post
Hard to follow... Why is this a static quantity? density and mass fraction are not static.

Adding the flux gives you a reasonable prediction of the quantity at the next time step, which might be useful in some cases, but not in your case, as far as I can see.
ustbdynamic is offline   Reply With Quote

Old   April 26, 2021, 07:29
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by ustbdynamic View Post
For example, using m_h2o = C_VOLUME(c,t) * C_R(c,t) * C_YI(c,t,i), you may obtain the available reactant is 5 kg. Within the calculation time step, the net flux into the cell may be 10 kg.
So the total available reactant is 15 kg.
No, the total available reactant at the time step is 5 kg.
15 kg is the prediction for the total available reactant at the next time step. But the extra 10 kg is not yet in your cell.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 26, 2021, 22:25
Smile
  #8
Member
 
xingangzheng
Join Date: Jul 2009
Posts: 37
Rep Power: 16
ustbdynamic is on a distinguished road
Quote:
Originally Posted by pakk View Post
No, the total available reactant at the time step is 5 kg.
15 kg is the prediction for the total available reactant at the next time step. But the extra 10 kg is not yet in your cell.
Thank you again.
There still seems to be some doubt.

Take the previous for example.
Assuming a single component gas, C_YI(c,t,i)=1. m_h2o = C_VOLUME(c,t) * C_R(c,t) * 1, which will be approximately a constant for the pressure changed not very much. (nearly kept 5 kg in the cell).

If there is zero flux in and out of the cell,the maximum condensation indeed equal to 5 kg. But if there is 10 kg flux each time, the maximum condensation can be greater than 5 kg at each time.

As is the case for condenser with only entrances. It may condense much more mass than its holding in a time step. Of course, condensation mass also has a certain relationship with the time step size.

Therefor, I think the mass flux influences the available reactant mass for both current time step and the next time step.

I don't know if I've made it clear.
ustbdynamic is offline   Reply With Quote

Old   April 27, 2021, 01:01
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
If you have 10000 money in your bank account, and every month you earn 2000 money, how much can you spend now?

My answer is 10000 money.

But I see your point. If I increase the time step to ten years, I have 10000 money, and earn 240000 money. How much can I spend in the ten years? You can argue 250000 is a better answer. Sure, but then your problem is different: your time step is too large!

Make the time step small enough, so that the change is small. If you don't, you will get convergence problems anyway. And then, you can simply ignore the flux.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 27, 2021, 01:58
Default
  #10
Member
 
xingangzheng
Join Date: Jul 2009
Posts: 37
Rep Power: 16
ustbdynamic is on a distinguished road
Quote:
Originally Posted by pakk View Post
If you have 10000 money in your bank account, and every month you earn 2000 money, how much can you spend now?

My answer is 10000 money.

But I see your point. If I increase the time step to ten years, I have 10000 money, and earn 240000 money. How much can I spend in the ten years? You can argue 250000 is a better answer. Sure, but then your problem is different: your time step is too large!

Make the time step small enough, so that the change is small. If you don't, you will get convergence problems anyway. And then, you can simply ignore the flux.
Dear pakk, thank you very much. I will rethink this process.
ustbdynamic is offline   Reply With Quote

Old   April 27, 2021, 02:52
Default
  #11
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by ustbdynamic View Post
Dear pakk, thank you very much. I will rethink this process.
You're welcome. Your question is very important for a good understanding, great that you asked!
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   April 27, 2021, 03:56
Default
  #12
Member
 
xingangzheng
Join Date: Jul 2009
Posts: 37
Rep Power: 16
ustbdynamic is on a distinguished road
Quote:
Originally Posted by pakk View Post
You're welcome. Your question is very important for a good understanding, great that you asked!

Dear pakk, I'm sorry again to trouble you.

If without considering the convergence problems or other questions, Can the following code realize the functions described above. In particular, the use of C (C0), C1 to match the flux direction (flow into or out of the cell).

Thank you very much.

m_h2o = C_VOLUME(c,t) * C_R(c,t) * C_YI(c,t,i);
c_face_loop(c,t,n)
{
f = C_FACE(c,t,n);
tf = C_FACE_THREAD(c,t,n);
/* At faces with out flow */
if(F_FLUX(f,tf) > 0.0)
{
f_h2o += F_FLUX(f,tf) * C_YI(c,t,i);
}
else
{
/* At faces with in flow */
t1 = F_C1_THREAD(f,tf);
c1 = F_C1(f,tf);
f_h2o += - F_FLUX(f,tf) * C_YI(c1,t1,i);
}
}
/* Available amount of h2o based on cell content in one calculation step */
dm_h2o = m_h2o + f_h2o * CURRENT_TIMESTEP;
ustbdynamic is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moisture evaporation - CELL based approach Kummi OpenFOAM 0 October 14, 2019 07:33
Neighboring cells in tetrahedral mesh vishwesh OpenFOAM Programming & Development 9 November 10, 2017 07:06
How to use "translation" in solidBodyMotionFunction in OpenFOAM rupesh_w OpenFOAM Running, Solving & CFD 5 August 16, 2016 04:27
[General] Wrong Calculation of Cell Volume olli191 ParaView 1 August 3, 2016 04:09
How to include cell volumes in calculation of volScalarField? zordiack OpenFOAM Programming & Development 4 April 11, 2014 05:57


All times are GMT -4. The time now is 11:56.