meshToMesh0.H
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 Class
25  Foam::meshToMesh0
26 
27 Description
28  Serial mesh to mesh interpolation class.
29 
30 SourceFiles
31  meshToMesh0.C
32  calculateMeshToMesh0Addressing.C
33  calculateMeshToMesh0Weights.C
34  meshToMesh0Templates.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef meshToMesh0_H
39 #define meshToMesh0_H
40 
41 #include "fvMesh.H"
42 #include "HashTable.H"
43 #include "fvPatchMapper.H"
44 #include "scalarList.H"
45 #include "className.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 template<class Type>
53 class indexedOctree;
54 
55 class treeDataCell;
56 
57 /*---------------------------------------------------------------------------*\
58  Class meshToMesh0 Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class meshToMesh0
62 {
63  // Private Data
64 
65  //- Source mesh reference
66  const fvMesh& fromMesh_;
67 
68  //- Target mesh reference
69  const fvMesh& toMesh_;
70 
71  //- fromMesh patch labels
72  HashTable<label> fromMeshPatches_;
73 
74  //- toMesh patch labels
75  HashTable<label> toMeshPatches_;
76 
77  //- Patch map
78  HashTable<word> patchMap_;
79 
80  //- toMesh patch labels which cut the from-mesh
81  HashTable<label> cuttingPatches_;
82 
83  //- Cell addressing
84  labelList cellAddressing_;
85 
86  //- Boundary addressing
87  labelListList boundaryAddressing_;
88 
89  //- Inverse-distance interpolation weights
90  mutable scalarListList* inverseDistanceWeightsPtr_;
91 
92  //- Inverse-volume interpolation weights
93  mutable scalarListList* inverseVolumeWeightsPtr_;
94 
95  //- Cell to cell overlap addressing
96  mutable labelListList* cellToCellAddressingPtr_;
97 
98  //- Overlap volume
99  mutable scalar V_;
100 
101 
102  // Private Member Functions
103 
104  //- Calculates mesh to mesh addressing pattern.
105  // For each cell from one mesh find the closest cell centre
106  // in the other mesh
107  void calcAddressing();
108 
109  void cellAddresses
110  (
111  labelList& cells,
112  const pointField& points,
113  const fvMesh& fromMesh,
114  const List<bool>& boundaryCell,
116  ) const;
117 
118  void calculateInverseDistanceWeights() const;
119 
120  void calculateInverseVolumeWeights() const;
121 
122  void calculateCellToCellAddressing() const;
123 
124  const scalarListList& inverseDistanceWeights() const;
125 
126  const scalarListList& inverseVolumeWeights() const;
127 
128  const labelListList& cellToCellAddressing() const;
129 
130 
131  // Private static data members
132 
133  //- Direct hit tolerance
134  static const scalar directHitTol;
135 
136 
137 public:
138 
139  // Declare name of the class and its debug switch
140  ClassName("meshToMesh0");
141 
142 
143  //- Enumeration specifying required accuracy
144  enum order
145  {
150  };
151 
152 
153  // Constructors
154 
155  //- Construct from the two meshes, the patch name map for the patches
156  // to be interpolated and the names of the toMesh-patches which
157  // cut the fromMesh
159  (
160  const fvMesh& fromMesh,
161  const fvMesh& toMesh,
162  const HashTable<word>& patchMap,
163  const wordList& cuttingPatchNames
164  );
165 
166  //- Construct from the two meshes assuming there is an exact mapping
167  // between the patches
169  (
170  const fvMesh& fromMesh,
171  const fvMesh& toMesh
172  );
173 
174 
175  //- Destructor
176  ~meshToMesh0();
177 
178 
179  //- Patch-field interpolation class
181  :
183  {
184  const labelList& directAddressing_;
185 
186 
187  public:
188 
189  // Constructors
190 
191  //- Construct given addressing
192  patchFieldInterpolator(const labelList& addr)
193  :
194  directAddressing_(addr)
195  {}
196 
197 
198  //- Destructor
199  virtual ~patchFieldInterpolator()
200  {}
201 
202 
203  // Member Functions
205  label size() const
206  {
207  return directAddressing_.size();
208  }
210  bool direct() const
211  {
212  return true;
213  }
215  bool hasUnmapped() const
216  {
217  return false;
218  }
220  const labelList& directAddressing() const
221  {
222  return directAddressing_;
223  }
224  };
225 
226 
227  // Member Functions
228 
229  // Access
231  const fvMesh& fromMesh() const
232  {
233  return fromMesh_;
234  }
236  const fvMesh& toMesh() const
237  {
238  return toMesh_;
239  }
240 
241  //- From toMesh cells to fromMesh cells
242  const labelList& cellAddressing() const
243  {
244  return cellAddressing_;
245  }
246 
247  //- Overlap volume
248  scalar V() const
249  {
250  return V_;
251  }
252 
253 
254  // Interpolation
255 
256  //- Map field
257  template<class Type>
258  void mapField
259  (
260  Field<Type>&,
261  const Field<Type>&,
262  const labelList& adr
263  ) const;
264 
265  //- Interpolate field using inverse-distance weights
266  template<class Type>
267  void interpolateField
268  (
269  Field<Type>&,
271  const labelList& adr,
272  const scalarListList& weights
273  ) const;
274 
275  //- Interpolate field using inverse-volume weights
276  template<class Type>
277  void interpolateField
278  (
279  Field<Type>&,
281  const labelListList& adr,
282  const scalarListList& weights
283  ) const;
284 
285 
286  //- Interpolate field using cell-point interpolation
287  template<class Type>
288  void interpolateField
289  (
290  Field<Type>&,
292  const labelList& adr,
293  const vectorField& centres
294  )const;
295 
296 
297  //- Interpolate internal volume field
298  template<class Type>
300  (
301  Field<Type>&,
304  ) const;
305 
306  template<class Type>
308  (
309  Field<Type>&,
312  ) const;
313 
314 
315  //- Interpolate volume field
316  template<class Type>
317  void interpolate
318  (
322  ) const;
323 
324  template<class Type>
325  void interpolate
326  (
330  ) const;
331 
332 
333  //- Interpolate volume field
334  template<class Type>
336  (
339  ) const;
340 
341  template<class Type>
343  (
346  ) const;
347 };
348 
349 
350 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 
352 } // End namespace Foam
353 
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 
356 #ifdef NoRepository
357  #include "meshToMesh0Templates.C"
358 #endif
359 
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 
362 #endif
363 
364 // ************************************************************************* //
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Serial mesh to mesh interpolation class.
Definition: meshToMesh0.H:60
order
Enumeration specifying required accuracy.
Definition: meshToMesh0.H:143
void interpolateInternalField(Field< Type > &, const GeometricField< Type, fvPatchField, volMesh > &, order=INTERPOLATE) const
Interpolate internal volume field.
Generic GeometricField class.
const fvMesh & toMesh() const
Definition: meshToMesh0.H:235
const cellShapeList & cells
const pointField & points
const labelList & cellAddressing() const
From toMesh cells to fromMesh cells.
Definition: meshToMesh0.H:241
void mapField(Field< Type > &, const Field< Type > &, const labelList &adr) const
Map field.
An STL-conforming hash table.
Definition: HashTable.H:61
const fvMesh & fromMesh() const
Definition: meshToMesh0.H:230
virtual ~patchFieldInterpolator()
Destructor.
Definition: meshToMesh0.H:198
~meshToMesh0()
Destructor.
Definition: meshToMesh0.C:194
Patch-field interpolation class.
Definition: meshToMesh0.H:179
patchFieldInterpolator(const labelList &addr)
Construct given addressing.
Definition: meshToMesh0.H:191
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:47
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
const labelList & directAddressing() const
Definition: meshToMesh0.H:219
virtual const scalarListList & weights() const
scalar V() const
Overlap volume.
Definition: meshToMesh0.H:247
void interpolateField(Field< Type > &, const GeometricField< Type, fvPatchField, volMesh > &, const labelList &adr, const scalarListList &weights) const
Interpolate field using inverse-distance weights.
void interpolate(GeometricField< Type, fvPatchField, volMesh > &, const GeometricField< Type, fvPatchField, volMesh > &, order=INTERPOLATE) const
Interpolate volume field.
bool hasUnmapped() const
Are there unmapped values? I.e. do all size() elements get.
Definition: meshToMesh0.H:214
A class for managing temporary objects.
Definition: PtrList.H:53
meshToMesh0(const fvMesh &fromMesh, const fvMesh &toMesh, const HashTable< word > &patchMap, const wordList &cuttingPatchNames)
Construct from the two meshes, the patch name map for the patches.
Definition: meshToMesh0.C:43
Namespace for OpenFOAM.
ClassName("meshToMesh0")