CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Add vector field in momentum conservation equation (https://www.cfd-online.com/Forums/openfoam/244340-add-vector-field-momentum-conservation-equation.html)

nikoscham August 3, 2022 08:33

Add vector field in momentum conservation equation
 
Hi community!

I would like to add a vector field (with constant value) in the momentum conservation equation.

I have the following equation form in the solver:

Code:

  fvVectorMatrix UEqn
    (
        fvm::ddt(U) + fvm::div(phi, U)
      + fvm::Sp(C*pow(1-lf, 2)/(rhoRef*(pow(lf, 3)+q)), U)
      + MRF.DDt(U)
      + turbulence->divDevReff(U)
    ==
        fvOptions(U)
    );

which is part of the meltingFoam solver (see here https://www.cfd-online.com/Forums/op...e-solvers.html). This solver is described in the paper https://www.researchgate.net/publica...th_experiments

I would like to subtract a constant vector field (Up) from the velocity vector U.

I changed the code as follows:

Code:

  fvVectorMatrix UEqn
    (
        fvm::ddt(U) + fvm::div(phi, U)
      + fvm::Sp(C*pow(1-lf, 2)/(rhoRef*(pow(lf, 3)+q)), U - Up) //modified
      + MRF.DDt(U)
      + turbulence->divDevReff(U)
    ==
        fvOptions(U)
    );

Moreover I added the following in the createFields.H


Code:

Info<< "Reading field Up\n" << endl;
volVectorField Up
(
    IOobject
    (
        "Up",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    mesh
 );

By compiling the solver, however I get errors. Part of the error log is the following:

Code:

/opt/OpenFOAM/OpenFOAM-v2012/src/finiteVolume/lnInclude/fvmSup.C:142:1: note:  template argument deduction/substitution failed:
In file included from meltingPullFoam.C:97:0:
UEqn.H:12:63: note:  ‘Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >’ is not derived from ‘const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>’
      + fvm::Sp(C*pow(1-lf, 2)/(rhoRef*(pow(lf, 3)+q)), U - Up) //added
                                                              ^
In file included from /opt/OpenFOAM/OpenFOAM-v2012/src/finiteVolume/lnInclude/fvmSup.H:165:0,
                from /opt/OpenFOAM/OpenFOAM-v2012/src/finiteVolume/lnInclude/fvm.H:49,
                from /opt/OpenFOAM/OpenFOAM-v2012/src/finiteVolume/lnInclude/fvCFD.H:10,
                from meltingPullFoam.C:48:
/opt/OpenFOAM/OpenFOAM-v2012/src/finiteVolume/lnInclude/fvmSup.C:156:1: note: candidate: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::Sp(const dimensionedScalar&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
  Foam::fvm::Sp

It seems that the operation (U-Up) is not accepted. . .

Do you have any proposals or tips?

Thank you in advance!


Nikos

jherb August 28, 2022 11:40

The method fvm::Sp() is used to add a source term implicitly to an equation to be solved, meaning as matrix components on the "left" side of the equation. So its argument must be the field to be solved (U in your case). But now, you also try to add the Up field to the matrix, which is not solved for. So you have to put on the "right" side of the equation explicitly. So I guess, you have to split this fmv::Sp() term into two, one for with fvm::Sp(..., U) and one without fvm:Sp() and just Up.

nikoscham November 24, 2022 04:07

Thank you Joachim for your reply. I have split the two terms as you proposed. For the second term (with the constant Up vector) I have tried to use fvm::Sp(..., Up) but I get:

Code:

--> FOAM FATAL ERROR: (openfoam-2012)
incompatible fields for operation
    [U] - [Up]

  From void Foam::checkMethod(const Foam::fvMatrix<Type>&, const Foam::fvMatrix<Type>&, const char*) [with Type = Foam::Vector<double>]
    in file /opt/OpenFOAM/OpenFOAM-v2012/src/finiteVolume/lnInclude/fvMatrix.C at line 1319.

 FOAM aborting

What I have finally done is to use
Code:

fvc::Sp(..., Up)
in order to add this term on the "right" side of the equation explicitly. It works now, however, don't know if the results are correct. I have to compare them with another software I suppose. What do you think?

jherb December 4, 2022 19:35

You are right, you need to use the explicit operator fvc::Sp() for Up, because it is obviously not the solution variable, so you cannot use the implicit fvm::Sp().


All times are GMT -4. The time now is 20:46.