CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Bugs (https://www.cfd-online.com/Forums/openfoam-bugs/)
-   -   bug in OpenFOAM!!! (https://www.cfd-online.com/Forums/openfoam-bugs/108476-bug-openfoam.html)

hawkeye321 October 24, 2012 12:41

bug in OpenFOAM!!!
 
Hi FOAMERS
I am trying to simulate flow in an-isotropic porous medium. As you might know, I have to define the permeability as a tensor with zero non diagonal elements. The Darcy source term in the momentum equation becomes

+ ((PermInvTen) & (fvc::Sp(Visc,U)))

where PermInvTen is a tensor with diagonal elements of 1/kxx, 1/kyy and 1/ kzz.
When I am using fvc (explicit) it compiles successfully. However, using fvm (implicit) gives the following error
------------------------------------------------------------------
BR1IM003.C:84:40: error: no match for ‘operator&’ in ‘PermTen & Foam::fvm::Sp(const Foam::dimensionedScalar&, Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&) [with Type = Foam::Vector<double>, Foam::dimensionedScalar = Foam::dimensioned<double>](((Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>&)(& U)))’
/opt/openfoam171/src/OpenFOAM/lnInclude/wordI.H:167:19: note: candidates are: Foam::word Foam::operator&(const Foam::word&, const Foam::word&)
/opt/openfoam171/src/OpenFOAM/lnInclude/dimensionSet.H:273:29: note: Foam::dimensionSet Foam::operator&(const Foam::dimensionSet&, const Foam::dimensionSet&)
/opt/openfoam171/src/finiteVolume/lnInclude/readPISOControls.H:8:10: warning: unused variable ‘momentumPredictor’
/opt/openfoam171/src/finiteVolume/lnInclude/readPISOControls.H:11:10: warning: unused variable ‘transonic’
/opt/openfoam171/src/finiteVolume/lnInclude/readPISOControls.H:14:9: warning: unused variable ‘nOuterCorr’
make: *** [Make/linux64GccDPOpt/BR1IM003.o] Error 1
-------------------------------------------------------------------------
Does any one know whether OF can handle the dot product of a tensor and implicitly treated vector or not? Is this a bug in foam?

Regards

wyldckat October 24, 2012 14:42

Greetings Mahdi,

You're still using OpenFOAM 1.7.1... I don't know for certain, but is very likely/possible that said bug has already been fixed in the current version of OpenFOAM 2.1.

We (any one in this forum) can test with OpenFOAM 2.1.1 or 2.1.x, if you can provide a small test case or test utility verifying the math operation you want to achieve!

Best regards,
Bruno

AnjaMiehe September 17, 2013 07:49

1 Attachment(s)
Hello,

the "bug" (I don't know if it is one really or if there is a good reason why it is not coded this way) is still there in 2.1.1 and even 2.2.1.

For anyone who would like to contribute / try. As a very basic example without real physical meaning, I took icoFoam, named it to icoTensorFoam, added a volTensorField and an expression to the velocity equation as proposed in at least 2 posts in the forum for anisotropic permeability.

Add to createFields.H:
Code:

  // Permeability volTensorField
  volTensorField PermInv
  (
    IOobject
    (
      "PermInv",
      runTime.timeName(),
      mesh,
      IOobject::NO_READ,
      IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedTensor("PermInv",dimless/sqr(dimLength), tensor::zero)
  );

For the icoTensorFoam.C add / modify:
Code:

PermInv=10.0*tensor(1,0,0,0,0,0,0,0,0)+5.0*tensor(0,0,0,1,0,0,1,0,0);
       
        fvVectorMatrix UEqn
        (
            fvm::ddt(U)
          + fvm::div(phi, U)
          - fvm::laplacian(nu, U)
        //  + (PermInv & fvm::Sp(nu, U))
          + (PermInv & fvc::Sp(nu, U))
        );

        solve(UEqn == -fvc::grad(p));

PermInv is a tensor with 10 at XX, 5 at YY and ZZ position and 0 off-diagonal. The non-commented line compiles, the commented one does not.

I added a tar.gz with the code as well.
Every hint is appreciated, thanks in advance

wyldckat September 28, 2013 09:14

Greetings Anja,

The issue here is that the desired method "Sp()" is not implemented in the name space fvm. For more information about what fvm and fvc are exactly: http://openfoamwiki.net/index.php/Op...%28OpenFOAM%29

As for existing "Sp()" methods for each one, we can look into the Doxygen generated code documentation:
On fvm:
Code:

template<class Type > tmp< fvMatrix< Type > >    Sp (const DimensionedField< scalar, volMesh > &, const GeometricField< Type, fvPatchField, volMesh > &)

template<class Type > tmp< fvMatrix< Type > >    Sp (const tmp< DimensionedField< scalar, volMesh > > &, const GeometricField< Type, fvPatchField, volMesh > &)

template<class Type > tmp< fvMatrix< Type > >    Sp (const tmp< volScalarField > &, const GeometricField< Type, fvPatchField, volMesh > &)

template<class Type > tmp< fvMatrix< Type > >    Sp (const dimensionedScalar &, const GeometricField< Type, fvPatchField, volMesh > &)

template<class Type > zeroField    Sp (const zero &, const GeometricField< Type, fvPatchField, volMesh > &)

On fvc:
Code:

template<class Type > tmp< GeometricField< Type, fvPatchField, volMesh > >    Sp (const volScalarField &sp, const GeometricField< Type, fvPatchField, volMesh > &vf)

template<class Type > tmp< GeometricField< Type, fvPatchField, volMesh > >    Sp (const tmp< volScalarField > &tsp, const GeometricField< Type, fvPatchField, volMesh > &vf)

template<class Type > tmp< GeometricField< Type, fvPatchField, volMesh > >    Sp (const dimensionedScalar &sp, const GeometricField< Type, fvPatchField, volMesh > &vf)

Now, on your source code, you are using "Sp(nu, U)", where:
  • "nu" is a dimensioned scalar.
  • "U" is a volume field.
If we look at the possibilities above... it's the 3rd method on fvc and the 4th one on fvm. So, on the arguments side, the desired method exists.

Now let's look at the returning value. fvc only returns geometric patch fields and fvm only returns matrices. Therefore, this should be the origin of the compiling problem.

So, let's look at the evidences:
  1. This compiles:
    Code:

            fvVectorMatrix UEqn
            (
                fvm::ddt(U)
              + fvm::div(phi, U)
              - fvm::laplacian(nu, U)
              + (PermInv & fvc::Sp(nu, U))
            );

  2. This does not compile:
    Code:

            fvVectorMatrix UEqn
            (
                fvm::ddt(U)
              + fvm::div(phi, U)
              - fvm::laplacian(nu, U)
              + (PermInv & fvm::Sp(nu, U))
            );

  3. So, this clearly indicates that the operator "&" is the one breaking things. And the compiler does tell us this, in the middle of the confusing output, that "Foam:: operator&" has several overloads, but not the one we're looking for.
  4. Therefore, looking for the "operator&" in the documentation... :eek: there are sooooo many operators &... :confused:... good luck finding the one being used with fvc and the one missing for fvm :(
  5. The idea is that you have to look for the following triplet:
    • The "operator&" operates with fvc as:
      Code:

      fv matrix = operator&( volume tensor field, geometric patch field )
    • The "operator&" operates with fvm should do:
      Code:

      fv matrix = operator&( volume tensor field, fv matrix )
  6. If the desired method is missing, have a look at the other methods to see if there is one similar enough on fvm that can be used as basis for implementing an "operator&" for it.
Best regards,
Bruno

AnjaMiehe September 30, 2013 02:27

Hello Bruno,
thank you very much for your detailed explanation.
Unfortunately, my coding skills are not of a level that I could take something "similar as a basis for implementation" here.
Code:

& fvm::Sp()
would be nice to have, but luckily
Code:

& fvc::Sp()
works for me although it is but the explicit implementation. So I will stick with it for the moment.

Thanks again,
Best regards,
Anja

ngj October 5, 2013 07:51

Good day,

As a follow up, considering the resulting matrix under the assumption that fvm::Sp(something,U) would actually work and that the operation
Code:

tensor & fvm::Sp()
would create an implicit contribution to the left hand side of the matrix system, as is what is wanted.

This would create implicit terms for all velocity components in e.g. the momentum equation for the first velocity component. This does not make sense in the context of a segregated approach on the solution of the pressure-velocity coupling, where all other velocity components than the i'th are considered know from the previous time step in the i'th momentum equation.

Kind regards

Niels


All times are GMT -4. The time now is 15:34.