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 {
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  fvMesh,
332  >(vm)
333 {
334  makeWeights();
335 }
336 
337 
338 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
339 
341 {}
342 
343 
344 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
345 
347 {
348  makeWeights();
349 
350  return true;
351 }
352 
353 
355 {
356  makeWeights();
357 }
358 
359 
361 {
362  makeWeights();
363 }
364 
365 
367 {
368  makeWeights();
369 }
370 
371 
373 (
374  const volVectorField& vf,
375  pointVectorField& pf
376 ) const
377 {
378  interpolateUnconstrained(vf, pf);
379 
380  // Apply displacement constraints
382 }
383 
384 
385 // ************************************************************************* //
static const Foam::dimensionedScalar C("C", Foam::dimTemperature, 234.5)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Templated abstract base-class for demand-driven mesh objects used to automate their allocation to the...
static const DimensionedField< Type, GeoMesh > & null()
Return a null DimensionedField.
const Mesh & mesh() const
Return mesh.
static const char *const typeName
Definition: Field.H:105
Generic GeometricField class.
GeometricBoundaryField< Type, PatchField, GeoMesh > Boundary
Type of the boundary field.
fileName & instance() const
Return the instance directory, constant, system, <time> etc.
Definition: IOobject.C:355
IOobject(const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Definition: IOobject.C:167
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
void setSize(const label)
Reset size of List.
Definition: List.C:281
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
const volVectorField & C() const
Return cell centres.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:893
const UCompactListList< label > & polyBFacePatches() const
Return poly-bFace-patch addressing.
Definition: fvMesh.C:951
const UCompactListList< label > & polyBFacePatchFaces() const
Return poly-bFace-patch-face addressing.
Definition: fvMesh.C:1027
void constrainDisplacement(pointVectorField &displacement, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints),.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:403
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1361
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelListList & pointCells() const
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronise values on all mesh points.
Interpolate from cell centres to points (vertices) using inverse distance weighting.
virtual bool movePoints()
Correct weighting factors for moving mesh.
virtual void topoChange(const polyTopoChangeMap &)
Update mesh topology using the morph engine.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
volPointInterpolation(const fvMesh &)
Constructor given fvMesh.
void interpolateDisplacement(const volVectorField &, pointVectorField &) const
Interpolate from volField to pointField.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Template functions to aid in the implementation of demand driven data.
label patchi
const pointField & points
label nPoints
const fvPatchList & patches
Namespace for OpenFOAM.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
static const zero Zero
Definition: zero.H:97
List< label > labelList
A List of labels.
Definition: labelList.H:56
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const dimensionSet dimless
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
vector point
Point is a vector.
Definition: point.H:41
PointField< scalar > pointScalarField
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
Addressing for a faceList slice.
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
UList< label > labelUList
Definition: UList.H:65
faceListList boundary(nPatches)
labelList f(nPoints)
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=*(cellModeller::lookup("hex"));labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells]=cellShape(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< small) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &mergedCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< SLList< face > > pFaces[nBCs]
Definition: readKivaGrid.H:229
Foam::surfaceFields.