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/)
-   -   Getting volume of cells with mesh.V does not work (https://www.cfd-online.com/Forums/openfoam-programming-development/178972-getting-volume-cells-mesh-v-does-not-work.html)

juggler October 20, 2016 16:02

Getting volume of cells with mesh.V does not work
 
Hello everyone!

For the last few days, I was toying around with some Algorithms I found in a Paper and tried to put them in an OpenFOAM Solver. Some Calculations require the Volume of Cells. Since all of the other Field Variables are of Type volScalarField or volVectorField, I thought of creating a volScalarField and initializing it with mesh.V().

Google turned up this Thread: http://http://www.cfd-online.com/Forums/openfoam/82866-write-cell-volumes.html
The second Answer provided a Code-Snippet, which seemed to be exactly what I was looking for:

Code:

volScalarField cv   
    (           
    IOobject
              (                   
        "cv",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,                   
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar("zero",dimVolume,0.0)
    );

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

However, wmake seems not to like this:

Code:

optimVariables.H:77:24: error: passing ‘const Internal {aka const Foam::DimensionedField<double, Foam::volMesh>}’ as ‘this’ argument of ‘void Foam::DimensionedField<Type, GeoMesh>::operator=(const Foam::DimensionedField<Type, GeoMesh>&) [with Type = double; GeoMesh = Foam::volMesh]’ discards qualifiers [-fpermissive]
    cv.internalField() = mesh.V();
                        ^

I am running OpenFOAM 4.0 under Ubuntu Mate 15.04.

It feels like I am missing something pretty obvious about the usage of someField.internalField() and mesh.V(). Some additional googling told me that mesh.V() returns a scalarField, which resembles a volScalarField without boundaryField and should be able to be written to a volScalarField using the internalField(). Is this correct? Also, is it possible to write to a internalField()? I tried grepping for "internalField() =" in $FOAM_SRC, but found nothing (possibly my grep skills are not the best:)). What would be the correct way to do this?

Also I tried to initialize the internalField to a constant:

Code:

    cv.internalField() = 1.0;
which yields using wmake

Code:

optimVariables.H:77:24: error: passing ‘const Internal {aka const Foam::DimensionedField<double, Foam::volMesh>}’ as ‘this’ argument of ‘void Foam::DimensionedField<Type, GeoMesh>::operator=(const Foam::dimensioned<Type>&) [with Type = double; GeoMesh = Foam::volMesh]’ discards qualifiers [-fpermissive]
    cv.internalField() = 1.0;

Googling the error message told me something about the Implementation of the underlaying classes and operators might be off, but I honestly can't believe that. I'd also like to avoid digging deeper in the code than necessary...

Is there any other way to achieve this? Most of my input for those Equations are volScalar/VectorFields, but as long as I get a volScalarField in the end that I can write to file, I would not mind doing things an other way.

confused Greetings,

Juggler

jherb October 20, 2016 18:33

Perhaps this post (http://www.cfd-online.com/Forums/ope...tml#post488967) can help you with assigning the volume sizes to your new field.

But why do you need a new field at all? Why can't you just use mesh.V() (see e.g. https://github.com/OpenFOAM/OpenFOAM...ceFilter.C#L60)

juggler October 21, 2016 19:12

Thank you very much, jherb, your answer set me to the right track!

In the source file you linked to, the Fields were accessed using .ref() instead of .internalField(). I tried this

Code:

    cv.ref() = mesh.V();
and it compiled without problems.
I got curious about .ref() and asked Google: http://www.cfd-online.com/Forums/openfoam-programming-development/174102-new-problem-version-4-0-boundary-field-become-read-only.html

Turns out that the internalField() Method was changed recently and can no longer be used for write access. I suspected something like this in the first place since the code snippet had resolved the issue in the Thread it came from, but did no longer work for OF40, but I wanted to rule out any mistakes i could have made.

Greetings,

Juggler


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