|
[Sponsors] |
Access raw field data (scalars, vectors) on mesh |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 24, 2012, 09:05 |
Access raw field data (scalars, vectors) on mesh
|
#1 |
Senior Member
Join Date: Dec 2011
Posts: 111
Rep Power: 20 |
Hi,
I am trying to develop a writer module (.so shared library) to OpenFOAM to allow me to write the mesh and solution in a different format while running the analysis (in contrast to FIRST running the analysis and THEN converting to another format). To save disk space, I have a dictionary where I specify which fields I want to print: Code:
objectNames (U p); I tried to follow the code used in the sampling and probes libraries, since they do something not very far from what I need. I have successfully identified the fields I give in the dictionary, and made two functions that shall write the data: Code:
void Foam::h5Write::fieldWriteScalar() { forAll(scalarFields_, fieldI) { Info<< "fieldWriteScalar: " << scalarFields_[fieldI] << endl; } } Code:
fieldWriteScalar: p fieldWriteVector: U Code:
//Initialize a plain continous array for the data scalar vectorData[vectorField.size()][3]; // Loop through the field and construct the array forAll(vectorField, iter) { vectorData[iter][0] = vectorField[iter].x(); vectorData[iter][1] = vectorField[iter].y(); vectorData[iter][2] = vectorField[iter].z(); } // Write the data to disk writeFcn(vectorData); // Imaginary write function Thanks in advance. Last edited by haakon; September 24, 2012 at 09:37. |
|
September 24, 2012, 17:29 |
|
#2 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
I'm confused. Why does "<< scalarFields_[fieldI]" output the field name? It should output the field data in list form. This makes me wonder what scalarFields_ is.
Why are you copying the data from vectorField into vectorData? Shouldn't you make your write function work with the native OF data structures? Also, using a forAll loop over all the cells is slow.
__________________
~~~ Follow me on twitter @DavidGaden |
|
September 25, 2012, 10:12 |
|
#3 |
Senior Member
Join Date: Dec 2011
Posts: 111
Rep Power: 20 |
First I will try to explain a little more:
The scalarFields_ and vectorFields_ variables are lists containing references (names) to the different scalar- and vectorfields that are going to be written. The creation of these lists are a pure copy from src/sampling/probes/probesGrouping.C and associated files. My final goal is to have the solution written in a HDF5 (possibly also pNetCDF or CGNS) archive, rather than the one-file-per-variable-per-process-per-timestep approach. To do this, I need the data to be stored continously in memory, and then point H5Dwrite to the first element of this continous data chunk. As far as I know I cannot give H5Dwrite a pointer to OF's datastructures. Then I am left with constructing a simple array, copy the data I need into this and then pass a pointer to the first element to H5Dwrite. Please correct me if I am mistaken. The reason for doing this is to reduce the total number of files created by OpenFOAM during the analysis, and especially when involving lagrangian particles. The hopper tutorial produces 39 files per timestep per process! That is simply too much. Further work then also includes writing particle information to this archive. However, I have found the solution on my own (after a week with frustrating trial-and-error): Code:
forAll(vectorFields_, fieldI) Info<< "fieldWriteVector: " << vectorFields_[fieldI] << endl; const volVectorField& field = obr_.lookupObject<volVectorField> ( vectorFields_[fieldI] ); //Initialize a plain continous array for the data scalar vectorData[field.size()][3]; // Loop through the field and construct the array forAll(field, iter) { vectorData[iter][0] = field[iter].x(); vectorData[iter][1] = field[iter].y(); vectorData[iter][2] = field[iter].z(); } // // Initialize and create HDF5 dataset here // (cut away - not intersting) // // Do the actual write H5Dwrite ( dsetID, H5T_SCALAR, H5S_ALL, H5S_ALL, plistID, vectorData ); } I will of course release this work to the public after I have done some initial testing and verification. |
|
September 25, 2012, 11:01 |
|
#4 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
If you replace the forAll loop with a pointer loop, it will be about 10x faster. OpenFOAM implements these in src\OpenFOAM\fields\Fields\Field\FieldM.H... but this will make your code ugly and difficult to maintain.
__________________
~~~ Follow me on twitter @DavidGaden |
|
Tags |
access, data, field, raw |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[snappyHexMesh] Add Mesh Layers doesnt work on the whole surface | Kryo | OpenFOAM Meshing & Mesh Conversion | 13 | February 17, 2022 08:34 |
Gambit problems | Althea | FLUENT | 22 | January 4, 2017 04:19 |
How to access to field point data | zxj160 | OpenFOAM Programming & Development | 6 | May 21, 2015 06:35 |
The Field Scalars in Tascflow | Darcy | CFX | 0 | November 19, 2003 23:14 |
Mesh for 3 dim Geometry | Phil | FLUENT | 9 | July 12, 2000 05:39 |