CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   output the face area vectors (https://www.cfd-online.com/Forums/openfoam/151352-output-face-area-vectors.html)

openfoammaofnepo April 9, 2015 04:21

output the face area vectors
 
Dear All, I write a small utility code to output the face area vectors (it is modified from GradU utility):

Code:

/*---------------------------------------------------------------------------*\
  =========                |
  \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox
  \\    /  O peration    |
    \\  /    A nd          | Copyright (C) 2011 OpenFOAM Foundation
    \\/    M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Application
    FaceAreaVector

Description
    output the face area vector of  internal faces

\*---------------------------------------------------------------------------*/

#include <fstream>
#include <iostream>
#include "fvMesh.H"
#include "Time.H"
//#include "primitiveMesh.H"
#include "argList.H"
#include "polyMesh.H"
using namespace std;
int main(int argc, char *argv[])
{
    # include "setRootCase.H"
    # include "createTime.H"
    # include "createMesh.H"
    using namespace Foam;

    Info<< "Output face vectors of faces\n" << endl;
    label iFace = 39;
 
    scalar x[iFace];
    scalar y[iFace];
    scalar z[iFace];
Line 53   forAll(mesh.Sf(), faceI)
    {
        x[faceI] = mesh.Sf()[faceI].x();
        y[faceI] = mesh.Sf()[faceI].y();
        z[faceI] = mesh.Sf()[faceI].z();

    }
 
/*
    ofstream o_file;
    o_file.open("Internal_Face_Vectors.txt");

    if(o_file.is_open())
    {
        for(label i=0;i<=iFace-1;i++)
        {
          o_file<<x[i]<<" "<<y[i]<<" "<<z[i]<<" "<<endl;
        }       
    }           
    o_file.close();
*/

}


// ************************************************************************* //

But I have the following errors:

Code:

FaceAreaVector.C:53:5: error: invalid use of incomplete type ‘const struct Foam::surfaceVectorField’
/home/user/OpenFOAM/OpenFOAM-2.1.1/src/OpenFOAM/lnInclude/pointFieldsFwd.H:52:7: error: declaration of ‘const struct Foam::surfaceVectorField’
FaceAreaVector.C:55:35: error: no match for ‘operator[]’ in ‘mesh.Foam::fvMesh::Sf()[faceI]’
FaceAreaVector.C:56:35: error: no match for ‘operator[]’ in ‘mesh.Foam::fvMesh::Sf()[faceI]’
FaceAreaVector.C:57:35: error: no match for ‘operator[]’ in ‘mesh.Foam::fvMesh::Sf()[faceI]’

Could anyone tell what causes the problems? I checked many times but did not find the reason. Thank you in advance!

OFFO

alexeym April 9, 2015 04:36

Hi,

Compiler tried to give you a hint:

Code:

FaceAreaVector.C:53:5: error: invalid use of incomplete type ‘const struct Foam::surfaceVectorField’
Basically it says "I don't know what Foam::surfaceVectorField is". You should include surfaceFields.H.

Are you sure you have got only 39 internal faces?

openfoammaofnepo April 9, 2015 04:44

Thank you so much. I can compile it now.

39 is just an assumed for code debugging. But this is also my question. 39 is hard coded, how can I make the code know automatically about the number of internal faces and boundary faces? Thank you.

Quote:

Originally Posted by alexeym (Post 540728)
Hi,

Compiler tried to give you a hint:

Code:

FaceAreaVector.C:53:5: error: invalid use of incomplete type ‘const struct Foam::surfaceVectorField’
Basically it says "I don't know what Foam::surfaceVectorField is". You should include surfaceFields.H.

Are you sure you have got only 39 internal faces?


alexeym April 9, 2015 04:53

Hi,

fvMesh has nInternalFaces (http://foam.sourceforge.net/docs/cpp...b8ffda0dced7bb) and nFaces (http://foam.sourceforge.net/docs/cpp...153de7da0e92e8) methods inherited from primitiveMesh.

You can use Lists (http://foam.sourceforge.net/docs/cpp/a01366.html) to store x, y, and z. It has append method, which automatically adjusts the size of list. Also you can write coordinates directly to a file without intermediate storage.

openfoammaofnepo April 9, 2015 05:18

Thank you so much for your help. When I also tried to write out the area vector of boundary faces, the code is as follows:

Code:

/*---------------------------------------------------------------------------*\
  =========                |
  \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox
  \\    /  O peration    |
    \\  /    A nd          | Copyright (C) 2011 OpenFOAM Foundation
    \\/    M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Application
    FaceAreaVector

Description
    output the face area vector of  internal faces

\*---------------------------------------------------------------------------*/

#include <fstream>
#include <iostream>
#include "fvMesh.H"
#include "Time.H"
//#include "primitiveMesh.H"
#include "argList.H"
#include "polyMesh.H"
#include "surfaceFields.H"

using namespace std;
int main(int argc, char *argv[])
{
    # include "setRootCase.H"
    # include "createTime.H"
    # include "createMesh.H"
    using namespace Foam;

    Info<< "Output face vectors of internal faces\n" << endl;
    label iFace = 253375;
 
    scalar x[iFace];
    scalar y[iFace];
    scalar z[iFace];
    forAll(mesh.Sf(), faceI)
    {
        x[faceI] = mesh.Sf()[faceI].x();
        y[faceI] = mesh.Sf()[faceI].y();
        z[faceI] = mesh.Sf()[faceI].z();

    }
 

    ofstream o_file;
    o_file.open("Internal_Face_Vectors.txt");

    if(o_file.is_open())
    {
        for(label i=0;i<=iFace-1;i++)
        {
          o_file<<x[i]<<" "<<y[i]<<" "<<z[i]<<" "<<endl;
        }       
    }           
    o_file.close();

    Info<< "Output face vectors of boundary faces\n" << endl;
    label ibcFace = 4275;

    scalar xbc[ibcFace];
    scalar ybc[ibcFace];
    scalar zbc[ibcFace];

    forAll(mesh.boundaryMesh(), patchI)
    {
Line 85      forAll(mesh.boundaryMesh()[patchI].Sf(), faceI)
        {
            xbc[faceI] = mesh.boundaryMesh()[patchI].Sf()[faceI].x();
            ybc[faceI] = mesh.boundaryMesh()[patchI].Sf()[faceI].y();
            zbc[faceI] = mesh.boundaryMesh()[patchI].Sf()[faceI].z();
        }
    }

    ofstream o_file_bc;
    o_file_bc.open("Boundary_Face_Vectors.txt");
    if(o_file_bc.is_open())
    {
        for(label i=0;i<=ibcFace-1;i++)
        {
            o_file_bc<<xbc[i]<<" "<<ybc[i]<<" "<<zbc[i]<<" "<<endl;
        }
    }
}


// ************************************************************************* //

But unfornutely there are still some errors:

Code:

FaceAreaVector.C:85:9: error: ‘const class Foam::polyPatch’ has no member named ‘Sf’
FaceAreaVector.C:87:54: error: ‘const class Foam::polyPatch’ has no member named ‘Sf’
FaceAreaVector.C:88:54: error: ‘const class Foam::polyPatch’ has no member named ‘Sf’
FaceAreaVector.C:89:54: error: ‘const class Foam::polyPatch’ has no member named ‘Sf’

Could you please help me have a look at this error information? Thank you so much.
OFFO

Quote:

Originally Posted by alexeym (Post 540743)
Hi,

fvMesh has nInternalFaces (http://foam.sourceforge.net/docs/cpp...b8ffda0dced7bb) and nFaces (http://foam.sourceforge.net/docs/cpp...153de7da0e92e8) methods inherited from primitiveMesh.

You can use Lists (http://foam.sourceforge.net/docs/cpp/a01366.html) to store x, y, and z. It has append method, which automatically adjusts the size of list. Also you can write coordinates directly to a file without intermediate storage.


alexeym April 9, 2015 05:36

Well, you can try using documentation without my help. It is true, polyPatch does not have Sf method, it has faceAreas method (http://foam.sourceforge.net/docs/cpp...10863a66b838fa).

Alternatively, you can explicitly demand mesh.boundaryMesh()[patchI] as const fvPatch& using assignment before nested loop, fvPatch has Sf method (http://foam.sourceforge.net/docs/cpp...6f373b993f0690).


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