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

Write a calculated variable to postProcessing

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 18, 2021, 10:38
Default Write a calculated variable to postProcessing
  #1
Member
 
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 5
Vitor Monteiro is on a distinguished road
Hello, friends!


I'm trying to analyze the total mass of each component of my multi phase (fluidized bed pirolysis) simulations due time.

The total mass is calculated by the integration of (alphaGas*rhoGas) through volumes.

I've been trying it adding a controlDict coded function.

I've tried to use the simple calculations but I could have not write it to a file to plot data. Like this, mGas.write() doesn't work:

Code:
totalMass
{
    type            coded;
    libs            ("libutilityFunctionObjects.so");
    name            totalMass;
    writeControl    timeStep;

    codeWrite
    #{
        const volScalarField& alphaGas = mesh().lookupObject<volScalarField>("alpha.gas");
        const volScalarField& rhoGas = mesh().lookupObject<volScalarField>("thermo:rho.gas");
        const scalarField& v = mesh().V();

        const double& mGas = gSum(alphaGas*rhoGas*v);

        Info<< "coded totalMass output:" << endl
            << "    volIntegrate(all) for alpha.gas*rho.gas = "      << mGas << endl
            << endl;
    
        mGas.write();

    #};
}
Then i've tried to write the new variable as a field. This way I can write it but gSum integration didn't work.

Code:
totalMass
{
    type            coded;
    libs            ("libutilityFunctionObjects.so");
    name            totalMass;
    writeControl    timeStep;

    codeWrite
    #{
        const volScalarField& alphaGas = mesh().lookupObject<volScalarField>("alpha.gas");
        const volScalarField& rhoGas = mesh().lookupObject<volScalarField>("thermo:rho.gas");
        const scalarField& v = mesh().V();

        Info<< "coded totalMass output:" << endl
            << "    volIntegrate(all) for alpha.gas*rho.gas = "      << gSum(alphaGas*rhoGas*v) << endl
            << endl;

        volScalarField mGas
            (
                IOobject
                (
                    "mGas",
                    mesh().time().timeName(),
                    mesh(),
                    IOobject::NO_READ,
                    IOobject::AUTO_WRITE
                ),
                gSum(alphaGas*rhoGas*v)
            )
        mGas.write();
    #};
}
Vitor Monteiro is offline   Reply With Quote

Old   March 18, 2021, 14:25
Default
  #2
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Did you try to write your scalar to a file
mAlletto is offline   Reply With Quote

Old   March 18, 2021, 14:30
Default
  #3
Member
 
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 5
Vitor Monteiro is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
Did you try to write your scalar to a file
I thought the first implementation of mGas.write() would do this. But not.

How could I write to a file?

Sorry, I'm begginer to OF.

ERROR OF THE FIRST CODE ABOVE:

Code:
/home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/system/controlDict/functions/totalMass: In member function ‘virtual bool Foam::totalMassFunctionObject::write()’:
/home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/system/controlDict/functions/totalMass:128:10: error: request for member ‘write’ in ‘mGas’, which is of non-class type ‘const double’
/opt/openfoam8/wmake/rules/General/transform:25: recipe for target 'Make/linux64GccDPInt32Opt/functionObjectTemplate.o' failed
make: *** [Make/linux64GccDPInt32Opt/functionObjectTemplate.o] Error 1

--> FOAM FATAL IO ERROR: 
Failed wmake "dynamicCode/totalMass/platforms/linux64GccDPInt32Opt/lib/libtotalMass_048a1bfbed8a92a0b430065db7859e48d887c5b6.so"


file: /home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/system/controlDict/functions/totalMass from line 48 to line 60.

    From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
    in file db/dynamicLibrary/codedBase/codedBase.C at line 206.

Inconsistency detected by ld.so: dl-close.c: 811: _dl_close: Assertion `map->l_init_called' failed!

ERROR OF THE SECOND ONE

Code:
/home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/system/controlDict/functions/totalMass: In member function ‘virtual bool Foam::totalMassFunctionObject::write()’:
/home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/system/controlDict/functions/totalMass:123:13: error: no matching function for call to ‘Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject, double)’
In file included from /opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.H:717:0,
                 from /opt/openfoam8/src/OpenFOAM/lnInclude/GeometricScalarField.H:38,
                 from /opt/openfoam8/src/OpenFOAM/lnInclude/GeometricFields.H:34,
                 from /opt/openfoam8/src/finiteVolume/lnInclude/volFields.H:37,
                 from /opt/openfoam8/src/finiteVolume/lnInclude/surfaceInterpolationScheme.C:27,
                 from /opt/openfoam8/src/finiteVolume/lnInclude/surfaceInterpolationScheme.H:308,
                 from /opt/openfoam8/src/finiteVolume/lnInclude/surfaceInterpolate.H:41,
                 from /opt/openfoam8/src/finiteVolume/lnInclude/fvc.H:39,
                 from /opt/openfoam8/src/finiteVolume/lnInclude/fvCFD.H:8,
                 from functionObjectTemplate.C:26:
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:697:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&, const wordList&, const wordList&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh; Foam::wordList = Foam::List<Foam::word>]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:697:1: note:   candidate expects 4 arguments, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:655:1: note: candidate: 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>]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:655:1: note:   candidate expects 4 arguments, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:621:1: note: candidate: 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]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:621:1: note:   candidate expects 3 arguments, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:592:1: note: candidate: 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]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:592:1: note:   no known conversion for argument 1 from ‘Foam::IOobject’ to ‘const Foam::word&’
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:561:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::word&, const Foam::GeometricField<Type, PatchField, GeoMesh>&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:561:1: note:   no known conversion for argument 1 from ‘Foam::IOobject’ to ‘const Foam::word&’
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:530:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:530:1: note:   no known conversion for argument 2 from ‘double’ to ‘const Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >&’
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:499:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:499:1: note:   no known conversion for argument 2 from ‘double’ to ‘const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>&’
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:471:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:471:1: note:   candidate expects 1 argument, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:443:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(Foam::GeometricField<Type, PatchField, GeoMesh>&&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:443:1: note:   candidate expects 1 argument, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:413:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::GeometricField<Type, PatchField, GeoMesh>&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:413:1: note:   candidate expects 1 argument, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:378:1: note: candidate: 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]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:378:1: note:   candidate expects 3 arguments, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:343:1: note: candidate: 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]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:343:1: note:   no known conversion for argument 2 from ‘double’ to ‘const Mesh& {aka const Foam::fvMesh&}’
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:317:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensionSet&, const Foam::Field<Type>&, const Foam::PtrList<PatchField<Type> >&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh; Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:317:1: note:   candidate expects 5 arguments, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:293:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Internal&, const Foam::PtrList<PatchField<Type> >&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh; Foam::GeometricField<Type, PatchField, GeoMesh>::Internal = Foam::DimensionedField<double, Foam::volMesh>]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:293:1: note:   candidate expects 3 arguments, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:266:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensioned<Type>&, 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>]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:266:1: note:   candidate expects 5 arguments, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:240:1: note: candidate: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensioned<Type>&, const Foam::word&) [with Type = double; PatchField = Foam::fvPatchField; GeoMesh = Foam::volMesh; Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:240:1: note:   candidate expects 4 arguments, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:215:1: note: candidate: 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>]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:215:1: note:   candidate expects 5 arguments, 2 provided
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:191:1: note: candidate: 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]
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 ^
/opt/openfoam8/src/OpenFOAM/lnInclude/GeometricField.C:191:1: note:   candidate expects 4 arguments, 2 provided
make: *** [Make/linux64GccDPInt32Opt/functionObjectTemplate.o] Error 1
/opt/openfoam8/wmake/rules/General/transform:25: recipe for target 'Make/linux64GccDPInt32Opt/functionObjectTemplate.o' failed

--> FOAM FATAL IO ERROR: 
Failed wmake "dynamicCode/totalMass/platforms/linux64GccDPInt32Opt/lib/libtotalMass_8c0abe8d276be6bf178da552b57d5183bd8d3f7e.so"


file: /home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/system/controlDict/functions/totalMass from line 48 to line 60.

    From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
    in file db/dynamicLibrary/codedBase/codedBase.C at line 206.

Inconsistency detected by ld.so: dl-close.c: 811: _dl_close: Assertion `map->l_init_called' failed!
Vitor Monteiro is offline   Reply With Quote

Old   March 18, 2021, 14:38
Default
  #4
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
There are a lot of threads here discussing how to write to a ASCII file. A few minutes googling openfoam write to ASCII will find a lot of pages.
mAlletto is offline   Reply With Quote

Old   March 19, 2021, 08:11
Default
  #5
Senior Member
 
Join Date: Jan 2014
Posts: 179
Rep Power: 12
hxaxtma is on a distinguished road
Code:
if (Pstream::master())
{
    std::ofstream fs;
    fs.open ("./postProcessing/stats_blablabla.dat", std::fstream::app);	
    fs.precision(12);
    fs << mesh.time().value() << "\t" << V_ << "\t" << rho_ << "\t" << p_ << "\t" << T_<< "\t" << "\n";
    fs.close();
}
hxaxtma is offline   Reply With Quote

Old   March 20, 2021, 08:06
Default
  #6
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
This piece of code is working for me. What this coded function object does is to calculate the center of mass of a bubble in each time step and write it to a file:


Code:

    centerOfGravityAir
    {
        libs        ("libutilityFunctionObjects.so");

        type coded;
        // Name of on-the-fly generated functionObject
        name writeCenterOfGravityAir;
        writeControl  timeStep;
        
        executeControl timeStep;
        
        codeOptions
        #{
            -I$(LIB_SRC)/finiteVolume/lnInclude \
            -I$(LIB_SRC)/OpenFOAM/lnInclude
        #};


        codeInclude
        #{
            #include "volFieldsFwd.H"
            #include "OFstream.H"
        #};
        
        codeData
        #{
              autoPtr<OFstream> outputFilePtr;
        #};
            
        codeRead
        #{
           
             outputFilePtr.reset(new OFstream("centerOfGravityAir.dat"));
           
        #};
        
        codeExecute
        #{
        
             const volScalarField& alpha1 = mesh().lookupObject<volScalarField>("alpha.water");
             
             scalar alphaTot (0.0);
             scalar cOG (0.0);
             
             
             forAll(alpha1,cellI)
             {
                 alphaTot += 1.0 - alpha1[cellI];
                 cOG += (1.0 - alpha1[cellI])*alpha1.mesh().C()[cellI].z();
             }
             
             reduce(alphaTot, sumOp<scalar>());
             reduce(cOG, sumOp<scalar>());
             
             cOG /= (alphaTot + VSMALL);
            
             if (Pstream::myProcNo() == 0)
             {
                 outputFilePtr() << mesh().time().timeName() << " " << cOG << endl;
             }
             
             Info << "cog = "  << mesh().time().timeName() << " " << cOG << endl;
             
        #};
        
        codeWrite
        #{

        #};
    }
randolph likes this.
mAlletto is offline   Reply With Quote

Old   March 20, 2021, 10:38
Default
  #7
Member
 
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 5
Vitor Monteiro is on a distinguished road
Thank you so much!
It helps a lot. Actually, I was testing this volume integration at the multiphaseEulerFoam tutorial (bubbleColumnEvaporating). Now I can go on my research.

This was the coded function object that worked for me:

Code:
totalMass
{
    type            coded;
    libs            ("libutilityFunctionObjects.so");
    name            totalMass;
    writeControl    writeTime;//timeStep;
    executeControl    writeTime;

        codeInclude
        #{
            #include "volFieldsFwd.H"
            #include "OFstream.H"
        #};

        codeData
        #{
              autoPtr<OFstream> outputFilePtr;
        #};

        codeRead
        #{           
         outputFilePtr.reset(new OFstream("totalMass.dat"));   
         outputFilePtr() <<   "# Time    gSum(alphaGas*rhoGas*v)    gSum(alphaGas)"   << endl; 
        #};

    codeExecute
    #{
        const volScalarField& alphaGas = mesh().lookupObject<volScalarField>("alpha.gas");
        const volScalarField& rhoGas = mesh().lookupObject<volScalarField>("thermo:rho.gas");
        const scalarField& v = mesh().V();

    outputFilePtr() << mesh().time().timeName() << "    "
            << gSum(alphaGas*rhoGas*v) << "    "
            << gSum(alphaGas)  << endl;
    #};

}
I couldn't able to integrate using IOobject, don't know what was doing wrong. But this way is simpler and functionable.

Thank you so much!
Vitor Monteiro is offline   Reply With Quote

Old   March 24, 2021, 12:34
Default
  #8
Member
 
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 5
Vitor Monteiro is on a distinguished road
Quote:
Originally Posted by Vitor Monteiro View Post
Code:
totalMass
{
    type            coded;
    libs            ("libutilityFunctionObjects.so");
    name            totalMass;
    writeControl    writeTime;//timeStep;
    executeControl    writeTime;

        codeInclude
        #{
            #include "volFieldsFwd.H"
            #include "OFstream.H"
        #};

        codeData
        #{
              autoPtr<OFstream> outputFilePtr;
        #};

        codeRead
        #{           
         outputFilePtr.reset(new OFstream("totalMass.dat"));   
         outputFilePtr() <<   "# Time    gSum(alphaGas*rhoGas*v)    gSum(alphaGas)"   << endl; 
        #};

    codeExecute
    #{
        const volScalarField& alphaGas = mesh().lookupObject<volScalarField>("alpha.gas");
        const volScalarField& rhoGas = mesh().lookupObject<volScalarField>("thermo:rho.gas");
        const scalarField& v = mesh().V();

    outputFilePtr() << mesh().time().timeName() << "    "
            << gSum(alphaGas*rhoGas*v) << "    "
            << gSum(alphaGas)  << endl;
    #};

}
How can I enable the phaseSystem functions into my coded function object, to gather informations about each phase.

I'd tried to simply use #include phaseSystem.H but it didn't work. I want to use functions like this:

Code:
autoPtr<phaseSystem> fluidPtr
(
    phaseSystem::New(mesh)
);
phaseSystem& fluid = fluidPtr();
phaseSystem::phaseModelList& phases = fluid.phases();

phaseModel& phase1 = fluid.multiComponentPhases()[0];
phaseModel& phase2 = fluid.multiComponentPhases()[1];
UPtrList<volScalarField>& Y2 = phase2.YActiveRef();

forAll(fluid.multiComponentPhases(), multiComponentPhasei)
    {
        phaseModel& phase = fluid.multiComponentPhases()[multiComponentPhasei];

        UPtrList<volScalarField>& Y = phase.YActiveRef();
        const volScalarField& alpha = phase;
        const volScalarField& rho = phase.rho();

        forAll(Y, i)
        { 

               ...
Someone knows?
Vitor Monteiro is offline   Reply With Quote

Old   March 24, 2021, 13:19
Default
  #9
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Did you try:

Code:

codeOptions 

        #{ 

             -I$(LIB_SRC)/phaseSystemModels/multiphaseInter/phasesSystem/lnInclude/   

        #};
mAlletto is offline   Reply With Quote

Old   March 24, 2021, 13:38
Default
  #10
Member
 
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 5
Vitor Monteiro is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
Did you try:
Code:
codeOptions 
        #{ 
             -I$(LIB_SRC)/phaseSystemModels/multiphaseInter/phasesSystem/lnInclude/  
        #};
Yes. I forgot to say that. It didn't work.
Actually, I also tried this, since I'm using OpenFOAM 8:
Code:
        codeOptions
        #{
-I/opt/openfoam8/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/lnInclude
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude
        #};
My coded function object is been constructed like this:
Code:
totalMass
{
    type            coded;
    libs            ("libutilityFunctionObjects.so");
    name            totalMass;
    writeControl    writeTime;
    executeControl    timeStep;//writeTime;

        codeInclude
        #{
            #include "volFieldsFwd.H"
            #include "OFstream.H"   
        #};

        codeOptions
        #{
-I/opt/openfoam8/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/lnInclude
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude
        #};

    codeLibs
        #{
        #};

        codeData
        #{
              autoPtr<OFstream> outputFilePtr;

#include "phaseSystem.H"
autoPtr<phaseSystem> fluidPtr
(
    phaseSystem::New(mesh)
);
phaseSystem& fluid = fluidPtr();
phaseSystem::phaseModelList& phases = fluid.phases();
        #};

        codeRead
        #{           
         fileName outputDir = "./postProcessing/totalMass/" + mesh().time().timeName(); 
         mkDir(outputDir);
             outputFilePtr.reset(new OFstream(outputDir/"totalMass.dat"));   
         outputFilePtr() <<   "# Time    gSum(alphaGas*rhoGas*v)    gSum(alphaGas)"   << endl;
        #};

    codeWrite
    #{
    #};

    codeExecute
    #{
      forAll(fluid.multiComponentPhases(), multiComponentPhasei) // fases
      {
        phaseModel& phase = fluid.multiComponentPhases()[multiComponentPhasei];
        UPtrList<volScalarField>& Y = phase.YActiveRef();
        const volScalarField& alpha = phase;
        const volScalarField& rho = phase.rho();

        forAll(Y, i) // espécies
        {

        phaseModel& phasei = Y[i].name();
        //phaseModel& phase1 = fluid.multiComponentPhases()[0];    

     outputFilePtr() << mesh().time().timeName() << "    "
            << gSum(alpha*rho*v) << "    "
            << gSum(alpha)  << endl;

         Info<< "coded totalMass output:" << endl
            << "    volIntegrate(all) for alpha.gas*rho.gas = "      << alpha << endl
            << endl;

     }; // fim for
       }; //fim for
 
    #}; // fim Execute

 } // fim coded

Error obtained:
Code:
Using dynamicCode for functionObject totalMass at line 60 in "/home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/system/controlDict/functions/totalMass"
Creating new library in "dynamicCode/totalMass/platforms/linux64GccDPInt32Opt/lib/libtotalMass_326dfb08bc2c83669ba89b736cb4c23055d73758.so"
Invoking "wmake -s libso /home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/dynamicCode/totalMass"
wmake libso /home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/dynamicCode/totalMass
Make/linux64GccDPInt32Opt/options:66: *** missing separator.  Pare.
Make/linux64GccDPInt32Opt/options:66: *** missing separator.  Pare.
wmake error: file 'Make/linux64GccDPInt32Opt/sourceFiles' could not be created in /home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/dynamicCode/totalMass

--> FOAM FATAL IO ERROR: 
Failed wmake "dynamicCode/totalMass/platforms/linux64GccDPInt32Opt/lib/libtotalMass_326dfb08bc2c83669ba89b736cb4c23055d73758.so"


file: /home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/system/controlDict/functions/totalMass from line 60 to line 109.

    From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
    in file db/dynamicLibrary/codedBase/codedBase.C at line 206.

Inconsistency detected by ld.so: dl-close.c: 811: _dl_close: Assertion `map->l_init_called' failed!
Vitor Monteiro is offline   Reply With Quote

Old   March 24, 2021, 13:53
Default
  #11
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Did you try to put the #include statement in codeInclude?
mAlletto is offline   Reply With Quote

Old   March 24, 2021, 13:55
Default
  #12
Member
 
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 5
Vitor Monteiro is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
Did you try to put the #include statement in codeInclude?
Yes. Then I've got this:
Code:
Using dynamicCode for functionObject totalMass at line 60 in "/home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/system/controlDict/functions/totalMass"
Creating new library in "dynamicCode/totalMass/platforms/linux64GccDPInt32Opt/lib/libtotalMass_0bbae05ec8449bd9ed9eae095bd5ddc094e82abe.so"
Invoking "wmake -s libso /home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/dynamicCode/totalMass"
wmake libso /home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/dynamicCode/totalMass
Make/linux64GccDPInt32Opt/options:60: *** missing separator.  Pare.
Make/linux64GccDPInt32Opt/options:60: *** missing separator.  Pare.
wmake error: file 'Make/linux64GccDPInt32Opt/sourceFiles' could not be created in /home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/dynamicCode/totalMass
Inconsistency detected by ld.so: dl-close.c: 811: _dl_close: Assertion `map->l_init_called' failed!

--> FOAM FATAL IO ERROR: 
Failed wmake "dynamicCode/totalMass/platforms/linux64GccDPInt32Opt/lib/libtotalMass_0bbae05ec8449bd9ed9eae095bd5ddc094e82abe.so"


file: /home/vitor/SIMULATIONS/tutorials8/multiphase/multiphaseEulerFoam/laminar/bubbleColumnEvaporating/system/controlDict/functions/totalMass from line 60 to line 110.

    From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
    in file db/dynamicLibrary/codedBase/codedBase.C at line 206.
Vitor Monteiro is offline   Reply With Quote

Old   March 24, 2021, 14:00
Default
  #13
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
You need a back slash between the two lines in codeOption
See the working example I sent
mAlletto is offline   Reply With Quote

Old   March 24, 2021, 14:01
Default
  #14
Member
 
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 5
Vitor Monteiro is on a distinguished road
It seems like it worked:
Code:
totalMass
{
    type            coded;
    libs            ("libutilityFunctionObjects.so");
    name            totalMass;
    writeControl    writeTime;
    executeControl    timeStep;//writeTime;

        codeInclude
        #{
            #include "volFieldsFwd.H"
            #include "OFstream.H"   
        #include "phaseSystem.H"
        #};

        codeOptions
        #{
-I/opt/openfoam8/applications/solvers/multiphase/multiphaseEulerFoam/phaseSystems/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude
        #};

    codeLibs
        #{
        #};

        codeData
        #{
              autoPtr<OFstream> outputFilePtr;
          autoPtr<phaseSystem> fluidPtr;
        #};

        codeRead
        #{
             fileName outputDir = "./postProcessing/totalMass/" + mesh().time().timeName(); 
         mkDir(outputDir);
             outputFilePtr.reset(new OFstream(outputDir/"totalMass.dat"));   
         outputFilePtr() <<   "# Time    gSum(alphaGas*rhoGas*v)    gSum(alphaGas)"   << endl;
        #};

    codeWrite
    #{

    #};

    codeExecute
    #{
    phaseSystem& fluid = fluidPtr();

      forAll(fluid.multiComponentPhases(), multiComponentPhasei) // fases
      {
        phaseModel& phase = fluid.multiComponentPhases()[multiComponentPhasei];
        UPtrList<volScalarField>& Y = phase.YActiveRef();
        const volScalarField& alpha = phase;
        const volScalarField& rho = phase.rho();
    const scalarField& v = mesh().V();

        forAll(Y, i) // espécies
        {

     const double& m = gSum(alpha*rho*v);
     outputFilePtr() << mesh().time().timeName() << "    "
            << Y[i].name() << "    "
            << m  << endl;

         Info<< "coded totalMass output:" << endl
            << "    name: " << Y[i].name() << endl
        << "    mass: " << m << endl
            << endl;

     }; // fim for
       }; //fim for
 
    #}; // fim Execute

} // fim coded
However, now it seems like something is missing:
Code:
object of type N4Foam11phaseSystemE is not allocated

    From function T& Foam::autoPtr<T>::operator()() [with T = Foam::phaseSystem]
    in file /opt/openfoam8/src/OpenFOAM/lnInclude/autoPtrI.H at line 139.

FOAM aborting

#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::error::abort() at ??:?
#2  Foam::totalMassFunctionObject::execute() at /opt/openfoam8/src/OpenFOAM/lnInclude/errorManip.H:84
#3  Foam::functionObjects::timeControl::execute() at ??:?
#4  Foam::functionObjectList::start() at ??:?
#5  Foam::Time::run() const at ??:?
#6  ? at ??:?
#7  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#8  ? at ??:?
Aborted (core dumped)

Last edited by Vitor Monteiro; March 24, 2021 at 15:14.
Vitor Monteiro is offline   Reply With Quote

Old   March 25, 2021, 12:02
Default
  #15
Member
 
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 5
Vitor Monteiro is on a distinguished road
Same error occurred (see above, I edited my reply):


object of type N4Foam11phaseSystemE is not allocated
Vitor Monteiro is offline   Reply With Quote

Old   March 26, 2021, 04:54
Default
  #16
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
can you try something like this in codeExecute


Code:

const phaseSystem& fluid = mesh().lookupObject<phaseSystem>
and remove






Code:
autoPtr<phaseSystem> fluidPtr;
Since your phaesSystem object already exists you do not need to create it but just retrieve it from the datebase

Last edited by mAlletto; March 26, 2021 at 06:55.
mAlletto is offline   Reply With Quote

Old   March 26, 2021, 12:26
Default
  #17
Member
 
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 5
Vitor Monteiro is on a distinguished road
Code:
: error: invalid initialization of reference of type ‘const Foam::phaseSystem&’ from expression of type ‘<unresolved overloaded function type>’
make: *** [Make/linux64GccDPInt32Opt/functionObjectTemplate.o] Error 1
I've got another error. Do you know what is happening?


The curious thing is that I can use this functions properly at my edited solver of multiphaseEulerFoam.C or YEqns.H but, in the coded function object inside controlDict it doesn't work.
Maybe its some other library I have to activate? Or something like that?

This is the working code implemented at YEqns.H, for example:

Code:
forAll(fluid.multiComponentPhases(), multiComponentPhasei)
    {
        phaseModel& phase = fluid.multiComponentPhases()[multiComponentPhasei];
        UPtrList<volScalarField>& Y = phase.YActiveRef(); 
        const volScalarField& alpha = phase;
        const volScalarField& rho = phase.rho();

        forAll(Y, i)
        {
          ...
Vitor Monteiro is offline   Reply With Quote

Old   March 26, 2021, 14:35
Default
  #18
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
It is clear that the object you are looking for is visible in the main solver. It is created in the createField.H file. This is the outermost scope.

A coded function objects does not know anything about the application. If you want an object there which is used from the main application you have to retrieve it from the database
mAlletto is offline   Reply With Quote

Old   March 29, 2021, 11:10
Thumbs up
  #19
Member
 
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 5
Vitor Monteiro is on a distinguished road
That's true. I understood that. Since I wasn't knowing how to retrieve that information, I've prefered to implement that calculus and write it to a file inside the main solver. So I edit and compiled that. This way I could solve the problema.

Thank you very much for help.

Vitor Monteiro is offline   Reply With Quote

Old   March 29, 2021, 11:25
Default
  #20
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15
mAlletto will become famous soon enough
Can you post the code? Maybe it's of help for someone else
mAlletto is offline   Reply With Quote

Reply

Tags
coded functions, gsum(), integration, postprocessing, write to file


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
mesh file for flow over a circular cylinder Ardalan Main CFD Forum 7 December 15, 2020 13:06
Condensation as an additional variable Clark Griswold CFX 2 April 21, 2012 07:20
Additional variable as output of an expression Chander CFX 1 November 22, 2011 12:54
error in COMSOL:'ERROR:6164 Duplicate Variable' bhushas COMSOL 1 May 30, 2008 04:35
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 20:09


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