CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Entropy calculation in OpenFoam (https://www.cfd-online.com/Forums/openfoam/116694-entropy-calculation-openfoam.html)

immortality April 23, 2013 08:37

Entropy calculation in OpenFoam
 
I have found a figure of entropy in this article that has made by OpenFOAM:
I'm wondering if does OF calculates entropy?which solvers does have it?I couldn't find a useful thread about this subject in the forum.
that can improve my work and the conclusions.
can anyone guide me through?

immortality April 23, 2013 21:08

hi all again
does anyone know an example for adding entropy equation to any of the compressible (or even other) solvers?
It this work possible with a rational effort?or is too complicated?
Has anyone think about this subject (seeing entropy values) so far?
I thank any of thoughts

immortality April 24, 2013 12:48

no any opinion about entropy in OpenFOAM?
does have a solver calculate entropy?
any hint?

immortality April 25, 2013 02:09

no one is interested?

immortality April 26, 2013 22:25

how i can't find anything useful in the forum search related to this subject?
Means no one has ever thought about?!!

wyldckat April 29, 2013 18:56

Hi Ehsan,

According to the paper you've indicated, it seems that the solver "rhoCentralFoam" was used to calculate entropy.

I've searched OpenFOAM's source code with the following command:
Code:

find $FOAM_SRC -name "*.[CH]" | xargs grep -isl 'Entropy'
It will look in the "$FOAM_SRC" folder, look for files with extension "C" or "H" and indicate which files have the text "Entropy" in them. For more on this: http://www.cfd-online.com/Forums/ope...tml#post328484 - post #8

The same could be done with the text editor "Kate", which can find text inside files on a particular folder.

The files that were found were:
Code:

./thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.H
./thermophysicalModels/reactionThermo/mixtures/basicMultiComponentMixture/basicMultiComponentMixture.H
./thermophysicalModels/specie/thermo/eConst/eConstThermo.H
./thermophysicalModels/specie/thermo/hPolynomial/hPolynomialThermo.C
./thermophysicalModels/specie/thermo/hPolynomial/hPolynomialThermo.H
./thermophysicalModels/specie/thermo/thermo/thermo.H
./thermophysicalModels/specie/thermo/hConst/hConstThermo.H
./thermophysicalModels/specie/thermo/janaf/janafThermo.H
./thermophysicalModels/specie/thermo/hExponential/hExponentialThermo.H

From what I can see, you can easily adapt the utility that calculates "Cp" to calculate "S", namely: http://www.cfd-online.com/Forums/ope...cp-values.html


As for not find much information on this topic: it's OpenFOAM. It's only natural that there are several undocumented or poorly documented details about OpenFOAM's features. But the great thing about OpenFOAM is that the source code is completely open for anyone to look at it and study it :D

Best regards,
Bruno

immortality April 30, 2013 06:52

thanks so much.
then entropy is calculated but not is shown.could simply change this behavior?(I have tested simple things like MUST_WRITE without success)
will specificHeat.C work by changing only Cp to s or how?
--------------------------
hi again
I made little changes like this:
Code:

int main(int argc, char *argv[])
{
    timeSelector::addOptions();

#  include "setRootCase.H"
#  include "createTime.H"

    instantList timeDirs = timeSelector::select0(runTime, args);

#  include "createMesh.H"

    forAll(timeDirs, timeI)
    {
        runTime.setTime(timeDirs[timeI], timeI);

        Info<< "Time = " << runTime.timeName() << endl;

        mesh.readUpdate();

        Info<< "Re-reading thermophysical properties\n" << endl;
        autoPtr<psiThermo> pThermo
        (
            psiThermo::New(mesh)
        );
        psiThermo& thermo = pThermo();
        thermo.validate(args.executable(), "s");

        Info<< "    Calculating entropy" << endl;
        volScalarField s
        (
            IOobject
            (
                "s",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ
            ),
            thermo.s()
        );

        s.write();

        Info<< endl;
    }

    Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
        << "  ClockTime = " << runTime.elapsedClockTime() << " s"
        << nl << endl;

    Info<< "End\n" << endl;

    return 0;
}

but the error is:
Code:

SOURCE=entropy.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/finiteVolume/lnInclude -IlnInclude -I. -I/opt/openfoam220/src/OpenFOAM/lnInclude -I/opt/openfoam220/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/entropy.o
entropy.C: In function ‘int main(int, char**)’:
entropy.C:70:20: error: ‘class Foam::psiThermo’ has no member named ‘s’
make: *** [Make/linux64GccDPOpt/entropy.o] Error 1

why psiThermo doesn't know s?

wyldckat April 30, 2013 17:45

Quote:

Originally Posted by immortality (Post 424138)
why psiThermo doesn't know s?

:confused:

I wrote "S", not "s"! ;)
Quote:

Originally Posted by wyldckat (Post 424034)
you can easily adapt the utility that calculates "Cp" to calculate "S"


immortality May 1, 2013 03:51

in the solver its s.I changed s to S but erroe is same:
Code:

Making dependency list for source file entropy.C
SOURCE=entropy.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/finiteVolume/lnInclude -IlnInclude -I. -I/opt/openfoam220/src/OpenFOAM/lnInclude -I/opt/openfoam220/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/entropy.o
entropy.C: In function ‘int main(int, char**)’:
entropy.C:70:20: error: ‘class Foam::psiThermo’ has no member named ‘S’
make: *** [Make/linux64GccDPOpt/entropy.o] Error 1

please have a look into it yourself !:D

wyldckat May 1, 2013 08:21

Hi Ehsan,

I didn't test it myself before... and I was assuming that if there was a "Cp", there should be an "S" as well... but apparently it doesn't exist yet! Looks like the OpenFOAM authors never needed a complete entropy field.

And this isn't very simple to solve either. Here's the situation:
  1. The "S" method I saw is present in the "species" class, which means that it calculates only for a single value, not all values in a field.
  2. Problem is that the "species" information is deeply embedded into the thermodynamics mechanism that OpenFOAM uses.
  3. So the simplest solution would be to add a new method "S", which was copied-pasted-changed from the "Cp" method that is present in "heThermo": https://github.com/OpenFOAM/OpenFOAM...asic/heThermo/
    edit: In other words, copy the methods named "Cp" to "S" inside the class "heThermo".
  4. The same would have to be done to the "basicThermo" class.
  5. Then rebuild "src/thermophysicalModels/basic" library.
This may seem simple, but a lot more changes might be necessary for this to actually properly work.
Worst thing is that this requires changing the core source code in OpenFOAM, which I don't know if you want to do this, since this would add even more complexity to your thesis, just because you need to calculate the entropy.

I'm going to look a bit more into this, because I think I overlooked something... but I don't know when I might find a better answer for this.

Best regards,
Bruno

wyldckat May 1, 2013 15:35

1 Attachment(s)
Hi Ehsan,

I think you can consider yourself very lucky today! I've managed to figure out a solution without having to hack directly into OpenFOAM's source code!
It took some C++ voodoo (mostly tricks with templates and macros), but it works!

The only downside is that you have to modify the source code every time you change "thermoType" in "constant/thermophysicalProperties".
This is exemplified in the comment section in "entropy.C" that starts with:
Code:

/*
For reference:

    makeTheLenghtyTypedefName(

The code that will need changing is this block:
Code:

//Define here the components of the thermodynamic class
#define myLengthyThermoClass makeTheLenghtyTypedefName( \
      psiThermo, \
      hePsiThermo, \
      pureMixture, \
      sutherlandTransport, \
      sensibleEnthalpy, \
      janafThermo, \
      perfectGas, \
      specie \
      )

The final application is named entropy. To build it, simply run:
Code:

wmake
Note about OpenFOAM 2.2.0: See post #17
______________________

Now, explain what I had to do:
  1. Read the following post for an introduction into this topic: http://www.cfd-online.com/Forums/ope...tml#post424475 - post #12
  2. I had to create a header file that locally replaces "makeThermo.H". You can see it inside the attached file.
  3. Then include both this header file and the file "psiThermos.C", which is originally used to create all of the "psiThermo" models, but with our local "makeThermo.H" file, we recreate the typedefs.
  4. This way we now have access to all of the basic "psiThermo" models, as shown here: https://github.com/OpenFOAM/OpenFOAM...o/psiThermos.C
  5. Now, since the naming scheme is quite cumbersome, I added a local definition that helps concatenate the typedef on the demand, namely with the following macros:
    • "makeTheLenghtyTypedefName" - this macro helps concatenate the local typedef we will be using.
    • "myLengthyThermoClass" - this is an alias for the local typedef we will be using.
  6. So instead of creating an "autoptr<psiThermo>" as it is usually done in solvers and utilities, we now use the "myLengthyThermoClass" alias and use it directly to instantiate the "thermo" variable.
  7. This way, we have access to stuff that isn't accessible from "psiThermo", more specifically we can access the "pureMixture" class, which gives us access to all of the species, janaf/thermo and gas properties that we usually don't have access to! :D
  8. Then, since we need to calculate the entropy "S" for all of the volume cells and patch faces, I copy-paste-adapted the contents of the method "Cp()" from "src/thermophysicalModels/basic/heThermo/heThermo.C", directly into the main application source code file "entropy.C".
And that's all there is to it! :rolleyes:

There's going to be some more people interested in this, because this gives access to the methods for the currently loaded thermodynamic sub-models!

Best regards,
Bruno

immortality May 1, 2013 15:41

then s is only there and they never have used it?
so there is a lot of work to do with it.could find the equation that entropy calculated from that?
if it can be done is very nice.but if is so complicated never mind!:D
----------------------
your post received after mine!
really it works?I don't believe it!:D
its second chance i get today.except for this I figured out an issue i was engaged with for months!what a nice day!:D
surprising.I'll test it soon.
i think this thread of mine was a brilliant one and so valuable like those effective questions you had told me about before!:D;)
the second one is http://www.cfd-online.com/Forums/ope...cp-values.html
and third prize with a small distance belongs to:
http://www.cfd-online.com/Forums/ope...uring-run.html :D
but no prize I have awarded yet!:D:rolleyes:
I'm happy that it can help others.
thank you very much.:)
(what a post with a lot of big grin icon):D

wyldckat May 1, 2013 15:49

Quote:

Originally Posted by immortality (Post 424493)
then s is only there and they never have used it?

"S" probably is used internally, but doesn't seem to be used for external consumption, such as generating the complete "S" field.

Quote:

Originally Posted by immortality (Post 424493)
could find the equation that entropy calculated from that?

:confused: I don't understand the question... do you mean:
  1. Is it possible to find out how "S" is actually calculated?
  2. (Or) Is is possible to find what "S" is being used for internally in OpenFOAM?

immortality May 1, 2013 16:12

I edited the before post.;)
I think 1 is more near to my intention.
what does 2 mean?:D

wyldckat May 1, 2013 16:37

Quote:

Originally Posted by wyldckat (Post 424496)
1. Is it possible to find out how "S" is actually calculated?[/LIST]

Let's see...
Quote:

https://github.com/OpenFOAM/OpenFOAM...thermoI.H#L252
Code:

template<class Thermo, template<class> class Type>
inline Foam::scalar
Foam::species::thermo<Thermo, Type>::S(const scalar p, const scalar T) const
{
    return this->s(p, T)/this->W();
}


So, it's calculated from the molar entropy, divided by the molecular weight.

The molar entropy is calculated depending on the equation of state. For example, in "janaf" it's calculated in this method:
Quote:

https://github.com/OpenFOAM/OpenFOAM...ThermoI.H#L213
Code:

template<class EquationOfState>
inline Foam::scalar Foam::janafThermo<EquationOfState>::s
(
    const scalar p,
    const scalar T
) const
{
    const coeffArray& a = coeffs(T);
    return
    this->RR*
    (
        (((a[4]/4.0*T + a[3]/3.0)*T + a[2]/2.0)*T + a[1])*T + a[0]*::log(T)
      + a[6]
    );
}




As for the other question:
Quote:

Originally Posted by wyldckat (Post 424496)
2. (Or) Is is possible to find what "S" is being used for internally in OpenFOAM?[/LIST]

In other words: if "S" is not accessible externally, then what is it used for internally?
Answer: looks like it's mostly for calculating "Gibbs free energy - g()" and "Helmholtz free energy - a()": https://github.com/OpenFOAM/OpenFOAM...thermoI.H#L172

All of this was found thanks to the Doxygen generated documentation: http://www.openfoam.org/docs/cpp/

immortality May 2, 2013 09:42

hi
it displayes this error when compiling:
Code:

ehsan@Ehsan-com:~/Desktop/entropyHePsi$ wmake
Making dependency list for source file entropy.C
could not open file cyclicAMILduInterfaceField.H for source file entropy.C
could not open file cyclicAMILduInterface.H for source file entropy.C
could not open file cyclicAMIPolyPatch.H for source file entropy.C
SOURCE=entropy.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/thermophysicalModels/specie/lnInclude -I/opt/openfoam220/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/openfoam220/src/OpenFOAM/lnInclude -I/opt/openfoam220/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/entropy.o
In file included from /opt/openfoam220/src/finiteVolume/lnInclude/jumpCyclicAMIFvPatchField.H:47:0,
                from /opt/openfoam220/src/finiteVolume/lnInclude/fixedJumpAMIFvPatchField.H:71,
                from /opt/openfoam220/src/finiteVolume/lnInclude/fixedJumpAMIFvPatchFields.H:29,
                from /opt/openfoam220/src/thermophysicalModels/basic/lnInclude/heThermo.C:32,
                from /opt/openfoam220/src/thermophysicalModels/basic/lnInclude/heThermo.H:320,
                from /opt/openfoam220/src/thermophysicalModels/basic/lnInclude/hePsiThermo.H:39,
                from /opt/openfoam220/src/thermophysicalModels/basic/lnInclude/psiThermos.C:41,
                from entropy.C:32:
/opt/openfoam220/src/finiteVolume/lnInclude/cyclicAMIFvPatchField.H:62:40: fatal error: cyclicAMILduInterfaceField.H: No such file or directory
compilation terminated.
make: *** [Make/linux64GccDPOpt/entropy.o] Error 1


wyldckat May 2, 2013 10:01

OpenFOAM 2.2.0 has some broken stuff that has been already been fixed in 2.2.x....

Anyway, the quick fix is as follows:
  1. Edit the file "Make/options" and replace:
    Code:

    EXE_INC = \
        -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
        -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
        -I$(LIB_SRC)/finiteVolume/lnInclude

    For this:
    Code:

    EXE_INC = \
        -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
        -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
        -I$(LIB_SRC)/meshTools/lnInclude \
        -I$(LIB_SRC)/finiteVolume/lnInclude

  2. Then run:
    Code:

    wclean
    wmake


immortality May 2, 2013 10:37

thank you.it works except one of the cases:D.the error in this case is this:
Code:

ehsan@Ehsan-com:~/Desktop/WR_pimple_p$ entropy
/*---------------------------------------------------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.2.0                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
Build  : 2.2.0-b363e8d14789
Exec  : entropy
Date  : May 02 2013
Time  : 18:59:03
Host  : "Ehsan-com"
PID    : 7363
Case  : /home/ehsan/Desktop/WR_pimple_p
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Time = 0
Re-reading thermophysical properties

--> FOAM Warning :
    From function polyBoundaryMesh::groupPatchIDs() const
    in file meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C at line 474
    Patch empty specifies a group empty which is also a patch name. This might give problems later on.
--> FOAM Warning :
    From function groovyBCFvPatchField<Type>::groovyBCFvPatchField(const fvPatch& p,const DimensionedField<Type, volMesh>& iF,const dictionary& dict)
    in file groovyBCFvPatchField.C at line 131
    No value defined for T on right therefore using 20{0}
--> FOAM Warning :
    From function groovyBCFvPatchField<Type>::groovyBCFvPatchField(const fvPatch& p,const DimensionedField<Type, volMesh>& iF,const dictionary& dict)
    in file groovyBCFvPatchField.C at line 131
    No value defined for T on left therefore using 20{0}
#0  Foam::error::printStack(Foam::Ostream&) in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#1  Foam::sigFpe::sigHandler(int) in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#2  in "/lib/x86_64-linux-gnu/libc.so.6"
#3  Foam::hePsiThermo<Foam::psiThermo, Foam::pureMixture<Foam::sutherlandTransport<Foam::species::thermo<Foam::janafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> > > >::calculate() in "/home/ehsan/OpenFOAM/ehsan-2.2.0/platforms/linux64GccDPOpt/bin/entropy"
#4 
 in "/home/ehsan/OpenFOAM/ehsan-2.2.0/platforms/linux64GccDPOpt/bin/entropy"
#5  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#6 
 in "/home/ehsan/OpenFOAM/ehsan-2.2.0/platforms/linux64GccDPOpt/bin/entropy"
Floating point exception

is it related to S?
S dimensions is in SI,correct?
is there any real gas model in OF rather than perfectGas?

wyldckat May 2, 2013 10:41

The problem is that the T field is not properly defined for the time instance "0". It's assuming values of 0 K (zero Kelvin!) for the "left" and "right" patches, which therefore leads to some massive problems!

Try:
Code:

entropy -time '1e-30:'

immortality September 8, 2013 09:18

Hi Bruno
I changed the dictionary for one of my cases as this:
Code:

#define myLengthyThermoClass makeTheLenghtyTypedefName( \
      psiThermo, \
      hePsiThermo, \
      pureMixture, \
      constTransport, \
      sensibleEnthalpy, \
      hConstThermo, \
      perfectGas, \
      specie \
      )

but this is the error:
Code:

Create time

Create mesh for time = 0.01586

Time = 0.01586
Re-reading thermophysical properties

[3]
[3]
[3] --> FOAM FATAL ERROR:
[3] Not implemented
[3]
[3]    From function scalar hConstThermo<equationOfState>::s(const scalar p, const scalar T) const
[3]    in file /opt/openfoam220/src/thermophysicalModels/specie/lnInclude/hConstThermoI.H at line 150.
[3]
FOAM parallel run aborting
[3]
[3] #0  Foam::error::printStack(Foam::Ostream&) in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
[3] #1  Foam::error::abort()[1]    Calculating S
[0]
[0]
[0] --> FOAM FATAL ERROR:
[0] Not implemented
[0]
[0]    From function scalar hConstThermo<equationOfState>::s(const scalar p, const scalar T) const
[0]    in file /opt/openfoam220/src/thermophysicalModels/specie/lnInclude/hConstThermoI.H at line 150.
[0]
FOAM parallel run aborting
[0]
 in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
[3] #2  [2]
[2]
[2] --> FOAM FATAL ERROR:
[2] Not implemented
[2]
[2]    From function scalar hConstThermo<equationOfState>::s(const scalar p, const scalar T) const
[2]    in file /opt/openfoam220/src/thermophysicalModels/specie/lnInclude/hConstThermoI.H at line 150.
[2]
FOAM parallel run aborting
[2]

[1]
[1] --> FOAM FATAL ERROR:
[1] Not implemented
[1]
[1]    From function scalar hConstThermo<equationOfState>::s(const scalar p, const scalar T) const
[1]    in file /opt/openfoam220/src/thermophysicalModels/specie/lnInclude/hConstThermoI.H at line 150.
[1]
FOAM parallel run aborting
[1]
[2] #0  Foam::error::printStack(Foam::Ostream&)[0] #0  Foam::error::printStack(Foam::Ostream&)[1] #0  Foam::error::printStack(Foam::Ostream&)
[3]  in "/home/ehsan/OpenFOAM/ehsan-2.2.0/platforms/linux64GccDPOpt/bin/entropyConst"
[3] #3  __libc_start_main in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
[2] #1  Foam::error::abort() in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
[0] #1  Foam::error::abort() in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
[1] #1  Foam::error::abort() in "/lib/x86_64-linux-gnu/libc.so.6"
[3] #4  in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
[2] #2  in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
[1] #2 

--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 3 in communicator MPI_COMM_WORLD
with errorcode 1.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------
[3]  in "/home/ehsan/OpenFOAM/ehsan-2.2.0/platforms/linux64GccDPOpt/bin/entropyConst"
 in "/opt/openfoam220/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
[0] #2 

[2]  in "/home/ehsan/OpenFOAM/ehsan-2.2.0/platforms/linux64GccDPOpt/bin/entropyConst"
[2] #3  __libc_start_main[1]  in "/home/ehsan/OpenFOAM/ehsan-2.2.0/platforms/linux64GccDPOpt/bin/entropyConst"
[1] #3  __libc_start_main--------------------------------------------------------------------------
mpirun has exited due to process rank 3 with PID 6760 on
node Ehsan-com exiting without calling "finalize". This may
have caused other processes in the application to be
terminated by signals sent by mpirun (as reported here).
--------------------------------------------------------------------------

:confused:


All times are GMT -4. The time now is 08:02.