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

[HowTo]pointVectorField to volVectorField ???

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By frobaux
  • 1 Post By frobaux

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 27, 2017, 10:20
Question [HowTo]pointVectorField to volVectorField ???
  #1
New Member
 
Join Date: Nov 2016
Posts: 16
Rep Power: 9
ycui is on a distinguished road
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 Can anyone help me on this problem

Thanks in advance!

ycui
ycui is offline   Reply With Quote

Old   January 27, 2017, 10:41
Default
  #2
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21
floquation will become famous soon enough
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.
floquation is offline   Reply With Quote

Old   January 27, 2017, 11:26
Default
  #3
New Member
 
Join Date: Nov 2016
Posts: 16
Rep Power: 9
ycui is on a distinguished road
Quote:
Originally Posted by floquation View Post
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 is offline   Reply With Quote

Old   February 1, 2017, 05:49
Default
  #4
New Member
 
Join Date: Nov 2016
Posts: 16
Rep Power: 9
ycui is on a distinguished road
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.
ycui is offline   Reply With Quote

Old   October 2, 2019, 02:41
Default
  #5
Senior Member
 
krishna kant
Join Date: Feb 2016
Location: Hyderabad, India
Posts: 133
Rep Power: 10
kk415 is on a distinguished road
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:ointVolInterpolation:ointVolInterpolatio n(Foam:ointMesh 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"
kk415 is offline   Reply With Quote

Old   October 3, 2019, 11:04
Default
  #6
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
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 likes this.
frobaux is offline   Reply With Quote

Old   October 4, 2019, 06:17
Default
  #7
Senior Member
 
krishna kant
Join Date: Feb 2016
Location: Hyderabad, India
Posts: 133
Rep Power: 10
kk415 is on a distinguished road
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 ?
kk415 is offline   Reply With Quote

Old   October 4, 2019, 07:38
Default
  #8
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
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
kk415 likes this.

Last edited by frobaux; October 4, 2019 at 10:06.
frobaux is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialize a uniform 0 volVectorField Schag OpenFOAM 4 July 24, 2024 03:18
Interpolation of a volVectorField onto processor patches Mithrandirrr OpenFOAM Programming & Development 2 April 5, 2023 18:36
making a volVectorField sina_mech OpenFOAM Programming & Development 7 July 7, 2016 15:49
Multiplication of two volVectorField ChGr OpenFOAM Programming & Development 1 May 30, 2016 12:08
copy/write a same volVectorField to every time step folder hy1112006 OpenFOAM Programming & Development 0 April 18, 2016 23:33


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