CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Output meshsize/cellsize (https://www.cfd-online.com/Forums/openfoam/82180-output-meshsize-cellsize.html)

Rickard.Solsjo November 19, 2010 02:32

Output meshsize/cellsize
 
Hi, I want to do postprocessing of my data in MatLab and need the size of my cells corresponding to the value in that cell.
Basically, if I do mass-averaged PDF I need to include the volume of my cell, but since I have used SnappyHexMesh to refine Im in a pickle.
Does anyone know the output order of OpenFoam

Regards
me

herbert November 19, 2010 03:29

Hi Rickard,

if I got you right, you are already able to export some data to Matlab. You can do it with the cell volumes in the same way by simply creating a volScalarField which holds the cell volumes (access with mesh.V()) and exporting it like the other values. The ordering will of course be the same.

Regards,
Stefan

Rickard.Solsjo November 19, 2010 03:36

Thx for your reply!
Transporting the data to matlab from openfoam is okay; either just the raw data in ascii form or using sampleDict where I can split the plane.
Since I am new to this kind of postprocessing, perhaps I can ask you in detail what you mean by creating a volScalarField with mesh.V() The information about cell volumes are already accessable?

Regards
R

herbert November 19, 2010 05:12

Hi,

you would have to code it inside your solver just like any other field that is written to disk.

If you had no experience in doing so, there might be an easier way I don't know.

Regards,
Stefan

boger November 20, 2010 09:35

Simply
Code:

mesh.V().write()
should work to write the cell volumes to files in each time directory in files that look just like your solution variables.

Rickard.Solsjo November 22, 2010 03:45

Hey man, I solved it like this.

*---------------------------------------------------------------------------*/

#include "fvCFD.H"


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{

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

volScalarField checkvol
(
IOobject
(
"checkvol",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("checkvol",dimensionSet(0,3,0,0, 0),0 )
);

checkvol.internalField()=mesh.V();

checkvol.write();



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

return(0);
}

boger November 22, 2010 07:51

Looks great, but I'm curious: Does all of that get you something that you don't get with a simple mesh.V().write()?

Rickard.Solsjo November 22, 2010 08:40

Dont know =)
Im not used to programming, I am just happy i managed this you know

niklas November 22, 2010 09:18

why dont you just create a mass variable and extract it in the same way you extract the other variables?

Rickard.Solsjo November 22, 2010 09:36

Okay, would it be easier?

idrama November 26, 2010 08:31

Hello Folks!

Has anybody managed it to write program which computes the cell volume of alpha1? I have done something, but I am struggling with result, i.e. the data are strange. My code is

#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

using namespace std;

int main(int argc, char *argv[])
{
timeSelector::addOptions();
#include "setRootCase.H"
#include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
#include "createMesh.H"

runTime.setTime(timeDirs[0], 0);

#include "createFields.H"

volScalarField cellVolume
(
IOobject
(
"cellVolume",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar ("cellAlpha1Volume",dimensionSet(0,3,0,0,0,0,0) ,0)
);

cellVolume.internalField() = mesh.V();

volScalarField cellAlpha1Volume
(
IOobject
(
"cellAlpha1Volume",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar ("cellAlpha1Volume",dimensionSet(0,3,0,0,0,0,0) ,0)
);

Info << "\nStarting Time loop\n" << endl;

forAll(timeDirs, timeI)
{
Info << "Time = " << runTime.timeName() << endl;

runTime.setTime(timeDirs[timeI], timeI);
//mesh.readUpdate();
//
//
Info << "Computing" << nl << endl;

volScalarField alpha1
(
IOobject
(
"alpha1",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh

);

cellAlpha1Volume = cellAlpha1Volume + alpha1*cellVolume;
Info << "Max value = " << max(cellAlpha1Volume).value() << endl
<< "Min value = " << min(cellAlpha1Volume).value() << nl << endl;
}

runTime.setTime(timeDirs[0],0);

Info << "Writing cellAlpha1Volume to time directory 0"<< nl;

cellAlpha1Volume.write();

Info<< "End" << endl;

return 0;
}

Hopefully anybody can check it.


All times are GMT -4. The time now is 19:45.