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   July 6, 2016, 17:10
Default
  #41
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by Baden View Post
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.
Transient simulations takes way longer that steady state one. If your problem has a steady state solution, I'd suggest you to run it before to check if the results are as expected and the physics are correctly implemented.

Since you were not familiar with transient/steady state problems, I suggest you to read Patankar's book (S.V. Patankar, Numerical Heat Transfer and Fluid Flow - you can find it online). You will get information about the time step you can use, and also the different transient methods you can apply.
Baden likes this.
Bruno Machado is offline   Reply With Quote

Old   July 6, 2016, 17:20
Default
  #42
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 10
Baden is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
Transient simulations takes way longer that steady state one. If your problem has a steady state solution, I'd suggest you to run it before to check if the results are as expected and the physics are correctly implemented.

Since you were not familiar with transient/steady state problems, I suggest you to read Patankar's book (S.V. Patankar, Numerical Heat Transfer and Fluid Flow - you can find it online). You will get information about the time step you can use, and also the different transient methods you can apply.
Thank you very much for this information. I have found the book online here and will read it before moving forward with the transient solver.

The only reason I haven't been testing the physics using the steady solver is due to the porosity being a function of time. Is there a temporary workaround for this so that I can use the steady solver until I establish a viable model?
Baden is offline   Reply With Quote

Old   July 7, 2016, 13:02
Default
  #43
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by Baden View Post
Thank you very much for this information. I have found the book online here and will read it before moving forward with the transient solver.

The only reason I haven't been testing the physics using the steady solver is due to the porosity being a function of time. Is there a temporary workaround for this so that I can use the steady solver until I establish a viable model?
I don't think you can test it without using the transient solver. But just to make sure the values returned are correct, compare it with a spreadsheet and see if it is what you are expecting. Then, move to the next stage, otherwise it will be difficult to track bugs later.
Bruno Machado is offline   Reply With Quote

Old   July 16, 2016, 09:53
Default variable porosity
  #44
New Member
 
Hooman
Join Date: Jan 2016
Posts: 19
Rep Power: 10
hooman.esl is on a distinguished road
Hi all,
I am simulation porous media that at first there are water, methane and hydrate (solid phase), as the pressure decreases the solid phase(hydrate) will dissociate to water and methane.
here i have to define a effective porosity that is a function of hydrate saturation using UDF.

phi(eff)=phi(abs)*(1-Saturation(hydrate))

can any one help me how to do it?
hooman.esl is offline   Reply With Quote

Old   July 20, 2016, 05:20
Default
  #45
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by hooman.esl View Post
Hi all,
I am simulation porous media that at first there are water, methane and hydrate (solid phase), as the pressure decreases the solid phase(hydrate) will dissociate to water and methane.
here i have to define a effective porosity that is a function of hydrate saturation using UDF.

phi(eff)=phi(abs)*(1-Saturation(hydrate))

can any one help me how to do it?
you gotta create a DEFINE_PROFILE for the porosity and DEFINE_SOURCE for a sink term for the phases you are consuming (or generating).

There are many examples in this topic, have a look, try it and return questions if you have.
hooman.esl likes this.
Bruno Machado is offline   Reply With Quote

Old   July 20, 2016, 07:55
Default hydrate dissociation
  #46
New Member
 
Hooman
Join Date: Jan 2016
Posts: 19
Rep Power: 10
hooman.esl is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
you gotta create a DEFINE_PROFILE for the porosity and DEFINE_SOURCE for a sink term for the phases you are consuming (or generating).

There are many examples in this topic, have a look, try it and return questions if you have.
Thanks Bruno for your reply i will do it.
i am new in fluent and i have some basic questions.
i have defined two phases (water and methane) in porous media, now i have to define the third phase (hydrate as a solid phase ) that is stagnant and has no motion.
1)how can i define the initial saturation of this solid phase in porous media? does it need a UDF?

2) the hydrate will dissociate as the pressure fall bellow the hydrate stability pressure (p(equilibrium).

ch4.6h2o----> ch4 + 6h2o

should i define it as a reaction or just a multi phase flow with defining source and sink?

3) i have to define the kinetic of hydrate dissociation for fluent using UDF,

mass generation rate of gas= K*phi*S(hydrate)*(p(equilibrium)-p)
phi= porosity, K=dissociation rate constant, S= saturation of hydrate, p=pressure
should i define this in source term of mass equation?

your answer will be helpfull for me.
thank you.
hooman.esl is offline   Reply With Quote

Old   July 20, 2016, 08:05
Default
  #47
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by hooman.esl View Post
Thanks Bruno for your reply i will do it.
i am new in fluent and i have some basic questions.
i have defined two phases (water and methane) in porous media, now i have to define the third phase (hydrate as a solid phase ) that is stagnant and has no motion.
1)how can i define the initial saturation of this solid phase in porous media? does it need a UDF?

2) the hydrate will dissociate as the pressure fall bellow the hydrate stability pressure (p(equilibrium).

ch4.6h2o----> ch4 + 6h2o

should i define it as a reaction or just a multi phase flow with defining source and sink?

3) i have to define the kinetic of hydrate dissociation for fluent using UDF,

mass generation rate of gas= K*phi*S(hydrate)*(p(equilibrium)-p)
phi= porosity, K=dissociation rate constant, S= saturation of hydrate, p=pressure
should i define this in source term of mass equation?

your answer will be helpfull for me.
thank you.
1) you can define one UDS for the solid phase. The initial saturation will be your initial condition for the scalar.

2) You can define the reactions in your UDF and use it as source/sink term for the mass/species equation.

3) If you have the generation or sink of species, both mass and species conservation equations must be considered for this source/sink term, otherwise there will be no conservation.
hooman.esl and Baden like this.
Bruno Machado is offline   Reply With Quote

Old   July 20, 2016, 13:04
Default
  #48
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 10
Baden is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
I don't think you can test it without using the transient solver. But just to make sure the values returned are correct, compare it with a spreadsheet and see if it is what you are expecting. Then, move to the next stage, otherwise it will be difficult to track bugs later.
I am currently writing the code for a randomized initial porosity distribution but am having some trouble. Earlier in this thread, you stated the following:

Quote:
Originally Posted by Bruno Machado View Post
you can add #include <stdlib.h> and use the function randomize() to generate a random number to you.
I was unable to do this method as I must use interpreted code and the method you mentioned requires compiled code. From my understanding, my best option is to generate the random porosity values in a file using a third-party program and use one of the two following methods to assign the data to UDM (and later the porosity profile in the DEFINE_PROFILE() macro) and somehow have Fluent interpolate between the given points.
  1. Use fscanf() in a DEFINE_INIT() macro to read the file and assign the values to UDM.
  2. Use File > Read > Profile in Fluent to upload the file as the UDM profile.
From what I've read, I believe that method 2 would be better because method 1 requires that the user create an array with an exact size (where the size is the number of cells) to hold the corresponding porosity value for each cell.

My questions is will either of these two methods do what I'm trying to do? And if so, which one is preferred?

Last edited by Baden; July 20, 2016 at 19:02.
Baden is offline   Reply With Quote

Old   July 22, 2016, 07:24
Default
  #49
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by Baden View Post
I am currently writing the code for a randomized initial porosity distribution but am having some trouble. Earlier in this thread, you stated the following:



I was unable to do this method as I must use interpreted code and the method you mentioned requires compiled code. From my understanding, my best option is to generate the random porosity values in a file using a third-party program and use one of the two following methods to assign the data to UDM (and later the porosity profile in the DEFINE_PROFILE() macro) and somehow have Fluent interpolate between the given points.
  1. Use fscanf() in a DEFINE_INIT() macro to read the file and assign the values to UDM.
  2. Use File > Read > Profile in Fluent to upload the file as the UDM profile.
From what I've read, I believe that method 2 would be better because method 1 requires that the user create an array with an exact size (where the size is the number of cells) to hold the corresponding porosity value for each cell.

My questions is will either of these two methods do what I'm trying to do? And if so, which one is preferred?
I'd try the first approach, but instead of using the DEFINE_INIT use the DEFINE_ON_DEMAND. But nothing stops you to try both and see which one works easier for you.
Bruno Machado is offline   Reply With Quote

Old   July 22, 2016, 17:15
Default
  #50
Member
 
Join Date: Jun 2016
Posts: 64
Rep Power: 10
Baden is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
I'd try the first approach, but instead of using the DEFINE_INIT use the DEFINE_ON_DEMAND. But nothing stops you to try both and see which one works easier for you.
I couldn't get the second approach to work, so I've been focusing on the first approach as you suggested.

Here is the code I'm currently using:
Code:
#include "udf.h"
#define ID 2 /* thread ID of the fluid (porous zone) */

DEFINE_INIT(UDMI_init, d) {
    Domain *d = Get_Domain(1);
    Thread *t = Lookup_Thread(d, ID);
    cell_t c;
    FILE *fp;
    int i;
    int j = 0;
    float f1[10000];
    
    fp = fopen("data.txt", "r");
    for (i = 0; i < 10000; i++) {
        fscanf(fp, "%f", &f1[i]);
    }    
    fclose(fp);
    
    thread_loop_c(t, d) {
        begin_c_loop(c, t) {
            C_UDMI(c, t, 0) = C_UDMI(c, t, 1) = C_UDMI(c, t, 2) = f1[j];
            j++;
        }
        end_c_loop(c, t)
    }
}
The data.txt file is a text file containing 10,000 random porosity values between 0.1 and 0.3 which was generated using VBA. I do have a couple questions.
  1. Why do you suggest using DEFINE_ON_DEMAND rather than DEFINE_INIT? I tried changing the above code to a DEFINE_ON_DEMAND macro and running it before initialization, but when I ran the simulation afterwards it returned 0 for all the UDMI value.
  2. In the above code, I've highlighted a number in red. From my understanding, this number should be the same as the number of cells I'm looping over so that each cell is assigned a porosity value from the file. I estimated the 10,000 number from the number of hexahedral cells in zone 2 from my mesh. Is there a way to more accurately predict what this number should be?
  3. Are there any fundamental errors in the above code? Are there any improvements I could make?
Baden is offline   Reply With Quote

Old   July 25, 2016, 07:07
Default porous media
  #51
New Member
 
Hooman
Join Date: Jan 2016
Posts: 19
Rep Power: 10
hooman.esl is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
1) you can define one UDS for the solid phase. The initial saturation will be your initial condition for the scalar.

2) You can define the reactions in your UDF and use it as source/sink term for the mass/species equation.

3) If you have the generation or sink of species, both mass and species conservation equations must be considered for this source/sink term, otherwise there will be no conservation.
Hi Bruno
i want to simulate porous media just for one phase in two way
1) Check the “Porous Zone” to enable porous zone in cell zone condition
2) using a momentum source term

i have done them and the pressure contours in both was the same.
but the velocity contours was different.
the code is:

#include "udf.h"
#define por_gdl 0.4
#define i_permeability 5.68e6 // Inverse Permeability (1/m^2)
#define urf 0.1 // under relaxation factor for stability of momentum source term
real s1=0., s2=0.;
DEFINE_SOURCE(xmom_src,c,t,dS,eqn)
{
real source, mu, u;
mu = C_MU_L(c,t);
u = C_U(c,t);
source = -(mu*u*i_permeability);
dS[eqn] = -(mu*i_permeability);
s1 = s1*(1-urf) + source*urf;
return s1;
}
DEFINE_SOURCE(ymom_src,c,t,dS,eqn)
{
real source, mu, v;
mu = C_MU_L(c,t);
v = C_V(c,t);
source = -(mu*v*i_permeability);
dS[eqn] = -(mu*i_permeability);
s2 = s2*(1-urf) + source*urf;
return s2;
}




can u tell me what is the problem?
hooman.esl 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 06:38
simpleFoam error - "Floating point exception" mbcx4jc2 OpenFOAM Running, Solving & CFD 12 August 4, 2015 03:20
Help for the small implementation in turbulence model shipman OpenFOAM Programming & Development 25 March 19, 2014 11:08
pisoFoam with k-epsilon turb blows up - Some questions Heroic OpenFOAM Running, Solving & CFD 26 December 17, 2012 04:34
Orifice Plate with a fully developed flow - Problems with convergence jonmec OpenFOAM Running, Solving & CFD 3 July 28, 2011 06:24


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