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 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] 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; 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] 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 |
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) |
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(); 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. |