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

Trying to implement interpolation in openFOAM

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

Like Tree3Likes
  • 1 Post By niklas
  • 1 Post By niklas
  • 1 Post By niklas

Reply
 
LinkBack Thread Tools Display Modes
Old   January 10, 2012, 12:20
Default Trying to implement interpolation in openFOAM
  #1
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 198
Rep Power: 8
deji is on a distinguished road
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
File Type: jpg Interpolation.JPG (7.6 KB, 245 views)
deji is offline   Reply With Quote

Old   January 11, 2012, 11:53
Default
  #2
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 198
Rep Power: 8
deji is on a distinguished road
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.
deji is offline   Reply With Quote

Old   January 13, 2012, 10:59
Default all faces or a specific one
  #3
Senior Member
 
Fabian Roesler
Join Date: Mar 2009
Location: Germany
Posts: 209
Rep Power: 10
fabian_roesler is on a distinguished road
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
fabian_roesler is offline   Reply With Quote

Old   January 13, 2012, 11:19
Default
  #4
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 198
Rep Power: 8
deji is on a distinguished road
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 13:57.
deji is offline   Reply With Quote

Old   January 13, 2012, 13:14
Default
  #5
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 198
Rep Power: 8
deji is on a distinguished road
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.
deji is offline   Reply With Quote

Old   January 13, 2012, 14:13
Default
  #6
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 198
Rep Power: 8
deji is on a distinguished road
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!!!
deji is offline   Reply With Quote

Old   January 14, 2012, 01:16
Default
  #7
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 198
Rep Power: 8
deji is on a distinguished road
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??
deji is offline   Reply With Quote

Old   January 16, 2012, 03:25
Default
  #8
Senior Member
 
Fabian Roesler
Join Date: Mar 2009
Location: Germany
Posts: 209
Rep Power: 10
fabian_roesler is on a distinguished road
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
fabian_roesler is offline   Reply With Quote

Old   January 16, 2012, 14:09
Default
  #9
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 198
Rep Power: 8
deji is on a distinguished road
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?
deji is offline   Reply With Quote

Old   January 23, 2012, 13:24
Default
  #10
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 198
Rep Power: 8
deji is on a distinguished road
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!!!

deji is offline   Reply With Quote

Old   January 24, 2012, 03:06
Thumbs up Would be nice
  #11
Senior Member
 
Fabian Roesler
Join Date: Mar 2009
Location: Germany
Posts: 209
Rep Power: 10
fabian_roesler is on a distinguished road
Hi deji

Congratulations. Would be interesting to see your solution. Thanks for posting.

Regards

Fabian
fabian_roesler is offline   Reply With Quote

Old   January 24, 2012, 03:53
Default
  #12
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 21
niklas will become famous soon enoughniklas will become famous soon enough
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<interpolation<vector> > Uinterp = interpolation<vector>::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 likes this.
niklas is offline   Reply With Quote

Old   January 24, 2012, 09:49
Default
  #13
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 198
Rep Power: 8
deji is on a distinguished road
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<interpolation<vector> > Uinterp = interpolation<vector>::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?
deji is offline   Reply With Quote

Old   January 24, 2012, 09:59
Default
  #14
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 21
niklas will become famous soon enoughniklas will become famous soon enough
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.
hua1015 likes this.
niklas is offline   Reply With Quote

Old   January 24, 2012, 10:04
Default
  #15
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 21
niklas will become famous soon enoughniklas will become famous soon enough
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.
niklas is offline   Reply With Quote

Old   January 24, 2012, 10:11
Default
  #16
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 198
Rep Power: 8
deji is on a distinguished road
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
deji is offline   Reply With Quote

Old   January 24, 2012, 12:11
Default
  #17
Member
 
valerio
Join Date: Jun 2009
Location: Nancy
Posts: 30
Rep Power: 9
Alucard is on a distinguished road
Quote:
Originally Posted by deji View Post
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.
Alucard is offline   Reply With Quote

Old   July 6, 2012, 06:24
Default
  #18
Member
 
Björn Windén
Join Date: Feb 2012
Location: University of Southampton UK
Posts: 37
Rep Power: 6
winden is on a distinguished road
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.
winden is offline   Reply With Quote

Old   July 6, 2012, 06:53
Default
  #19
Member
 
Björn Windén
Join Date: Feb 2012
Location: University of Southampton UK
Posts: 37
Rep Power: 6
winden is on a distinguished road
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 : ) .
winden is offline   Reply With Quote

Old   September 25, 2014, 08:54
Default
  #20
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 8
linch is on a distinguished road
Quote:
Originally Posted by niklas View Post
Code:
    dictionary interpolationDict = mesh.solutionDict().subDict("interpolationSchemes");
    autoPtr<interpolation<vector> > Uinterp = interpolation<vector>::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.
linch is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible bug in OpenFoam Interpolation class MMC15 OpenFOAM Bugs 2 March 23, 2014 13:55
2D Mesh Generation Tutorial for GMSH aeroslacker Open Source Meshers: Gmsh, Netgen, CGNS, ... 12 January 19, 2012 04:52
Modified OpenFOAM Forum Structure and New Mailing-List pete Site News & Announcements 0 June 29, 2009 05:56
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 18:07
OpenFOAM Training and Workshop Zagreb 2628Jan2006 hjasak OpenFOAM 1 February 2, 2006 22:07


All times are GMT -4. The time now is 22:46.