
[Sponsors] 
Interpolation using interpolationLookUpTable or interpolationTable classes 

LinkBack  Thread Tools  Display Modes 
October 2, 2009, 16:56 
Interpolation using interpolationLookUpTable or interpolationTable classes

#1 
New Member
Scott Haynes
Join Date: May 2009
Posts: 10
Rep Power: 9 
I’d like to perform an interpolation on a volScalarField using a lookup table of values, interpolating linearly between defined points. For example if I have points (x & y, as shown in the table below and volScalarField X, I want to make a volScalarField Y corresponding to column y.
x  y  0  0 1  2 X=[0.2 0.4 0.5 0.6] i.e. Y would equal Y=[0.4 0.8 1.0 1.2 Based on the table . My first question is what class would be the best for this type of interpolation (Note that in the end it will not be a linear as shown above). After reading through the doxygen guide it looks like there are two classes to start with, "interpolationLookUpTable" and "interpolationTable". I'm not sure of the distinction between the two. I found a previous post regarding interpolationTable so I started there and I wrote a short program to figure out how to use it . Code:
#include "fvCFD.H" #include "interpolationTable.H" #include "List.H" int main(int argc, char *argv[]) { #include "setRootCase.H" #include "createTime.H" #include "createMesh.H" volScalarField X ( IOobject ( "X", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); // xy // Tuple2<scalar,scalar> a(0,0); Tuple2<scalar,scalar> b(1,2); List< Tuple2<scalar,scalar> > c ( a, b ); scalar d=0.5; Foam::interpolationTable<List<Tuple2<scalar,scalar> > > JUNK(c, {0,1,0,0}, ""); volScalarField Y=JUNK(X); Info << Y << endl; return 0; } crap3.C: In function âint main(int, char**)â: crap3.C:40: error: expected primaryexpression before â{â token crap3.C:41: error: no match for call to â(Foam::interpolationTable<Foam::List<Foam::Tuple2 <double, double> > >) (Foam::volScalarField&)â I think the error in line 40 has something to do with the boundsHandling argument. The constructor for this class is: Code:
interpolationTable ( const List<Tuple2<scalar, Type> >& values, const boundsHandling bounds, const fileName& fName ); Thanks 

May 19, 2011, 10:04 

#2 
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 8 
Hello Scott,
did you find a solution for implementing lookup tabels and the difference between mentioned classes? Regards, Ilya 

May 19, 2011, 11:52 

#3 
New Member
Scott Haynes
Join Date: May 2009
Posts: 10
Rep Power: 9 
It's been so long I can't remember specifically what I was asking but I do remember the solution. I just went ahead and wrote a function to do look ups for scalar fields, see below.
Code:
volScalarField SHlibInterp::Interp1(List<scalar> X, List<scalar> Y,volScalarField& Xi,volScalarField& Yi) { scalar m; scalar b; int FOUND; int jj; forAll(Xi.internalField(),ii) { FOUND=0; jj=0; while((FOUND==0) && (jj<X.size())) { if(Xi.internalField()[ii]<X[0]) { Yi.internalField()[ii]=0; FOUND=1; } else if(Xi.internalField()[ii]>X[X.size()]) { Yi.internalField()[ii]=Y[jj]; FOUND=1; } else if(Xi.internalField()[ii]>=X[jj] && Xi.internalField()[ii]<X[jj+1]) { m=(Y[jj+1]Y[jj])/(X[jj+1]X[jj]); b=Y[jj]m*X[jj]; Yi.internalField()[ii]=m*Xi.internalField()[ii]+b; FOUND=1; }; jj=jj+1; }; }; return(Yi); }; 

May 20, 2011, 07:06 

#4 
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 8 
Thank you!


August 31, 2012, 08:51 
Reading Scalars from dictionaries

#5  
Member

Quote:
I have a similar problem. It seems that your function is suitable for interpolating between scalars. So I want to use your function. But I should read X, Y and Xi from dictionaries. Do you have any idea to do this? Sincerely yours, Hossein 

September 3, 2012, 07:23 

#6 
Member

Hello,
It is solved. 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
momentum interpolation for collocated grid  Hadian  Main CFD Forum  4  December 25, 2009 08:25 
spline interpolation  bajjal  Main CFD Forum  0  May 29, 2006 08:27 
Interpolation for ghost cell help  zonexo  Main CFD Forum  0  March 11, 2006 21:03 
Single v.s. double precision  Confused  CFX  9  April 19, 2004 18:33 
Parallel Computing Classes at San Diego Supercomputer Center Jan. 2022  Amitava Majumdar  Main CFD Forum  0  January 5, 1999 13:00 