CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Can I get OpenFOAM to Calculate Energy Flux for me? (https://www.cfd-online.com/Forums/openfoam-post-processing/177430-can-i-get-openfoam-calculate-energy-flux-me.html)

k13113y September 13, 2016 08:21

Can I get OpenFOAM to Calculate Energy Flux for me?
 
Hi all,

I'm running a simulation that propagates internal waves through a stratified fluid and I want to calculate the energy flux at various points throughout my domain over time.

The formula for energy flux is simply J = pU and I already have output files for p and U for each time step.

My question is, how do I get OpenFOAM to multiply pressure and velocity and generate a new output file called "energyFlux"?

Thanks :)

k13113y September 13, 2016 08:40

So far I have:

Code:

volVectorField
(
    IOobject
    (
        "energyFlux",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    p*U
);

written into the createFields.H file of the interDyMFoam Solver. But I'm unsure of whether this is the right format and how I should recompile the solver.

akidess September 13, 2016 09:18

foamCalc multiply p U:
https://openfoamwiki.net/index.php/Contrib_foamCalcEx

g.freeman September 13, 2016 09:22

Quote:

Originally Posted by k13113y (Post 617734)
So far I have:

Code:

volVectorField
(
    IOobject
    (
        "energyFlux",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    p*U
);

written into the createFields.H file of the interDyMFoam Solver. But I'm unsure of whether this is the right format and how I should recompile the solver.

Hello, the correct versione should be like:

Code:


const vector energyFlux = p*U

volVectorField energyFlux
(
    IOobject
    (
        "energyFlux",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    dimensionedScalar("energyFlux",p.dimension*U.dimension,)
);

You need to specify AUTO_WRITE otherwise it will not write anything. You're right when you say to write it into createField.H file; for recompiling the solver just go into the solver folder, in you case $FOAM_SOLVERS/multiphase/interFoam/interDyMFoam, and type wclean, then wmake.

Hope this is useful for you :)

k13113y September 13, 2016 09:24

hey this is great!! Many thanks :D

My only question now is: does it matter where I place it in the createFields.H file? I'm assuming it must be after p and U...

g.freeman September 13, 2016 09:37

Quote:

Originally Posted by k13113y (Post 617741)
hey this is great!! Many thanks :D

My only question now is: does it matter where I place it in the createFields.H file? I'm assuming it must be after p and U...

It doesn't matter since it only reads the fields and then creates the output files.
In the past I've never cared where I write and it has always worked

EDIT: there's a mistake in the last line of the code: after p.dimension()*U.dimension(), after the comma you need to write 0.0.

Code:

dimensionedScalar('energyFlux",p.dimension()*U.dimension(),0.0)
If you prefer you can also specify the dimensions as dimMass/dimTime/dimTime/dimTime, which is pU dimensions.

k13113y September 13, 2016 09:45

Hmm I seem to be getting an error when I try to compile.

Code:

Info<< "Reading field energyFlux\n" <<endl;
const vector energyFlux=p_rgh*U;
volVectorField energyFlux
(
    IOobject
    (
        "energyFlux",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
);

Code:

In file included from /opt/openfoam4/src/OpenFOAM/lnInclude/postProcess.H:129:0,
                from interEnergyFluxFoam.C:58:
./createFields.H: In function ‘int main(int, char**)’:
./createFields.H:32:30: error: conversion from ‘Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >’ to non-scalar type ‘const vector {aka const Foam::Vector<double>}’ requested
 const vector energyFlux=p_rgh*U;
                              ^
./createFields.H:36:5: error: conflicting declaration ‘Foam::volVectorField energyFlux’
    (
    ^
./createFields.H:32:14: note: previous declaration as ‘const vector energyFlux’
 const vector energyFlux=p_rgh*U;
              ^
./createFields.H:43:42: error: ‘Foam::volScalarField {aka class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                                          ^
./createFields.H:43:54: error: ‘Foam::volVectorField {aka class Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                                                      ^
./createFields.H:43:22: error: expected primary-expression before ‘(’ token
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                      ^
./createFields.H:43:42: error: ‘Foam::volScalarField {aka class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                                          ^
./createFields.H:43:54: error: ‘Foam::volVectorField {aka class Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                                                      ^
./createFields.H:43:64: error: expected primary-expression before ‘)’ token
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                                                                ^
In file included from interEnergyFluxFoam.C:67:0:
createFields.H:32:30: error: conversion from ‘Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >’ to non-scalar type ‘const vector {aka const Foam::Vector<double>}’ requested
 const vector energyFlux=p_rgh*U;
                              ^
createFields.H:36:5: error: conflicting declaration ‘Foam::volVectorField energyFlux’
    (
    ^
createFields.H:32:14: note: previous declaration as ‘const vector energyFlux’
 const vector energyFlux=p_rgh*U;
              ^
createFields.H:43:42: error: ‘Foam::volScalarField {aka class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                                          ^
createFields.H:43:54: error: ‘Foam::volVectorField {aka class Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                                                      ^
createFields.H:43:22: error: expected primary-expression before ‘(’ token
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                      ^
createFields.H:43:42: error: ‘Foam::volScalarField {aka class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                                          ^
createFields.H:43:54: error: ‘Foam::volVectorField {aka class Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                                                      ^
createFields.H:43:64: error: expected primary-expression before ‘)’ token
    dimensionedScalar("energyFlux",p_rgh.dimension*U.dimension,)
                                                                ^
/opt/openfoam4/wmake/rules/General/transform:8: recipe for target 'Make/linux64GccDPInt32Opt/interEnergyFluxFoam.o' failed
make: *** [Make/linux64GccDPInt32Opt/interEnergyFluxFoam.o] Error 1

I tried removing the dimension and the const variable and the application compiled but the file never appeared in the output.

g.freeman September 13, 2016 09:49

I think it is because one argument in dimensionedScalar function is missing, check the edit at my last post

k13113y September 13, 2016 09:56

ah sorry, it still has a similar error. I'm using OF 4.0 but I don't think that should matter.

Code:

In file included from /opt/openfoam4/src/OpenFOAM/lnInclude/postProcess.H:129:0,
                from interEnergyFluxFoam.C:58:
./createFields.H: In function ‘int main(int, char**)’:
./createFields.H:32:30: error: conversion from ‘Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >’ to non-scalar type ‘const vector {aka const Foam::Vector<double>}’ requested
 const vector energyFlux=p_rgh*U;
                              ^
./createFields.H:36:5: error: conflicting declaration ‘Foam::volVectorField energyFlux’
    (
    ^
./createFields.H:32:14: note: previous declaration as ‘const vector energyFlux’
 const vector energyFlux=p_rgh*U;
              ^
./createFields.H:43:42: error: ‘Foam::volScalarField {aka class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension()*U.dimension(),0.0)
                                          ^
./createFields.H:43:56: error: ‘Foam::volVectorField {aka class Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension()*U.dimension(),0.0)
                                                        ^
In file included from interEnergyFluxFoam.C:67:0:
createFields.H:32:30: error: conversion from ‘Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >’ to non-scalar type ‘const vector {aka const Foam::Vector<double>}’ requested
 const vector energyFlux=p_rgh*U;
                              ^
createFields.H:36:5: error: conflicting declaration ‘Foam::volVectorField energyFlux’
    (
    ^
createFields.H:32:14: note: previous declaration as ‘const vector energyFlux’
 const vector energyFlux=p_rgh*U;
              ^
createFields.H:43:42: error: ‘Foam::volScalarField {aka class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension()*U.dimension(),0.0)
                                          ^
createFields.H:43:56: error: ‘Foam::volVectorField {aka class Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>}’ has no member named ‘dimension’
    dimensionedScalar("energyFlux",p_rgh.dimension()*U.dimension(),0.0)
                                                        ^
/opt/openfoam4/wmake/rules/General/transform:8: recipe for target 'Make/linux64GccDPInt32Opt/interEnergyFluxFoam.o' failed
make: *** [Make/linux64GccDPInt32Opt/interEnergyFluxFoam.o] Error 1


k13113y September 13, 2016 12:15

Okay I have managed to make it work.

Here is what I added to my createFields.H file:

Code:

// Adding a new field: energyFlux

Info<< "Reading field energyFlux\n" <<endl;
volVectorField energyFlux
(
    IOobject
    (
        "energyFlux",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    p_rgh*U
);

and I also made a new file called energyFluxEqn.H inside the interDyMFoam folder (which is the solver I am using). That file is simple and looks like this:

Code:

{
    energyFlux == p_rgh * U;
}

Then I ran:

Code:

wclean
wmake

And now each write interval contains a file called energyFlux.

;)


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