CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Getting volume of cells with mesh.V does not work

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 4 Post By juggler

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 20, 2016, 16:02
Default Getting volume of cells with mesh.V does not work
  #1
New Member
 
Join Date: Oct 2016
Posts: 3
Rep Power: 9
juggler is on a distinguished road
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

Last edited by juggler; October 20, 2016 at 16:06. Reason: fixed Code formatting
juggler is offline   Reply With Quote

Old   October 20, 2016, 18:33
Default
  #2
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 21
jherb is on a distinguished road
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)
jherb is offline   Reply With Quote

Old   October 21, 2016, 19:12
Default
  #3
New Member
 
Join Date: Oct 2016
Posts: 3
Rep Power: 9
juggler is on a distinguished road
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

Last edited by juggler; October 21, 2016 at 19:15. Reason: fixed link
juggler is offline   Reply With Quote

Reply

Tags
internalfield, mesh.v, volscalarfield


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[snappyHexMesh] snappyHexMesh sticking point natty_king OpenFOAM Meshing & Mesh Conversion 11 February 20, 2024 09:12
How to use a UDF to set the volume fraction in the cells next to a wall? DF15 Fluent UDF and Scheme Programming 33 August 20, 2020 13:36
[ICEM] Problem with prism cells sidharath ANSYS Meshing & Geometry 0 September 1, 2015 07:09
snappyhexmesh remove blockmesh geometry philipp1 OpenFOAM Running, Solving & CFD 2 December 12, 2014 10:58
[blockMesh] non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Meshing & Mesh Conversion 7 April 17, 2013 05:42


All times are GMT -4. The time now is 01:42.