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 {
34  defineTypeNameAndDebug(cellAspectRatio, 0);
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 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:350
Foam::cellAspectRatio::~cellAspectRatio
virtual ~cellAspectRatio()
Destructor.
Definition: cellAspectRatio.C:50
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
cellAspectRatio.H
Foam::gAverage
Type gAverage(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:604
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
Foam::MoveableMeshObject
Definition: MeshObject.H:220
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::cellList
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::primitiveMesh::cellVolumes
const scalarField & cellVolumes() const
Definition: primitiveMeshCellCentresAndVols.C:96
Foam::cellAspectRatio
(Rough approximation of) cell aspect ratio
Definition: cellAspectRatio.H:51
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:84
Foam::cellAspectRatio::cellAspectRatio
cellAspectRatio(const polyMesh &)
Construct given an polyMesh.
Definition: cellAspectRatio.C:40
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::primitiveMesh::faceCentres
const vectorField & faceCentres() const
Definition: primitiveMeshFaceCentresAndAreas.C:77
Foam::MeshObject
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:88
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:593
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
Foam::primitiveMesh::faceAreas
const vectorField & faceAreas() const
Definition: primitiveMeshFaceCentresAndAreas.C:89