CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   How to scale a volScalarField by cell volume? (http://www.cfd-online.com/Forums/openfoam-solving/104417-how-scale-volscalarfield-cell-volume.html)

tgvosk July 9, 2012 09:13

How to scale a volScalarField by cell volume?
 
Hello,

I am trying to scale a volScalarField (myField) by cell volume. Based on other threads on this topic, I have the following code (which works)

Code:

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

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

    myField = myField * cellVolume;

What I would like to know is whether there is a way of doing this directly with field operations (without creating an intermediate volScalarField to store the cell volume or looping through all cells and multiplying cell-by-cell).

Any suggestions?

stevenvanharen July 9, 2012 09:58

Use this:

Code:

T.internalField() *=  mesh.V();

tgvosk July 9, 2012 10:25

Thanks!
 
Steven,

Thanks, that's what I was looking for! Both of the following work as expected.

Code:

myField = mag(fvc::laplacian(T));
 myField.internalField() *= mesh.V();

Code:

myField.internalField() = mag(fvc::laplacian(T)) * mesh.V();


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