CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Problem adding rhoPhi (https://www.cfd-online.com/Forums/openfoam-programming-development/121883-problem-adding-rhophi.html)

haze_1986 August 7, 2013 05:46

Problem adding rhoPhi
 
I am trying to solve this:
Code:

fvScalarMatrix SEqn
    (
        fvm::ddt(rho,S)
        + fvm::div(rhoPhi, S)
        - fvm::laplacian(DT, S)
    );

I need to add in rhoPhi in createFields.H, I used the code from interFoam as below:

Code:

    Info<< "Reading field rho\n" << endl;
    volScalarField rho
    (
        IOobject
        (
            "rho",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

    surfaceScalarField rhoPhi
    (
        IOobject
        (
            "rho*phi",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        rho*phi
    );

There is an error with compilation:
Code:

createFields.H:90: error: no matching function for call to ‘Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh>::GeometricField(Foam::IOobject, Foam::tmp<Foam::Field<double> >)’
/opt/OpenFOAM/OpenFOAM-1.6-ext/src/OpenFOAM/lnInclude/GeometricField.C:653: note: candidates are: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&, const Foam::wordList&) [with Type = double, PatchField = Foam::fvsPatchField, GeoMesh = Foam::surfaceMesh]

Would appreciate if anyone can enlighten me on what went wrong. Will provide more info if needed. TIA.

Azur August 7, 2013 10:34

In your case rho is a volScalarField while in interFoam rho1 is a dimensionedScalar.


You can't multiply a surfaceScalarField (phi) with a volScalarField (rho). For a volScalarField all values are defined at the cell centres and for surfaceScalarFields at the face centres of each cell.
So you first have to interpolate the centre values of the rho field to the face centres.
Afterwards you can multiply phi with this new rho field:

Code:

surfaceScalarField rhoPhi
(
    IOobject
    (
        "rho*phi",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    linearInterpolate(rho) * phi
);

or as ist is done in compressibleInterFoam:

Code:

surfaceScalarField rhoPhi
    (
        IOobject
        (
            "rho*phi",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        fvc::interpolate(rho)*phi
    );

The difference between linearInterpolate(rho) and fvc::interpolate(rho) is explained in:
http://openfoamwiki.net/index.php/Op...eInterpolation

haze_1986 August 7, 2013 10:55

Thank you very much, fixed.


All times are GMT -4. The time now is 07:48.