CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   lookup non included scalars from a list (http://www.cfd-online.com/Forums/openfoam-programming-development/105864-lookup-non-included-scalars-list.html)

atoof August 11, 2012 02:34

lookup non included scalars from a list
 
Hi,

I need to lookup a list from a dictionary composed such as follows:

c_vs_w
100
(
( 0 0.001)
( 0.01 0.001)
( 0.02 0.001)
( 0.03 0.001)
.
.
.
)

I want to access to second values of above list by looking up the first values. During the run, it should be looked up non-included scalar from the list (finding corresponding value of 0.015 ,for instance). Can someone suggest me how to do it?
I study different utility and application such as interpolateXY, interpolationTable , etc.

Thank you in advance,
Moha

Hisham August 11, 2012 07:30

Quote:

Originally Posted by atoof (Post 376533)
Hi,

I need to lookup a list from a dictionary composed such as follows:

c_vs_w
100
(
( 0 0.001)
( 0.01 0.001)
( 0.02 0.001)
( 0.03 0.001)
.
.
.
)

I want to access to second values of above list by looking up the first values. During the run, it should be looked up non-included scalar from the list (finding corresponding value of 0.015 ,for instance). Can someone suggest me how to do it?
I study different utility and application such as interpolateXY, interpolationTable , etc.

Thank you in advance,
Moha

Hello

Your post is not really sufficient for you to get help. I suggest you give more details:
http://www.cfd-online.com/Forums/ope...-get-help.html

I think you can take a look at:
Code:

tmp<Field<Type> > timeVaryingMappedFixedValueFvPatchField<Type>::interpolate)
in the C++ doc.

Regards
Hisham

atoof August 13, 2012 01:05

Dear Hisham,

Thanks for reply. Indeed, in my simulation, I obtain a passive scalar (b) by solving a transport equation in a field with a certain U and P. Then I need to interpolate scalars from a table as a source term (W) by the value of "b" and send it to a solver. This lookup table consists of lists such as
100
(
(b1 w1)
(b2 w2)
(b3 w3)
(b4 w4)
.
.
.
)
.
I need to reach a "W" which is corresponding with a "b". My question is "How can this procedure be done?".

I studied timeVaryingMappedFixedValueFvPatchField but I don't know how to use it. I think this function in used for boundary condition. But I should find the source term in my entire field.

Best Regards
Hossein

Hisham August 13, 2012 06:03

Dear Hossein,

I do not really know if such a possibility is actually available in OpenFOAM. I am sure someone must have implemented it before. The available interpolations are time interpolations or space interpolations over the mesh.

Nevertheless, introducing interpolation to the code in your case should not be difficult.

I think it may be interesting to take a look at other libraries for interpolation (to link to your solver):

gsl: http://www.gnu.org/software/gsl/
http://www.gnu.org/software/gsl/manu...rpolation.html

CGAL: http://www.cgal.org/Manual/latest/do...:Interpolation

A more careful search can yield better (more convenient) options.

Regards
Hisham

ngj August 13, 2012 08:14

Hi Hossein

You should be able to do something in the following way, where I assume you have the b and w coefficients as two scalarFields (the code below has not been tested).

Code:

// scalarField B = <KNOWN>
// scalarField W = <KNOWN>

// Your parameter b-simulation
scalar bSim(<some value>);

// Your source term w-simulation
scalar wSim( Foam::interpolateXY( bSim, B, W ) );

interpolateXY is a function and not an object, which I why you cannot construct it.

Furthermore, remember to include the following in your files:

Code:

#include "interpolateXY.H"
Please note that this yields a linear interpolation. If you need other types (higher order) interpolation scheme, then I am not sure if it is readably available in OF.

Kind regards,

Niels

atoof August 14, 2012 01:19

Thanks Niels,
It seems that I can implement it my code. I test it asp.
Code:

// scalarField B = <KNOWN>
// scalarField W = <KNOWN>
 
// Your parameter b-simulation
scalar bSim(<some value>);
 
// Your source term w-simulation
scalar wSim( Foam::interpolateXY( bSim, B, W ) );

But I have a file contains a list which includes both "b" and "w" such as my previous post. how can I define this list(of list) and access to it's member.

Best Regards,
Hossein

kathrin_kissling August 14, 2012 02:25

Hey,

are the lists of the same size as your mesh?

Best

Kathrin

atoof August 15, 2012 07:21

Hello Kathrin,

Not necessarily. In my code, it has 100 members.

Sincerely yours,

Hossein

atoof August 16, 2012 16:53

Dears,
You should be able to do something in the following way, where I assume you have the b and w coefficients as two scalarFields (the code below has not been tested).

I read some other posts such as:
http://www.cfd-online.com/Forums/ope...tml#post308408
But I do not know the format of input files (X,Y,Xi in above code) to the code? and how can I read them through the code?

Thank you in advance,
Hossein

atoof September 3, 2012 07:31

Solved
 
Dears,

Finally we find the solution:D. We Used the following for reeding scalars from two lists in a dictionary.
Code:

    IOobject dictHdr
    (
                    "listTestDict",
                    runTime.system(),
                    mesh,
                    IOobject::MUST_READ,
                    IOobject::NO_WRITE
    );

    IOdictionary dict(dictHdr);

    List<scalar> X(dict.lookup("X"));
    List<scalar> Y(dict.lookup("Y"));



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