CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Scalar Transport Equation with a source term using functionObjects and fvOptions (https://www.cfd-online.com/Forums/openfoam-solving/234357-scalar-transport-equation-source-term-using-functionobjects-fvoptions.html)

mmohaqeqf March 3, 2021 14:50

Scalar Transport Equation with a source term using functionObjects and fvOptions
 
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 March 5, 2021 13:15

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 March 8, 2021 18:12

For those interested in a solution, follow the discussion here:


https://www.cfd-online.com/Forums/op...tml#post798262


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