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

convert Foam::volTensorField to double*

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 3, 2024, 09:45
Question convert Foam::volTensorField to double*
  #1
New Member
 
Daria Romanova
Join Date: Jun 2016
Posts: 1
Rep Power: 0
RomanovaDI is on a distinguished road
I need to convert volTensorField variable tf of OpenFOAM to c++ array of double. I've got the error:

Code:
cannot convert ‘Foam::volTensorField’ {aka ‘Foam::GeometricField<Foam::Tensor<double>, Foam::fvPatchField, Foam::volMesh>’} to ‘double*’
If I use tf.cdata() the error is:

Code:
cannot convert ‘const Foam::Tensor<double>*’ to ‘double*’
RomanovaDI is offline   Reply With Quote

Old   April 3, 2024, 13:29
Default
  #2
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 745
Rep Power: 14
Tobermory will become famous soon enough
Well that is understandable. A volTensorField is a completely different object to an array of doubles ...

Not convinced? Well, volTensorField is a typedef in volFieldsFwd.H (https://cpp.openfoam.org/v8/volField....html#l00062):
Code:
typedef GeometricField<tensor, fvPatchField, volMesh> volTensorField;
i.e. is a GeometricField. Now take a look in GeometricField.H (https://cpp.openfoam.org/v8/Geometri...8H_source.html) and you'll start to see the difference.
Tobermory is offline   Reply With Quote

Old   April 3, 2024, 15:03
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by RomanovaDI View Post
I need to convert volTensorField variable tf of OpenFOAM to c++ array of double. I've got the error:

Code:
cannot convert ‘Foam::volTensorField’ {aka ‘Foam::GeometricField<Foam::Tensor<double>, Foam::fvPatchField, Foam::volMesh>’} to ‘double*’
If I use tf.cdata() the error is:

Code:
cannot convert ‘const Foam::Tensor<double>*’ to ‘double*’

If you don't mind some ugliness and ONLY do this correctly, you can write something like the following:


Code:
volTensorField fld = ...;


reinterpret_cast<const scalar*>(fld.primitiveField().cdata());


// OR 
reinterpret_cast<const pTraits<tensor>::cmptType*>(fld.primitiveField().cdata());
but you must be really, really careful and know exactly what you are doing.
NOTE: always use scalar instead of double for the underlying component type since it is also possible to compile with single-precision or mixed-precision and then the tensor will comprise float not double.


NOTE: the above will only get you read access to the internal volume field, which is likely what you want anyhow. No really easy to do the same thing for each of the boundary fields as well without lots of code.
olesen is offline   Reply With Quote

Reply

Tags
cast, convert, double, openfoam, voltensorfield


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
Tool to convert OpenFoam mesh to SU2 mesh (2D and 3D) Combas SU2 45 October 16, 2024 18:26
[snappyHexMesh] Convert stl files and multi region abrunet OpenFOAM Meshing & Mesh Conversion 1 July 1, 2014 11:15
convert to structed mesh ok___ko Mesh Generation & Pre-Processing 0 April 22, 2013 06:23
convert a structured multiblock grid to an one unstructured: modification of cells Mirage ANSYS 0 July 18, 2012 10:14
ImageMagick will not convert jpg to mpg musahossein Main CFD Forum 1 December 2, 2011 11:44


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