CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Can I get OpenFOAM to Calculate Energy Flux for me?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 13, 2016, 08:21
Default Can I get OpenFOAM to Calculate Energy Flux for me?
  #1
New Member
 
Evan
Join Date: May 2016
Posts: 23
Rep Power: 9
k13113y is on a distinguished road
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 is offline   Reply With Quote

Old   September 13, 2016, 08:40
Default
  #2
New Member
 
Evan
Join Date: May 2016
Posts: 23
Rep Power: 9
k13113y is on a distinguished road
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.

Last edited by k13113y; September 13, 2016 at 08:41. Reason: code blocks
k13113y is offline   Reply With Quote

Old   September 13, 2016, 09:18
Default
  #3
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29
akidess will become famous soon enough
foamCalc multiply p U:
https://openfoamwiki.net/index.php/Contrib_foamCalcEx
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
akidess is offline   Reply With Quote

Old   September 13, 2016, 09:22
Default
  #4
New Member
 
Join Date: May 2016
Posts: 28
Rep Power: 9
g.freeman is on a distinguished road
Quote:
Originally Posted by k13113y View Post
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
g.freeman is offline   Reply With Quote

Old   September 13, 2016, 09:24
Default
  #5
New Member
 
Evan
Join Date: May 2016
Posts: 23
Rep Power: 9
k13113y is on a distinguished road
hey this is great!! Many thanks

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...
k13113y is offline   Reply With Quote

Old   September 13, 2016, 09:37
Default
  #6
New Member
 
Join Date: May 2016
Posts: 28
Rep Power: 9
g.freeman is on a distinguished road
Quote:
Originally Posted by k13113y View Post
hey this is great!! Many thanks

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.
g.freeman is offline   Reply With Quote

Old   September 13, 2016, 09:45
Default
  #7
New Member
 
Evan
Join Date: May 2016
Posts: 23
Rep Power: 9
k13113y is on a distinguished road
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.
k13113y is offline   Reply With Quote

Old   September 13, 2016, 09:49
Default
  #8
New Member
 
Join Date: May 2016
Posts: 28
Rep Power: 9
g.freeman is on a distinguished road
I think it is because one argument in dimensionedScalar function is missing, check the edit at my last post
g.freeman is offline   Reply With Quote

Old   September 13, 2016, 09:56
Default
  #9
New Member
 
Evan
Join Date: May 2016
Posts: 23
Rep Power: 9
k13113y is on a distinguished road
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 is offline   Reply With Quote

Old   September 13, 2016, 12:15
Default
  #10
New Member
 
Evan
Join Date: May 2016
Posts: 23
Rep Power: 9
k13113y is on a distinguished road
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.

k13113y is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to calculate the flux of this term grad(alpha1)*alphaf*U? keepfit OpenFOAM Running, Solving & CFD 2 June 9, 2016 15:08
How to calculate the flux of this term grad(alpha1)*alphaf*U? keepfit OpenFOAM 0 June 6, 2016 10:42
Not able to calculate wall heat flux in cfd post vikasy123 FLUENT 1 November 21, 2015 00:44
Compare 2D axi-symmetric and 3D. Is OpenFOAM calculate the velocity wrong? RalphS OpenFOAM 6 November 13, 2010 20:51
Why FVM for high-Re flows? Zhong Lei Main CFD Forum 23 May 14, 1999 13:22


All times are GMT -4. The time now is 03:01.