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/)
-   -   automatic interpolation of field on call (https://www.cfd-online.com/Forums/openfoam-programming-development/126944-automatic-interpolation-field-call.html)

romant November 29, 2013 09:54

automatic interpolation of field on call
 
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.

akidess November 29, 2013 10:23

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

romant November 29, 2013 10:30

Quote:

Originally Posted by akidess (Post 464044)
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 http://www.cfd-online.com/Forums/ope...tml#post254946 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

akidess November 29, 2013 12:32

Please post the code as you have implemented it.

romant November 29, 2013 12:44

Quote:

Originally Posted by akidess (Post 464061)
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.


All times are GMT -4. The time now is 05:20.