CEPS  24.01
Cardiac ElectroPhysiology Simulator
Geometry.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 #pragma once
32 
33 #include "geometry/Mesh.hpp"
36 
37 // Forward declaration
39 
49 class Geometry : public CepsObject
50 {
51 
52  // Geometry partitioner is responsible for setting many things in
53  friend class GeometryPartitioner;
54  friend class PtscotchPartitioner;
55 
56  public:
57 
59  Geometry();
60 
62  explicit Geometry(InputParameters *params);
63 
65  ~Geometry();
66 
72  void
74 
75  // Meshes
76 
78  void
79  setMeshOfDim(CepsUInt dim, const CepsString& meshFileName);
80 
84  void
85  set3dMesh(const CepsString& meshFileName);
86 
90  void
91  set2dMesh(const CepsString& meshFileName);
92 
96  void
97  set1dMesh(const CepsString& meshFileName);
98 
100  Mesh*
101  getMeshOfDim(CepsUInt dim) const;
102 
104  Mesh*
105  get3dMesh() const;
106 
108  Mesh*
109  get2dMesh() const;
110 
112  Mesh*
113  get1dMesh() const;
114 
116  CepsBool
117  hasMeshOfDim(CepsUInt dim) const;
118 
120  CepsBool
121  has3dMesh() const;
122 
124  CepsBool
125  has2dMesh() const;
126 
128  CepsBool
129  has1dMesh() const;
130 
131  // File names
132 
135  getFileNamesForDim(CepsUInt dim) const;
136 
139  getVolumicFileNames() const;
140 
143  getSurfacicFileNames() const;
144 
147  getCableFileNames() const;
148 
150  const CepsString&
151  getCoupledNodesFileName() const;
152 
156  void
157  setCoupledNodesFile(const CepsString& coupledNodesFile);
158 
159  // Partitioning
160 
166  void
168 
175  void
177 
182  getPartitioningMethod() const;
183 
185  void
187 
190  getPartitionWeights() const;
191 
199  CepsUInt
201 
202  // Number of nodes/cells
203 
205  CepsUInt
206  getNbCells() const;
207 
209  CepsUInt
210  getNbBoundaryCells() const;
211 
213  CepsUInt
214  getNbNodes() const;
215 
217  CepsUInt
218  getNbHaloNodes() const;
219 
221  CepsUInt
222  getNbNodesLocal() const;
223 
225  CepsUInt
226  getNbOwnedNodesLocal() const;
227 
229  CepsUInt
230  getNbHaloNodesLocal() const;
231 
237  CepsUInt
238  getNbCellsLocal() const;
239 
245  CepsUInt
246  getNbBoundaryCellsLocal() const;
247 
249  CepsUInt
250  getMaxNodeConnectivity() const;
251 
253  CepsReal
254  getMaxCellDiameter() const;
255 
256  // Acces to cellary entities
257 
259  GeomNode*
260  getNode(CepsNodeGlobalIndex globalID, CepsBool ownedOnly=false);
261 
263  GeomCell*
264  getCell(CepsCellGlobalIndex globalID);
265 
267  void
268  print(std::ostream& os = std::cout) const;
269 
271  friend std::ostream&
272  operator<<(std::ostream& os, const Geometry& g);
273 
274  // Data distribution
275 
290  void
292  CepsUInt* nBdCells,
293  CepsUInt* nNodes,
294  CepsUInt* nHaloNodes,
295  std::ostream& os = std::cout) const;
296 
303  void
305  CepsUInt* nBdCells,
306  CepsUInt* nNodes,
307  CepsUInt* nHaloNodes) const;
308 
319  void
321  CepsUInt* nBDCells,
322  CepsUInt* nNodes,
323  CepsUInt* nHaloNodes) const;
324 
325  // Indexing methods
326 
329  getNodesToSend();
330 
334 
338 
342 
344  const CepsVector<CepsUInt>&
346 
348  const CepsVector<CepsUInt>&
350 
353  getCoupledNodes();
354 
358  void
359  scale(CepsReal scaleFactor);
360 
361 
362  protected:
363 
369  CepsUInt
371 
374  CepsReal
376 
378  void
379  initialize();
380 
384  void
386 
388  void
390 
392  void
394 
395  protected:
396 
399 
400  // GLOBAL DATA
401  //---------------------------------------------------------------------------*
402  // The following data is the same for every process
403  //---------------------------------------------------------------------------*
406 
409 
416 
419 
420  // Unbalancing information
422 
427 
428  //---------------------------------------------------------------------------*
429  // LOCAL DATA (specific to the process)
430  //---------------------------------------------------------------------------*
433 
436 
439 
442 
444 
445 };
446 
448 std::ostream& operator<< (std::ostream& os, const Geometry& g);
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
CepsGlobalIndex CepsCellGlobalIndex
Indices of cells.
Definition: CepsTypes.hpp:222
std::map< _Key, _Tp, _Compare, _Alloc > CepsMap
C++ map.
Definition: CepsTypes.hpp:196
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
CepsGlobalIndex CepsNodeGlobalIndex
Indices of nodes.
Definition: CepsTypes.hpp:224
CepsArray< _Type, 3U > CepsArray3
C++ array, 3 elements.
Definition: CepsTypes.hpp:165
std::unordered_multimap< _Key, _Tp, _Hash, _KeyEqual, _Alloc > CepsMultiMap
C++ multimap.
Definition: CepsTypes.hpp:205
std::ostream & operator<<(std::ostream &os, const Geometry &g)
Displays some info about geometry.
Definition: Geometry.cpp:524
PartitioningMethod
Enum only meant to hold the method typedef.
Base class for other (big) CEPS classes. All classes can get a pointer to this base class and also co...
Definition: CepsObject.hpp:40
Abstract class for geometrical cell. On top of index and attributes managament, the cell has informat...
Definition: GeomCell.hpp:48
Base class for nodes used in meshes.
Definition: GeomNode.hpp:53
Class is used to compute a geometry (multiple meshes) partitioning.
Encapsulates all the geometrical data.
Definition: Geometry.hpp:50
void printDataDistribution(CepsUInt *nCells, CepsUInt *nBdCells, CepsUInt *nNodes, CepsUInt *nHaloNodes, std::ostream &os=std::cout) const
Displays the data distribution (percentages of cell and nodes ownership) for each process.
Definition: Geometry.cpp:534
void scale(CepsReal scaleFactor)
Scale the entire geometry.
Definition: Geometry.cpp:676
CepsVector< CepsSet< CepsNodeGlobalIndex > > m_nodesToSend
List of nodes of which to send data to other process (build at partitioning)
Definition: Geometry.hpp:435
const CepsMap< CepsAttribute, CepsUInt > & getPartitionWeights() const
Set the weights to be put on each region before partitioning.
Definition: Geometry.cpp:268
CepsVector< CepsNodeGlobalIndex > m_nodePartitionMap
Map of node indices from read geometry to partitioned geometry.
Definition: Geometry.hpp:424
CepsUInt m_maxNodeConnectivity
Maximum number of neighbors found for current geometry.
Definition: Geometry.hpp:414
CepsBool has1dMesh() const
true if geometry has 1d data
Definition: Geometry.cpp:188
CepsUInt getNbHaloNodesLocal() const
Number of halo nodes local to this process.
Definition: Geometry.cpp:405
GeomNode * getNode(CepsNodeGlobalIndex globalID, CepsBool ownedOnly=false)
Returns a pointer to the node with given global ID. Nullptr if node is not owned or halo.
Definition: Geometry.cpp:459
CepsUInt m_nbHaloNodes
Number of halo nodes (all meshes, all process)
Definition: Geometry.hpp:413
void setPartitionWeightsFromString(const CepsString &s)
Sets the partition weights for given regions. Default is 1 everywhere.
Definition: Geometry.cpp:746
CepsUInt getNbBoundaryCellsLocal() const
Number of boundary cells local to this process (3d, 2d and 1d). N.B as we have implemented a multiple...
Definition: Geometry.cpp:433
CepsVector< GeomCellJunction * > m_junctionCells
Fake cells to join meshes.
Definition: Geometry.hpp:432
void initialize()
Sets default values.
Definition: Geometry.cpp:729
void setCoupledNodesFile(const CepsString &coupledNodesFile)
Reads mesh couplings from this file.
Definition: Geometry.cpp:224
void set2dMesh(const CepsString &meshFileName)
Creates the 2D mesh data.
Definition: Geometry.cpp:127
CepsArray3< CepsBool > m_hasMeshOfDim
If the geometry contains XD data.
Definition: Geometry.hpp:407
CepsUInt getNbBoundaryCells() const
Number of boundary cells of the geometry (global).
Definition: Geometry.cpp:377
const CepsVector< CepsUInt > & getNodeOffsetPerMesh()
Number of nodes per mesh.
Definition: Geometry.cpp:661
Mesh * get3dMesh() const
Pointer on the 3D mesh.
Definition: Geometry.cpp:149
InputParameters * m_parameters
Config used to setup the geometry, if any.
Definition: Geometry.hpp:397
const CepsVector< CepsSet< CepsNodeGlobalIndex > > & getNodesToReceive()
List of nodes of which to get data to other process (build at partitioning)
Definition: Geometry.cpp:637
void setPartitioningMethod(PartitioningMethod method)
Sets the partitioning method.
Definition: Geometry.cpp:250
CepsArray3< Mesh * > m_meshes
pointer to xD mesh instance
Definition: Geometry.hpp:431
const CepsVector< CepsString > & getVolumicFileNames() const
Files with 3D cells.
Definition: Geometry.cpp:200
CepsMultiMap< CepsNodeGlobalIndex, CepsNodeGlobalIndex > m_coupledNodes
Pairs of coupled nodes.
Definition: Geometry.hpp:441
const CepsVector< CepsString > & getCableFileNames() const
Files with 1D cells.
Definition: Geometry.cpp:212
CepsReal m_maxCellDiameter
Largest cell size across meshes.
Definition: Geometry.hpp:415
CepsBool m_hasCoupledNodes
Whether the geometry has connections or not.
Definition: Geometry.hpp:408
CepsUInt getNbHaloNodes() const
Number of halo nodes of the geometry (global)
Definition: Geometry.cpp:389
Geometry()
Default constructor.
Definition: Geometry.cpp:43
CepsUInt m_nbNodes
Number of nodes (all meshes, all process)
Definition: Geometry.hpp:412
const CepsVector< CepsUInt > & getCellOffsetPerMesh()
Number of cells per mesh.
Definition: Geometry.cpp:655
Mesh * get2dMesh() const
Pointer on the 2D mesh.
Definition: Geometry.cpp:155
CepsUInt m_nbCells
Number of non-boundary cells (all meshes, all process)
Definition: Geometry.hpp:410
const CepsVector< CepsNodeGlobalIndex > & getNodePartitionMap()
The node index map from before to after partitioning.
Definition: Geometry.cpp:643
CepsUInt getNbOwnedNodesLocal() const
Number of nodes local to this process, without halo nodes.
Definition: Geometry.cpp:395
const CepsString & getCoupledNodesFileName() const
Coupled nodes file name.
Definition: Geometry.cpp:218
CepsMap< CepsAttribute, CepsVector< CepsCellGlobalIndex > > m_connections
Junctions.
Definition: Geometry.hpp:443
CepsBool has2dMesh() const
true if geometry has 2d data
Definition: Geometry.cpp:182
PartitioningMethod m_partitioningMethod
How the geometry is partitioned.
Definition: Geometry.hpp:398
CepsVector< CepsUInt > m_cellOffsetPerMesh
Offset of each mesh.
Definition: Geometry.hpp:417
void setMeshOfDim(CepsUInt dim, const CepsString &meshFileName)
Creates mesh data of given dimension.
Definition: Geometry.cpp:103
void getLocalDistribution(CepsUInt *nCells, CepsUInt *nBdCells, CepsUInt *nNodes, CepsUInt *nHaloNodes) const
Gets the local data distribution of all the domains.
Definition: Geometry.cpp:591
CepsBool has3dMesh() const
true if geometry has 3d data
Definition: Geometry.cpp:176
Mesh * get1dMesh() const
Pointer on the 1D mesh.
Definition: Geometry.cpp:161
CepsReal computeMaxCellDiameter()
Finds the largest cell diameter.
Definition: Geometry.cpp:710
const CepsVector< CepsString > & getFileNamesForDim(CepsUInt dim) const
Mesh file names.
Definition: Geometry.cpp:194
CepsString m_coupledNodesFileName
Connections file name, if any.
Definition: Geometry.hpp:405
void setupWithParameters(InputParameters *params)
Initializes the instance with all parameters.
Definition: Geometry.cpp:64
CepsVector< CepsCellGlobalIndex > m_cellPartitionMap
Map of cell indices from read geometry to partitioned geometry.
Definition: Geometry.hpp:426
PartitioningMethod getPartitioningMethod() const
Partitioning method (flavours of scotch)
Definition: Geometry.cpp:256
CepsUInt getNbNodesLocal() const
Number of nodes local to this process, with halo nodes.
Definition: Geometry.cpp:416
CepsReal getMaxCellDiameter() const
Get the largest diameter of geom cells across meshes.
Definition: Geometry.cpp:450
const CepsVector< CepsString > & getSurfacicFileNames() const
Files with surfacic cells.
Definition: Geometry.cpp:206
CepsVector< CepsSet< CepsNodeGlobalIndex > > m_nodesToReceive
List of nodes of which to get data to other process (build at partitioning)
Definition: Geometry.hpp:438
CepsUInt computePartition()
Launches the computation of a partitioning. A Geometry may not be manipulated before a partitioning h...
Definition: Geometry.cpp:274
const CepsVector< CepsSet< CepsNodeGlobalIndex > > & getNodesToSend()
List of nodes of which to send data to other process (build at partitioning)
Definition: Geometry.cpp:631
void set3dMesh(const CepsString &meshFileName)
Creates the 3D mesh data.
Definition: Geometry.cpp:121
void updateGeometryInfo()
Update each mesh info.
Definition: Geometry.cpp:789
friend std::ostream & operator<<(std::ostream &os, const Geometry &g)
Displays some info.
Definition: Geometry.cpp:524
void setPartitioningMethodFromString(const CepsString &s)
Sets the partioning method from the input string.
Definition: Geometry.cpp:234
Mesh * getMeshOfDim(CepsUInt dim) const
Return the mesh of requested dimension.
Definition: Geometry.cpp:139
CepsUInt getNbNodes() const
Number of nodes of the geometry (global)
Definition: Geometry.cpp:383
CepsUInt m_nbBoundaryCells
Number of boundary cells (all meshes, all process)
Definition: Geometry.hpp:411
CepsVector< CepsUInt > m_nodeOffsetPerMesh
Offset of each mesh.
Definition: Geometry.hpp:418
void print(std::ostream &os=std::cout) const
Displays some info.
Definition: Geometry.cpp:495
CepsUInt getMaxNodeConnectivity() const
Maximum number of adjacent nodes.
Definition: Geometry.cpp:444
~Geometry()
Destructor.
Definition: Geometry.cpp:56
CepsUInt getNbCellsLocal() const
Number of cells local to this process (3d, 2d and 1d). N.B as we have implemented a multiple ownershi...
Definition: Geometry.cpp:422
GeomCell * getCell(CepsCellGlobalIndex globalID)
Returns a pointer to the cell with given global ID. Nullptr if cell is not owned.
Definition: Geometry.cpp:478
CepsUInt computeMaxNodeConnectivity()
Finds the maximum number of adjacent nodes.
Definition: Geometry.cpp:695
CepsBool hasMeshOfDim(CepsUInt dim) const
true if geometry has data of requested dimension
Definition: Geometry.cpp:167
CepsMap< CepsAttribute, CepsUInt > m_partitionWeights
nb of unknowns per regions for unbalanced partitions
Definition: Geometry.hpp:421
CepsArray3< CepsVector< CepsString > > m_meshFilenames
All the meshes file names.
Definition: Geometry.hpp:404
const CepsVector< CepsCellGlobalIndex > & getCellPartitionMap()
The node index map from before to after partitioning.
Definition: Geometry.cpp:649
void setPartitionWeights(const CepsMap< CepsAttribute, CepsUInt > &weights)
Set the weights to be put on each region before partitioning.
Definition: Geometry.cpp:262
void getGlobalDistribution(CepsUInt *nCells, CepsUInt *nBDCells, CepsUInt *nNodes, CepsUInt *nHaloNodes) const
Gets the global data distribution of the domains.
Definition: Geometry.cpp:604
void set1dMesh(const CepsString &meshFileName)
Creates the 1D mesh data.
Definition: Geometry.cpp:133
void updateMeshInfo(CepsUInt dim)
Communicate mesh ownership data to all processes.
Definition: Geometry.cpp:763
const CepsMultiMap< CepsNodeGlobalIndex, CepsNodeGlobalIndex > & getCoupledNodes()
Coupled nodes local (owned or in the halo) of this process.
Definition: Geometry.cpp:667
CepsUInt getNbCells() const
Number of non-boundary cells of the geometry (global).
Definition: Geometry.cpp:371
Reads and stores simulation configuration.
Geometrical information of 1,2 or 3D distributed cells.
Definition: Mesh.hpp:57
Geometry partitioning with PtScotch.