|
[Sponsors] |
Getting volume of cells with mesh.V does not work |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 20, 2016, 17:02 |
Getting volume of cells with mesh.V does not work
|
#1 |
New Member
Join Date: Oct 2016
Posts: 3
Rep Power: 10 |
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(); 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(); ^ 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] cv.internalField() = 1.0; 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 17:06. Reason: fixed Code formatting |
|
October 20, 2016, 19:33 |
|
#2 |
Senior Member
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22 |
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) |
|
October 21, 2016, 20:12 |
|
#3 |
New Member
Join Date: Oct 2016
Posts: 3
Rep Power: 10 |
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 Last edited by juggler; October 21, 2016 at 20:15. Reason: fixed link |
|
Tags |
internalfield, mesh.v, volscalarfield |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[snappyHexMesh] snappyHexMesh sticking point | natty_king | OpenFOAM Meshing & Mesh Conversion | 11 | February 20, 2024 10: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 14:36 |
[ICEM] Problem with prism cells | sidharath | ANSYS Meshing & Geometry | 0 | September 1, 2015 08:09 |
snappyhexmesh remove blockmesh geometry | philipp1 | OpenFOAM Running, Solving & CFD | 2 | December 12, 2014 11:58 |
[blockMesh] non-orthogonal faces and incorrect orientation? | nennbs | OpenFOAM Meshing & Mesh Conversion | 7 | April 17, 2013 06:42 |