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

How to get the heighth,length of a 2D cell?

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

Like Tree8Likes
  • 4 Post By elmo555
  • 4 Post By Taataa

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 24, 2009, 03:43
Default How to get the heighth,length of a 2D cell?
  #1
Member
 
jingjing
Join Date: Mar 2009
Location: shanghai,China
Posts: 30
Rep Power: 17
zhajingjing is on a distinguished road
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.
Attached Files
File Type: c waveElevationVStime.C (4.5 KB, 14 views)
File Type: c an improved version.C (4.2 KB, 13 views)
zhajingjing is offline   Reply With Quote

Old   December 2, 2009, 21:05
Default
  #2
Member
 
Richard Kenny
Join Date: Mar 2009
Posts: 64
Rep Power: 18
richpaj is on a distinguished road
isn't it possible to simply use gAverage (volume averaging)?


Richard
richpaj is offline   Reply With Quote

Old   May 4, 2014, 16:49
Default
  #3
New Member
 
Join Date: Oct 2013
Posts: 19
Rep Power: 12
Daniel73 is on a distinguished road
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?
Daniel73 is offline   Reply With Quote

Old   March 25, 2015, 06:47
Default Did you get an answer to get dx, dy and dz?
  #4
New Member
 
Sam Fredriksson
Join Date: Dec 2010
Posts: 20
Rep Power: 15
safre is on a distinguished road
Did you get an answer to get dx, dy and dz?
safre is offline   Reply With Quote

Old   June 8, 2016, 06:59
Default
  #5
Member
 
Lennart
Join Date: Feb 2016
Posts: 46
Rep Power: 10
elmo555 is on a distinguished road
Hey guys,

Quote:
Originally Posted by Daniel73 View Post
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 View Post
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
elmo555 is offline   Reply With Quote

Old   January 8, 2018, 18:16
Default
  #6
Senior Member
 
Taher Chegini
Join Date: Nov 2014
Location: Houston, Texas
Posts: 125
Rep Power: 12
Taataa is on a distinguished road
In case someone was looking for a complete answer, here is the code to get the deltas in each direction for each cell:

Code:
const surfaceVectorField& deltas = mesh().delta();
forAll(deltas, I)
{
    Info<<  "dx[" << I << "] = " << deltas[I].x() <<endl;
    Info<<  "dy[" << I << "] = " << deltas[I].y() <<endl;
}
Taataa is offline   Reply With Quote

Old   July 15, 2018, 10:25
Default what does x,y,z mean here?
  #7
Member
 
王莹
Join Date: May 2017
Posts: 51
Rep Power: 8
Alisa_W is on a distinguished road
Hello,

I am focusing on the definition of deltax, deltay and deltaz in OF. I am so happy to see your answer and it really give me some ideas! However I still have some problems.

Does it mean that when I want to use deltax(or deltay, etc) in a piece of code, I just need define "deltas" first (like your code "const surfaceVectorField& deltas = mesh().delta(); ") and use deltas[I].x() in loops?

Another puzzle is what x, y, z represent. Does x, y, z here represent three directions in Cartesian coordinates? However, in fluid mechanics, x,y,z represent streamwise direction, normal direction and spanwise direction. A typical physical quantity is y+(yplus).

Thanks a lot! Anyone who can give me some suggestions is welome!

Alisa.

Quote:
Originally Posted by Taataa View Post
In case someone was looking for a complete answer, here is the code to get the deltas in each direction for each cell:

Code:
const surfaceVectorField& deltas = mesh().delta();
forAll(deltas, I)
{
    Info<<  "dx[" << I << "] = " << deltas[I].x() <<endl;
    Info<<  "dy[" << I << "] = " << deltas[I].y() <<endl;
}
Alisa_W is offline   Reply With Quote

Old   July 15, 2018, 11:11
Default
  #8
Senior Member
 
Taher Chegini
Join Date: Nov 2014
Location: Houston, Texas
Posts: 125
Rep Power: 12
Taataa is on a distinguished road
Here is how delta is defined in OF:
Code:
forAll(owner, facei)
{
    delta[facei] = C[neighbour[facei]] - C[owner[facei]];
}
So essentially, delta for each face is the distance between the centers of its neighbor and owner cells. If that's what do you want in your code then yes, you can use that.
Taataa is offline   Reply With Quote

Old   July 15, 2018, 23:27
Default
  #9
Member
 
王莹
Join Date: May 2017
Posts: 51
Rep Power: 8
Alisa_W is on a distinguished road
What I want is xyz in dynamic mechanics level. However, your idea makes me understand OF frame more clearly. Thank you!

Quote:
Originally Posted by Taataa View Post
Here is how delta is defined in OF:
Code:
forAll(owner, facei)
{
    delta[facei] = C[neighbour[facei]] - C[owner[facei]];
}
So essentially, delta for each face is the distance between the centers of its neighbor and owner cells. If that's what do you want in your code then yes, you can use that.
Alisa_W is offline   Reply With Quote

Old   April 27, 2021, 05:54
Default x,y,z length in every cell
  #10
New Member
 
shiyu
Join Date: Mar 2018
Location: london
Posts: 7
Rep Power: 8
shiyu is on a distinguished road
Quote:
Originally Posted by Alisa_W View Post
What I want is xyz in dynamic mechanics level. However, your idea makes me understand OF frame more clearly. Thank you!
Hi Wang,

I am wondering if you have found a better solution of x,y,z lengths in every cell, instead of the delta distance between every two cells.

Thanks

BR,
Shiyu
shiyu is offline   Reply With Quote

Old   April 30, 2021, 07:44
Default
  #11
Member
 
Daniel
Join Date: May 2018
Posts: 43
Rep Power: 7
CFDanielGER is on a distinguished road
Hello everybody,


am I right that this code give you the deltas in x, y and z for every cell, I mean the dimensions of each cell or is it the distance between two cell center points?



Quote:
Originally Posted by Taataa View Post
Here is how delta is defined in OF:
Code:
forAll(owner, facei)
{
    delta[facei] = C[neighbour[facei]] - C[owner[facei]];
}
So essentially, delta for each face is the distance between the centers of its neighbor and owner cells. If that's what do you want in your code then yes, you can use that.



Is there maybe a more efficient way than using a forAll loop? I guess this may be rather time consuming for large meshes?


Many thanks for your help!

Last edited by CFDanielGER; April 30, 2021 at 14:37.
CFDanielGER 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
How to determine the direction of cell face vectors on processor patches sebastian_vogl OpenFOAM Programming & Development 1 October 11, 2016 13:17
How to determine the direction of cell face vectors on processor patches sebastian_vogl OpenFOAM Running, Solving & CFD 0 October 27, 2009 08:47
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Meshing & Mesh Conversion 2 July 15, 2005 04:15
Warning 097- AB Siemens 6 November 15, 2004 04:41
cell to cell relation CMB Siemens 1 December 4, 2003 04:05


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