CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   adding "h" field to sonicFoam (http://www.cfd-online.com/Forums/openfoam-programming-development/119354-adding-h-field-sonicfoam.html)

immortality June 15, 2013 09:38

adding "h" field to sonicFoam
 
Hi
how can add "h" field to sonicFoam?

wyldckat June 15, 2013 11:00

Hi Ehsan,

It depends on how exactly you want to calculate the field "h" and if it should affect the flow of the fluid as well or not.

I did a bit of searching and this does not look like to be an easy task, at least according to this bug report: http://www.openfoam.org/mantisbt/view.php?id=86

Best regards,
Bruno

immortality June 15, 2013 11:20

Hi dear Bruno
it only suffice that be calculated through e,p nd rho as you know:h=e+p/rho
and doesn't affect the flow.is it difficult to define a field for that so that it obtains from three other fields(e,p,rho)?

wyldckat June 15, 2013 11:46

Mmm... the "e" is a field that already exists... OK, try adding the following code, after the equation for "e" is solved:
Code:

volScalarField h
(
    IOobject
    (
        "h",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    e+p/rho
);

I based myself on this tutorial: http://openfoamwiki.net/index.php/Ho...ure_to_icoFoam - but I have not tested it.

immortality June 15, 2013 11:57

you mean in createFields,right?
where it should be exactly added?:confused:
Code:

Info<< "Reading thermophysical properties\n" << endl;

    autoPtr<psiThermo> pThermo
    (
        psiThermo::New(mesh)
    );
    psiThermo& thermo = pThermo();
    thermo.validate(args.executable(), "e");

    volScalarField& p = thermo.p();
    volScalarField& e = thermo.he();
    const volScalarField& psi = thermo.psi();

    volScalarField rho
    (
        IOobject
        (
            "rho",
            runTime.timeName(),
            mesh
        ),
        thermo.rho()
    );

    Info<< "Reading field U\n" << endl;
    volVectorField U
    (
        IOobject
        (
            "U",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );
   
    Info<< "Reading field gas\n" << endl;
    volScalarField gas
    (
        IOobject
        (
            "gas",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

    #include "compressibleCreatePhi.H"


    Info<< "Creating turbulence model\n" << endl;
    autoPtr<compressible::turbulenceModel> turbulence
    (
        compressible::turbulenceModel::New
        (
            rho,
            U,
            phi,
            thermo
        )
    );


wyldckat June 15, 2013 12:00

No, no... I said after solving the equation "e"... this means in "eEqn.H", if I'm not mistaken on the name of the file.

immortality June 15, 2013 12:47

is it true?
Code:

{
    solve
    (
        fvm::ddt(rho, e)
      + fvm::div(phi, e)
      - fvm::laplacian(turbulence->alphaEff(), e)
    ==
      - p*fvc::div(phi/fvc::interpolate(rho))
    );

    thermo.correct();
}
volScalarField h
(
    IOobject
    (
        "h",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    e+p/rho
);


immortality June 15, 2013 12:51

Bruno its the error:
Code:

ehsan@Ehsan-com:~/Desktop/Solvers/sonicFoamWGMaxCo_220$ wmake
Making dependency list for source file sonicFoamModified.C
SOURCE=sonicFoamModified.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam220/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam220/src/turbulenceModels/compressible/turbulenceModel -I/opt/openfoam220/src/finiteVolume/lnInclude -I/opt/openfoam220/src/finiteVolume/cfdTools -I/opt/openfoam220/src/meshTools/lnInclude -I/opt/openfoam220/src/sampling/lnInclude -I/opt/openfoam220/src/fvOptions/lnInclude -IlnInclude -I. -I/opt/openfoam220/src/OpenFOAM/lnInclude -I/opt/openfoam220/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/sonicFoamModified.o
In file included from sonicFoamModified.C:64:0:
eEqn.H: In function ‘int main(int, char**)’:
eEqn.H:25:1: error: no matching function for call to ‘Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject, Foam::fvMesh&, Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >)’
eEqn.H:25:1: note: candidates are:
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:605:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&, const wordList&, const wordList&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::wordList = Foam::List<Foam::word>]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:605:1: note:  no known conversion for argument 2 from ‘Foam::fvMesh’ to ‘const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&’
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:570:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&, const Foam::word&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:570:1: note:  no known conversion for argument 2 from ‘Foam::fvMesh’ to ‘const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&’
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:540:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::word&, const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:540:1: note:  candidate expects 2 arguments, 3 provided
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:507:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::word&, const Foam::GeometricField<Type, PatchField, GeoMesh>&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:507:1: note:  candidate expects 2 arguments, 3 provided
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:475:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:475:1: note:  candidate expects 2 arguments, 3 provided
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:444:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:444:1: note:  candidate expects 1 argument, 3 provided
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:412:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::GeometricField<Type, PatchField, GeoMesh>&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:412:1: note:  candidate expects 1 argument, 3 provided
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:371:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dictionary&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:371:1: note:  no known conversion for argument 3 from ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ to ‘const Foam::dictionary&’
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:331:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:331:1: note:  candidate expects 2 arguments, 3 provided
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:304:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensionSet&, const Foam::Field<TypeR>&, const Foam::PtrList<PatchField<Type> >&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:304:1: note:  candidate expects 5 arguments, 3 provided
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:274:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensioned<Form>&, const wordList&, const wordList&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh, Foam::wordList = Foam::List<Foam::word>]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:274:1: note:  candidate expects 5 arguments, 3 provided
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:245:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensioned<Form>&, const Foam::word&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:245:1: note:  no known conversion for argument 3 from ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ to ‘const Foam::dimensioned<double>&’
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:217:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensionSet&, const wordList&, const wordList&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh, Foam::wordList = Foam::List<Foam::word>]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:217:1: note:  candidate expects 5 arguments, 3 provided
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:187:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensionSet&, const Foam::word&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
/opt/openfoam220/src/OpenFOAM/lnInclude/GeometricField.C:187:1: note:  no known conversion for argument 3 from ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ to ‘const Foam::dimensionSet&’
/opt/openfoam220/src/finiteVolume/lnInclude/readPISOControls.H:3:15: warning: unused variable ‘nOuterCorr’ [-Wunused-variable]
/opt/openfoam220/src/finiteVolume/lnInclude/readPISOControls.H:12:16: warning: unused variable ‘momentumPredictor’ [-Wunused-variable]
/opt/openfoam220/src/finiteVolume/lnInclude/readPISOControls.H:15:16: warning: unused variable ‘transonic’ [-Wunused-variable]
make: *** [Make/linux64GccDPOpt/sonicFoamModified.o] Error 1


wyldckat June 15, 2013 13:04

I'm trying this myself and it doesn't work. "p/rho" doesn't have the same units as "e" (edit: or structure?).

But I've just now remembered something... what thermal properties have you defined for your case?
Because the "e" field is in fact "thermo.he()", which means that it can be "h", depending on the options, therefore not requiring any additional coding.

immortality June 15, 2013 13:45

yes they both have the same dimension.
no it doesn't accept enthalpy as the bug link you gave confirm it.maybe can replace it by R*T that R is approximately 287.14 for air
is it possible?
in general adding a new field from existing fields doesn't have a routine method?

wyldckat June 15, 2013 15:07

Hi Ehsan,

Sorry, but something strange happened back then. I know that compiling went wrong when using "h = e + p/rho", but now it's working... very strange :confused:...

OK, the modifications I did were as follows:
  1. Edit the file "createFields.H" and append the following code:
    Code:

        volScalarField h
        (
            IOobject
            (
                "h",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::AUTO_WRITE
            ),
            e
        );

    Note: "e" instead of "mesh" is for initializing the field with the same dimensions.
  2. Then edit the file "eEqn.H" and add this line before the last "}":
    Code:

    h = e + p/rho;
  3. Don't forget to save the files (I might have forgotten to do this step a few hours ago :().
Then run:
Code:

wmake
And this is all it takes!


_____________
In regards to the initial idea, I had forgotten that the following:
Code:

volScalarField h
(
    IOobject
    (
        "h",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    e+p/rho
);

should only be used when:
  1. The "e+p/rho" gave only a dimensioned scalar, not a complete dimensioned scalar field.
  2. "MUST_READ" would have given you troubles, since you only wanted to calculate it after everything was done...
Best regards,
Bruno


All times are GMT -4. The time now is 17:45.