|
[Sponsors] |
April 3, 2024, 09:45 |
convert Foam::volTensorField to double*
|
#1 |
New Member
Daria Romanova
Join Date: Jun 2016
Posts: 1
Rep Power: 0 |
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*’ Code:
cannot convert ‘const Foam::Tensor<double>*’ to ‘double*’ |
|
April 3, 2024, 13:29 |
|
#2 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 745
Rep Power: 14 |
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; |
|
April 3, 2024, 15:03 |
|
#3 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
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()); 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. |
||
Tags |
cast, convert, double, openfoam, voltensorfield |
|
|
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 |