|
[Sponsors] |
Write a calculated variable to postProcessing |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 18, 2021, 11:38 |
Write a calculated variable to postProcessing
|
#1 |
Member
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 6 |
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(); #}; } 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(); #}; } |
|
March 18, 2021, 15:25 |
|
#2 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
Did you try to write your scalar to a file
|
|
March 18, 2021, 15:30 |
|
#3 |
Member
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 6 |
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! |
|
March 18, 2021, 15:38 |
|
#4 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
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.
|
|
March 19, 2021, 09:11 |
|
#5 |
Senior Member
Join Date: Jan 2014
Posts: 179
Rep Power: 12 |
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(); } |
|
March 20, 2021, 09:06 |
|
#6 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
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 #{ #}; } |
|
March 20, 2021, 11:38 |
|
#7 |
Member
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 6 |
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; #}; } Thank you so much! |
|
March 24, 2021, 13:34 |
|
#8 | |
Member
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 6 |
Quote:
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) { ... |
||
March 24, 2021, 14:19 |
|
#9 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
Did you try:
Code:
codeOptions #{ -I$(LIB_SRC)/phaseSystemModels/multiphaseInter/phasesSystem/lnInclude/ #}; |
|
March 24, 2021, 14:38 |
|
#10 | |
Member
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 6 |
Quote:
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 #}; 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! |
||
March 24, 2021, 14:53 |
|
#11 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
Did you try to put the #include statement in codeInclude?
|
|
March 24, 2021, 14:55 |
|
#12 |
Member
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 6 |
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. |
|
March 24, 2021, 15:00 |
|
#13 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
You need a back slash between the two lines in codeOption
See the working example I sent |
|
March 24, 2021, 15:01 |
|
#14 |
Member
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 6 |
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 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 16:14. |
|
March 25, 2021, 13:02 |
|
#15 |
Member
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 6 |
Same error occurred (see above, I edited my reply):
object of type N4Foam11phaseSystemE is not allocated |
|
March 26, 2021, 05:54 |
|
#16 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
can you try something like this in codeExecute
Code:
const phaseSystem& fluid = mesh().lookupObject<phaseSystem> Code:
autoPtr<phaseSystem> fluidPtr; Last edited by mAlletto; March 26, 2021 at 07:55. |
|
March 26, 2021, 13:26 |
|
#17 |
Member
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 6 |
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 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) { ... |
|
March 26, 2021, 15:35 |
|
#18 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
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 |
|
March 29, 2021, 12:10 |
|
#19 |
Member
Vitor Monteiro
Join Date: Nov 2020
Posts: 32
Rep Power: 6 |
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. |
|
March 29, 2021, 12:25 |
|
#20 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
Can you post the code? Maybe it's of help for someone else
|
|
Tags |
coded functions, gsum(), integration, postprocessing, write to file |
|
|
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 14:06 |
Condensation as an additional variable | Clark Griswold | CFX | 2 | April 21, 2012 08:20 |
Additional variable as output of an expression | Chander | CFX | 1 | November 22, 2011 13:54 |
error in COMSOL:'ERROR:6164 Duplicate Variable' | bhushas | COMSOL | 1 | May 30, 2008 05:35 |
Replace periodic by inlet-outlet pair | lego | CFX | 3 | November 5, 2002 21:09 |