CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Average of Scalar of a cellset during the calculation for each time step (http://www.cfd-online.com/Forums/openfoam/90089-average-scalar-cellset-during-calculation-each-time-step.html)

safre June 30, 2011 06:20

Average of Scalar of a cellset during the calculation for each time step
 
Hello

I would like to monitor as well as later on post process spatial averages of scalar fields. My strategy was to collect the cells to be averaged in different cellSets. I would then like to average a number of scalar fields for each of these cellSets during my computation.

Is there someone who have done this before and can give a hint on how to do this?

Best regards, Sam

nimasam June 30, 2011 09:26

maybe swak4foam help you to do it, look for in openFOAM wiki

marupio June 30, 2011 17:35

I don't know much about cellSets, but you could add an IOdictionary to the createFields, except instead of MUST_READ and NO_WRITE, set it to NO_READ, and AUTO_WRITE, and put it in runTime.timeName() instead of constant. Then fill it with the average values for each variable for each cellSet at every time step. e.g. myDict.set(varName, average(scalarField)); << very rough

That way it will output your dictionary to the time directories with average values.

safre October 4, 2011 17:13

Thank you for your help
 
Thank you for your help!

fcollonv October 7, 2011 11:15

Average a cellSet during the run with cellSource
 
Hello Sam,

There is a non-intrusive & nice way to do it by using the cellSource.

The explanation in the code is
Code:

00024 Class
00025    Foam::fieldValues::cellSource
00026 
00027 Description
00028    Cell source variant of field value function object. Values of user- 00029    specified fields reported for collections of cells.
00030 
00031    cellObj1                        // Name also used to identify output folder
00032    {
00033        type            cellSource;
00034        functionObjectLibs ("libfieldValueFunctionObjects.so");
00035        enabled        true;
00036        outputControl  outputTime;
00037        log            true;      // log to screen?
00038        valueOutput    true;      // Write values at run-time output times?
00039        source          cellZone;  // Type of cell source or all for the full domain
00040        sourceName      c0;
00041        operation      volAverage;
00042        fields
00043        (
00044            p
00045            U
00046        );
00047    }
00048 
00049    where operation is one of:
00050      - none
00051      - sum
00052      - volAverage
00053      - volIntegrate
00054      - weightedAverage

Personally I use it to compute the volume average of the heat release

HRR
{
type cellSource;
functionObjectLibs ("libfieldFunctionObjects.so");
enabled false;
outputControl timeStep;
outputInterval 1;
log true; // log to screen?
valueOutput false; // Write values at run-time output times?
source all; // cellZone or all
sourceName c0;
operation volIntegrate;
fields
(
dQf
);
}

Good luck

Frederic

N.B.: A cellSet is maybe not working directly, you may have to convert it into cellZone. For that there is the tool setsToZones

safre October 11, 2011 10:28

This looks very promising - thank you!
 
This looks very promising - thank you!

newOFuser August 12, 2012 03:31

Hi Frederick,

I am a new user of OF, and would appreciate if you could clear the following doubts (based on the volume integral code provided):
How are the cell sources/cell zones defined? What does c0 refer to?

Thanks,
ak

fcollonv August 14, 2012 03:31

Hi ak,

To create cell zone, you have to create cell set using 'setSet'. Then using the same tool, you can convert a cell set in cell zone.
Go to a case directory. Type the command 'setSet' - it looks like a console software. Type 'help' to get more information and examples.
N.B.: To know which 'source's are available, type something like
Code:

cellSet c0 new dummy
'c0' is simply a name given to the cell zone (in OpenFOAM every element is found based on a string).

Cheers,

Frederic

newOFuser August 14, 2012 13:15

Hello

Thanks for the prompt reply. It is very useful.

I tried the following:

1. Created makeCellSets.setSet file with the following details:

cellSet combustor new boxToCell (-0.02 0 0) (0 0.025 0.04)
cellSet combustor add boxToCell (0 -0.025 0) (0.2 0.025 0.04)
cellZoneSet combustorZone new setToCellZone combustor

2. Then, using an Allrun script, the following was performed:

runApplication blockMesh
runApplication setSet -batch makeCellSets.setSet
rm -f constant/polyMesh/sets/*_old
runApplication setsToZones -noFlipMap

3. In system/controlDict, the following was included:

HRR
{
type cellSource;
functionObjectLibs ("libfieldFunctionObjects.so");
enabled true;
outputControl timeStep;
outputInterval 1;
log false; // log to screen?
valueOutput false; // Write values at run-time output times?
source cellZone; // cellZone or all
sourceName combustorZone;
operation volIntegrate;
fields
(
p // For testing
U // For testing
chemistrySh
);
}

While this worked for volIntegrate for p and U (just for testing code), the HRR/0/cellSource.dat file had no data for chemistrySh

# Source : cellZone combustorZone
# Cells : 258720
# Time sum(V) volIntegrate(p) volIntegrate(U) volIntegrate(chemistrySh)
2e-06 0.00042 41.9985 (-1.51726e-05 -1.78689e-07 9.04692e-20)
4e-06 0.00042 42.0006 (-1.95745e-05 -2.44872e-07 -1.95267e-19)
6e-06 0.00042 42.0038 (-8.04091e-06 -2.64433e-07 -2.09461e-16)

The cellSet and cellZone approach as you suggested works quite well. Thanks!

I am not sure though why it is not able to record the volume Integral of chemistrySh using this approach.
In the solver, when I use fvc::domainIntegrate(chemistrySh).value(), it works just fine and can output the result in the terminal as well.

Could you let me know how you define dQf in your code, or what could be wrong with my approach?

In my createFields, I have:
volScalarField chemistrySh
// DimensionedField<scalar, volMesh> chemistrySh
(
IOobject
(
"chemistry::Sh",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar("chemistrySh", dimEnergy/dimTime/dimVolume, 0.0)
);


Thanks!
ak

newOFuser August 14, 2012 14:06

Hi

Got this figured out:

Defined chemistrySh as follows:
volScalarField chemistrySh
(
IOobject
(
"chemistrySh",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

A 0/chemistrySh file was also required in the case directory.

I should also add another way to calculate the volume integral, as follows:
volHRR
{
type volumeIntegrate;
functionObjectLibs ("libsimpleFunctionObjects.so");
enabled true;
outputControl timeStep;
outputInterval 1;
log false; // log to screen?
valueOutput false; // Write values at run-time output times?
fields
(
chemistrySh
);
}

-ak

newOFuser August 14, 2012 16:38

Hi

I am now having difficulty printing out the data when I run computations in parallel. Any ideas how to proceed?

ak

Edit. When I use the 2nd option above, it says: Can only probe registered volScalar, volVector, volSphericalTensor, volSymmTensor and volTensor fields

fcollonv August 15, 2012 04:11

Save heat release
 
Hi ak,

The second option is a good idea. But I advice you to use a name totally different like "heatRelease". Then it should work as you wrote it i.e. using a volScalarField storing Sh (the error can come when you try to integrate the DimensionedField<scalar, volMesh> for example).

To print output for all processors, you have to use 'Pout' instead of 'Info'.

Best regards,

Frederic

newOFuser August 15, 2012 10:32

Hello

Thanks for the suggestions, and all the help!

I was able to get it to run in parallel mode.

Thanks,
ak


All times are GMT -4. The time now is 09:51.