CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   const_cast and pointScalarField (http://www.cfd-online.com/Forums/openfoam-programming-development/71915-const_cast-pointscalarfield.html)

myheroisalex January 19, 2010 17:27

const_cast and pointScalarField
 
Hello OpenFoam-Users,

I got a problem with compiling a modified interDyMFoam-solver.
My goal is to modify the mesh motion every n-th timestep and I found out that this can be done by a const_cast:

Code:

pointScalarField& field =
const_cast<pointScalarField&>
(
mesh.objectRegistry::lookupObject<pointScalarField>
(
"pointDisplacementz"
)
);

But that lets the following error occur:

Code:

[...]                                                                                                         
/home/michael/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/DimensionedField.H: At global scope:                                                               
/home/michael/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/DimensionedField.H: In instantiation of ‘Foam::DimensionedField<double, Foam::pointMesh>’:         
/home/michael/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/pointFieldsFwd.H:53:  instantiated from ‘Foam::GeometricField<double, Foam::pointPatchField, Foam::pointMesh>’                                                                                                                                                     
/home/michael/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/objectRegistryTemplates.C:114:  instantiated from ‘const Type& Foam::objectRegistry::lookupObject(const Foam::word&) const [with Type = Foam::GeometricField<double, Foam::pointPatchField, Foam::pointMesh>]’                                                     
interDyMFoam.C:66:  instantiated from here                                                                                                                     
/home/michael/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/DimensionedField.H:83: error: invalid use of incomplete type ‘struct Foam::pointMesh’             
/home/michael/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/pointFieldsFwd.H:47: error: forward declaration of ‘struct Foam::pointMesh’
/home/michael/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/DimensionedField.H:92: error: invalid use of incomplete type ‘struct Foam::pointMesh’             
/home/michael/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/pointFieldsFwd.H:47: error: forward declaration of ‘struct Foam::pointMesh’                       
/home/michael/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/DimensionedField.C:58: error: invalid use of incomplete type ‘struct Foam::pointMesh’             
/home/michael/OpenFOAM/OpenFOAM-1.6.x/src/OpenFOAM/lnInclude/pointFieldsFwd.H:47: error: forward declaration of ‘struct Foam::pointMesh’ 
[Similar error messages follow]

The same code with 'volScalarField' instead of 'pointScalarField' compiles succesfully. So there es anything about that pointScalarField.
Anyone knows the reason or has a hint?

Thank you for reading this and, of course, for your answers.

hjasak January 20, 2010 06:53

Go to the file you are compiling and add

#include "pointMesh.H"

at the top.

Hrv

myheroisalex January 21, 2010 11:56

HeyHey Hrv,

thanks alot for that hint! I would have never thought of that (C++ skills not present ;D).
So, much thanks to you and a C++-lesson to me!


For all OF-users finding this thread in the future:

You have to add
#include "pointMesh.H"
#include "pointPatchField.H"
at the top(!) of your file

The cast for editing mesh-movement may look like:
(For motion-solver displacementLaplacian)

Info << "Reading field pointDisplacement" << endl;
pointVectorField& pointDisplacement = const_cast<pointVerctorField&>
(
mesh.objectRegistry::lookupObject<pointVectorField >
(
"pointDisplacement"
)
);

[and again for cellDisplacement]

Writing new values on boundary:

label patchIndex = mesh.boundaryMesh().findPatchID("patch_name");
cellDisplacement.boundaryField()[patchIndex] = newvalue;
pointDisplacement.boundaryField()[patchIndex] = newvalue;

Nikolac April 26, 2016 11:02

Greetings from the future! Thank you, this was very useful!
Best,
N


All times are GMT -4. The time now is 03:53.