CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   access to volume of the cells (http://www.cfd-online.com/Forums/openfoam/73039-access-volume-cells.html)

romant February 25, 2010 05:14

access to volume of the cells
 
Hej,

I know that I can access the volume of the cells with mesh.V(). But for some reason, the following two lines of code give an error message upon compiling

Code:

const fvMesh& mesh = alpha1_.mesh();
const volScalarField& volumeCell = mesh.V();

The error message is
Code:

invalid initialization of reference of type ‘const Foam::volScalarField&’ from expression of type ‘const Foam::DimensionedField<double, Foam::volMesh>’
Does anybody have an idea why this assignment does not work?

betakv February 26, 2010 02:09

Hi,

try this const scalarField& Volumes = mesh.V();

Vojta

romant February 26, 2010 03:54

half done
 
this worked for the part that it did not complain while compiling, the problem now is that it is not a volumeField anymore. therefore I can not use it in further calculations for volumefields like in this one

Code:

const volScalarField& p = alpha1_.db().lookupObject<volScalarField>("p");
    volScalarField limitedAlpha1 = min(max(alpha1_, scalar(0)), scalar(1));
    const fvMesh& mesh = alpha1_.mesh(); // get the underlying mesh
    const scalarField& volumeCell = mesh.V();

      limitedAlpha1 * rho1() * volumeCell * (Tsat_-Tinf_) *
        combFrequency_/(ifg_ * (1-limitedAlpha1)),
      rho2()*0.0*combFrequency_*(pSat()/p)

I want to calculate the mass "rho1()*volumeCell*limitedAlpha1" of the water within the cell. How would I do this.

romant March 3, 2010 04:51

anyone
 
Does anyone have an idea? The goal is to have a volScalarField with dimensions m^3, containing the cell volumes in order to calculate further with it.

The programmer's guide gives

volScalarField foo = mesh.V(), but this assignment does not work.

l_r_mcglashan March 3, 2010 05:42

A quick fix might be to set the internalField of a volScalarField:

Code:

volumeCell.internalField() = mesh.V();
Edit: Corrected.

ngj March 3, 2010 05:51

Hi

According to Doxygen, this is the following is the way to access the volume:

const Foam::DimensionedField<double, Foam::volMesh> & foo = mesh.V();

See
http://foam.sourceforge.net/doc/Doxy...4cd0efe7fb3baa

Best regards,

Niels

romant March 3, 2010 06:14

Code:

const Foam::DimensionedField<double, Foam::volMesh> & volumeCell = mesh.V();
Does compile but then I run into the problem that I can't use it to calculate the mass or something else by simply multiplying it, because the operator "*" is not defined for this data type.

This is the reason I want a volScalarField, which contains the volume of each cell of the mesh. It doesn't even have to be dimensioned, because that can be fixed with work arounds. But it must be possible to somehow get the volume of each cell into a volScalarField.

Code:

const volScalarField& volumeCell.internalField() = mesh.V();
does not compile, neither does any other combination

ngj March 3, 2010 06:39

Hi

A work around, as you have spent a lot of time on this is to do for instance as follows:

// gamma being a volScalarField
scalarField V = mesh.V();
forAll(V,i)
{
gamma[i] *= V[i];
}

Good luck,

Niels

jens_klostermann March 3, 2010 09:14

I would go with Laurence idea:

volScalarField cellVolu
(
IOobject
(
"cellVolu",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("zero", dimVolume, 0.0)
);
cellVolu.internalField() = mesh.V();


At least for me it does the job!

Jens

romant March 3, 2010 09:23

Hej Jens, thanks for the reply, one more question about the following code snippet

Code:

volScalarField cellVolu
    (
    IOobject
      (
        "cellVolu",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
      ),
        mesh,
    dimensionedScalar("zero", dimVolume, 0.0)
    ); 
    cellVolu.internalField() = mesh.V();

Do I integrate this code into the createFields.H and then read it out while in my solver like
Code:

const volScalarField& volumes = alpha1_.db().lookupObject<volScalarField>("cellVolu");
?

jens_klostermann March 3, 2010 10:37

I don't know, what you want to do. But cellVolu gives you a field of the cell volumes (this is already of type volScalarField).
If alpha1 is your volume fraction denity*cellVolu gives you the mass per cell. (but this is not the answer?)

Hope it helps.

Jens

romant March 3, 2010 10:50

Thank you for this snippet. I will try the method tomorrow and see what I get.

romant March 4, 2010 07:36

thanks
 
Thanks, this worked wonderfully.


All times are GMT -4. The time now is 04:39.