1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 cfMesh is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "polyMeshGenAddressing.H"
27 #include "demandDrivenData.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
40 void polyMeshGenAddressing::updateGeometry
42 const boolList& changedFace
45 const pointFieldPMG& p = mesh_.points();
46 const faceListPMG& faces = mesh_.faces();
48 //- update face centres and face areas
49 if( faceCentresPtr_ && faceAreasPtr_ )
51 vectorField& fCtrs = *faceCentresPtr_;
52 vectorField& fAreas = *faceAreasPtr_;
55 # pragma omp parallel for if( faces.size() > 100 ) \
59 if( changedFace[faceI] )
61 const face& f = faces[faceI];
62 const label nPoints = f.size();
64 // If the face is a triangle, do a direct calculation for
65 // efficiency and to avoid round-off error-related problems
68 fCtrs[faceI] = (1.0/3.0)*(p[f[0]] + p[f[1]] + p[f[2]]);
70 0.5*((p[f[1]] - p[f[0]])^(p[f[2]] - p[f[0]]));
74 vector sumN = vector::zero;
76 vector sumAc = vector::zero;
78 point fCentre = p[f[0]];
79 for(label pI=1;pI<nPoints;++pI)
86 for(label pI=0;pI<nPoints;++pI)
88 const point& nextPoint = p[f.nextLabel(pI)];
90 vector c = p[f[pI]] + nextPoint + fCentre;
91 vector n = (nextPoint - p[f[pI]])^(fCentre - p[f[pI]]);
99 fCtrs[faceI] = (1.0/3.0)*sumAc/(sumA + VSMALL);
100 fAreas[faceI] = 0.5*sumN;
105 //- update cell centres and cell volumes
106 if( cellCentresPtr_ && cellVolumesPtr_ && faceCentresPtr_ && faceAreasPtr_ )
108 const vectorField& fCtrs = *faceCentresPtr_;
109 const vectorField& fAreas = *faceAreasPtr_;
110 vectorField& cellCtrs = *cellCentresPtr_;
111 scalarField& cellVols = *cellVolumesPtr_;
113 const labelList& own = mesh_.owner();
114 const cellListPMG& cells = mesh_.cells();
117 # pragma omp parallel for if( cells.size() > 100 ) \
118 schedule(dynamic, 10)
122 const cell& c = cells[cellI];
126 if( changedFace[c[fI]] )
134 cellCtrs[cellI] = vector::zero;
135 cellVols[cellI] = 0.0;
137 //- estimate position of cell centre
138 vector cEst(vector::zero);
140 cEst += fCtrs[c[fI]];
144 if( own[c[fI]] == cellI )
146 // Calculate 3*face-pyramid volume
147 const scalar pyr3Vol =
158 // Calculate face-pyramid centre
160 (3.0/4.0)*fCtrs[c[fI]] + (1.0/4.0)*cEst;
162 // Accumulate volume-weighted face-pyramid centre
163 cellCtrs[cellI] += pyr3Vol*pc;
165 // Accumulate face-pyramid volume
166 cellVols[cellI] += pyr3Vol;
170 // Calculate 3*face-pyramid volume
171 const scalar pyr3Vol =
181 // Calculate face-pyramid centre
183 (3.0/4.0)*fCtrs[c[fI]] + (1.0/4.0)*cEst;
185 // Accumulate volume-weighted face-pyramid centre
186 cellCtrs[cellI] += pyr3Vol*pc;
188 // Accumulate face-pyramid volume
189 cellVols[cellI] += pyr3Vol;
192 cellCtrs[cellI] /= cellVols[cellI];
193 cellVols[cellI] /= 3.0;
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 } // End namespace Foam
203 // ************************************************************************* //