volPointInterpolationTemplates.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 "volFields.H"
28 #include "pointFields.H"
29 #include "surfaceFields.H"
30 #include "emptyFvPatch.H"
31 #include "coupledPointPatchField.H"
32 #include "pointConstraints.H"
33 #include "UCompactListList.H"
34 #include "syncTools.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 template<class Type>
40 (
43 ) const
44 {
45  if (debug)
46  {
47  Pout<< "volPointInterpolation::interpolateUnconstrained("
48  << "const GeometricField<Type, fvPatchField, volMesh>&, "
49  << "GeometricField<Type, pointPatchField, pointMesh>&) : "
50  << "interpolating field from cells to points"
51  << endl;
52  }
53 
54  const labelListList& pointCells = mesh().pointCells();
55  const polyBoundaryMesh& pbm = mesh().boundaryMesh();
56  const fvBoundaryMesh& fvbm = mesh().boundary();
57 
58  const primitivePatch& boundary = boundaryPtr_();
59 
60  // Cache calls to patch coupled flags
61  boolList isCoupledPolyPatch(pbm.size(), false);
62  boolList isCoupledFvPatch(fvbm.size(), false);
63  forAll(isCoupledFvPatch, patchi)
64  {
65  isCoupledPolyPatch[patchi] = pbm[patchi].coupled();
66  isCoupledFvPatch[patchi] = fvbm[patchi].coupled();
67  }
68 
69  pf = Zero;
70 
71  // Interpolate from the cells
72  forAll(pointWeights_, pointi)
73  {
74  forAll(pointWeights_[pointi], pointCelli)
75  {
76  const label celli = pointCells[pointi][pointCelli];
77 
78  pf[pointi] += pointWeights_[pointi][pointCelli]*vf[celli];
79  }
80  }
81 
82  // Get the boundary neighbour field
84  (
87  );
88 
89  // Interpolate from the boundary faces
90  forAll(boundaryPointWeights_, bPointi)
91  {
92  const label pointi = boundary.meshPoints()[bPointi];
93 
94  const labelList& pFaces = boundary.pointFaces()[bPointi];
95 
96  forAll(boundaryPointWeights_[bPointi], bPointFacei)
97  {
98  // FV indices
99  const labelUList patches =
100  mesh().polyBFacePatches()[pFaces[bPointFacei]];
101  const labelUList patchFaces =
102  mesh().polyBFacePatchFaces()[pFaces[bPointFacei]];
103 
104  forAll(boundaryPointWeights_[bPointi][bPointFacei], i)
105  {
106  // If FV coupled only, add the neighbouring cell value
107  if
108  (
109  !isCoupledPolyPatch[patches[i]]
110  && isCoupledFvPatch[patches[i]]
111  )
112  {
113  pf[pointi] +=
114  boundaryPointNbrWeights_[bPointi][bPointFacei][i]
115  *vfBnf[patches[i]][patchFaces[i]];
116  }
117 
118  // If not coupled, add a weight to the boundary value
119  if
120  (
121  !isCoupledPolyPatch[patches[i]]
122  && !isCoupledFvPatch[patches[i]]
123  )
124  {
125  pf[pointi] +=
126  boundaryPointWeights_[bPointi][bPointFacei][i]
127  *vf.boundaryField()[patches[i]][patchFaces[i]];
128  }
129  }
130  }
131  }
132 
133  // Synchronise
134  syncTools::syncPointList(mesh(), pf, plusEqOp<Type>(), pTraits<Type>::zero);
135 }
136 
137 
138 template<class Type>
140 (
143 ) const
144 {
145  interpolateUnconstrained(vf, pf);
146 
147  // Apply constraints
149 }
150 
151 
152 template<class Type>
155 (
157  const word& name,
158  const bool cache
159 ) const
160 {
162 
163  const pointMesh& pm = pointMesh::New(vf.mesh());
164  const objectRegistry& db = pm.thisDb();
165 
166  if (!cache || vf.mesh().changing())
167  {
168  // Delete any old occurrences to avoid double registration
169  if (db.objectRegistry::template foundObject<PointFieldType>(name))
170  {
171  PointFieldType& pf =
172  db.objectRegistry::template lookupObjectRef<PointFieldType>
173  (
174  name
175  );
176 
177  if (pf.ownedByRegistry())
178  {
179  solution::cachePrintMessage("Deleting", name, vf);
180  pf.release();
181  delete &pf;
182  }
183  }
184 
186  (
188  (
189  name,
190  pm,
191  vf.dimensions()
192  )
193  );
194 
195  interpolate(vf, tpf.ref());
196 
197  return tpf;
198  }
199  else
200  {
201  if (!db.objectRegistry::template foundObject<PointFieldType>(name))
202  {
203  solution::cachePrintMessage("Calculating and caching", name, vf);
204  tmp<PointFieldType> tpf = interpolate(vf, name, false);
205  PointFieldType* pfPtr = tpf.ptr();
206  regIOobject::store(pfPtr);
207  return *pfPtr;
208  }
209  else
210  {
211  PointFieldType& pf =
212  db.objectRegistry::template lookupObjectRef<PointFieldType>
213  (
214  name
215  );
216 
217  if (pf.upToDate(vf))
218  {
219  solution::cachePrintMessage("Reusing", name, vf);
220  return pf;
221  }
222  else
223  {
224  solution::cachePrintMessage("Deleting", name, vf);
225  pf.release();
226  delete &pf;
227 
228  solution::cachePrintMessage("Recalculating", name, vf);
229  tmp<PointFieldType> tpf = interpolate(vf, name, false);
230 
231  solution::cachePrintMessage("Storing", name, vf);
232  PointFieldType* pfPtr = tpf.ptr();
233  regIOobject::store(pfPtr);
234 
235  return *pfPtr;
236  }
237  }
238  }
239 }
240 
241 
242 template<class Type>
245 (
247 ) const
248 {
249  return interpolate(vf, "volPointInterpolate(" + vf.name() + ')', false);
250 }
251 
252 
253 template<class Type>
256 (
258 ) const
259 {
261  interpolate(tvf());
262 
263  tvf.clear();
264 
265  return tpf;
266 }
267 
268 
269 // ************************************************************************* //
const fvPatchList & patches
Foam::surfaceFields.
tmp< GeometricField< Type, pointPatchField, pointMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &) const
Interpolate volField using inverse distance weighting.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const word & name() const
Return name.
Definition: IOobject.H:315
const Boundary & boundaryField() const
Return const-reference to the boundary field.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Traits class for primitives.
Definition: pTraits.H:50
Generic GeometricField class.
fvMesh & mesh
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
const dimensionSet & dimensions() const
Return dimensions.
A list of faces which address into the list of points.
A class for handling words, derived from string.
Definition: word.H:59
const objectRegistry & thisDb() const
Return database. For now is its polyMesh.
Definition: pointMesh.H:109
void interpolateUnconstrained(const GeometricField< Type, fvPatchField, volMesh > &, GeometricField< Type, pointPatchField, pointMesh > &) const
Interpolate from volField to pointField.
static const zero Zero
Definition: zero.H:97
faceListList boundary(nPatches)
tmp< GeometricBoundaryField > boundaryNeighbourField() const
Return BoundaryField of the values on the other side of couples.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Foam::polyBoundaryMesh.
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:235
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:40
const labelListList & pointFaces() const
Return point-face addressing.
const Mesh & mesh() const
Return mesh.
Generic GeometricBoundaryField class.
Definition: fvMesh.H:80
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
fvConstraints constrain(rhoEqn)
label patchi
Foam::fvBoundaryMesh.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
T * ptr() const
Return tmp pointer for reuse.
Definition: tmpI.H:205
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:312
static void cachePrintMessage(const char *message, const word &name, const FieldType &vf)
Helper for printing cache message.