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

FvPatchFields - read and write values in a patch

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 11, 2012, 13:47
Question FvPatchFields - read and write values in a patch
  #1
Member
 
Vitor Vasconcelos
Join Date: Jan 2012
Posts: 33
Rep Power: 14
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.

Code:

Code:
template<class Type>
cosFixedValueFvPatchField<Type>::cosFixedValueFvPatchField
(
    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()),
    startRamp_(readScalar(dict.lookup("startRamp"))),
    endRamp_(readScalar(dict.lookup("endRamp"))),
    curTimeIndex_(-1)
{

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

    // Tentativa de ler o valor da gravidade
    uniformDimensionedVectorField gv(IOobject
                     ("g",
                      this->db().time().constant(),
                      this->db(),
                      IOobject::MUST_READ,
                      IOobject::NO_WRITE)
                     );
    Info << "---- Saida g: " << gv << endl;

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

    // Cria o mesh
    Foam::fvMesh mesh(Foam::IOobject(
                     Foam::fvMesh::defaultRegion,
                     this->db().time().timeName(),
                     this->db().time(),
                     Foam::IOobject::MUST_READ
                     ));
 
    // 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 << " ";  
      pr++;
    }
    }
    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,

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

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

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
mesh file for flow over a circular cylinder Ardalan Main CFD Forum 7 December 15, 2020 13:06
[Helyx OS] Helyx-OS (GUI for SnappyHexMesh elvis OpenFOAM Community Contributions 210 January 30, 2017 18: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
Phase locked average in run time panara OpenFOAM 2 February 20, 2008 14:37


All times are GMT -4. The time now is 00:55.