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

automatic interpolation of field on call

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

Reply
 
LinkBack Thread Tools Display Modes
Old   November 29, 2013, 10:54
Default automatic interpolation of field on call
  #1
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 360
Rep Power: 12
romant is on a distinguished road
I have a question. Let's say I have a field
Code:
const volScalarField& k
and I have a some labels, let's call them
Code:
label faceI        // surface between two cells
label faceCellI   // cell center
when I now call
Code:
k[faceCellI]
I get the value of k at the cell center, as the label points to a cell center. When I call
Code:
k[faceI]
do I get the interpolated value from the face? I always thought that I would need to interpolate the field first and then call the interpolated field in order to get my value at the interface between two cells. However, after implementing it this way, I still get a value, which also seems reasonable.

Now the question, does OpenFOAM automatically interpolate in these cases? I wonder if the same also works for volVectorFields, when retrieving a value from the interface between two neighboring cells (through a label) that it then interpolates.
__________________
~roman
romant is offline   Reply With Quote

Old   November 29, 2013, 11:23
Default
  #2
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 919
Rep Power: 17
akidess will become famous soon enough
Both faceI and faceCellI in your example are labels (this pretty much is equal to a integer). Suppose faceI = 1, and faceCelli = 1, how would the code you show know if it's supposed to return a interpolated or cell centre value? Keep in mind the code doesn't know the name of your variable, only the location in memory. Thus, from the very brief snippets you show, you should get the cell centre value in both cases.

- Anton
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
*Help define the OpenFOAM stackexchange Q&A site: http://area51.stackexchange.com/prop...oam-technology
akidess is offline   Reply With Quote

Old   November 29, 2013, 11:30
Default
  #3
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 360
Rep Power: 12
romant is on a distinguished road
Quote:
Originally Posted by akidess View Post
Both faceI and faceCellI in your example are labels (this pretty much is equal to a integer). Suppose faceI = 1, and faceCelli = 1, how would the code you show know if it's supposed to return a interpolated or cell centre value? Keep in mind the code doesn't know the name of your variable, only the location in memory. Thus, from the very brief snippets you show, you should get the cell centre value in both cases.

- Anton
This is what I thought as well, however. The reason I got to this point is because when I interpolated value for k onto a surface mesh, and then used the faceI value, I ended up getting a temperature value :-)

I am using this method Field value inside a boundary condition class to find the global indices for the cell interface opposite to the patch on a boundary. With this label I then would like to retrieve the velocity and k. At first I thought this should work very easily by using the interpolated (onto the surface mesh) fields in combination with the label oppFaceI which I retrieve from the mentioned method
__________________
~roman
romant is offline   Reply With Quote

Old   November 29, 2013, 13:32
Default
  #4
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 919
Rep Power: 17
akidess will become famous soon enough
Please post the code as you have implemented it.
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
*Help define the OpenFOAM stackexchange Q&A site: http://area51.stackexchange.com/prop...oam-technology
akidess is offline   Reply With Quote

Old   November 29, 2013, 13:44
Default
  #5
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Stockholm, Sweden
Posts: 360
Rep Power: 12
romant is on a distinguished road
Quote:
Originally Posted by akidess View Post
Please post the code as you have implemented it.

I think I have found my answer, however, here comes the code
Code:
// get access to the mesh for opposite faces
    const fvMesh& mesh = patch().boundaryMesh().mesh();

    // access to everything else
    const turbulenceModel& turbModel =
        db().lookupObject<turbulenceModel>("turbulenceModel");
    const tmp<volScalarField> tk = turbModel.k();
    const volScalarField& k = tk();
    const surfaceScalarField kSurface = fvc::interpolate(k);

forAll(mutw, faceI)
    {
        label faceCellI = patch().faceCells()[faceI];
        label oppFaceI =
            mesh.cells()[faceCellI].opposingFaceLabel
            (
                faceI+patch().patch().start(),
                mesh.faces()
            );

        // calculate distance between wall and opposing face
        // get coordinates of centre of face opposite the patch boundary face
        vector faceCentre  = mesh.faceCentres()[oppFaceI];

        // get coordinates of centre of patch at the boundary face
        vector patchFaceCentre =
            mesh.faceCentres()[faceI+patch().patch().start()];

        // distance to opposite face
        scalar yn = mag(patchFaceCentre - faceCentre);

        // dimensionless distance to opposite face, using k at the opposite
        // face
        scalar yStarn = yn*sqrt(kSurface[oppFaceI])*rhon/mun;
    }
I think one problem that I have was to define kSurface at first
Code:
const surfaceScalarField& kSurface = fvc::interpolate(k)
this lead to bogus readings of the value that I actually wanted to read.
__________________
~roman
romant 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
Setting an external B0_x field in MHD module fferroni FLUENT 6 July 13, 2015 05:29
Annoying issue of automatic "Rescale to Data Range " with paraFoam/paraview 3.12 keepfit OpenFOAM Paraview & paraFoam 60 September 18, 2013 03:23
How to get the velocity field from the pressure field Hermano Main CFD Forum 2 November 29, 2011 09:32
automatic call a function in a program gerado OpenFOAM 9 June 29, 2009 02:30
2D CFD code using SIMPLE algorithm bfan Main CFD Forum 3 June 22, 2002 22:01


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