CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to add global Scalar to model? (https://www.cfd-online.com/Forums/openfoam-programming-development/92514-how-add-global-scalar-model.html)

seboxx September 16, 2011 05:53

How to add global Scalar to model?
 
Hi there,

I am calculating a scalar function over the whole domain of my model, which works out nicely.
Now I would like to have in stored separately for post processing.
But I don't think volScalarField is the right class to save my value since then it would be recalculated at every cell consuming more computation time then necessary.
I think it is a rather easy problem, but somehow I can't find any proper class like globalIOScalar(?!) that fulfills my needs...

I hope someone of you can help me out here ;-)

Thank you,

sebastian

marupio September 16, 2011 11:09

I use an output dictionary for objects that don't write themselves. Create an IOdictionary, set to runTime.timeName(), and NO_READ, AUTO_WRITE. Then, at every timestep you set the new value:

outputDict.set("nameOfScalar", myScalar);

And it will appear in the time directory.

seboxx September 17, 2011 04:11

Hi marupio,

thanks for the advice. But I cannot get it to work.

Quote:

error: 'outputDict' was not declared in this scope
Do I need to include a special library to have this object?
outputDict.set doesn't even appear in the doxygen documentation...
Where did you get that from?

Thanks,

sebastian

marupio September 17, 2011 09:12

Sorry I wasn't clear!

Try this:
<code>
// In createField.H:
IOdictionary outputDict
(
IOobject
(
"outputDict",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
)
);

// In your solver loop, before runTime.write();
outputDict.set("nameOfScalar", myScalar);
</code>

seboxx September 17, 2011 11:29

That worked!

Thank you!


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