CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to get the heighth,length of a 2D cell? (http://www.cfd-online.com/Forums/openfoam-programming-development/70420-how-get-heighth-length-2d-cell.html)

zhajingjing November 24, 2009 04:43

How to get the heighth,length of a 2D cell?
 
2 Attachment(s)
I want to improve my postprocessing tool for my wave tank to make it suitable for a wave tank with non-uniform mesh.In order to get the average value of a field with non-uniform mesh,I have to calculate the size of each cell (the heigt,length,width of a rectangular cell) as a weight factor,but I don't know how to get this kind of geomertric information of a cell.
One method is to get the coordinate value of the vertices of a cell,then make one subtract another.But I
can't go on at the detail.
Code:


  forAll(mesh.cellCentres,cellid)
    {
 
        if(abs(mesh.cellCentres[cellid].x()-x)<=deltaX/2)  //deltaX:the length of a cell, choose out the cells at the x point along the 2D wave tank
 
      {
        ncells++;
        sumField+=field[cellid]*deltaY;//deltaY: the height of a cell
        weight+=deltaY;
 
        Info<<ncells<<"cell No"<< cellid <<"field value"<<field[cellid]<<endl;
      }                       
 
    } 
 
  sumField=sumField/weight;  //the average value of the gamma field at the x point along the wave tank

The question is , how to calculate the deltaX,deltaY according to the cellid that has been chosen out.

in the following short script:
Code:

const labelList patchCells = this->patch().faceCells();
const fvPatchScalarField& gamma=patch().lookupPatchField<volScalarField,scalar >("gamma");
const pointField& points = mesh.points();
forAll(patchCells,i)
{
 labelList cellpoints=mesh.cellPoints(patchCells[i]);
 label size=cellpoints.size();
 for(int j=0,j<size,j++)    //???如何读取单元尺寸
 {   
  points[cellpoints[j]].y()
 
 ...
 gamma[patchCells[i]]*...
    waveAtWavemaker_=...

I know something about how to access the coordinate value of a vertex of a cell,but I don't know how to access two vertices at the same time, if I could, of course I will get the height of a cell(2D)

Is there anyone can help me?Thanks


two attachments: the old version of the wave tank postprocessing tool,
and another is a new version waiting to be improved to postprocess the non-uniform mesh wave tank.

richpaj December 2, 2009 22:05

isn't it possible to simply use gAverage (volume averaging)?


Richard

Daniel73 May 4, 2014 16:49

Hey guys,
Do you know how i can find the deltaX, deltaY and deltaZ of a cell?
I can use some thing like "scalar dx = mesh.C()[0].x() * 2.;" for serial, but for parallel case it needs many considerations...
So do you know any simple function?

safre March 25, 2015 07:47

Did you get an answer to get dx, dy and dz?
 
Did you get an answer to get dx, dy and dz?

elmo555 June 8, 2016 06:59

Hey guys,

Quote:

Originally Posted by Daniel73 (Post 489761)
Hey guys,
Do you know how i can find the deltaX, deltaY and deltaZ of a cell?
I can use some thing like "scalar dx = mesh.C()[0].x() * 2.;" for serial, but for parallel case it needs many considerations...
So do you know any simple function?

Quote:

Originally Posted by safre (Post 538123)
Did you get an answer to get dx, dy and dz?

Not sure if you're still interested in this (your question is from 2014), but this is how you can get the distances between cells:
Code:

mesh.delta()
It returns cell distances for each face as surfaceVectorField and is implemented as:
Code:

forAll(owner, facei)

 {
 delta[facei] = C[neighbour[facei]] - C[owner[facei]];
 }

in fvMeshGeometry.C


All times are GMT -4. The time now is 17:56.