CFD Online Logo CFD Online URL
Home > Forums > OpenFOAM Programming & Development

FvPatchFields - read and write values in a patch

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

LinkBack Thread Tools Display Modes
Old   December 11, 2012, 14:47
Question FvPatchFields - read and write values in a patch
Vitor Vasconcelos
Join Date: Jan 2012
Posts: 33
Rep Power: 8
vitors is on a distinguished road
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,

Attached Images
File Type: jpg nonuniform.jpg (51.6 KB, 9 views)

Last edited by vitors; December 11, 2012 at 14:52. Reason: Improve code visualization
vitors is offline   Reply With Quote


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
[Helyx OS] Helyx-OS (GUI for SnappyHexMesh elvis OpenFOAM Community Contributions 210 January 30, 2017 19:57
Journal file clicks buttons but doesn't write values, why? kingjewel1 FLUENT 2 April 3, 2012 04:30
How to read or write case by commands during simulation with Fluent lzgwhy FLUENT 4 April 20, 2011 22:02
mesh file for flow over a circular cylinder Ardalan Main CFD Forum 6 April 17, 2010 23:40
Phase locked average in run time panara OpenFOAM 2 February 20, 2008 15:37

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