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

Interpolation using interpolationLookUpTable or interpolationTable classes

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

Reply
 
LinkBack Thread Tools Display Modes
Old   October 2, 2009, 16:56
Default Interpolation using interpolationLookUpTable or interpolationTable classes
  #1
New Member
 
Scott Haynes
Join Date: May 2009
Posts: 10
Rep Power: 8
scotth2o is on a distinguished road
Id 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
    );
                        //  x|y
                        //------
    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;
}
When I compile I get the following errors



crap3.C: In function int main(int, char**):
crap3.C:40: error: expected primary-expression 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
           );
At this point I'd like to know if this is the most efficient way to solve the problem. If so can someone help with the syntax of the example above?

Thanks
scotth2o is offline   Reply With Quote

Old   May 19, 2011, 10:04
Default
  #2
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 174
Rep Power: 7
linch is on a distinguished road
Hello Scott,

did you find a solution for implementing lookup tabels and the difference between mentioned classes?

Regards,
Ilya
linch is offline   Reply With Quote

Old   May 19, 2011, 11:52
Default
  #3
New Member
 
Scott Haynes
Join Date: May 2009
Posts: 10
Rep Power: 8
scotth2o is on a distinguished road
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);
    };
scotth2o is offline   Reply With Quote

Old   May 20, 2011, 07:06
Default
  #4
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 174
Rep Power: 7
linch is on a distinguished road
Thank you!
linch is offline   Reply With Quote

Old   August 31, 2012, 08:51
Default Reading Scalars from dictionaries
  #5
Member
 
Hossein
Join Date: Apr 2010
Posts: 62
Rep Power: 7
atoof is on a distinguished road
Send a message via Yahoo to atoof
Quote:
Originally Posted by scotth2o View Post

Code:
volScalarField SHlibInterp::Interp1(List<scalar> X, List<scalar> Y,volScalarField& Xi,volScalarField& Yi)
Hello Scott,

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
atoof is offline   Reply With Quote

Old   September 3, 2012, 07:23
Default
  #6
Member
 
Hossein
Join Date: Apr 2010
Posts: 62
Rep Power: 7
atoof is on a distinguished road
Send a message via Yahoo to atoof
Hello,

It is solved.
atoof 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
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. 20-22 Amitava Majumdar Main CFD Forum 0 January 5, 1999 13:00


All times are GMT -4. The time now is 20:53.