lduPrimitiveMesh.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::lduPrimitiveMesh
29 
30 Description
31  Simplest concrete lduMesh that stores the addressing needed by lduMatrix.
32 
33 SourceFiles
34  lduPrimitiveMesh.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_lduPrimitiveMesh_H
39 #define Foam_lduPrimitiveMesh_H
40 
41 #include "lduMesh.H"
42 #include "labelList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class lduPrimitiveMesh Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 class lduPrimitiveMesh
54 :
55  public lduMesh,
56  public lduAddressing
57 {
58  // Private Data
59 
60  //- Lower addressing
61  labelList lowerAddr_;
62 
63  //- Upper addressing
64  labelList upperAddr_;
65 
66  //- List of pointers for each patch
67  // with only those pointing to interfaces being set
68  lduInterfacePtrsList interfaces_;
69 
70  //- Concrete interfaces
71  PtrList<const lduInterface> primitiveInterfaces_;
72 
73  //- Patch field evaluation schedule
74  lduSchedule patchSchedule_;
75 
76  //- Communicator to use for any parallel communication
77  const label comm_;
78 
79 
80  // Private Member Functions
81 
82  //- Get size of all meshes
83  static label totalSize(const PtrList<lduPrimitiveMesh>&);
84 
85  label findConnectedInterface
86  (
87  const lduMesh& myMesh,
88  const PtrList<lduPrimitiveMesh>& otherMeshes,
89  const labelPairList& procAndInterfaces,
90 
91  const label nbrProci,
92  const label myRank
93  ) const;
94 
95 
96  //- No copy construct
97  lduPrimitiveMesh(const lduPrimitiveMesh&) = delete;
98 
99  //- No copy assignment
100  void operator=(const lduPrimitiveMesh&) = delete;
101 
102 
103 public:
104 
105  // Static data
106 
107  // Declare name of the class and its debug switch
108  ClassName("lduPrimitiveMesh");
109 
110 
111  // Constructors
112 
113  //- Construct from number of cells
114  explicit lduPrimitiveMesh(const label nCells);
115 
116  //- Construct from components but without interfaces. Add interfaces
117  // separately using addInterfaces
119  (
120  const label nCells,
121  labelList& l,
122  labelList& u,
123  const label comm,
124  bool reuse
125  );
126 
127 
128  //- Add interfaces to a mesh constructed without
129  void addInterfaces
130  (
132  const lduSchedule& ps
133  );
134 
135  //- Construct from components and re-use storage.
137  (
138  const label nCells,
139  labelList& l,
140  labelList& u,
142  const lduSchedule& ps,
143  const label comm
144  );
145 
146  //- Construct by combining multiple meshes. The meshes come from
147  // processors procIDs:
148  // procIDs[0] : local processor (myMesh)
149  // procIDs[i] : processor where otherMeshes[i-1] comes from
150  // procAgglomMap : for every processor which processor it agglomerates
151  // onto. The new processor numbers are in compact
152  // numbering (so ranks in communicator comm), i.e.
153  // similar to cell-restrict-addressing.
154  // We need this information to be able to map
155  // inter-processor interfaces
156  // cellOffsets : for every processor the offset it gets in the mesh
157  // faceMap : for every processor, for every face, the destination
158  // face. Negative for flipped faces.
159  // boundaryMap : for every processor, for every patch, -1 or the new
160  // patch index in the mesh.
161  // boundaryFaceMap : for every processor, for every patch, for every
162  // patch face:
163  // - the new internal face (if boundaryMap=-1)
164  // - the new patch face (if boundaryMap>=0)
165  // Faces becoming internal are negative for flipped
166  // faces.
168  (
169  const label comm,
170  const labelList& procAgglomMap,
171 
172  const labelList& procIDs,
173  const lduMesh& myMesh,
174  const PtrList<lduPrimitiveMesh>& otherMeshes,
175 
176  labelList& cellOffsets,
177  labelList& faceOffsets,
179  labelListList& boundaryMap,
180  labelListListList& boundaryFaceMap
181  );
182 
183 
184  //- Destructor
185  virtual ~lduPrimitiveMesh() = default;
186 
187 
188  // Member Functions
189 
190  // Access
191 
192  //- Return true if thisDb() is a valid DB
193  virtual bool hasDb() const
194  {
195  return false;
196  }
197 
198  //- Return ldu addressing
199  virtual const lduAddressing& lduAddr() const
200  {
201  return *this;
202  }
203 
204  //- Return non-const ldu addressing
205  virtual lduAddressing& lduAddr()
206  {
207  return *this;
208  }
209 
210  //- Return a list of pointers for each patch
211  //- with only those pointing to interfaces being set
212  virtual lduInterfacePtrsList interfaces() const
213  {
214  return interfaces_;
215  }
216 
217  //- Return a non-const list of pointers for each patch
218  //- with only those pointing to interfaces being set
220  {
221  return interfaces_;
222  }
224  //- Return a non-const list of primitive interfaces
226  {
227  return primitiveInterfaces_;
228  }
229 
230  //- Return a list of pointers for each patch
231  // with only those pointing to interfaces being set
232  // (reference to cached interfaces)
233  const lduInterfacePtrsList& rawInterfaces() const
234  {
235  return interfaces_;
236  }
237 
238  //- Return communicator used for parallel communication
239  virtual label comm() const
240  {
241  return comm_;
242  }
243 
244  //- Return Lower addressing
245  virtual const labelUList& lowerAddr() const
246  {
247  return lowerAddr_;
248  }
249 
250  //- Return Upper addressing
251  virtual const labelUList& upperAddr() const
252  {
253  return upperAddr_;
254  }
255 
256  //- Return non-const Lower addressing
257  virtual labelList& lowerAddr()
258  {
259  return lowerAddr_;
260  }
261 
262  //- Return non-const Upper addressing
263  virtual labelList& upperAddr()
264  {
265  return upperAddr_;
266  }
267 
268  //- Return patch addressing
269  virtual const labelUList& patchAddr(const label i) const
270  {
271  return interfaces_[i].faceCells();
272  }
273 
274  //- Return patch evaluation schedule
275  virtual const lduSchedule& patchSchedule() const
276  {
277  return patchSchedule_;
278  }
279 
280 
281  // Helper
282 
283  //- Select either mesh0 (meshI is 0) or otherMeshes[meshI-1]
284  static const lduMesh& mesh
285  (
286  const lduMesh& mesh0,
287  const PtrList<lduPrimitiveMesh>& otherMeshes,
288  const label meshI
289  );
290 
291  //- Gather meshes from other processors using agglomComm.
292  // Received meshes get GAMGInterface.
293  static void gather
294  (
295  const label agglomComm,
296  const lduMesh& mesh,
297  PtrList<lduPrimitiveMesh>& otherMeshes
298  );
299 
300  //- Get non-scheduled send/receive schedule
301  template<class ProcPatch>
303 
304  //- Calculate upper-triangular order
305  static labelList upperTriOrder
306  (
307  const label nCells,
309  const labelUList& upper
310  );
311 
312  //- Check if in upper-triangular ordering
313  static void checkUpperTriangular
314  (
315  const label size,
316  const labelUList& l,
317  const labelUList& u
318  );
319 
320  //- Calculate global cell-cells
322  (
323  const lduMesh& mesh,
324  const globalIndex& globalNumbering
325  );
326 };
327 
328 
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 
331 } // End namespace Foam
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 
335 #ifdef NoRepository
336  #include "lduPrimitiveMeshTemplates.C"
337 #endif
338 
339 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
340 
341 #endif
342 
343 // ************************************************************************* //
void addInterfaces(lduInterfacePtrsList &interfaces, const lduSchedule &ps)
Add interfaces to a mesh constructed without.
virtual ~lduPrimitiveMesh()=default
Destructor.
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:53
virtual const labelUList & lowerAddr() const
Return Lower addressing.
ClassName("lduPrimitiveMesh")
virtual const labelUList & upperAddr() const
Return Upper addressing.
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
Definition: stringOps.C:1187
PtrList< const lduInterface > & primitiveInterfaces()
Return a non-const list of primitive interfaces.
List< lduScheduleEntry > lduSchedule
A List of lduSchedule entries.
Definition: lduSchedule.H:46
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:61
virtual bool hasDb() const
Return true if thisDb() is a valid DB.
virtual label comm() const
Return communicator used for parallel communication.
virtual const lduAddressing & lduAddr() const
Return ldu addressing.
static lduSchedule nonBlockingSchedule(const lduInterfacePtrsList &)
Get non-scheduled send/receive schedule.
Simplest concrete lduMesh that stores the addressing needed by lduMatrix.
static const lduMesh & mesh(const lduMesh &mesh0, const PtrList< lduPrimitiveMesh > &otherMeshes, const label meshI)
Select either mesh0 (meshI is 0) or otherMeshes[meshI-1].
static void gather(const label agglomComm, const lduMesh &mesh, PtrList< lduPrimitiveMesh > &otherMeshes)
Gather meshes from other processors using agglomComm.
virtual const lduSchedule & patchSchedule() const
Return patch evaluation schedule.
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
Definition: stringOps.C:1171
static void checkUpperTriangular(const label size, const labelUList &l, const labelUList &u)
Check if in upper-triangular ordering.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
static labelListList globalCellCells(const lduMesh &mesh, const globalIndex &globalNumbering)
Calculate global cell-cells.
The class contains the addressing required by the lduMatrix: upper, lower and losort.
const lduInterfacePtrsList & rawInterfaces() const
Return a list of pointers for each patch.
virtual lduInterfacePtrsList interfaces() const
Return a list of pointers for each patch with only those pointing to interfaces being set...
static labelList upperTriOrder(const label nCells, const labelUList &lower, const labelUList &upper)
Calculate upper-triangular order.
Namespace for OpenFOAM.
label size() const
Return number of equations.
virtual const labelUList & patchAddr(const label i) const
Return patch addressing.