volPointInterpolate.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 | Copyright (C) 2011-2016 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 "volFields.H"
28 #include "pointFields.H"
29 #include "emptyFvPatch.H"
30 #include "coupledPointPatchField.H"
31 #include "pointConstraints.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 template<class Type>
36 void Foam::volPointInterpolation::pushUntransformedData
37 (
38  List<Type>& pointData
39 ) const
40 {
41  // Transfer onto coupled patch
42  const globalMeshData& gmd = mesh().globalData();
43  const indirectPrimitivePatch& cpp = gmd.coupledPatch();
44  const labelList& meshPoints = cpp.meshPoints();
45 
46  const mapDistribute& slavesMap = gmd.globalCoPointSlavesMap();
47  const labelListList& slaves = gmd.globalCoPointSlaves();
48 
49  List<Type> elems(slavesMap.constructSize());
50  forAll(meshPoints, i)
51  {
52  elems[i] = pointData[meshPoints[i]];
53  }
54 
55  // Combine master data with slave data
56  forAll(slaves, i)
57  {
58  const labelList& slavePoints = slaves[i];
59 
60  // Copy master data to slave slots
61  forAll(slavePoints, j)
62  {
63  elems[slavePoints[j]] = elems[i];
64  }
65  }
66 
67  // Push slave-slot data back to slaves
68  slavesMap.reverseDistribute(elems.size(), elems, false);
69 
70  // Extract back onto mesh
71  forAll(meshPoints, i)
72  {
73  pointData[meshPoints[i]] = elems[i];
74  }
75 }
76 
77 
78 template<class Type>
79 void Foam::volPointInterpolation::addSeparated
80 (
81  GeometricField<Type, pointPatchField, pointMesh>& pf
82 ) const
83 {
84  if (debug)
85  {
86  Pout<< "volPointInterpolation::addSeparated" << endl;
87  }
88 
89  typename GeometricField<Type, pointPatchField, pointMesh>::
90  Internal& pfi = pf.ref();
91 
92  typename GeometricField<Type, pointPatchField, pointMesh>::
93  Boundary& pfbf = pf.boundaryFieldRef();
94 
95  forAll(pfbf, patchi)
96  {
97  if (pfbf[patchi].coupled())
98  {
99  refCast<coupledPointPatchField<Type>>
100  (pfbf[patchi]).initSwapAddSeparated
101  (
103  pfi
104  );
105  }
106  }
107 
108  // Block for any outstanding requests
110 
111  forAll(pfbf, patchi)
112  {
113  if (pfbf[patchi].coupled())
114  {
115  refCast<coupledPointPatchField<Type>>
116  (pfbf[patchi]).swapAddSeparated
117  (
119  pfi
120  );
121  }
122  }
123 }
124 
125 
126 template<class Type>
128 (
131 ) const
132 {
133  if (debug)
134  {
135  Pout<< "volPointInterpolation::interpolateInternalField("
136  << "const GeometricField<Type, fvPatchField, volMesh>&, "
137  << "GeometricField<Type, pointPatchField, pointMesh>&) : "
138  << "interpolating field from cells to points"
139  << endl;
140  }
141 
142  const labelListList& pointCells = vf.mesh().pointCells();
143 
144  // Multiply volField by weighting factor matrix to create pointField
145  forAll(pointCells, pointi)
146  {
147  if (!isPatchPoint_[pointi])
148  {
149  const scalarList& pw = pointWeights_[pointi];
150  const labelList& ppc = pointCells[pointi];
151 
152  pf[pointi] = Zero;
153 
154  forAll(ppc, pointCelli)
155  {
156  pf[pointi] += pw[pointCelli]*vf[ppc[pointCelli]];
157  }
158  }
159  }
160 }
161 
162 
163 template<class Type>
164 Foam::tmp<Foam::Field<Type>> Foam::volPointInterpolation::flatBoundaryField
165 (
167 ) const
168 {
169  const fvMesh& mesh = vf.mesh();
170  const fvBoundaryMesh& bm = mesh.boundary();
171 
172  tmp<Field<Type>> tboundaryVals
173  (
174  new Field<Type>(mesh.nFaces()-mesh.nInternalFaces())
175  );
176  Field<Type>& boundaryVals = tboundaryVals.ref();
177 
179  {
180  label bFacei = bm[patchi].patch().start() - mesh.nInternalFaces();
181 
182  if
183  (
184  !isA<emptyFvPatch>(bm[patchi])
185  && !vf.boundaryField()[patchi].coupled()
186  )
187  {
189  (
190  boundaryVals,
191  vf.boundaryField()[patchi].size(),
192  bFacei
193  ) = vf.boundaryField()[patchi];
194  }
195  else
196  {
197  const polyPatch& pp = bm[patchi].patch();
198 
199  forAll(pp, i)
200  {
201  boundaryVals[bFacei++] = Zero;
202  }
203  }
204  }
205 
206  return tboundaryVals;
207 }
208 
209 
210 template<class Type>
212 (
215 ) const
216 {
217  const primitivePatch& boundary = boundaryPtr_();
218 
219  Field<Type>& pfi = pf.primitiveFieldRef();
220 
221  // Get face data in flat list
222  tmp<Field<Type>> tboundaryVals(flatBoundaryField(vf));
223  const Field<Type>& boundaryVals = tboundaryVals();
224 
225 
226  // Do points on 'normal' patches from the surrounding patch faces
227  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228 
229  forAll(boundary.meshPoints(), i)
230  {
231  label pointi = boundary.meshPoints()[i];
232 
233  if (isPatchPoint_[pointi])
234  {
235  const labelList& pFaces = boundary.pointFaces()[i];
236  const scalarList& pWeights = boundaryPointWeights_[i];
237 
238  Type& val = pfi[pointi];
239 
240  val = Zero;
241  forAll(pFaces, j)
242  {
243  if (boundaryIsPatchFace_[pFaces[j]])
244  {
245  val += pWeights[j]*boundaryVals[pFaces[j]];
246  }
247  }
248  }
249  }
250 
251  // Sum collocated contributions
253 
254  // And add separated contributions
255  addSeparated(pf);
256 
257  // Push master data to slaves. It is possible (not sure how often) for
258  // a coupled point to have its master on a different patch so
259  // to make sure just push master data to slaves.
260  pushUntransformedData(pfi);
261 }
262 
263 
264 template<class Type>
266 (
269  const bool overrideFixedValue
270 ) const
271 {
272  interpolateBoundaryField(vf, pf);
273 
274  // Apply constraints
275  const pointConstraints& pcs = pointConstraints::New(pf.mesh());
276 
277  pcs.constrain(pf, overrideFixedValue);
278 }
279 
280 
281 template<class Type>
283 (
286 ) const
287 {
288  if (debug)
289  {
290  Pout<< "volPointInterpolation::interpolate("
291  << "const GeometricField<Type, fvPatchField, volMesh>&, "
292  << "GeometricField<Type, pointPatchField, pointMesh>&) : "
293  << "interpolating field from cells to points"
294  << endl;
295  }
296 
297  interpolateInternalField(vf, pf);
298 
299  // Interpolate to the patches preserving fixed value BCs
300  interpolateBoundaryField(vf, pf, false);
301 }
302 
303 
304 template<class Type>
307 (
309  const wordList& patchFieldTypes
310 ) const
311 {
312  const pointMesh& pm = pointMesh::New(vf.mesh());
313 
314  // Construct tmp<pointField>
316  (
318  (
319  IOobject
320  (
321  "volPointInterpolate(" + vf.name() + ')',
322  vf.instance(),
323  pm.thisDb()
324  ),
325  pm,
326  vf.dimensions(),
327  patchFieldTypes
328  )
329  );
330 
331  interpolateInternalField(vf, tpf());
332 
333  // Interpolate to the patches overriding fixed value BCs
334  interpolateBoundaryField(vf, tpf(), true);
335 
336  return tpf;
337 }
338 
339 
340 template<class Type>
343 (
345  const wordList& patchFieldTypes
346 ) const
347 {
348  // Construct tmp<pointField>
350  interpolate(tvf(), patchFieldTypes);
351  tvf.clear();
352  return tpf;
353 }
354 
355 
356 template<class Type>
359 (
361  const word& name,
362  const bool cache
363 ) const
364 {
366 
367  const pointMesh& pm = pointMesh::New(vf.mesh());
368  const objectRegistry& db = pm.thisDb();
369 
370  if (!cache || vf.mesh().changing())
371  {
372  // Delete any old occurences to avoid double registration
373  if (db.objectRegistry::template foundObject<PointFieldType>(name))
374  {
375  PointFieldType& pf = const_cast<PointFieldType&>
376  (
377  db.objectRegistry::template lookupObject<PointFieldType>(name)
378  );
379 
380  if (pf.ownedByRegistry())
381  {
382  solution::cachePrintMessage("Deleting", name, vf);
383  pf.release();
384  delete &pf;
385  }
386  }
387 
388 
390  (
392  (
393  IOobject
394  (
395  name,
396  vf.instance(),
397  pm.thisDb()
398  ),
399  pm,
400  vf.dimensions()
401  )
402  );
403 
404  interpolate(vf, tpf.ref());
405 
406  return tpf;
407  }
408  else
409  {
410  if (!db.objectRegistry::template foundObject<PointFieldType>(name))
411  {
412  solution::cachePrintMessage("Calculating and caching", name, vf);
413  tmp<PointFieldType> tpf = interpolate(vf, name, false);
414  PointFieldType* pfPtr = tpf.ptr();
415  regIOobject::store(pfPtr);
416  return *pfPtr;
417  }
418  else
419  {
420  PointFieldType& pf = const_cast<PointFieldType&>
421  (
422  db.objectRegistry::template lookupObject<PointFieldType>(name)
423  );
424 
425  if (pf.upToDate(vf)) //TBD: , vf.mesh().points()))
426  {
427  solution::cachePrintMessage("Reusing", name, vf);
428  return pf;
429  }
430  else
431  {
432  solution::cachePrintMessage("Deleting", name, vf);
433  pf.release();
434  delete &pf;
435 
436  solution::cachePrintMessage("Recalculating", name, vf);
437  tmp<PointFieldType> tpf = interpolate(vf, name, false);
438 
439  solution::cachePrintMessage("Storing", name, vf);
440  PointFieldType* pfPtr = tpf.ptr();
441  regIOobject::store(pfPtr);
442 
443  // Note: return reference, not pointer
444  return *pfPtr;
445  }
446  }
447  }
448 }
449 
450 
451 template<class Type>
454 (
456 ) const
457 {
458  return interpolate(vf, "volPointInterpolate(" + vf.name() + ')', false);
459 }
460 
461 
462 template<class Type>
465 (
467 ) const
468 {
469  // Construct tmp<pointField>
471  interpolate(tvf());
472  tvf.clear();
473  return tpf;
474 }
475 
476 
477 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:221
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Generic GeometricField class.
PrimitivePatch< face, IndirectList, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
void interpolateBoundaryField(const GeometricField< Type, fvPatchField, volMesh > &vf, GeometricField< Type, pointPatchField, pointMesh > &pf) const
Interpolate boundary field without applying constraints/boundary.
void constrain(GeometricField< Type, pointPatchField, pointMesh > &pf, const bool overrideValue=false) const
Apply boundary conditions (single-patch constraints) and.
void interpolateInternalField(const GeometricField< Type, fvPatchField, volMesh > &, GeometricField< Type, pointPatchField, pointMesh > &) const
Interpolate internal field from volField to pointField.
static const pointConstraints & New(const pointMesh &mesh)
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
Application of (multi-)patch point contraints.
A list of faces which address into the list of points.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Pre-declare SubField and related Field type.
Definition: Field.H:57
A class for handling words, derived from string.
Definition: word.H:59
static void syncUntransformedData(const polyMesh &mesh, List< Type > &pointData, const CombineOp &cop)
Helper: sync data on collocated points only.
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,&oldCyclicPolyPatch::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:235
List< label > labelList
A List of labels.
Definition: labelList.H:56
static const zero Zero
Definition: zero.H:91
faceListList boundary(nPatches)
tmp< GeometricField< Type, pointPatchField, pointMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &) const
Interpolate volField using inverse distance weighting.
const dimensionSet & dimensions() const
Return dimensions.
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1140
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:34
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:198
Internal::FieldType & primitiveFieldRef()
Return a reference to the internal field.
static void waitRequests(const label start=0)
Wait until all requests (from start onwards) have finished.
Definition: UPstream.C:117
label nFaces() const
const objectRegistry & thisDb() const
Return database. For now is its polyMesh.
Definition: pointMesh.H:118
label patchi
const Mesh & mesh() const
Return mesh.
Foam::fvBoundaryMesh.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const labelListList & pointFaces() const
Return point-face addressing.
A class for managing temporary objects.
Definition: PtrList.H:54
Registry of regIOobjects.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
static void cachePrintMessage(const char *message, const word &name, const FieldType &vf)
Helper for printing cache message.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const fileName & instance() const
Definition: IOobject.H:337
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:545
label nInternalFaces() const
const word & name() const
Return name.
Definition: IOobject.H:260