CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Pre-Processing

Mapping csv (or other text format) data sets onto volumetric mesh

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 24, 2017, 11:14
Default Mapping csv (or other text format) data sets onto volumetric mesh
  #1
Senior Member
 
Vesselin Krastev
Join Date: Jan 2010
Location: University of Tor Vergata, Rome
Posts: 368
Rep Power: 20
vkrastev is on a distinguished road
Hi all,

my issue is quite straightforward: I need to map a data set (velocity field), which is contained in a csv file, onto an OpenFOAM mesh for flow initialization. The data set is 3D and ordered in columns. I have 3 columns representing the x,y,z coordinates of the nodes where velocities are stored, plus 3 columns representing the x,y,z velocity components. I know how to export data from OF to csv files (through Paraview), but I don't know how to do the opposite. Note that in my case the coordinates contained in the csv file are perfectly conformal to the coordinates of the cell centres in the target mesh. The latter is a simple 64^3 cubic mesh with equally spaced hexahedrons.

Thank you in advance for your help

V.
vkrastev is offline   Reply With Quote

Old   July 24, 2017, 11:25
Default
  #2
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30
akidess will become famous soon enough
I don't think there's a built-in way. It's fairly straight forward to write your own tool though that reads your input file, finds the corresponding cells (using the convieniently named mesh.findCell function) and sets the value. Your mesh is so small you probably don't even need to worry about parallelization.
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
akidess is offline   Reply With Quote

Old   July 24, 2017, 12:52
Default
  #3
Senior Member
 
Vesselin Krastev
Join Date: Jan 2010
Location: University of Tor Vergata, Rome
Posts: 368
Rep Power: 20
vkrastev is on a distinguished road
Quote:
Originally Posted by akidess View Post
I don't think there's a built-in way.
I was suspecting this, what surprises me is that I've found a relatively low amount of people asking about this (missing) feature around the web...


Quote:
Originally Posted by akidess View Post
(using the convieniently named mesh.findCell function) and sets the value.
Can you share some coding example or piece of existing code where this function is applied?

Thanks

V.
vkrastev is offline   Reply With Quote

Old   July 25, 2017, 05:41
Default
  #4
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30
akidess will become famous soon enough
I wrote very similar code for my PhD, but it will take a while to dig it up again.
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
akidess is offline   Reply With Quote

Old   July 25, 2017, 05:52
Default
  #5
Senior Member
 
Vesselin Krastev
Join Date: Jan 2010
Location: University of Tor Vergata, Rome
Posts: 368
Rep Power: 20
vkrastev is on a distinguished road
Quote:
Originally Posted by akidess View Post
I wrote very similar code for my PhD, but it will take a while to dig it up again.
Well, if you succeed in digging it up that would be great.

Thanks anyway for your responses.

V.
vkrastev is offline   Reply With Quote

Old   July 27, 2017, 16:49
Default
  #6
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30
akidess will become famous soon enough
Code:
    for (long row=1; row<=csv_total_rows; row++)
    {
        for(long column=1; column<=csv_total_columns; column++)
        {
            long index = (row-1)*csv_total_columns+column-1;
            scalar xpos = csv_data[index].nodeposition[0];
            scalar ypos = csv_data[index].nodeposition[1];
            scalar zpos = csv_data[index].nodeposition[2];
            vector pos(xpos, ypos, zpos);
            label ofCellLabel = vsf().mesh().findCell(pos);
            vsf[ofCellLabel] = csv_data[index].value();
        }
    }
Where vsf is your volScalarField, and you read and parsed the CSV file by standard C++ methods somewhere else. Easy
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
akidess is offline   Reply With Quote

Old   July 28, 2017, 14:58
Default
  #7
Senior Member
 
Vesselin Krastev
Join Date: Jan 2010
Location: University of Tor Vergata, Rome
Posts: 368
Rep Power: 20
vkrastev is on a distinguished road
Ok, thanks.
vkrastev is offline   Reply With Quote

Old   June 17, 2019, 09:41
Default Where to implement this code?
  #8
New Member
 
Wolvi_Tin
Join Date: Jun 2019
Posts: 1
Rep Power: 0
kudetisiddhartha is on a distinguished road
Quote:
Originally Posted by akidess View Post
Code:
    for (long row=1; row<=csv_total_rows; row++)
    {
        for(long column=1; column<=csv_total_columns; column++)
        {
            long index = (row-1)*csv_total_columns+column-1;
            scalar xpos = csv_data[index].nodeposition[0];
            scalar ypos = csv_data[index].nodeposition[1];
            scalar zpos = csv_data[index].nodeposition[2];
            vector pos(xpos, ypos, zpos);
            label ofCellLabel = vsf().mesh().findCell(pos);
            vsf[ofCellLabel] = csv_data[index].value();
        }
    }
Where vsf is your volScalarField, and you read and parsed the CSV file by standard C++ methods somewhere else. Easy
Hallo,

I am very new to OpenFoam and c++ coding. I have a similar case like this. Can you please help me on how and where should i implement this in my source code?
Regards
kudetisiddhartha 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Salome cgns format mesh to SU2 JPBLourenco SU2 19 November 18, 2019 03:11
UDF for Mapping 3D Experimental Data (Heat Generation) to Mesh jbo214 Fluent UDF and Scheme Programming 1 May 15, 2017 16:47
Mapping values from 2D mesh to 3D mesh boundary during runtime benk OpenFOAM Programming & Development 1 June 13, 2014 03:39
Compare two data sets same mesh gregjunqua OpenFOAM Post-Processing 0 February 24, 2014 21:02
Icemcfd 11: Loss of mesh from surface mesh option? Joe CFX 2 March 26, 2007 19:10


All times are GMT -4. The time now is 07:09.