parallelFvGeometryScheme.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) 2022 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 
30 #include "fvMesh.H"
31 #include "syncTools.H"
32 #include "primitiveMeshTools.H"
33 #include "surfaceFields.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(parallelFvGeometryScheme, 0);
41  (
42  fvGeometryScheme,
43  parallelFvGeometryScheme,
44  dict
45  );
46 }
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::parallelFvGeometryScheme::adjustGeometry()
51 {
52  // Swap face centres and areas
53  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
54 
55  pointField faceCentres(mesh_.faceCentres());
56  vectorField faceAreas(mesh_.faceAreas());
57  {
58  pointField syncedBCentres;
59  syncedBCentres = SubField<vector>
60  (
64  );
66  (
67  mesh_,
68  syncedBCentres
69  );
70 
71  vectorField syncedBAreas;
72  syncedBAreas = SubField<vector>
73  (
74  mesh_.faceAreas(),
77  );
79  (
80  mesh_,
81  syncedBAreas,
82  eqOp<vector>(),
83  transformOriented()
84  );
85 
86  const auto& pbm = mesh_.boundaryMesh();
87  for (const auto& pp : pbm)
88  {
89  const auto* ppp = isA<coupledPolyPatch>(pp);
90 
91  //if (ppp)
92  //{
93  // Pout<< "For patch:" << ppp->name()
94  // << " size:" << ppp->size()
95  // << endl;
96  // forAll(*ppp, i)
97  // {
98  // const label facei = ppp->start()+i;
99  // Pout<< " Face:" << facei << nl
100  // << " meshFc:" << faceCentres[facei] << nl
101  // << " meshFa:" << faceAreas[facei] << nl
102  // << endl;
103  // }
104  //}
105 
106  if (ppp && !ppp->owner())
107  {
108  // Delete old cached geometry
109  const_cast<coupledPolyPatch&>
110  (
111  *ppp
113 
114  SubField<point> patchFc
115  (
116  faceCentres,
117  ppp->size(),
118  ppp->start()
119  );
120  patchFc = SubField<vector>
121  (
122  syncedBCentres,
123  ppp->size(),
124  ppp->offset()
125  );
126 
127  SubField<vector> patchArea
128  (
129  faceAreas,
130  ppp->size(),
131  ppp->start()
132  );
133  patchArea = SubField<vector>
134  (
135  syncedBAreas,
136  ppp->size(),
137  ppp->offset()
138  );
139  }
140  }
141  }
142 
143 
144  // Force recalculating cell properties
145  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146 
147  pointField cellCentres(mesh_.nCells());
148  scalarField cellVolumes(mesh_.nCells());
150  (
151  mesh_,
152  faceCentres,
153  faceAreas,
154  cellCentres,
155  cellVolumes
156  );
157 
158 
159  label nFaces = 0;
160  forAll(faceCentres, facei)
161  {
162  const auto& oldFc = mesh_.faceCentres()[facei];
163  const auto& newFc = faceCentres[facei];
164  const auto& oldFa = mesh_.faceAreas()[facei];
165  const auto& newFa = faceAreas[facei];
166 
167  if (oldFc != newFc || oldFa != newFa)
168  {
169  nFaces++;
170 
171  if (mesh_.isInternalFace(facei))
172  {
174  << "Different geometry for internal face:" << facei
175  << " oldFc:" << oldFc << nl
176  << " newFc:" << newFc << nl
177  << " oldFa:" << oldFa << nl
178  << " newFa:" << newFa << nl
179  << endl;
180  }
181  }
182  }
183 
184  label nCells = 0;
185  forAll(cellCentres, celli)
186  {
187  const auto& oldCc = mesh_.cellCentres()[celli];
188  const auto& newCc = cellCentres[celli];
189  const auto& oldCv = mesh_.cellVolumes()[celli];
190  const auto& newCv = cellVolumes[celli];
191 
192  if (oldCc != newCc || oldCv != newCv)
193  {
194  nCells++;
195  //Pout<< "cell:" << celli << nl
196  // << " oldCc:" << oldCc << nl
197  // << " newCc:" << newCc << nl
198  // << " oldCv:" << oldCv << nl
199  // << " newCv:" << newCv << nl
200  // << endl;
201  }
202  }
203 
204  Info<< "parallelFvGeometryScheme::movePoints() : "
205  << "adjusted geometry of faces:"
206  << returnReduce(nFaces, sumOp<label>())
207  << " of cells:"
208  << returnReduce(nCells, sumOp<label>())
209  << endl;
210 
211  const_cast<fvMesh&>(mesh_).primitiveMesh::resetGeometry
212  (
213  std::move(faceCentres),
214  std::move(faceAreas),
215  std::move(cellCentres),
216  std::move(cellVolumes)
217  );
218 }
219 
220 
221 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
222 
223 Foam::parallelFvGeometryScheme::parallelFvGeometryScheme
224 (
225  const fvMesh& mesh,
226  const dictionary& dict
227 )
228 :
230  dict_(dict.subOrEmptyDict("geometry"))
231 {}
232 
233 
234 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
235 
237 {
238  if (!geometryPtr_)
239  {
240  if (debug)
241  {
242  Pout<< "parallelFvGeometryScheme::geometry() : "
243  << "constructing underlying scheme from " << dict_
244  << endl;
245  }
246  geometryPtr_ = fvGeometryScheme::New
247  (
248  mesh_,
249  dict_,
250  basicFvGeometryScheme::typeName
251  );
252  }
253  return geometryPtr_();
254 }
255 
256 
258 {
259  if (debug)
260  {
261  Pout<< "parallelFvGeometryScheme::movePoints() : "
262  << "recalculating primitiveMesh centres" << endl;
263  }
264 
265  // Do any primitive geometry calculation
266  const_cast<fvGeometryScheme&>(geometry()).movePoints();
267 
268  // Do in-place overriding processor boundary geometry
269  adjustGeometry();
270 }
271 
272 
274 {
275  return const_cast<fvGeometryScheme&>(geometry()).updateMesh(mpm);
276 }
277 
278 
281 {
282  return geometry().weights();
283 }
284 
285 
288 {
289  return geometry().deltaCoeffs();
290 }
291 
292 
295 {
296  return geometry().nonOrthDeltaCoeffs();
297 }
298 
299 
302 {
303  return geometry().nonOrthCorrectionVectors();
304 }
305 
306 
307 
308 // ************************************************************************* //
Foam::surfaceFields.
const polyBoundaryMesh & pbm
dictionary dict
const fvMesh & mesh_
Hold reference to mesh.
static void syncBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop, const TransformOp &top, const bool parRun=UPstream::parRun())
Synchronize values on boundary faces only.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
Macros for easy insertion into run-time selection tables.
bool isInternalFace(const label faceIndex) const noexcept
Return true if given face label is internal to the mesh.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void resetGeometry(pointField &&faceCentres, pointField &&faceAreas, pointField &&cellCentres, scalarField &&cellVolumes)
Reset the local geometry.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
virtual tmp< surfaceVectorField > nonOrthCorrectionVectors() const
Return non-orthogonality correction vectors.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:608
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
label nInternalFaces() const noexcept
Number of internal faces.
virtual tmp< surfaceScalarField > weights() const
Return linear difference weighting factors.
const vectorField & cellCentres() const
static tmp< fvGeometryScheme > New(const fvMesh &mesh, const dictionary &dict, const word &defaultScheme)
Return new tmp interpolation scheme.
virtual tmp< surfaceScalarField > deltaCoeffs() const
Return cell-centre difference coefficients.
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
virtual void movePoints()
Do what is necessary if the mesh has moved.
const vectorField & faceCentres() const
#define WarningInFunction
Report a warning using Foam::Warning.
virtual void updateMesh(const mapPolyMesh &mpm)
Update mesh for topology changes.
label nCells() const noexcept
Number of mesh cells.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const vectorField & faceAreas() const
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< vector > vectorField
Specialisation of Field<T> for vector.
static void makeCellCentresAndVols(const primitiveMesh &mesh, const vectorField &fCtrs, const vectorField &fAreas, vectorField &cellCtrs, scalarField &cellVols)
Calculate cell centres and volumes from face properties.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual tmp< surfaceScalarField > nonOrthDeltaCoeffs() const
Return non-orthogonal cell-centre difference coefficients.
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Abstract base class for geometry calculation schemes.
const fvGeometryScheme & geometry() const
Construct underlying fvGeometryScheme.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:485
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
const scalarField & cellVolumes() const