# Trying to implement interpolation in openFOAM

 Register Blogs Members List Search Today's Posts Mark Forums Read

January 10, 2012, 11:20
Trying to implement interpolation in openFOAM
#1
Senior Member

n/a
Join Date: Sep 2009
Posts: 199
Rep Power: 15
Can someone please give me some feedback? I am trying to figure this out and running out of ideas as to how to solve it: Please look at the attached jpg file. During run time, how can I acquire quantities at points V and N via interpolation, with P being the cell centered node?
Attached Images
 Interpolation.JPG (7.6 KB, 398 views)

 January 11, 2012, 10:53 #2 Senior Member   n/a Join Date: Sep 2009 Posts: 199 Rep Power: 15 It seems there is no one here on the forum that has a clue about this, and I do find that hard to believe. For the interpolated quantities at point N, I thought of two things: 1)Is there a function available in OpenFOAM that would allow me to gain access to these faces OR 2) Perhaps I can calculate the normal wall distance from the wall to the face, and subsequently get hold of all the faces at this distance from the wall. I have being digging through the forum and haven't found anything on this. There has to be a way or maybe I might have to code this, and some feedback on this will be extremely helpful.

 January 13, 2012, 09:59 all faces or a specific one #3 Senior Member   Fabian Roesler Join Date: Mar 2009 Location: Germany Posts: 213 Rep Power: 17 hi deji do you have a specific point in your mesh where you want to know the temperature? Then you could use a probe. If you want the temperatures on each face of the cells you could interpolate your volScalarField onto the faces gaining a surfaceScalarField. Hope this is what you meant. Regards Fabian

 January 13, 2012, 10:19 #4 Senior Member   n/a Join Date: Sep 2009 Posts: 199 Rep Power: 15 Hi Fabian. Well, if you look at the diagram, I would like to know quantities at point V, and it is at y*=10.8. So I suppose I could use a probe at run time, is that correct? So I can do this at this height for the entire 3D field? Also, I know how to compute the surface quantities, I just do not know how to access those particular faces near the wall, point N in the picture attached. Thanks much Fabian for your feedback, I really appreciate it. Cheers, Deji Last edited by deji; January 26, 2012 at 12:57.

 January 13, 2012, 12:14 #5 Senior Member   n/a Join Date: Sep 2009 Posts: 199 Rep Power: 15 It seems I ought to be able to use probe* to compute quantities at v, so I just have to figure out how to implement that for my entire domain.

 January 13, 2012, 13:13 #6 Senior Member   n/a Join Date: Sep 2009 Posts: 199 Rep Power: 15 After thinking about this, I do not think I can use probe to get the quantities at point V. I will have to interpolate for those quantities at run time. Still trying to figure it out!!!

 January 14, 2012, 00:16 #7 Senior Member   n/a Join Date: Sep 2009 Posts: 199 Rep Power: 15 Hello Foamers. Okay, so I think I've figured out how to get the interpolated surface quantities at point N. This is my thought and would greatly appreciate if someone can help comment or give me some feedback. 1) Acquire boundary faces 2) Get all internal faces 3) Perform dot product of unit face normals & axis direction of interest (say X), check magnitude, and select those magnitude is one. 4) Get cell height near wall using nearWallDist, and multiply value by 2 for cell height 5) Check the X location of the faces chosen from (3) and if it is the distance calculated from 4 away from the wall, it is the face whose quantities I pick to use..... Now I just have to code this, any feedback from the experts here on the forum??

 January 16, 2012, 02:25 #8 Senior Member   Fabian Roesler Join Date: Mar 2009 Location: Germany Posts: 213 Rep Power: 17 Hi deji I started into weekend after my last post and didn't check your replays. I think you’re on the right trip. I wanted to suggest the same thing: Identify the cells with boundary faces and select the face with a normal vector pointing away from the boundary face. This gets even simpler when using a hex mesh. Regards Fabian

 January 16, 2012, 13:09 #9 Senior Member   n/a Join Date: Sep 2009 Posts: 199 Rep Power: 15 Thanks for the feedbacks. I am working on the coding and trying to find a decent way of getting a list of just the internal faces. I am get a list of all the faces, patch faces, but not the internal faces alone. How would I go about to get that list?

 January 23, 2012, 12:24 #10 Senior Member   n/a Join Date: Sep 2009 Posts: 199 Rep Power: 15 Hello to the OpenFOAM forum. Problem fixed, if anyone has a similar issue, I can post the section of the code that covers this topic!!!

 January 24, 2012, 02:06 Would be nice #11 Senior Member   Fabian Roesler Join Date: Mar 2009 Location: Germany Posts: 213 Rep Power: 17 Hi deji Congratulations. Would be interesting to see your solution. Thanks for posting. Regards Fabian

 January 24, 2012, 02:53 #12 Super Moderator     Niklas Nordin Join Date: Mar 2009 Location: Stockholm, Sweden Posts: 694 Rep Power: 28 just discovered this thread probe will do the trick if you know the position at start, but if you want a variable position, calculated at runtime, I dont know if probe can do this. Althought with the recent improvement with formulas it might be possible. Still, what you want is something like this Code: ``` dictionary interpolationDict = mesh.solutionDict().subDict("interpolationSchemes"); autoPtr > Uinterp = interpolation::New(interpolationDict, U); vector pos(0,0,0); label cellI = mesh.findCell(pos); vector Ui = Uinterp->interpolate(pos, cellI);``` Here I have, as an example, put the interpolationSchemes dictionary in fvSolution. So you need to add the type of interpolation to fvSolution, like below. Code: ```interpolationSchemes { U SCHEME; }``` now SCHEME is obviously not a valid interplation scheme, but if you leave it like that it will tell you the valid options. N sharonyue and peterTr like this.

 January 24, 2012, 08:49 #13 Senior Member   n/a Join Date: Sep 2009 Posts: 199 Rep Power: 15 Hey Fabian. Sure, I will post the code that I implemented. Hey Niklas. I do know the points that I would like to probe, and it is many that I would need for a wall function. Hence, in this code: dictionary interpolationDict = mesh.solutionDict().subDict("interpolationSchemes" ); autoPtr > Uinterp = interpolation::New(interpolationDict, U); vector pos(0,0,0); label cellI = mesh.findCell(pos); vector Ui = Uinterp->interpolate(pos, cellI); So that means I would have multiple vector positions, perhaps I can loop through all the vectors, what do you think?

 January 24, 2012, 08:59 #14 Super Moderator     Niklas Nordin Join Date: Mar 2009 Location: Stockholm, Sweden Posts: 694 Rep Power: 28 you just change it to Code: ```vectorList positions = ..something; forAll(positions, i) { label cellI = mesh.findCell(positions[i]); vector Ui = Uinterp->interpolate(positions[i], cellI); }``` if the mesh and positions are static you can do the findCell loop only 1 time and store the cell labels, since the findCell operation is quite time-consuming, you'd want to do that as little as possible. Code: ```// outside the loop in the beginning vectorList positions; labelList cellIndex(positions.size()); forAll(positions, i) { cellIndex[i] = mesh.findCell(positions[i]); } // inside the loop forAll(positions, i) { vector Ui = Uinterp->interpolate(positions[i], cellIndex[i]); }``` dont copy/paste this as Im sure there are quite a few typo's. vortexnix and hua1015 like this.

 January 24, 2012, 09:04 #15 Super Moderator     Niklas Nordin Join Date: Mar 2009 Location: Stockholm, Sweden Posts: 694 Rep Power: 28 but if you have positions known at the start, why dont you just just probes. Here's how it would look like for 2 probes. (Just stick it in the controlDict) Code: ```functions { UProbes { type probes; functionObjectLibs ("libfieldFunctionObjects.so"); enabled true; outputControl timeStep; outputInterval 10; log false; valueOutput false; probeLocations ( ( 0.5 0.01 -0.01 ) (-1 0.0 0.0) ); fields ( U ); } }``` hua1015 likes this.

 January 24, 2012, 09:11 #16 Senior Member   n/a Join Date: Sep 2009 Posts: 199 Rep Power: 15 Thanks much Niklas. I actually know where I want to get the quantities, but not the exact points at runtime. Therefore, I will not be able to prescribe the points as probes in controlDict. Thanks again, I will try it... Cheers, Deji

January 24, 2012, 11:11
#17
Member

valerio
Join Date: Jun 2009
Location: Nancy
Posts: 30
Rep Power: 16
Quote:
 Originally Posted by deji Hello to the OpenFOAM forum. Problem fixed, if anyone has a similar issue, I can post the section of the code that covers this topic!!!
Hello I've a similar problem so i'll be glad to you if you can post (and explain a little) it.

July 6, 2012, 06:24
#18
Member

Björn Windén
Join Date: Feb 2012
Location: National Maritime Research Institute, Tokyo, Japan
Posts: 37
Rep Power: 13
Hi.

Any idea how you would achieve an interpolation like this
Quote:
 Code: ```forAll(positions, i) { cellIndex[i] = mesh.findCell(positions[i]); } forAll(positions, i) { vector Ui = Uinterp->interpolate(positions[i], cellIndex[i]); }```
in a function object where the positions and cell indices are set before the simulation starts and saved in memory to avoid calling the findCell command in every timestep? It works fine to save them as labelLists when running in serial but, when getting it to run in parallel, I run into trouble with the cell indices. I can't seem to get my head around how to get the global/local numbering to be consistent from when I save them to when I use them for interpolation.

I tried something like:

Before simulation start
Code:
```for ( int i=0 ; i <= npts ; i++)
{
cellsI[i]=-1;
cellsI[i]=mesh.findCell(pointLists[i]);
if (cellsI[i] != -1)
{
cellsI[i]= globalCells_.toGlobal(cellsI[i]);
}
}
reduce(cellsI,maxOp<List<label> >());```
And at each timestep:

Code:
```autoPtr<interpolation<scalar> > alphaint =interpolation<scalar>::New(interpolationDict_,obr_.lookupObject<volScalarField>("alpha1"));

for loop
{
if (cellsI[i] > 0)
{
alphai[i] = alphaint->interpolate(pointLists[i], cellsI[i]);
}
}
reduce(alphai,maxOp<List<double> >());```
I tried to put
Code:
`cellsI[i] = globalCells_.toLocal(cellLists_[i]);`
before the interpolation but without success.

PS. I want to use the interpolated values for some run-time calculations after I have retrieved them which is why I'm not simply using probes.

 July 6, 2012, 06:53 #19 Member   Björn Windén Join Date: Feb 2012 Location: National Maritime Research Institute, Tokyo, Japan Posts: 37 Rep Power: 13 As always, the minute after I posted, I figured out what was wrong. I got rid of the reduce(cellsI)-command and the toGlobal and then it works since everything is kept local without the masters interference : ) .

September 25, 2014, 08:54
#20
Senior Member

Illya Shevchuk
Join Date: Aug 2009
Posts: 176
Rep Power: 15
Quote:
 Originally Posted by niklas Code: ``` dictionary interpolationDict = mesh.solutionDict().subDict("interpolationSchemes"); autoPtr > Uinterp = interpolation::New(interpolationDict, U); vector pos(0,0,0); label cellI = mesh.findCell(pos); vector Ui = Uinterp->interpolate(pos, cellI);```
The code doesn't work in the OF 2.1.x. I'm gettig an error in the second line of it:
Quote:
 interpolateU.H: In function ‘int main(int, char**)’: interpolateU.H:2:9: error: ‘interpolation’ was not declared in this scope interpolateU.H:2:29: error: template argument 1 is invalid
Do I have to #include something, to make it work?

Solved: #include interpolation.H did the job

Regards,
Ilya

Last edited by linch; September 25, 2014 at 10:40.