CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   cellValues within a cellZone (https://www.cfd-online.com/Forums/openfoam-solving/248211-cellvalues-within-cellzone.html)

b.simpson March 2, 2023 11:44

cellValues within a cellZone
 
Hi,

I am using OpenFOAM-8. I want to get a file printed out at the writeTime containing specific field values for every cell within a cellZone. I specifically want to get the CO2 concentrations of each cell within the zone to use in a performance metric.

I have the cellZone and the CO2 source defined and I am able to get the average CO2 concentration for the cellZone but I am unable to get the CO2 values for each cell.

Does anyone know how to achieve this? Is there a functionObject that allows me to print out the cellValues for certain fields for each cell in a cellZone?

Kind regards,
Ben

alainislas March 9, 2023 06:15

Hi Ben Simpson,



Here is a piece of code that can help you


Code:

BenSimpsonFunction
{
    type        coded;
    libs        ("libutilityFunctionObjects.so");
    name        cellValues_within_a_cellZone;

    codeExecute
    #{
        //Access mesh cells, can use any vector or scalar field
        const volVectorField& U_ = mesh().lookupObject<volVectorField>("U");

        //Access cellZone
        const fvMesh& mesh = U_.mesh();
        word cellSetName = "myCellZone";
        label zoneID = mesh.cellZones().findZoneID(cellSetName);

        const labelList& cells = mesh.cellZones()[zoneID];

        forAll(cells, i)
        {
            do whatever you want here
        }

    #};

}

Then you simply call this function in your controlDict.


All times are GMT -4. The time now is 18:34.