All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
volPointInterpolation.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "volPointInterpolation.H"
27 #include "fvMesh.H"
28 #include "volFields.H"
29 #include "pointFields.H"
30 #include "demandDrivenData.H"
31 #include "pointConstraints.H"
32 #include "surfaceFields.H"
33 #include "syncTools.H"
34 #include "cpuTime.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(volPointInterpolation, 0);
41 }
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void Foam::volPointInterpolation::makeWeights()
47 {
48  if (debug)
49  {
50  Pout<< "volPointInterpolation::makeWeights() : "
51  << "constructing weighting factors"
52  << endl;
53  }
54 
55  const pointField& points = mesh().points();
56  const labelListList& pointCells = mesh().pointCells();
57  const polyBoundaryMesh& pbm = mesh().boundaryMesh();
58  const fvBoundaryMesh& fvbm = mesh().boundary();
59 
60  // Update addressing over all boundary faces
61  boundaryPtr_.reset
62  (
63  new primitivePatch
64  (
65  SubList<face>
66  (
67  mesh().faces(),
68  mesh().nFaces() - mesh().nInternalFaces(),
69  mesh().nInternalFaces()
70  ),
71  mesh().points()
72  )
73  );
74  const primitivePatch& boundary = boundaryPtr_();
75 
76  // Allocate storage for weighting factors
77  pointWeights_.clear();
78  pointWeights_.setSize(points.size());
79  boundaryPointWeights_.clear();
80  boundaryPointWeights_.setSize(boundary.meshPoints().size());
81  boundaryPointNbrWeights_.clear();
82  boundaryPointNbrWeights_.setSize(boundary.meshPoints().size());
83 
84  // Cache calls to patch coupled flags
85  boolList isCoupledPolyPatch(pbm.size(), false);
86  boolList isCoupledFvPatch(fvbm.size(), false);
87  forAll(isCoupledFvPatch, patchi)
88  {
89  isCoupledPolyPatch[patchi] = pbm[patchi].coupled();
90  isCoupledFvPatch[patchi] = fvbm[patchi].coupled();
91  }
92 
93  // Determine the factor to which a point has its values set by adjacent
94  // boundary faces, rather than connected cells
95  scalarList pointBoundaryFactor(mesh().nPoints(), Zero);
96  forAll(boundary.meshPoints(), bPointi)
97  {
98  const label pointi = boundary.meshPoints()[bPointi];
99 
100  const labelList& pFaces = boundary.pointFaces()[bPointi];
101 
102  forAll(pFaces, pPointFacei)
103  {
104  // Poly indices
105  const label patchi = pbm.patchID()[pFaces[pPointFacei]];
106  const label patchFacei = pbm.patchFaceID()[pFaces[pPointFacei]];
107 
108  // FV indices
109  const labelUList patches =
110  mesh().polyBFacePatches()[pFaces[pPointFacei]];
111  const labelUList patchFaces =
112  mesh().polyBFacePatchFaces()[pFaces[pPointFacei]];
113 
114  scalar nonCoupledMagSf = 0;
115  forAll(patches, i)
116  {
117  if
118  (
119  !isCoupledPolyPatch[patches[i]]
120  && !isCoupledFvPatch[patches[i]]
121  )
122  {
123  nonCoupledMagSf += fvbm[patches[i]].magSf()[patchFaces[i]];
124  }
125  }
126 
127  pointBoundaryFactor[pointi] =
128  max
129  (
130  pointBoundaryFactor[pointi],
131  nonCoupledMagSf/pbm[patchi].magFaceAreas()[patchFacei]
132  );
133  }
134  }
136  (
137  mesh(),
138  pointBoundaryFactor,
139  maxEqOp<scalar>(),
140  scalar(0)
141  );
142 
143  // Calculate inverse distances between cell centres and points
144  // and store in the weighting factor array
145  forAll(points, pointi)
146  {
147  if (pointBoundaryFactor[pointi] > 1 - rootSmall) continue;
148 
149  pointWeights_[pointi].setSize(pointCells[pointi].size());
150 
151  const scalar f = pointBoundaryFactor[pointi];
152 
153  forAll(pointCells[pointi], pointCelli)
154  {
155  const label celli = pointCells[pointi][pointCelli];
156 
157  pointWeights_[pointi][pointCelli] =
158  (1 - f)/mag(points[pointi] - mesh().C()[celli]);
159  }
160  }
161 
162  // Get the cell centres on the other side of coupled boundaries
163  typename volVectorField::Boundary CBnf
164  (
165  mesh().boundary(),
168  );
169  forAll(fvbm, patchi)
170  {
171  if
172  (
173  !isCoupledPolyPatch[patchi]
174  && isCoupledFvPatch[patchi]
175  )
176  {
177  CBnf[patchi] = fvbm[patchi].Cn() + fvbm[patchi].delta();
178  }
179  }
180 
181  // Calculate inverse distanced between boundary face centres and points and
182  // store in the boundary weighting factor arrays
183  forAll(boundary.meshPoints(), bPointi)
184  {
185  const label pointi = boundary.meshPoints()[bPointi];
186 
187  const labelList& pFaces = boundary.pointFaces()[bPointi];
188 
189  boundaryPointWeights_[bPointi].resize(pFaces.size());
190  boundaryPointNbrWeights_[bPointi].resize(pFaces.size());
191 
192  forAll(pFaces, bPointFacei)
193  {
194  // Poly indices
195  const label patchi = pbm.patchID()[pFaces[bPointFacei]];
196  const label patchFacei = pbm.patchFaceID()[pFaces[bPointFacei]];
197 
198  // FV indices
199  const labelUList patches =
200  mesh().polyBFacePatches()[pFaces[bPointFacei]];
201  const labelUList patchFaces =
202  mesh().polyBFacePatchFaces()[pFaces[bPointFacei]];
203 
204  boundaryPointWeights_[bPointi][bPointFacei].resize
205  (
206  patches.size(),
207  0
208  );
209  boundaryPointNbrWeights_[bPointi][bPointFacei].resize
210  (
211  patches.size(),
212  0
213  );
214 
215  forAll(patches, i)
216  {
217  const scalar a =
218  fvbm[patches[i]].magSf()[patchFaces[i]]
219  /pbm[patchi].magFaceAreas()[patchFacei];
220 
221  const scalar f = pointBoundaryFactor[pointi];
222 
223  // If FV coupled only, add a weight to the neighbouring cell.
224  // This is necessary because point synchronisation will not sum
225  // the contributions across this interface as would be the case
226  // with a poly coupled interface.
227  if
228  (
229  !isCoupledPolyPatch[patches[i]]
230  && isCoupledFvPatch[patches[i]]
231  )
232  {
233  const point C = CBnf[patches[i]][patchFaces[i]];
234  boundaryPointNbrWeights_[bPointi][bPointFacei][i] =
235  (1 - f)*a/mag(points[pointi] - C);
236  }
237 
238  // If not coupled, add a weight to the boundary value
239  if
240  (
241  !isCoupledPolyPatch[patches[i]]
242  && !isCoupledFvPatch[patches[i]]
243  )
244  {
245  const point Cf = fvbm[patches[i]].Cf()[patchFaces[i]];
246  boundaryPointWeights_[bPointi][bPointFacei][i] =
247  f*a/mag(points[pointi] - Cf);
248  }
249  }
250  }
251  }
252 
253  // Construct a sum of weights
254  pointScalarField sumWeights
255  (
256  IOobject
257  (
258  "volPointSumWeights",
260  mesh()
261  ),
262  pointMesh::New(mesh()),
264  );
265 
266  // Add the internal weights
267  forAll(pointWeights_, pointi)
268  {
269  forAll(pointWeights_[pointi], i)
270  {
271  sumWeights[pointi] += pointWeights_[pointi][i];
272  }
273  }
274 
275  // Add the boundary weights
276  forAll(boundary.meshPoints(), bPointi)
277  {
278  const label pointi = boundary.meshPoints()[bPointi];
279  forAll(boundaryPointWeights_[bPointi], i)
280  {
281  forAll(boundaryPointWeights_[bPointi][i], j)
282  {
283  sumWeights[pointi] += boundaryPointWeights_[bPointi][i][j];
284  sumWeights[pointi] += boundaryPointNbrWeights_[bPointi][i][j];
285  }
286  }
287  }
288 
289  // Synchronise over conformal couplings
291  (
292  mesh(),
293  sumWeights,
294  plusEqOp<scalar>(),
295  scalar(0)
296  );
297 
298  // Normalise internal weights
299  forAll(pointWeights_, pointi)
300  {
301  forAll(pointWeights_[pointi], i)
302  {
303  pointWeights_[pointi][i] /= sumWeights[pointi];
304  }
305  }
306 
307  // Normalise boundary weights
308  forAll(boundary.meshPoints(), bPointi)
309  {
310  const label pointi = boundary.meshPoints()[bPointi];
311  forAll(boundaryPointWeights_[bPointi], i)
312  {
313  forAll(boundaryPointWeights_[bPointi][i], j)
314  {
315  boundaryPointWeights_[bPointi][i][j] /= sumWeights[pointi];
316  boundaryPointNbrWeights_[bPointi][i][j] /= sumWeights[pointi];
317  }
318  }
319  }
320 }
321 
322 
323 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
324 
326 :
328 {
329  makeWeights();
330 }
331 
332 
333 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
334 
336 {}
337 
338 
339 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
340 
342 {
343  makeWeights();
344 
345  return true;
346 }
347 
348 
350 {
351  makeWeights();
352 }
353 
354 
356 {
357  makeWeights();
358 }
359 
360 
362 {
363  makeWeights();
364 }
365 
366 
368 (
369  const volVectorField& vf,
370  pointVectorField& pf
371 ) const
372 {
373  interpolateUnconstrained(vf, pf);
374 
375  // Apply displacement constraints
376  pointConstraints::New(pf.mesh()).constrainDisplacement(pf);
377 }
378 
379 
380 // ************************************************************************* //
Foam::surfaceFields.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:453
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static const char *const typeName
Definition: Field.H:105
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
GeometricBoundaryField< vector, fvPatchField, volMesh > Boundary
Type of the boundary field.
const dimensionSet dimless
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:138
fvMesh & mesh
UList< label > labelUList
Definition: UList.H:65
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1211
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:87
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
const pointField & points
static const DimensionedField< Type, GeoMesh > & null()
Return a null DimensionedField.
label nPoints
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
void interpolateUnconstrained(const GeometricField< Type, fvPatchField, volMesh > &, GeometricField< Type, pointPatchField, pointMesh > &) const
Interpolate from volField to pointField.
virtual void topoChange(const polyTopoChangeMap &)
Update mesh topology using the morph engine.
List< label > labelList
A List of labels.
Definition: labelList.H:56
static const zero Zero
Definition: zero.H:97
faceListList boundary(nPatches)
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
Interpolate from cell centres to points (vertices) using inverse distance weighting.
const labelListList & pointCells() const
const Mesh & mesh() const
Return mesh.
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
void interpolateDisplacement(const volVectorField &, pointVectorField &) const
Interpolate from volField to pointField.
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
Addressing for a faceList slice.
volPointInterpolation(const fvMesh &)
Constructor given fvMesh and pointMesh.
Template functions to aid in the implementation of demand driven data.
const UCompactListList< label > & polyBFacePatchFaces() const
Return poly-bFace-patch-face addressing.
Definition: fvMesh.C:941
label patchi
vector point
Point is a vector.
Definition: point.H:41
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const UCompactListList< label > & polyBFacePatches() const
Return poly-bFace-patch addressing.
Definition: fvMesh.C:865
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronise values on all mesh points.
dimensioned< scalar > mag(const dimensioned< Type > &)
fileName & instance() const
Return the instance directory, constant, system, <time> etc.
Definition: IOobject.C:355
const volVectorField & C() const
Return cell centres.
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:50
virtual bool movePoints()
Correct weighting factors for moving mesh.
Namespace for OpenFOAM.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:800