|
[Sponsors] |
Question about codeData in a codedFunctionObject |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 13, 2021, 03:49 |
Question about codeData in a codedFunctionObject
|
#1 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 615
Rep Power: 15 |
I have following coded function object:
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 #{ fileName outPutDir; std::ofstream fout; autoPtr<OFstream> outputFilePtr; #}; codeRead #{ outputFilePtr.reset(new OFstream("centerOfGravityAir.dat")); fout.open("centerOfGravityAir.txt"); #}; 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; if (Pstream::myProcNo() == 0) { fout << mesh().time().timeName() << " " << cOG << endl; outputFilePtr() << mesh().time().timeName() << " " << cOG << endl; } Info << "cog = " << mesh().time().timeName() << " " << cOG << endl; #}; codeWrite #{ #}; } The purpose of the function object is to write the center of gravity in z-direction of the air to a file. I have two file: one centerOfGravity.dat and one centerofGravity.txt. centerofGravity.txt is opened with an ofstream of c++ and the other one with and autoPtr<OFstream>. For the latter works and the former not. Apparently the reference to the variable gets somewhere lost if an std:fstream is used but not in the case of autoPtr<OFstream>. My question is: why is this so? Best Michael |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] Difference in calculating div(U*U) swak4FOAM vs. OpenFOAM codedFunctionObject | polo | OpenFOAM Community Contributions | 7 | October 1, 2013 10:22 |
small question about the functionalities of topological changes in OpenFoam | ngj | OpenFOAM Running, Solving & CFD | 2 | February 28, 2013 10:02 |
Question Re Engineering Data Source | imnull | ANSYS | 0 | March 5, 2012 13:51 |
internal field question - PitzDaily Case | atareen64 | OpenFOAM Running, Solving & CFD | 2 | January 26, 2011 15:26 |
Poisson Solver question | Suresh | Main CFD Forum | 3 | August 12, 2005 04:37 |