CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   FvPatchFields - read and write values in a patch (

vitors December 11, 2012 14:47

FvPatchFields - read and write values in a patch
1 Attachment(s)
Hello fellows,

I'll start replying myself. Sorry for that.
I've been doing research and diving into openfoam C++ documentation. I got some interesting results, but I am kind of stucked again.

I am implementing a BC based of fixedValueFvPatchField. Althought I want to change values in the future, I'm using this as base class as a training to understand openFoam BC's rationale.

Right now I'm able to read faces from my patch and, for example, get the normals of these faces. Quite promising, but I have two big doubts about how things work.

First one:

I created a mesh (following a former post of this forum) and based on it I got my patch (it is a wall which is a heat source) and was able to iterate over it face by face. I could do it using the mesh but I also tried to use a *this of my class. With both I got the same result. However, in my 0/T file I started my variable as nonuniform scalar from 1 to 840, which are the number of faces I have (attached are the my geometry).

My point is: how to access the different temperatures of each cell? I was wondering it could be stored as "weights" for faces. But the face.normal() and face.mag() are always the same.

My mesh is hexaedrical and, in fact, all faces have the same size. However, the nonuniform values are clearly different from cell to cell. Which data strucutres should I read?

The second point is also inside the first? is it ok to use a IOobject mesh to get values or is better to use this->patch().patch()?

My code is also attached. Sorry for the mess, but it is full of "Info" and very personal comments.



template<class Type>
    const fvPatch& p,
    const DimensionedField<Type, volMesh>& iF,
    const dictionary& dict
    fixedValueFvPatchField<Type>(p, iF),
    refValueLow_("refValueLow", dict, p.size()),
    refValueHigh_("refValueHigh", dict, p.size()),

    if (dict.found("value"))
            Field<Type>("value", dict, p.size())
      Info << "|||||||||||| Entered fixedValue operator== |||||||||||\n" << endl;
    //    refValueLow_ + (refValueHigh_ - refValueLow_)*currentScale()

    // Tentativa de ler o valor da gravidade
    uniformDimensionedVectorField gv(IOobject
    Info << "---- Saida g: " << gv << endl;

    //Tentando variar os valores do proprio campo (patchField)

    // Cria o mesh
    Foam::fvMesh mesh(Foam::IOobject(
    // Trying to understand the mesh and polypatch relation
    label patchID = mesh.boundaryMesh().findPatchID("combustivel");
    Info << "patchID: " << patchID << endl;

    //    const polyPatch& patchFound = mesh.boundaryMesh()[patchID];
    const polyPatch& patchFound = this->patch().patch();
    Info << "patchFound: \n" << patchFound << endl;

    labelList labelPatchFound( patchFound.meshPoints() );
    Info << "Tamanho da lista de pontos: " << labelPatchFound.size() << endl;

    vectorList faceNormals(patchFound.size(), vector::zero);
    scalarList faceMag(patchFound.size());
    Info << "Face inicial: " << patchFound.start() << endl;

    labelList minhasFaces(patchFound.faceCells());
    Info << "Tamanho da lista de faces: " << minhasFaces.size() << endl;

    // Verificando as direcoes do mesh
    Info << "geometricD: " << mesh.geometricD() << endl;

    // Tentar extrair apenas as faces com a normal no x positiva
    pointField meshPoints(mesh.points());
    unsigned int pr = 0;
    forAll(patchFound, faceI)
      //    const face& myFace = mesh.boundaryMesh()[patchID][faceI];
        const face& myFace = this->patch().patch()[faceI];
    faceNormals[faceI] = myFace.normal(mesh.points());
    //    faceMag[faceI] = myFace.mag(mesh.points());
    if(faceNormals[faceI].x() > 0)
      //Info << faceNormals[faceI] << " ";
      Info << faceI << " "; 
    Info << "\n\n--- Numero de faces com normal x positiva: " << pr << endl;
    const scalarField& pesos = this->patch().weights();
    Info << "size of scalarField: " << pesos.size() <<
      "scalarField: \n" << pesos << endl;

One last question: is mixedFvPatchField a good base class for the development I explained in this post?

Thanks for your time,


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