CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   [HowTo]pointVectorField to volVectorField ??? (https://www.cfd-online.com/Forums/openfoam-programming-development/183114-howto-pointvectorfield-volvectorfield.html)

ycui January 27, 2017 09:20

[HowTo]pointVectorField to volVectorField ???
 
Dear Foamer:

I want to read a flow field from Tecplot data into the OpenFOAM. The fluid information is based on fluid nodes, however, in OpenFOAM the fluid information is based on cells. So I want to do an interpolation.

The way I think so far is that I read the fluid information into a pointVectorField, then interpolate to the volVectorField. In the creatFields.H, I wrote:
Quote:

pointVectorField UPoint
(
IOobject
(
"UPoint",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
pointMesh
);

volVectorField U
(
IOobject
(
"U",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh
);
Then I want to do the Interpolation in this way:
Quote:

U = pointVolInterpolation::interpolate(UPoint);
But during compiling error said it cannot find the pointVolInterpolation.

I'm not sure if I doing in the right way or not:confused: Can anyone help me on this problem:confused:

Thanks in advance!:)

ycui

floquation January 27, 2017 09:41

I have never worked with the interpolation class, so I do not know how to use it.

However, I do know that in "dynamicRefineFvMesh" there is a local implementation to convert between cell data and point data.

Have a look at the method "maxPointField", "maxCellField" and/or "cellToPoint" [path for OF4.0]:
Code:

${FOAM_SRC}/dynamicFvMesh/dynamicRefineFvMesh
Perhaps it inspires you to do it yourself.

ycui January 27, 2017 10:26

Quote:

Originally Posted by floquation (Post 634852)
I have never worked with the interpolation class, so I do not know how to use it.

However, I do know that in "dynamicRefineFvMesh" there is a local implementation to convert between cell data and point data.

Have a look at the method "maxPointField", "maxCellField" and/or "cellToPoint" [path for OF4.0]:
Code:

${FOAM_SRC}/dynamicFvMesh/dynamicRefineFvMesh
Perhaps it inspires you to do it yourself.

Thank you for the reply.

It seems there is no function like pointToVol after version 1.6, only has function volToPoint.

ycui February 1, 2017 04:49

I have fixed this problem, few comments:
1. copy the pointVolInterpolation from an older version of OF, then compile;
2. pointVolInterpolation is a namespace and cannot be defined in creatFields.H, should be defined in other location;
3. define the point data as pointVectorFields with pointMesh, and define the volume data as volVectorFields with mesh, then do the interpolation.
4. the difference before and after the interpolation depends on the velocity fluctuations.

kk415 October 2, 2019 01:41

Hello YCUI,


I am trying to do the same. I copied the pointVectorField to my solver. I am getting the following error:


undefined reference to `Foam::pointVolInterpolation::pointVolInterpolatio n(Foam::pointMesh const&, Foam::fvMesh const&)'


My piece of code


const pointMesh pMesh(mesh);
volPointInterpolation vpi(mesh);
pointVectorField pointn = vpi.interpolate(gradPsi);
pointVolInterpolation pvi(pMesh, mesh);


Also these header files are defined before main function

#include "volPointInterpolation.H"
#include "pointVolInterpolation.H"
#include "pointMesh.H"
#include "pointFields.H"

frobaux October 3, 2019 10:04

Hi,
I don't use the pointVolInterpolation but a function called interpolatePointToCell inside a loop

The loop looks like:



Code:

forAll(mesh , idCell)
{
      gradPsiAtCell[idCell] = interpolatePointToCell(gradPsi, idCell)

}

where gradPsi is of type pointScalarField and gradPsiAtCell of type volScalarField (works also for vector fields)
and you need to
Code:

#include "interpolatePointToCell.H"
Hope it helps!
Fabien

kk415 October 4, 2019 05:17

Hello Fabian,


Thanks for your answer. It works beautifully. Can I get a little insight of the code interpolatepointToCell(trying to do it myself also but so far no success). Like VolPointInterpolation and PointVolInterpolation interpolates using inverse distance weight function. what does interpolatepointToCell do ?

frobaux October 4, 2019 06:38

To be honnest I didn't look into the code either. A fast check into the code show that its seems to be a simple average of all the values at the points surrounding the cell.



Code:

template<class Type>
Type Foam::interpolatePointToCell
(
    const GeometricField<Type, pointPatchField, pointMesh>& ptf,
    const label celli
)
{
    const primitiveMesh& mesh = ptf.mesh()();

    // get the cell from the indice of the cell

    const cell& cFaces = mesh.cells()[celli];


    // list of point surounding the cell
    labelHashSet pointHad(10*cFaces.size());

    Type sum = Zero;



    // for all face "f" of the input cell
    forAll(cFaces, i)
    {
        const face& f = mesh.faces()[cFaces[i]];
       

        // for all facePoint "fp" of the face, v being the global indice of that point.

        forAll(f, fp)
        {
            label v = f[fp];

            if (pointHad.insert(v)) // I guess that it inserts only if not already
                                            // present and return true in that case
            {
              sum += ptf[v];
            }
        }
    }

    return sum/pointHad.size();
}

Note that I have added the comments, so they are maybe not perfectly accurate.

From this, it would be very easy to copy and modify to have an inverse distance wieghting. Something like
Code:

if (pointHad.insert(v))
            {
                const scalar dist=mag(mesh().points()[v]-cFaces.centre())
              sum += ptf[v]*dist;
                sumDist+ = dist


            }
...
return sum/sumDist

Note that the code was not compiled and I'm not sure about mesh().points()[v].



Fabien :)


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