cellAspectRatio.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2020-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "cellAspectRatio.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
35 }
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 :
43 {
44  calcAspectRatio();
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
49 
51 {}
52 
53 
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 
56 void Foam::cellAspectRatio::calcAspectRatio()
57 {
58  if (debug)
59  {
60  InfoInFunction << "Calculating cell aspect ratio" << endl;
61  }
62 
63  const polyMesh& mesh = mesh_;
64  const pointField& cellCentres = mesh.cellCentres();
65  const scalarField& cellVolumes = mesh.cellVolumes();
66  const vectorField& faceAreas = mesh.faceAreas();
67  const vectorField& faceCentres = mesh.faceCentres();
68  const cellList& cells = mesh.cells();
69  //const faceList& faces = mesh.faces();
70  //const pointField& points = mesh.points();
71 
72  scalarField& aRatio = *this;
73  aRatio.setSize(mesh.nCells());
74 
75  forAll(cells, celli)
76  {
77  const point& cc = cellCentres[celli];
78  const cell& cFaces = cells[celli];
79 
80  scalar sumA = Zero;
81  scalar maxMag = Zero;
82 
83  for (const label facei : cFaces)
84  {
85  const vector& n = faceAreas[facei];
86 
87  sumA += mag(n);
88 
90  //const face& f = faces[facei];
91  //for (const label pointi : f)
92  //{
93  // const point& pt = points[pointi];
94  // const vector d(pt-cc);
95  // maxMag = max(maxMag, magSqr(d));
96  //}
97 
98  // Max distance from face centre to cell centre
99  const point& fc = faceCentres[facei];
100  maxMag = max(maxMag, magSqr(fc-cc));
101  }
102  sumA /= cFaces.size();
103 
104  aRatio[celli] = 1.0;
105  if (sumA > ROOTVSMALL)
106  {
107  // Local length scale
108  const scalar length = cellVolumes[celli]/sumA;
109 
110  if (length > ROOTVSMALL)
111  {
112  // Max edge length
113  maxMag = Foam::sqrt(maxMag);
114 
115  //aRatio[celli] = Foam::sqrt(4.0/3.0)*maxMag/length;
116  aRatio[celli] = 2.0*maxMag/length;
117  }
118  }
119  }
120 
121  if (debug)
122  {
123  InfoInFunction << "Calculated cell aspect ratio min:" << gMin(aRatio)
124  << " max:" << gMax(aRatio) << " average:" << gAverage(aRatio)
125  << endl;
126  }
127 }
128 
129 
130 // ************************************************************************* //
List< cell > cellList
List of cell.
Definition: cellListFwd.H:39
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Type gMin(const FieldField< Field, Type > &f)
(Rough approximation of) cell aspect ratio
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
const cellList & cells() const
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:85
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
void setSize(const label n)
Alias for resize()
Definition: List.H:316
dynamicFvMesh & mesh
const cellShapeList & cells
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Vector< scalar > vector
Definition: vector.H:57
const vectorField & cellCentres() const
int debug
Static debugging option.
Type gMax(const FieldField< Field, Type > &f)
defineTypeNameAndDebug(combustionModel, 0)
const vectorField & faceCentres() const
vector point
Point is a vector.
Definition: point.H:37
label nCells() const noexcept
Number of mesh cells.
Type gAverage(const FieldField< Field, Type > &f)
const vectorField & faceAreas() const
label n
Field< vector > vectorField
Specialisation of Field<T> for vector.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual ~cellAspectRatio()
Destructor.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
cellAspectRatio(const polyMesh &)
Construct given an polyMesh.
Namespace for OpenFOAM.
const scalarField & cellVolumes() const
#define InfoInFunction
Report an information message using Foam::Info.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127