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

How to interpolate field value at any give point in a cell?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 25, 2021, 01:43
Question How to interpolate field value at any give point in a cell?
  #1
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Dear Foamers,

suppose I know the point cloud (point mass particles) positions in the CFD domain. I want to know the velocities at the point mass particle locations.

Obvious we need to interpolate point field value in cell where the point particle is located. In my case, the U field is known, and the mesh is uniform. I could simply code a Trilinear interpolation scheme (or inverse distance weighting), however I suppose these algorithms already exist in OpenFOAM.

The thing is in OF, it is so complicated to fine-tune some functions, as the right low-level API is hard to find (most hated), and hard to use. what I did so far:

Code:
#include "interpolationCellPoint.H"
#include "interpolationCellPointFace.H"

....


autoPtr <Foam::interpolation<vector>> U_interp;

 Uf_interp = Foam::interpolation<vector>::New("cellPoint", U);
 //Uf_interp.reset(Foam::interpolation<vector>::New("cellPoint", U).ptr());
Suppose the point at vector p(x, y, z) is inside cell_i: so the interpolated velocity at p should be like:

Quote:
Foam::vector U_p = U_interp.interpolate(p, cell_i);
Nevertheless, it seems that interpolate function does not exit.
Quote:
class Foam::autoPtr<Foam::interpolation<Foam::Vector<dou ble> > >’ has no member named ‘interpolate’
But the function interpolate is clearly defined in code (line 84): What is the possible reason to for this error? I alwalys had headache to deal with OF's overly-complicated low-level functions or data structure (not modern C++ built-in ones), even after years of CFD/OF experience.

Any suggestions would be appreciated!

Update 1: tried a new method:

Code:
  const objectRegistry& db = mesh_.thisDb();
  const IOdictionary& fvSchemes = db.lookupObject<IOdictionary>("fvSchemes");
  dictionary interpolationSchemes = fvSchemes.subDict("interpolationSchemes");

  Uf_interp = Foam::interpolationCellPoint<vector>::New(interpolationSchemes, coupling_world.UField());

... 
vector Up = Uf_interp().interpolate(p, cell_i);
still no success. First error says "U" is missing in interpolationSchemes, when I add "U linear", and it says "flux(U)" is missing, in this case linear is no longer suitable. I can't believe I am stuck in this simple issue. Using OF with low level functions is really struggling.

Update 2: Can't believe so much time wasted on this simple issue (complexity-wise). Will implement Trilinear interpolation scheme for point field value at given position / cell-ID (uniform mesh), this might save my day!

Last edited by keepfit; October 25, 2021 at 09:59.
keepfit is offline   Reply With Quote

Old   October 25, 2021, 06:28
Default
  #2
Member
 
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 94
Rep Power: 15
einstein_zee is on a distinguished road
Hi there, Can you try this one "U_interp().interpolate(p, cell_i)".
einstein_zee is offline   Reply With Quote

Old   October 25, 2021, 07:12
Default
  #3
Member
 
s1291's Avatar
 
Join Date: Aug 2017
Location: Algeria
Posts: 98
Rep Power: 9
s1291 is on a distinguished road
Maybe it is useful to take a look to some function objects that use the interpolation, e.g.:

Code:
$FOAM_SRC/functionObjects/field/streamlines/streamlinesParticle.H
or
Code:
$FOAM_SRC/functionObjects/field/streamlines/streamlines.C
s1291 is offline   Reply With Quote

Old   October 25, 2021, 08:22
Talking
  #4
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by einstein_zee View Post
Hi there, Can you try this one "U_interp().interpolate(p, cell_i)".
Thanks! I added
Code:
dictionary interpolationDict = mesh.solutionDict().subDict("interpolationSchemes");
Uf_interp = Foam::interpolationCellPoint<vector>::New(interpolationDict, coupling_world.UField());
and tried your method to add "()", seems still not working

Code:
Entry 'interpolationSchemes' not found in dictionary "... mycase/system/fvSolution"
"interpolationSchemes" does exist in system/fvSchemes, why OF looking for the keyworld in fvSolution?
keepfit is offline   Reply With Quote

Old   October 25, 2021, 08:31
Talking
  #5
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by s1291 View Post
Maybe it is useful to take a look to some function objects that use the interpolation, e.g.:

Code:
$FOAM_SRC/functionObjects/field/streamlines/streamlinesParticle.H
or
Code:
$FOAM_SRC/functionObjects/field/streamlines/streamlines.C
Thanks for the hint. Again, i have to deal with the " particle::trackingData" API. Seems in OF some simplest functionalities are buried so deeply so that u have go through A LOT of digging up. . All I need is to obtain interpolated field at position p within given cell-i.
keepfit is offline   Reply With Quote

Old   October 25, 2021, 14:31
Default
  #6
Member
 
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 94
Rep Power: 15
einstein_zee is on a distinguished road
Quote:
Originally Posted by keepfit View Post
Thanks! I added
Code:
dictionary interpolationDict = mesh.solutionDict().subDict("interpolationSchemes");
Uf_interp = Foam::interpolationCellPoint<vector>::New(interpolationDict, coupling_world.UField());
and tried your method to add "()", seems still not working

Code:
Entry 'interpolationSchemes' not found in dictionary "... mycase/system/fvSolution"
"interpolationSchemes" does exist in system/fvSchemes, why OF looking for the keyworld in fvSolution?
It looks in fvSolution because you told him to . You are using "mesh.solutionDict()" and that is the solution dictionary("fvSolution")... you may try it with mesh.schemesDict() instead.
einstein_zee is offline   Reply With Quote

Old   October 26, 2021, 07:33
Default
  #7
Senior Member
 
David Long
Join Date: May 2012
Location: Germany
Posts: 104
Rep Power: 14
keepfit is on a distinguished road
Quote:
Originally Posted by einstein_zee View Post
It looks in fvSolution because you told him to . You are using "mesh.solutionDict()" and that is the solution dictionary("fvSolution")... you may try it with mesh.schemesDict() instead.
thanks for the tip. I actually did it in Update 1. However, the error is:

Quote:
Entry 'U' not found in dictionary "xxx/system/fvSchemes.interpolationSchemes"
when I change interpolationSchemes to:

Code:
interpolationSchemes
{
    default         linear;
    U               cellPoint;
}
It seems okay. I need to test whether the interpolate(pos, cell_i) function works or not.

Update 1:

Fluid velocity at point particle location seems not interpolated correctly by
Quote:
Foam::vector U_p = U_interp.interpolate(p, cell_i);
cellPoint changed to cellPointFace, the interpolated field at point p seems not right as well, according to point field values on the cell_i's vertices (U_p < every cell_point field value!).

Last edited by keepfit; October 26, 2021 at 12:08.
keepfit is offline   Reply With Quote

Old   May 30, 2022, 14:32
Default How interpolate results in cell points (nodes)
  #8
New Member
 
zurich
Join Date: Apr 2022
Posts: 3
Rep Power: 4
Saeb-sahand is on a distinguished road
How interpolate results in cell points (nodes)
For instace, how interpolate scalareField (P,T) in cell points?
Saeb-sahand is offline   Reply With Quote

Reply

Tags
interpolate, point field


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
[swak4Foam] swakExpression not writing to log alexfells OpenFOAM Community Contributions 3 March 16, 2020 19:19
How to get cell indices and manipulate field data ch1 OpenFOAM Programming & Development 5 September 25, 2019 12:17
fvc::interpolate(rAU) at boundary faces Jesper_Roland OpenFOAM Programming & Development 5 January 30, 2019 09:55
Get Velocity Field at a specific mesh point (centroid point) benhamlaoui OpenFOAM Programming & Development 0 March 26, 2018 10:00
OpenFOAM floating point Error upuli OpenFOAM Programming & Development 5 June 20, 2016 04:19


All times are GMT -4. The time now is 13:17.