CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Problem with coded source term for multiphaseEulerFoam

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

Like Tree2Likes
  • 1 Post By shuji_type97
  • 1 Post By jmilo

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 7, 2022, 21:23
Exclamation Problem with coded source term for multiphaseEulerFoam
  #1
New Member
 
Shuji Chang
Join Date: Apr 2022
Posts: 4
Rep Power: 4
shuji_type97 is on a distinguished road
Hi Foamers,

I would like to inquire about the coded source term in OpenFoam. Actually, I'm facing a problem.

When I use "codedSourceTerm" in OpenFoam, there are 3 options "codeAddSup", "codeAddRhoSup", and "codeAddAlphaRhoSup". I am not sure what's the meaning of these options. When I went to check the source code in OpenFoam9(https://cpp.openfoam.org/v9/massSource_8H_source.html), I found the description as below:
Code:
// Sources
 
             //- Add a source term to an equation
             FOR_ALL_FIELD_TYPES(DEFINE_FV_MODEL_ADD_SUP);
 
             //- Add a source term to a compressible equation
             FOR_ALL_FIELD_TYPES(DEFINE_FV_MODEL_ADD_RHO_SUP);
 
             //- Add a source term to a phase equation
             FOR_ALL_FIELD_TYPES(DEFINE_FV_MODEL_ADD_ALPHA_RHO_SUP);
Could anyone please teach me what's the difference between these 3 options and what's the meaning of "equation", "compressible equation", and "phase equation" here?

Meanwhile, I am trying to implement the kinetic model into CFD by source term. I used multiphaseEulerFoam as my solver, liquid and gas phase both are multicomponent. Please find my code for the source term below:

Code:
Growth
{
    type            coded;

    selectionMode   all;

    field           biomass.liquid;

    codeInclude
    #{
       #include "fvm.H"
    #};

    codeAddRhoSup
    #{
       Pout<< "**codeAddRhoSup**" << endl;
       
       const vectorField& C = mesh().C();
              
       // Get the required fields
       const volScalarField& B = mesh().lookupObject<volScalarField>("biomass.liquid");// mass fraction of biomass
       const volScalarField& O = mesh().lookupObject<volScalarField>("O2.liquid");// mass fraction of Oxygen
       const volScalarField& S = mesh().lookupObject<volScalarField>("substrate.liquid");// mass fraction of substrate
       const volScalarField& rhoL = mesh().lookupObject<volScalarField>("thermo:rho.liquid");// rho of liquid phase

       // Define the Kinetic parameters
       //dimensionedScalar  mum("mum", dimensionSet(0,0,-1,0,0,0,0), 2.78e-4); // 1/second
       //dimensionedScalar  ks("ks", dimensionSet(1,-3,0,0,0,0,0), 0.05); // kg/m^3
       //dimensionedScalar  ko("ks", dimensionSet(1,-3,0,0,0,0,0), 1e-4); //kg/m^3
       const scalar mum = 2.78e-1; // 2.78e-4
       const scalar ks  = 0;   // 0.05
       const scalar ko  = 0;   // 1e-4

       // Get the timestep
       const scalar deltaT = mesh().time().deltaT().value();
       
       // Creat the growth rate (mu) 
       volScalarField GrowthRate
       (
           IOobject
           (
               "GrowthRate",
               mesh().time().timeName(),
               mesh(),
               IOobject::NO_READ,
               IOobject::AUTO_WRITE
           ),
           mesh(),
           dimensionedScalar("GrowthRate", dimless/dimTime, 0.0)
       );

       // Compute the growth rate
       forAll(C, i)
       {
           GrowthRate[i] = mum*rhoL[i];
       }
       
       // Add to source term
       eqn += GrowthRate*B;
    #};
Here is a simplified kinetic model.

When I use codeAddRhoSup, it works. However, when I use it in codeAddAlphaRhoSup, error is reported:

Could you please teach me why this error happened?

I appreciate your help.

Shuji
Attached Images
File Type: jpg error.jpg (37.8 KB, 35 views)
instanton likes this.
shuji_type97 is offline   Reply With Quote

Old   July 14, 2022, 02:40
Default
  #2
New Member
 
Almanzo Arjuna
Join Date: Feb 2022
Location: East Java, Indonesia
Posts: 8
Rep Power: 4
Almanzo2000 is on a distinguished road
Hi as a fellow coded source user, with how tiny the documentation on coded source is, I'm not really an expert in this case but I can refer you to this post

coded energysource in fvModels

I don't know if this will help you, but as far as I understand codeAddRhoSup is for the compressible solver (e.g. chtMultiRegionFoam) and codeAddSup is for the incompressible one.

best of luck.
Almanzo2000 is offline   Reply With Quote

Old   July 22, 2022, 01:37
Default
  #3
New Member
 
John Parra
Join Date: Jun 2020
Posts: 3
Rep Power: 6
jmilo is on a distinguished road
Quote:
Originally Posted by shuji_type97 View Post
Hi Foamers,

I would like to inquire about the coded source term in OpenFoam. Actually, I'm facing a problem.

When I use "codedSourceTerm" in OpenFoam, there are 3 options "codeAddSup", "codeAddRhoSup", and "codeAddAlphaRhoSup". I am not sure what's the meaning of these options. When I went to check the source code in OpenFoam9(https://cpp.openfoam.org/v9/massSource_8H_source.html), I found the description as below:
Code:
// Sources
 
             //- Add a source term to an equation
             FOR_ALL_FIELD_TYPES(DEFINE_FV_MODEL_ADD_SUP);
 
             //- Add a source term to a compressible equation
             FOR_ALL_FIELD_TYPES(DEFINE_FV_MODEL_ADD_RHO_SUP);
 
             //- Add a source term to a phase equation
             FOR_ALL_FIELD_TYPES(DEFINE_FV_MODEL_ADD_ALPHA_RHO_SUP);
Could anyone please teach me what's the difference between these 3 options and what's the meaning of "equation", "compressible equation", and "phase equation" here?

Meanwhile, I am trying to implement the kinetic model into CFD by source term. I used multiphaseEulerFoam as my solver, liquid and gas phase both are multicomponent. Please find my code for the source term below:

Code:
Growth
{
    type            coded;

    selectionMode   all;

    field           biomass.liquid;

    codeInclude
    #{
       #include "fvm.H"
    #};

    codeAddRhoSup
    #{
       Pout<< "**codeAddRhoSup**" << endl;
       
       const vectorField& C = mesh().C();
              
       // Get the required fields
       const volScalarField& B = mesh().lookupObject<volScalarField>("biomass.liquid");// mass fraction of biomass
       const volScalarField& O = mesh().lookupObject<volScalarField>("O2.liquid");// mass fraction of Oxygen
       const volScalarField& S = mesh().lookupObject<volScalarField>("substrate.liquid");// mass fraction of substrate
       const volScalarField& rhoL = mesh().lookupObject<volScalarField>("thermo:rho.liquid");// rho of liquid phase

       // Define the Kinetic parameters
       //dimensionedScalar  mum("mum", dimensionSet(0,0,-1,0,0,0,0), 2.78e-4); // 1/second
       //dimensionedScalar  ks("ks", dimensionSet(1,-3,0,0,0,0,0), 0.05); // kg/m^3
       //dimensionedScalar  ko("ks", dimensionSet(1,-3,0,0,0,0,0), 1e-4); //kg/m^3
       const scalar mum = 2.78e-1; // 2.78e-4
       const scalar ks  = 0;   // 0.05
       const scalar ko  = 0;   // 1e-4

       // Get the timestep
       const scalar deltaT = mesh().time().deltaT().value();
       
       // Creat the growth rate (mu) 
       volScalarField GrowthRate
       (
           IOobject
           (
               "GrowthRate",
               mesh().time().timeName(),
               mesh(),
               IOobject::NO_READ,
               IOobject::AUTO_WRITE
           ),
           mesh(),
           dimensionedScalar("GrowthRate", dimless/dimTime, 0.0)
       );

       // Compute the growth rate
       forAll(C, i)
       {
           GrowthRate[i] = mum*rhoL[i];
       }
       
       // Add to source term
       eqn += GrowthRate*B;
    #};
Here is a simplified kinetic model.

When I use codeAddRhoSup, it works. However, when I use it in codeAddAlphaRhoSup, error is reported:

Could you please teach me why this error happened?

I appreciate your help.

Shuji
Hey, did you solve the problem? Here is my take on it:
1) in OF9, now you have to be mindful of the kind of problem you're solving.
* for incompressible flows (density doesn't change i.e: flow of liquids in pipes with heat transfer) you probably use "codeAddSup"
* for compressible flows (density changes, i.e: gas reaction) you probably use "codeAddRhoSup" in this case, fvModels adds the density to the source term. You can see this in fvModels.C
* for multiphase flows, you probably use "codeAddAlphaRhoSup" and fvModels will add the density and alpha required on the source term.
2) When you said
Quote:
I use codeAddRhoSup, it works
I'm not sure it actually worked. Did you see this print out in your output: **codeAddRhoSup**? I bet you didn't and it is because you're not using the right source term for multiphase: "codeAddAlphaRhoSup". Now, when you put your code under "codeAddAlphaRhoSup" you got an error, but I'm fairly certain that is the right way to use it.
3) Now, about this error: the source term has units kg/m3 s. Your "GrowthRate" variable has units of 1/s. This is what the code is complaining about. You might think that because you multiplied by a density it fixes the problems, but apparently "volScalarField" are unitless quantities, so your rhoL doesn't have any units; and OF9 complains about LHS being kg/m3s and the RHS being 1/s. I think the following works:

Code:
Growth
{
    type            coded;

    selectionMode   all;

    field           biomass.liquid;

    codeInclude
    #{
       #include "fvm.H"
    #};

    codeAddAlphaRhoSup
    #{
       Pout<< "**codeAddAlphaRhoSup**" << endl;
       
       const vectorField& C = mesh().C();
              
       // Get the required fields
       const volScalarField& B = mesh().lookupObject<volScalarField>("biomass.liquid");// mass fraction of biomass
       const volScalarField& O = mesh().lookupObject<volScalarField>("O2.liquid");// mass fraction of Oxygen
       const volScalarField& S = mesh().lookupObject<volScalarField>("substrate.liquid");// mass fraction of substrate
       const volScalarField& rhoL = mesh().lookupObject<volScalarField>("thermo:rho.liquid");// rho of liquid phase

       // Define the Kinetic parameters
       dimensionedScalar  K_O2("K_O2", dimensionSet(1,-3,0,0,0,0,0), 1.0e-4); //kg/m3
       dimensionedScalar  ub_max("ub_max", dimensionSet(0,0,-1,0,0,0,0), 0.278); //1/s
       dimensionedScalar  rhoB("rhoB", dimensionSet(1,-3,0,0,0,0,0), 1); //kg/m3
       //const scalar mum = 2.78e-1; // 2.78e-4
       //const scalar ks  = 0;   // 0.05
       //const scalar ko  = 0;   // 1e-4

       // Get the timestep
       const scalar deltaT = mesh().time().deltaT().value();
       
       // Creat the growth rate (mu) 
       volScalarField GrowthRate
       (
           IOobject
           (
               "GrowthRate",
               mesh().time().timeName(),
               mesh(),
               IOobject::NO_READ,
               IOobject::AUTO_WRITE
           ),
           mesh(),
           dimensionedScalar("GrowthRate", dimless/dimTime, 0.0)
       );

       // Compute the growth rate
       GrowthRate = ub_max*(O/(O + K_CO2/rho));

       // Add to source term
       eqn += GrowthRate*B*rhoX;
    #};
Specific things to note here:
1) inside the block "codeAddAlphaRhoSup" you can call "rho" and "alpha" and you'll get the density and the volume fraction of the field.
2) for the growth rate I used the Monod model and divided numerator and denominator by the density, leaving it only in terms of the mass fraction of oxygen. GrowthRate has now units of 1/s
3) rhoX is there just to add the missing units. Th RHS of eqn should have units kg/m3s as well.
shuji_type97 likes this.
jmilo is offline   Reply With Quote

Reply

Tags
coded source, multi component, multiphase model, multiphaseeulerfaom, source term

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
Source term for EVAPORATION in Energy Equ. - technical difficulty ? Kummi OpenFOAM 1 September 9, 2019 09:32
[OpenFOAM.org] Error creating ParaView-4.1.0 OpenFOAM 2.3.0 tlcoons OpenFOAM Installation 13 April 20, 2016 17:34
what is swap4foam ?? AB08 OpenFOAM 28 February 2, 2016 01:22
[Other] How to use finite area method in official OpenFOAM 2.2.0? Detian Liu OpenFOAM Meshing & Mesh Conversion 4 November 3, 2015 03:04
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 16:02


All times are GMT -4. The time now is 05:19.