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-------------------------------------------------------------------------------
10License
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
32namespace 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
56void 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// ************************************************************************* //
label n
void setSize(const label n)
Alias for resize()
Definition: List.H:218
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:91
(Rough approximation of) cell aspect ratio
virtual ~cellAspectRatio()
Destructor.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const vectorField & faceCentres() const
const scalarField & cellVolumes() const
const vectorField & cellCentres() const
label nCells() const noexcept
Number of mesh cells.
const vectorField & faceAreas() const
const cellList & cells() const
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
const cellShapeList & cells
#define InfoInFunction
Report an information message using Foam::Info.
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
vector point
Point is a vector.
Definition: point.H:43
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Type gAverage(const FieldField< Field, Type > &f)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Type gMin(const FieldField< Field, Type > &f)
Type gMax(const FieldField< Field, Type > &f)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333