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

Porosity Variation with Time

Register Blogs Community New Posts Updated Threads Search

Like Tree14Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 13, 2016, 10:57
Default
  #21
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
Quote:
Originally Posted by `e` View Post
Fluent uses ANSI C which follows a number of strict rules including the requirement of declaring all variables at the beginning of a code block. However, you can declare and initialise the domain thread on one line with:

Code:
Domain *d = Get_Domain(1);
Thank you `e`, that solved my problem.

I do have another question that I was not able to find a satisfactory answer to online. How do I view how the porosity changed with time? I've looked into setting up a monitor with the field variable of UDMI_0 selected, but I'm not sure which report type to choose.
Baden is offline   Reply With Quote

Old   June 13, 2016, 18:08
Default
  #22
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
You can save UDM values at each time step as you would with the velocities via File > Data File Quantities and select "User Memory 0". Then this data is available alongside your other variables in CFD-Post or other external postprocessing software. Note: transient data can accumulate significantly; perhaps write every 5-10 time steps instead.

Alternatively, you could write the UDM to a data file. This approach is more manual, but you could choose to save only the overall average or local average values instead (say, split your domain into blocks).
`e` is offline   Reply With Quote

Old   June 15, 2016, 17:26
Default
  #23
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
Quote:
Originally Posted by `e` View Post
You can save UDM values at each time step as you would with the velocities via File > Data File Quantities and select "User Memory 0". Then this data is available alongside your other variables in CFD-Post or other external postprocessing software. Note: transient data can accumulate significantly; perhaps write every 5-10 time steps instead.

Alternatively, you could write the UDM to a data file. This approach is more manual, but you could choose to save only the overall average or local average values instead (say, split your domain into blocks).
Thank you, I figured it out!

I do have a slightly different question though. How do I model a reaction between the fluid and the solid present in a porous zone? In my case, I have a porous rock with acid flowing through it, so how do I model this?

I was looking into species transport, but it appears you can only model reactions within the mixture with it. I'm thinking that all I need to do is write some UDF for the consumption of acid but I'm not sure what macro I would use or where the hook would be. I've seen some stuff using DEFINE_VR_RATE, but I'm not sure if that is what I need for my application.
Baden is offline   Reply With Quote

Old   June 17, 2016, 13:24
Default
  #24
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
After speaking with a grad student, I've come to the conclusion that I just need to modify the S term in the following equation to account for the consumption of acid due to reaction with the rock. The grad student referred to this as an "acid sink term".



From reading the manual, it appears that I can define this source term as either a constant value or a UDF.

My questions are as follows:
  1. Will modifying this source term to be a sink mean that I won't need to input anything into Fluent for the reaction mechanism (such as rate exponent or stoich. coefficient)
  2. I need the sink term to be dependent on each cell's properties and therefore should be calculated for each cell. What macro would I use in the UDF to achieve this? I believe that a DEFINE_SOURCE macro would be sufficient, but I am not clear what all the arguments are, namely the dS[] term. While I read the definition in the manual, I still don't quite understand it's purpose.
As always, any feedback is tremendously helpful.

Last edited by Baden; June 17, 2016 at 18:10.
Baden is offline   Reply With Quote

Old   June 17, 2016, 19:04
Default
  #25
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by Baden View Post
Will modifying this source term to be a sink mean that I won't need to input anything into Fluent for the reaction mechanism (such as rate exponent or stoich. coefficient)
Probably, are you running a single phase model? Do you need the acid to have balanced chemical equations with another phase?

Quote:
Originally Posted by Baden View Post
I need the sink term to be dependent on each cell's properties and therefore should be calculated for each cell. What macro would I use in the UDF to achieve this? I believe that a DEFINE_SOURCE macro would be sufficient, but I am not clear what all the arguments are, namely the dS[] term. While I read the definition in the manual, I still don't quite understand it's purpose.
DEFINE_SOURCE is applied for each cell and the properties of the cell can be accessed with the cell index and thread arguments (c and t). dS[] is an array of the derivatives of your source term and is optional (could return as zero). If this derivative is known and passed to the solver then Fluent can use an implicit approach rather than explicit approach to solving the source term for the relevant transport equation (more stable).
Baden likes this.
`e` is offline   Reply With Quote

Old   June 17, 2016, 19:43
Default Porosity Variation with Time
  #26
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
Quote:
Originally Posted by `e` View Post
Probably, are you running a single phase model? Do you need the acid to have balanced chemical equations with another phase?
I believe it is only single phase. I'm modeling the transport of diluted acid (acid and water). The only reaction is between the acid and the porous solid it is flowing through. Is my method correct to be able to accurately model this? Am I correct in assuming I don't need to enter any inputs into Fluent for the reaction mechanism?

Sorry for the repeat question, but I just want to make sure I understand what I'm doing.

Quote:
Originally Posted by `e` View Post
DEFINE_SOURCE is applied for each cell and the properties of the cell can be accessed with the cell index and thread arguments (c and t). dS[] is an array of the derivatives of your source term and is optional (could return as zero). If this derivative is known and passed to the solver then Fluent can use an implicit approach rather than explicit approach to solving the source term for the relevant transport equation (more stable).
Thank you for the detailed explanation, that was very helpful.
Baden is offline   Reply With Quote

Old   June 18, 2016, 06:53
Default
  #27
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
I couldn't say whether or not your method is valid (it's outside my field). It sounds about right, perhaps another user will respond. Have you checked what the standard modelling approach is from literature?
`e` is offline   Reply With Quote

Old   June 18, 2016, 07:19
Default
  #28
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 12
Bruno Machado is on a distinguished road
I am simulating fuel cell and the product of the reaction is liquid water. Thus, this occupy the void of the porosity. What I do is:

porosity = constant * (1 - s)

where 's' is the amount of liquid water.

You can probably going to use similar approach.
Bruno Machado is offline   Reply With Quote

Old   June 20, 2016, 11:33
Default
  #29
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
Quote:
Originally Posted by `e` View Post
I couldn't say whether or not your method is valid (it's outside my field). It sounds about right, perhaps another user will respond. Have you checked what the standard modelling approach is from literature?
I will attempt to do so.

Quote:
Originally Posted by Bruno Machado View Post
I am simulating fuel cell and the product of the reaction is liquid water. Thus, this occupy the void of the porosity. What I do is:

porosity = constant * (1 - s)

where 's' is the amount of liquid water.

You can probably going to use similar approach.
For my model, the porosity of a cell at any time is dependent on the change in time and the concentration of acid present in the cell. This value of concentration must change as the acid reacts with the porous solid, hence why I am seeking to find some way to create a "sink" for the acid.

In my original post, I stated that my formula for porosity is as follows:
Quote:
Where X contains a few constants as well as the current concentration of acid. My current problem is making changing this concentration of acid to account for the reaction. Is this what you mean by similar approach?

Last edited by Baden; June 20, 2016 at 14:01.
Baden is offline   Reply With Quote

Old   June 21, 2016, 05:52
Default
  #30
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 12
Bruno Machado is on a distinguished road
Quote:
Originally Posted by Baden View Post
I will attempt to do so.


For my model, the porosity of a cell at any time is dependent on the change in time and the concentration of acid present in the cell. This value of concentration must change as the acid reacts with the porous solid, hence why I am seeking to find some way to create a "sink" for the acid.

In my original post, I stated that my formula for porosity is as follows:Where X contains a few constants as well as the current concentration of acid. My current problem is making changing this concentration of acid to account for the reaction. Is this what you mean by similar approach?
You will change the concentration of the acid in the domain by adding a sink term. This sink term will be the reaction rate of acid (kg/m3s). This source term has to be added in the species AND mass equation, otherwise the continuity equation wont be obeyed.

The reaction rate probably has a relation with the porosity. Use that to implement the variation of the porosity in your code.
Baden likes this.
Bruno Machado is offline   Reply With Quote

Old   June 21, 2016, 10:19
Default
  #31
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
You will change the concentration of the acid in the domain by adding a sink term. This sink term will be the reaction rate of acid (kg/m3s). This source term has to be added in the species AND mass equation, otherwise the continuity equation wont be obeyed.
...
Where would I add the sink term to the species and mass equation? Are you referring to these?





Also, would I disable the "Reaction" option in the above images since the reaction is modeled by the sink?

Quote:
Originally Posted by Bruno Machado View Post
...
The reaction rate probably has a relation with the porosity. Use that to implement the variation of the porosity in your code.
In my case, the porosity has a relation with reaction rate, which I have added in my actual, unsimplified code.
Baden is offline   Reply With Quote

Old   June 21, 2016, 11:22
Default
  #32
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 12
Bruno Machado is on a distinguished road
Quote:
Originally Posted by Baden View Post
Where would I add the sink term to the species and mass equation? Are you referring to these?





Also, would I disable the "Reaction" option in the above images since the reaction is modeled by the sink?


In my case, the porosity has a relation with reaction rate, which I have added in my actual, unsimplified code.
yes, you are going to add there both mass and species sink. The reaction tab is in case you want fluent to deal with it base on the inbuilt models.
Baden likes this.
Bruno Machado is offline   Reply With Quote

Old   June 21, 2016, 16:07
Default
  #33
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
yes, you are going to add there both mass and species sink. The reaction tab is in case you want fluent to deal with it base on the inbuilt models.
Thank you very much, you have been incredibly helpful. I do have another question or two I hope you can answer.

Below I've included a simplified version of my current species source code:

Code:
#include "udf.h"

#define i_HCl 0
#define X 1.0

DEFINE_SOURCE(HCl_source,c,t,dS,eqn)
{
    real C = C_YI(c,t,i_HCl) * C_R(c,t); /* mass concentration of HCl */
    real source = -X * C; /* negative value = sink */
    dS[eqn] = 0.;
    
    return source;
}
My questions are as follows.

  1. Since this source is for the HCl part of the mixture, would I only hook the UDF into the mass source term and not the H2O species source? I thought I would make the H2O species source a constant value of 0 because the manual says this:
    Quote:
    Since you cannot specify the mass source for the last species explicitly, ANSYS Fluent will compute it by subtracting the sum of all other species mass sources from the specified total Mass source.
    However, earlier you said that I must provide both mass and species source so I'm slightly confused.
  2. How do I determine the proper index (i value used in C_YI(c,t,i)) of the HCl? In the above code, I just assumed it was 0 but again, I'm not sure.
Baden is offline   Reply With Quote

Old   June 21, 2016, 16:16
Default
  #34
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 12
Bruno Machado is on a distinguished road
Quote:
Originally Posted by Baden View Post
Thank you very much, you have been incredibly helpful. I do have another question or two I hope you can answer.

Below I've included a simplified version of my current species source code:

Code:
#include "udf.h"

#define i_HCl 0
#define X 1.0

DEFINE_SOURCE(HCl_source,c,t,dS,eqn)
{
    real C = C_YI(c,t,i_HCl) * C_R(c,t); /* mass concentration of HCl */
    real source = -X * C; /* negative value = sink */
    dS[eqn] = 0.;
    
    return source;
}
My questions are as follows.

  1. Since this source is for the HCl part of the mixture, would I only hook the UDF into the mass source term and not the H2O species source? I ask because the manual says this: However, earlier you said that I must provide both mass and species source so I'm slightly confused.
  2. How do I determine the proper index (i value used in C_YI(c,t,i)) of the HCl? In the above code, I just assumed it was 0 but again, I'm not sure.
1) The sum of all species mass fraction = 1, so fluent solve N-1 equations for species and the last is straightforward.

2) The list of your species you can check in the material properties. Go to the mixture tab and in name you can define the order of them. If you need source term to all the species you have, add an extra species with meaningless properties, so it won't affect you results.
Baden likes this.
Bruno Machado is offline   Reply With Quote

Old   June 29, 2016, 19:00
Default
  #35
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
1) The sum of all species mass fraction = 1, so fluent solve N-1 equations for species and the last is straightforward.

2) The list of your species you can check in the material properties. Go to the mixture tab and in name you can define the order of them. If you need source term to all the species you have, add an extra species with meaningless properties, so it won't affect you results.
This was very helpful, thank you.

I am currently in the process of adding the sink term for the acid species. The code is as follows:
Code:
#include "udf.h"

#define i_HCl 0 /* species index of HCl */
#define Sh_infinity 3. /* asymptotic Sherwood number for the pore */
#define D_m 3.6e-9 /* molecular diffusivity */
#define r_p 1.e-6 /* pore radius */
#define v 2. /* stoichiometric coefficient of the chemical reaction */
#define k_s 2.e-3 /* surface reaction rate constant */
#define a_0 5280. /* initial superficial area */
#define rho_s 2.71e+3 /* density of the solid phase */
real k_c = (Sh_infinity * D_m) / (2. * r_p); /* local mass transfer coefficient */


DEFINE_SOURCE(HCl_source,c,t,dS,eqn)
{
    real a_v = a_0 * (1 - C_UDMI(c,t,1)) / (1 - C_UDMI(c,t,0)); superficial area */
    real k_eff = a_v * (k_c * k_s) / (k_c + k_s); /* effective dissolution rate constant */
    real C = C_YI(c,t,i_HCl) * C_R(c,t); /* mass concentration of HCl */
    
    real source = -k_eff * C; /* negative value = sink */
    dS[eqn] = 0.;
    return source;
}
I define this as both a mass source term and HCl source term. The problem happens when I run the simulation. The console gives the message "reversed flow in 1680 faces on pressure-outlet 6". I'm assuming this reverse flow is caused by my source UDF because there was no reverse flow before I added it. How would I fix this problem?
Baden is offline   Reply With Quote

Old   June 30, 2016, 06:24
Default
  #36
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 12
Bruno Machado is on a distinguished road
Quote:
Originally Posted by Baden View Post
This was very helpful, thank you.

I am currently in the process of adding the sink term for the acid species. The code is as follows:
Code:
#include "udf.h"

#define i_HCl 0 /* species index of HCl */
#define Sh_infinity 3. /* asymptotic Sherwood number for the pore */
#define D_m 3.6e-9 /* molecular diffusivity */
#define r_p 1.e-6 /* pore radius */
#define v 2. /* stoichiometric coefficient of the chemical reaction */
#define k_s 2.e-3 /* surface reaction rate constant */
#define a_0 5280. /* initial superficial area */
#define rho_s 2.71e+3 /* density of the solid phase */
real k_c = (Sh_infinity * D_m) / (2. * r_p); /* local mass transfer coefficient */


DEFINE_SOURCE(HCl_source,c,t,dS,eqn)
{
    real a_v = a_0 * (1 - C_UDMI(c,t,1)) / (1 - C_UDMI(c,t,0)); superficial area */
    real k_eff = a_v * (k_c * k_s) / (k_c + k_s); /* effective dissolution rate constant */
    real C = C_YI(c,t,i_HCl) * C_R(c,t); /* mass concentration of HCl */
    
    real source = -k_eff * C; /* negative value = sink */
    dS[eqn] = 0.;
    return source;
}
I define this as both a mass source term and HCl source term. The problem happens when I run the simulation. The console gives the message "reversed flow in 1680 faces on pressure-outlet 6". I'm assuming this reverse flow is caused by my source UDF because there was no reverse flow before I added it. How would I fix this problem?
The reverse flow can happen during the solution of the problem. Once the iterations are carried, this number should decrease.

You can reduce the chances of it happening by adding the back flow values in your outlet boundary. It can also be something caused by the mesh quality. Depending on the nature of your problem (high pressure/velocity), it also has some influence on it.

Did you check the values of your porosity and are they as you expect?
Bruno Machado is offline   Reply With Quote

Old   July 1, 2016, 10:18
Default
  #37
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
The reverse flow can happen during the solution of the problem. Once the iterations are carried, this number should decrease.

You can reduce the chances of it happening by adding the back flow values in your outlet boundary. It can also be something caused by the mesh quality. Depending on the nature of your problem (high pressure/velocity), it also has some influence on it.

Did you check the values of your porosity and are they as you expect?
My inlet velocity is 1.65e-5 m/s and I believe I have a fairly high quality mesh. However, I was just running the acid sink code without the porosity variation code, so I will try adding it in and see if that fixes my problem.
Baden is offline   Reply With Quote

Old   July 5, 2016, 17:47
Default
  #38
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
I've been working on implementing the porosity variation code with the species transport enabled (WITHOUT the acid sink UDF implemented yet). I am getting reasonable porosity values, however, the graph of residuals looks nothing like it did prior to enabling a porous zone. Is this normal or is there an error in my setup of a porous zone?



Both simulations were run using the transient solver setting.
Baden is offline   Reply With Quote

Old   July 6, 2016, 03:55
Default
  #39
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 12
Bruno Machado is on a distinguished road
Quote:
Originally Posted by Baden View Post
I've been working on implementing the porosity variation code with the species transport enabled (WITHOUT the acid sink UDF implemented yet). I am getting reasonable porosity values, however, the graph of residuals looks nothing like it did prior to enabling a porous zone. Is this normal or is there an error in my setup of a porous zone?



Both simulations were run using the transient solver setting.
Can't tell. Residuals mean that the solution from one iteration to other varied a certain quantity. The only way of saying it is correct is by checking you results, or comparing with a benchmark data.
Bruno Machado is offline   Reply With Quote

Old   July 6, 2016, 15:39
Default
  #40
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 9
Baden is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
Can't tell. Residuals mean that the solution from one iteration to other varied a certain quantity. The only way of saying it is correct is by checking you results, or comparing with a benchmark data.
That is good to know. I've verified that the porosity variation code is working as intended and I am implementing the acid sink code (DEFINE_SOURCE macro). I was not experiencing reversed flow up until I added the acid sink code. However, with a time step of 0.01 seconds, the reversed flow ends at around time 0.78 seconds.

The solver doesn't seem to converge unless my time step is around 0.01 seconds. However, with such a small time step the simulation real life run-time is very high just to simulate 10 minutes of flow. I am trying to figure out if the acid sink code is working properly, but the results of a short simulation are inconclusive. These are the results from a time step of 0.01 seconds for 100 time steps:



My questions are as follows:
  1. Is there a problem with my acid sink code or am I simply not running the simulation for enough time steps?
  2. If the latter is the case, how do I run the simulation for longer without drastically increasing my real life run-time? I've already made my mesh coarser in order to temporarily reduce real life run-time. Any step size larger than 0.01 seconds doesn't seem to converge
Eventually, I need to be able to simulate a couple hours worth of flow, so the answers to these questions are very important.
Baden is offline   Reply With Quote

Reply

Tags
acid, porosity, time, transient, udf


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
decomposePar problem: Cell 0contains face labels out of range vaina74 OpenFOAM Pre-Processing 37 July 20, 2020 05:38
simpleFoam error - "Floating point exception" mbcx4jc2 OpenFOAM Running, Solving & CFD 12 August 4, 2015 02:20
Help for the small implementation in turbulence model shipman OpenFOAM Programming & Development 25 March 19, 2014 10:08
pisoFoam with k-epsilon turb blows up - Some questions Heroic OpenFOAM Running, Solving & CFD 26 December 17, 2012 03:34
Orifice Plate with a fully developed flow - Problems with convergence jonmec OpenFOAM Running, Solving & CFD 3 July 28, 2011 05:24


All times are GMT -4. The time now is 23:27.