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/)
-   -   Partial Summation of a Field (https://www.cfd-online.com/Forums/openfoam-programming-development/202476-partial-summation-field.html)

maksjood June 1, 2018 02:45

Partial Summation of a Field
 
Hi. I'm in need of summing up the values of a specific part of a scalar field. I've tried a for loop. The statement is as follows:

sum+=field[celli];

but I need the sum to be dimensioned and the above statement doesn't do that.

is there a way I can use sum() or gSum for this purpose?

zhangyan June 1, 2018 07:07

gSum does not include the dimension
 
just like this:
Code:

template<class Type, class GeoMesh>
dimensioned<Type> DimensionedField<Type, GeoMesh>::weightedAverage
(
    const DimensionedField<scalar, GeoMesh>& weightField
) const
{
    return
    (
        dimensioned<Type>
        (
            this->name() + ".weightedAverage(weights)",
            this->dimensions(),
            gSum(weightField*field())/gSum(weightField)
        )
    );
}


fumiya June 2, 2018 22:45

Alternative method
 
You can use the volFieldValue function object:

Code:

    volFieldValue1
    {
        type            volFieldValue;
        libs            ("libfieldFunctionObjects.so");

        log            true;
        writeControl    writeTime;
        writeFields    true;

        regionType      cellZone; // Create your cellZone that the sum needs to be calculated
        name            c0;      // and set its name
        operation      sum;

        fields
        (
            p // List of fields to operate on
        );
    }


maksjood June 2, 2018 22:50

It's done
 
Thanks everybody. I've accomplished my goal.


All times are GMT -4. The time now is 00:33.