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

const_cast and pointScalarField

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By myheroisalex

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 19, 2010, 17:27
Red face const_cast and pointScalarField
  #1
New Member
 
Michael G.
Join Date: Sep 2009
Location: Germany, Nds.
Posts: 13
Rep Power: 17
myheroisalex is on a distinguished road
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.
myheroisalex is offline   Reply With Quote

Old   January 20, 2010, 06:53
Default
  #2
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
Go to the file you are compiling and add

#include "pointMesh.H"

at the top.

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   January 21, 2010, 11:56
Default
  #3
New Member
 
Michael G.
Join Date: Sep 2009
Location: Germany, Nds.
Posts: 13
Rep Power: 17
myheroisalex is on a distinguished road
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;
albet and scleakey like this.
myheroisalex is offline   Reply With Quote

Old   April 26, 2016, 12:02
Default
  #4
New Member
 
Join Date: Mar 2014
Posts: 9
Rep Power: 12
Nikolac is on a distinguished road
Greetings from the future! Thank you, this was very useful!
Best,
N
Nikolac is offline   Reply With Quote

Reply


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



All times are GMT -4. The time now is 19:02.