primitiveMeshCellCentresAndVols.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Description
28 Efficient cell-centre calculation using face-addressing, face-centres and
29 face-areas.
30
31\*---------------------------------------------------------------------------*/
32
33#include "primitiveMesh.H"
34#include "primitiveMeshTools.H"
35
36// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37
39{
40 if (debug)
41 {
42 Pout<< "primitiveMesh::calcCellCentresAndVols() : "
43 << "Calculating cell centres and volumes"
44 << endl;
45 }
46
47 // These are always calculated in tandem, but only once.
48 if (cellCentresPtr_ || cellVolumesPtr_)
49 {
51 << "Cell centres or volumes already calculated"
52 << abort(FatalError);
53 }
54
55 // set the accumulated cell centre to zero vector
56 cellCentresPtr_ = new vectorField(nCells(), Zero);
57 vectorField& cellCtrs = *cellCentresPtr_;
58
59 // Initialise cell volumes to 0
60 cellVolumesPtr_ = new scalarField(nCells(), Zero);
61 scalarField& cellVols = *cellVolumesPtr_;
62
63 // Make centres and volumes
65 (
66 *this,
68 faceAreas(),
69 cellCtrs,
71 );
72
73 if (debug)
74 {
75 Pout<< "primitiveMesh::calcCellCentresAndVols() : "
76 << "Finished calculating cell centres and volumes"
77 << endl;
78 }
79}
80
81
82// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83
85{
86 if (!cellCentresPtr_)
87 {
88 //calcCellCentresAndVols();
89 const_cast<primitiveMesh&>(*this).updateGeom();
90 }
91
92 return *cellCentresPtr_;
93}
94
95
97{
98 if (!cellVolumesPtr_)
99 {
100 //calcCellCentresAndVols();
101 const_cast<primitiveMesh&>(*this).updateGeom();
102 }
103
104 return *cellVolumesPtr_;
105}
106
107
108// ************************************************************************* //
static void makeCellCentresAndVols(const primitiveMesh &mesh, const vectorField &fCtrs, const vectorField &fAreas, vectorField &cellCtrs, scalarField &cellVols)
Calculate cell centres and volumes from face properties.
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:79
const vectorField & faceCentres() const
const scalarField & cellVolumes() const
const vectorField & cellCentres() const
void calcCellCentresAndVols() const
Calculate cell centres and volumes.
label nCells() const noexcept
Number of mesh cells.
const vectorField & faceAreas() const
virtual void updateGeom()
Update all geometric data.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Field< vector > vectorField
Specialisation of Field<T> for vector.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
const scalarField & cellVols