Loading...
Searching...
No Matches
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\*---------------------------------------------------------------------------*/
28#include "cellAspectRatio.H"
29
30// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31
32namespace Foam
35}
36
37
38// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39
41:
42 MeshObject_type(mesh)
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 auto limits = gMinMax(aRatio);
124 auto avg = gAverage(aRatio);
125
126 InfoInFunction << "Calculated cell aspect ratio min:" << limits.min()
127 << " max:" << limits.max() << " average:" << avg
128 << endl;
129 }
130}
131
132
133// ************************************************************************* //
label n
void setSize(label n)
Alias for resize().
Definition List.H:536
(Rough approximation of) cell aspect ratio
cellAspectRatio(const polyMesh &)
Construct given an polyMesh.
virtual ~cellAspectRatio()
Destructor.
A cell is defined as a list of faces with extra functionality.
Definition cell.H:56
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
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:142
auto limits
Definition setRDeltaT.H:186
dynamicFvMesh & mesh
const cellShapeList & cells
#define InfoInFunction
Report an information message using Foam::Info.
Namespace for handling debugging switches.
Definition debug.C:45
Namespace for OpenFOAM.
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
dimensionedScalar sqrt(const dimensionedScalar &ds)
List< cell > cellList
List of cell.
Definition cellListFwd.H:41
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Field< vector > vectorField
Specialisation of Field<T> for vector.
vector point
Point is a vector.
Definition point.H:37
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
vectorField pointField
pointField is a vectorField.
Vector< scalar > vector
Definition vector.H:57
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299