CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   How to use "interpolation" utility in my own code (http://www.cfd-online.com/Forums/openfoam/91465-how-use-interpolation-utility-my-own-code.html)

frankyux August 11, 2011 14:57

How to use "interpolation" utility in my own code
 
Hello,

I am trying to call the interpolation functions from "finiteVolume" folder in my own code. My purpose is, by knowing a GeometricField ( "vf" for example ) and it's corresponding mesh grid ( mesh().C(), a volVectorField? ), given a coordinate (x0,y0,z0), interpolate the function value vf(x0,y0,z0).

I've read through the source code in " .../finiteVolume/interpolation/... " and " .../OpenFOAM/interpolations/... ", didn't find any function can fit my input format, which is a GeometricField, volVectorField, and a vector (x,y,z). Any similar situation have you been through before? Or any ideas?

Thanks for your time.

Frank

frankyux September 7, 2011 12:28

Have tried some alternative ways but still doesn't work, anybody knows how to solve it? or any similar situations?

kathrin_kissling September 7, 2011 13:57

Hi Frank,

what do you inted to do? Do you want to interpolate around a point?
Or do you want the value in a specific point?

For interpolation to the mesh faces just go
surfaceVectorField sVF = vF.interpolate();

Then search for the face center closest to what you need. Grap its face id and do
vector sV = sVF[faceI];

You definitely need to specify because interpolation is a very wide field...
Then we can try to help you!


Best

Kathrin

frankyux September 7, 2011 14:06

Hi Kathrin,

Thanks for the reply. My purpose is, given a specific point 'vector X', find out what is the value of vf.oldTime() at that point. And since that point 'X' may not exactly on the meshgrid, i need to interpolate it by the known vf values.

Frank

kathrin_kissling September 8, 2011 02:26

Hi Frank,

so what you need to do:

First find the cell where it is located:


label myCellLabel = mesh.findNearestCell(yourPoint);

labelList adjacentCells = mesh.cellCells()[myCellLabel];

Then find the centers of the adjacent cells calculte the distance to your point -> weighting factors and interpolate

Hope this being of help!

Kathrin

frankyux September 9, 2011 11:57

Thanks a lot Kathrin, this is very helpful.

I assume the default search method is 'octree' used in

label myCellLabel = mesh().findNearestCell(yourPoint);

it seems time consuming when doing the search. I also tried other method such as

label myCellLabel = mesh().findNearestCellLinear(yourPoint);
label myCellLabel = mesh().findNearestCellWalk(yourPoint, patchI);

where 'patchI' is my reference index. When I make the file, is says

finiteVolume/ddtSchemes/EulerDdtScheme/EulerDdtScheme.C: In member function ‘Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::EulerDdtScheme<Type>::fvmDdt(const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&) [with Type = Foam::Tensor<double>]’:
finiteVolume/ddtSchemes/EulerDdtScheme/EulerDdtSchemes.C:37: instantiated from here
finiteVolume/ddtSchemes/EulerDdtScheme/EulerDdtScheme.C:520: error: ‘const class Foam::fvMesh’ has no member named ‘findNearestCellWalk’

Doesn't all search utilities come from the following directory, or I missed something again?

/home/frank/OpenFOAM/OpenFOAM-2.0.0/src/meshTools/meshSearch/meshSearch.C

frankyux September 10, 2011 19:39

Problem solved, should use following commends:

meshSearch ms(mesh());
label myCellLabel = ms.findNearestCell(X,patchI);

with a reference seedcell patchI, the search is much faster than before. (given a large number of cells).

Again, many thanks Kathrin!

-Frank


All times are GMT -4. The time now is 10:12.