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/)
-   -   Porosity Variation with Time (https://www.cfd-online.com/Forums/fluent-udf/172803-porosity-variation-time.html)

Bruno Machado July 6, 2016 16:10

Quote:

Originally Posted by Baden (Post 608293)
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:

http://i.imgur.com/zgusJfj.png

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 July 6, 2016 16:20

Quote:

Originally Posted by Bruno Machado (Post 608299)
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?

Bruno Machado July 7, 2016 12:02

Quote:

Originally Posted by Baden (Post 608301)
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.

hooman.esl July 16, 2016 08:53

variable porosity
 
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?

Bruno Machado July 20, 2016 04:20

Quote:

Originally Posted by hooman.esl (Post 609772)
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 July 20, 2016 06:55

hydrate dissociation
 
Quote:

Originally Posted by Bruno Machado (Post 610390)
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.

Bruno Machado July 20, 2016 07:05

Quote:

Originally Posted by hooman.esl (Post 610430)
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.

Baden July 20, 2016 12:04

Quote:

Originally Posted by Bruno Machado (Post 608442)
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 (Post 608442)
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?

Bruno Machado July 22, 2016 06:24

Quote:

Originally Posted by Baden (Post 610493)
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.

Baden July 22, 2016 16:15

Quote:

Originally Posted by Bruno Machado (Post 610869)
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?

hooman.esl July 25, 2016 06:07

porous media
 
Quote:

Originally Posted by Bruno Machado (Post 610434)
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?


All times are GMT -4. The time now is 10:12.