All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cellsToCells.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) 2012-2023 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::cellsToCells
26 
27 Description
28  Class to calculate interpolative addressing and weights between the cells
29  of two overlapping meshes
30 
31 SourceFiles
32  cellsToCells.C
33  cellsToCellsParallelOps.C
34  cellsToCellsTemplates.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef cellsToCells_H
39 #define cellsToCells_H
40 
41 #include "remote.H"
42 #include "distributionMap.H"
43 #include "polyMesh.H"
44 #include "runTimeSelectionTables.H"
45 #include "treeBoundBox.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class cellsToCells Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class cellsToCells
57 {
58 protected:
59 
60  // Protected Data
61 
62  //- Index of processor that holds all of both sides, or -1
64 
65  //- For each source cell, the coupled local target cells
67 
68  //- For each target cell, the coupled local source cells
70 
71  //- For each source cell, the coupled target weights
73 
74  //- For each target cell, the coupled source weights
76 
77  //- Map from source patch cells to target-local source patch cells
79 
80  //- Map from target patch cells to source-local target patch cells
82 
83  //- When running in parallel, a map from local source cell index to
84  // source processor and cell index
86 
87  //- When running in parallel, a map from local target cell index to
88  // target processor and cell index
90 
91  //- The target mesh, distributed locally to the source
93 
94 
95  // Protected Member Functions
96 
97  // Intersection
98 
99  //- Initialise the addressing and weights
100  void initialise
101  (
102  const polyMesh& srcMesh,
103  const polyMesh& tgtMesh
104  );
105 
106  //- Calculate the addressing and weights
107  virtual scalar calculate
108  (
109  const polyMesh& srcMesh,
110  const polyMesh& tgtMesh
111  ) = 0;
112 
113  //- Normalise the weights for a given mesh
114  virtual void normalise
115  (
116  const polyMesh& mesh,
117  labelListList& localOtherCells,
118  scalarListList& weights
119  ) const = 0;
120 
121 
122  // Helpers
123 
124  //- Return src cell IDs for the overlap region
126  (
127  const polyMesh& srcMesh,
128  const polyMesh& tgtMesh
129  ) const;
130 
131  //- Append target cell neighbour cells to cellIDs list
132  void appendNbrCells
133  (
134  const label tgtCelli,
135  const polyMesh& mesh,
136  const DynamicList<label>& visitedTgtCells,
137  DynamicList<label>& nbrTgtCellIDs
138  ) const;
139 
140 
141  // Parallel operations
142 
143  //- Determine which target cells need to be sent to the source.
144  // This is done before intersection. Bound boxes are used to
145  // estimate what cells will intersect.
147  (
148  const polyMesh& srcMesh,
149  const polyMesh& tgtMesh
150  ) const;
151 
152  //- Distribute a mesh given its distribution map
154  (
155  const distributionMap& map,
156  const polyMesh& mesh,
157  autoPtr<polyMesh>& localMeshPtr
158  );
159 
160  //- Trim the local target addressing and mesh so that communication
161  // from the target to the source is optimised
162  void trimLocalTgt();
163 
164 
165 public:
166 
167  //- Run-time type information
168  TypeName("cellsToCells");
169 
170 
171  //- Declare runtime constructor selection table
173  (
174  autoPtr,
175  cellsToCells,
176  word,
177  (),
178  ()
179  );
180 
181 
182  // Constructors
183 
184  //- Construct null
185  cellsToCells();
186 
187  //- Disallow default bitwise copy construction
188  cellsToCells(const cellsToCells&) = delete;
189 
190 
191  //- Destructor
192  virtual ~cellsToCells();
193 
194 
195  // Selector
196 
197  //- Select from name
198  static autoPtr<cellsToCells> New(const word& cellsToCellsType);
199 
200 
201  // Member Functions
202 
203  // Access
204 
205  //- Index of the processor holding all cells of the cellsToCells,
206  // or -1 if spread across multiple processors
207  inline label singleProcess() const;
208 
209  //- Is this intersection on a single process?
210  inline bool isSingleProcess() const;
211 
212  //- Return a list indicating which source cells are coupled
213  PackedBoolList srcCoupled() const;
214 
215  //- Return a list indicating which target cells are coupled
216  PackedBoolList tgtCoupled() const;
217 
218 
219  // Interpolation
220 
221  //- Interpolate a source cell field to the target with no left
222  // over values specified. If the interpolation weight sum is less
223  // than one for a face then they will be normalised. If the
224  // interpolation weight sum is zero for a face then that face's
225  // value will be NaN.
226  template<class Type>
227  tmp<Field<Type>> srcToTgt(const Field<Type>& srcFld) const;
228 
229  //- Interpolate a source cell field to the target with left over
230  // values specified. If the interpolation weight sum is less than
231  // one for a face then the average will include the left over
232  // value multiplied by one minus the weight sum.
233  template<class Type>
235  (
236  const Field<Type>& srcFld,
237  const Field<Type>& leftOverTgtFld
238  ) const;
239 
240  //- Interpolate a target cell field to the source with no left
241  // over values specified. As the corresponding srcToTgt.
242  template<class Type>
243  tmp<Field<Type>> tgtToSrc(const Field<Type>& tgtFld) const;
244 
245  //- Interpolate a target cell field to the source with left
246  // over values specified. As the corresponding srcToTgt.
247  template<class Type>
249  (
250  const Field<Type>& tgtFld,
251  const Field<Type>& leftOverSrcFld
252  ) const;
253 
254 
255  // Source-to-target point finding
256 
257  //- Find the target processor and cell associated with a point in a
258  // source cell. Note that this will only work with derivations
259  // that fill a cell's stencil with everything that overlaps that
260  // cell. qt present this is just cellsToCellss::intersection, but
261  // we might add a cheaper bound-box based method like
262  // patchToPatches::rays in future.
264  (
265  const polyMesh& tgtMesh,
266  const label srcCelli,
267  const point& p
268  ) const;
269 
270 
271  // Manipulation
272 
273  //- Update addressing and weights for the given meshes. Returns the
274  // overlapping volume (if that is relevant to the method).
275  scalar update
276  (
277  const polyMesh& srcMesh,
278  const polyMesh& tgtMesh
279  );
280 
281 
282  // Member Operators
283 
284  //- Disallow default bitwise assignment
285  void operator=(const cellsToCells&) = delete;
286 };
287 
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 } // End namespace Foam
292 
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 
295 #include "cellsToCellsI.H"
296 
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 
299 #ifdef NoRepository
300  #include "cellsToCellsTemplates.C"
301 #endif
302 
303 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
304 
305 #endif
306 
307 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
A bit-packed bool list.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Class to calculate interpolative addressing and weights between the cells of two overlapping meshes.
Definition: cellsToCells.H:56
cellsToCells()
Construct null.
Definition: cellsToCells.C:139
tmp< Field< Type > > tgtToSrc(const Field< Type > &tgtFld) const
Interpolate a target cell field to the source with no left.
label singleProcess_
Index of processor that holds all of both sides, or -1.
Definition: cellsToCells.H:62
virtual void normalise(const polyMesh &mesh, labelListList &localOtherCells, scalarListList &weights) const =0
Normalise the weights for a given mesh.
autoPtr< distributionMap > srcMapPtr_
Map from source patch cells to target-local source patch cells.
Definition: cellsToCells.H:77
bool isSingleProcess() const
Is this intersection on a single process?
Definition: cellsToCellsI.H:36
labelListList tgtLocalSrcCells_
For each target cell, the coupled local source cells.
Definition: cellsToCells.H:68
autoPtr< polyMesh > localTgtMeshPtr_
The target mesh, distributed locally to the source.
Definition: cellsToCells.H:91
virtual ~cellsToCells()
Destructor.
Definition: cellsToCells.C:156
autoPtr< List< remote > > localTgtProcCellsPtr_
When running in parallel, a map from local target cell index to.
Definition: cellsToCells.H:88
labelList maskCells(const polyMesh &srcMesh, const polyMesh &tgtMesh) const
Return src cell IDs for the overlap region.
Definition: cellsToCells.C:71
TypeName("cellsToCells")
Run-time type information.
scalar update(const polyMesh &srcMesh, const polyMesh &tgtMesh)
Update addressing and weights for the given meshes. Returns the.
Definition: cellsToCells.C:236
tmp< Field< Type > > srcToTgt(const Field< Type > &srcFld) const
Interpolate a source cell field to the target with no left.
virtual scalar calculate(const polyMesh &srcMesh, const polyMesh &tgtMesh)=0
Calculate the addressing and weights.
void appendNbrCells(const label tgtCelli, const polyMesh &mesh, const DynamicList< label > &visitedTgtCells, DynamicList< label > &nbrTgtCellIDs) const
Append target cell neighbour cells to cellIDs list.
Definition: cellsToCells.C:110
remote srcToTgtPoint(const polyMesh &tgtMesh, const label srcCelli, const point &p) const
Find the target processor and cell associated with a point in a.
Definition: cellsToCells.C:209
PackedBoolList srcCoupled() const
Return a list indicating which source cells are coupled.
Definition: cellsToCells.C:186
static autoPtr< cellsToCells > New(const word &cellsToCellsType)
Select from name.
Definition: cellsToCells.C:163
labelListList tgtMeshSendCells(const polyMesh &srcMesh, const polyMesh &tgtMesh) const
Determine which target cells need to be sent to the source.
scalarListList tgtWeights_
For each target cell, the coupled source weights.
Definition: cellsToCells.H:74
declareRunTimeSelectionTable(autoPtr, cellsToCells, word,(),())
Declare runtime constructor selection table.
void trimLocalTgt()
Trim the local target addressing and mesh so that communication.
label singleProcess() const
Index of the processor holding all cells of the cellsToCells,.
Definition: cellsToCellsI.H:30
labelListList srcLocalTgtCells_
For each source cell, the coupled local target cells.
Definition: cellsToCells.H:65
scalarListList srcWeights_
For each source cell, the coupled target weights.
Definition: cellsToCells.H:71
PackedBoolList tgtCoupled() const
Return a list indicating which target cells are coupled.
Definition: cellsToCells.C:197
autoPtr< List< remote > > localSrcProcCellsPtr_
When running in parallel, a map from local source cell index to.
Definition: cellsToCells.H:84
autoPtr< distributionMap > tgtMapPtr_
Map from target patch cells to source-local target patch cells.
Definition: cellsToCells.H:80
void operator=(const cellsToCells &)=delete
Disallow default bitwise assignment.
void initialise(const polyMesh &srcMesh, const polyMesh &tgtMesh)
Initialise the addressing and weights.
Definition: cellsToCells.C:47
static List< remote > distributeMesh(const distributionMap &map, const polyMesh &mesh, autoPtr< polyMesh > &localMeshPtr)
Distribute a mesh given its distribution map.
Class containing processor-to-processor mapping information.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Struct for keeping processor, element (cell, face, point) index.
Definition: remote.H:57
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
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
Macros to ease declaration of run-time selection tables.
volScalarField & p