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

Scalar Transport Equation with a source term using functionObjects and fvOptions

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By mmohaqeqf

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 3, 2021, 15:50
Default Scalar Transport Equation with a source term using functionObjects and fvOptions
  #1
Member
 
Mohammad M F
Join Date: Jan 2016
Location: Washington DC, USA
Posts: 43
Rep Power: 10
mmohaqeqf is on a distinguished road
Hey all;
I want to run simpleFoam on a simple converging pipe (laminar and Newtonian) and at the same time add a scalar transport equation with a constant source term in the controlDict.
Note that the scalar transport field is called D (which I set to be dimensionless), with zero diffusion (so it is a pure convection problem), and the source term is intended to be applied at the entire domain (all the cells generate the same constant source value). Also note that for future steps, I need to have a source term which is a function of another field variable (say for example source = sqrt(U)/3 at each cell), but for now I need to start with a simple case of a constant source to get things started.



Here is my function object section along with the fvOption in my controlDict:


Code:
functions
{
    DTransport
    {
      type            scalarTransport;
      libs            ("solverFunctionObjects.so");
      resetOnStartUp  no;
      field                  D;
      schemesField     U;

      fvOptions
      {
        fixedSource
        {
         type        scalarFixedValueConstraint;
         enabled     true;

         scalarFixedValueConstraintCoeffs
         {
           selectionMode   all;
           volumeMode      specific;

           fieldValues
           {
             D             1;
           }
         }
       }
      }
    }
}
Then, I know I have to have a D file in my 0 folder, which is as follows:


Code:
dimensions      [0 0 0 0 0 0 0];


internalField   uniform 0;

boundaryField
{
     inlet
     {
         type            fixedValue;
         value           uniform 0;
     }

    outlet
    {
        type            zeroGradient;
    }

    wall
    {
        type            zeroGradient;
    }
}
When I run it, simpleFoam runs without an error; it also give a message about the source term, which indicates it understands what I want:


Selecting finite volume options type scalarFixedValueConstraint
Source: fixedSource
- selecting all cells
- selected 60152 cell(s) with volume 2.174888003341e-06


When simulation is complete, I get a D file in each time folder, which is basically the same as the D file in 0 folder, except that



Code:
 internalField   uniform 1;
which I think means that the source term is working (right?)

But then, I get another file called phi in each time folder, which is a surfaceScalarField with the unit of [0 3 -1 0 0 0 0], which I don't know anything about.


Can anyone help me find out what this phi is?


Also, what steps should I take to have a more complicated source term (e.g. that is a function of a field variable)?



Thanks
mmohaqeqf is offline   Reply With Quote

Old   March 5, 2021, 14:15
Default
  #2
Member
 
Mohammad M F
Join Date: Jan 2016
Location: Washington DC, USA
Posts: 43
Rep Power: 10
mmohaqeqf is on a distinguished road
Ok, I have made some progress on applying a coded type source term to my scalar transport equation through fvOptions in controlDict.
For example, below I added a source term to my scalar transport eqn which is in the form of a constant value times magnitude of velocity and it complies just fine.





Code:
functions
{
    dTransport
    {
      type            scalarTransport;
      libs            ("solverFunctionObjects");
      resetOnStartUp  no;
      field          dDamage;
      schemesField    U;

      fvOptions
      {
        dSource
        {
         type        scalarCodedSource;
         name        sourceTime;

         scalarCodedSourceCoeffs
         {
           selectionMode   all;
           volumeMode      specific;
           fields          (dDamage);
           name            sourceName;
           codeInclude
           #{
             #include "fvCFD.H"
             #include "fvc.H"
           #};
           codeCorrect
           #{
           #};
           codeAddSup
           #{
             const scalarField& V = mesh_.V();
             //const vectorField& C = mesh_.C();
             const volVectorField& U = mesh().lookupObject<volVectorField>("U");
             const volScalarField& Ux = U.component(0);
             const volScalarField& Uy = U.component(1);
             const volScalarField& Uz = U.component(2);
             
             scalarField& source = eqn.source();
             source = 0.001*Foam::mag(U)*V;

            
           #};
           codeConstrain
           #{
             Pout<< "**codeConstrain**"<< endl;
           #};
         }
       }
      }
    }
}
Next step for me is to calculate a source term which has gradient of velocity in it; but when I use fvc::gad(U) in my fvOptions, my controlDict does not compile, complaining about fvc not declared in this scope.
Anyone here to help?
mmohaqeqf is offline   Reply With Quote

Old   March 8, 2021, 19:12
Default
  #3
Member
 
Mohammad M F
Join Date: Jan 2016
Location: Washington DC, USA
Posts: 43
Rep Power: 10
mmohaqeqf is on a distinguished road
For those interested in a solution, follow the discussion here:


scalarCodedSource - source term - field/s
JulioPieri likes this.
mmohaqeqf is offline   Reply With Quote

Reply


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



All times are GMT -4. The time now is 01:32.