CEPS  24.01
Cardiac ElectroPhysiology Simulator
Geometry.cpp
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 #include "geometry/Geometry.hpp"
32 
35 
36 // ---------------------------------------------------------------------------
37 // PUBLIC
38 // ---------------------------------------------------------------------------
39 
40 // ---------------------------------------------------------------------------
41 // Create/destroy instance
42 
44  CepsObject()
45 {
46  initialize();
47 }
48 
50  CepsObject()
51 {
52  initialize();
53  setupWithParameters(params);
54 }
55 
57 {
58  for (CepsUInt dim=1; dim<=3; dim++)
59  if (hasMeshOfDim(dim))
61 }
62 
63 void
65 {
66  m_parameters = params;
67 
68  // Set meshes
69  CepsVector<CepsString> meshes, keys = {"1dMesh", "2dMesh", "3dMesh"};
70 
71  for (CepsUInt dim=1; dim<=3; dim++)
72  if (params->hasKey(keys[dim-1]))
73  {
74  meshes = ceps::split(params->getString(keys[dim-1]),",");
75  for (CepsString &mesh : meshes)
76  setMeshOfDim(dim,mesh);
77  }
78 
79  CEPS_ABORT_IF(not has3dMesh() and not has2dMesh() and not has1dMesh(),
80  "No meshes were provided in input file !"
81  );
82 
83  // Connections between meshes
84  if (params->hasKey("coupledNodesFile"))
85  setCoupledNodesFile(params->getString("coupledNodesFile"));
86 
87  if (params->hasKey("unknowns per region"))
88  setPartitionWeightsFromString(params->getString("unknowns per region"));
89 
90  // Compute domain partition
91  setPartitioningMethodFromString(params->getString("partitioningMethod","PTScotchNode"));
93 
94  CepsReal s = params->getReal("geometryScale",1.e0);
95  if (not ceps::equals(s,1.e0))
96  scale(s);
97 }
98 
99 // ---------------------------------------------------------------------------
100 // Meshes management
101 
102 void
103 Geometry::setMeshOfDim(CepsUInt dim, const CepsString &meshFileName)
104 {
105  CEPS_ABORT_IF(dim==0 or dim>3,
106  "Geometry::setMeshOfDim dim must be 1<=d<=3, got dim=" << dim
107  );
108  CepsString sd = ceps::toString(dim)+"D";
109 
110  if (not m_hasMeshOfDim[dim-1])
111  {
112  m_hasMeshOfDim[dim-1] = true;
113  m_meshes [dim-1] = ceps::getNew<Mesh>(dim);
114  m_meshes [dim-1]->setGeometry(this);
115  }
116 
117  m_meshFilenames[dim-1].push_back(meshFileName);
118 }
119 
120 void
121 Geometry::set3dMesh(const CepsString &meshFileName)
122 {
123  setMeshOfDim(3,meshFileName);
124 }
125 
126 void
127 Geometry::set2dMesh(const CepsString &meshFileName)
128 {
129  setMeshOfDim(2,meshFileName);
130 }
131 
132 void
133 Geometry::set1dMesh(const CepsString &meshFileName)
134 {
135  setMeshOfDim(1,meshFileName);
136 }
137 
138 Mesh*
140 {
141 
142  CEPS_ABORT_IF(dim==0 or dim>3,
143  "Geometry::getMeshOfDim dim must be 1<=d<=3, got dim=" << dim
144  );
145  return m_meshes.at(dim-1);
146 }
147 
148 Mesh*
150 {
151  return getMeshOfDim(3);
152 }
153 
154 Mesh*
156 {
157  return getMeshOfDim(2);
158 }
159 
160 Mesh*
162 {
163  return getMeshOfDim(1);
164 }
165 
166 CepsBool
168 {
169  CEPS_ABORT_IF(dim==0 or dim>3,
170  "Geometry::hasMeshOfDim dim must be 1<=d<=3, got dim=" << dim
171  );
172  return m_hasMeshOfDim.at(dim-1);
173 }
174 
175 CepsBool
177 {
178  return hasMeshOfDim(3);
179 }
180 
181 CepsBool
183 {
184  return hasMeshOfDim(2);
185 }
186 
187 CepsBool
189 {
190  return hasMeshOfDim(1);
191 }
192 
195 {
196  return m_meshFilenames.at (dim-1);
197 }
198 
201 {
202  return getFileNamesForDim(3);
203 }
204 
207 {
208  return getFileNamesForDim(2);
209 }
210 
213 {
214  return getFileNamesForDim(1);
215 }
216 
217 const CepsString&
219 {
220  return m_coupledNodesFileName;
221 }
222 
223 void
225 {
226  m_coupledNodesFileName = coupledNodesFile;
227  m_hasCoupledNodes = true;
228 }
229 
230 // ---------------------------------------------------------------------------
231 // Partitioning
232 
233 void
235 {
236  CepsString S = ceps::toUpper(s);
237 
238  if (S == "PTSCOTCHNODE")
240 
241  // Incorrect partitioning method was provided
242  std::stringstream ss;
243  ss << "Geometry Parameters: given partitioning method does not exist in CEPS." << std::endl
244  << " Valid keywords for partitioning methods are:" << std::endl;
245  ss << " - PTScotchNode" << std::endl;
246  CEPS_ABORT(ss.str());
247 }
248 
249 void
251 {
252  m_partitioningMethod = method;
253 }
254 
257 {
258  return m_partitioningMethod;
259 }
260 
261 void
263 {
264  m_partitionWeights = weights;
265 }
266 
269 {
270  return m_partitionWeights;
271 }
272 
273 CepsUInt
275 {
276  // Create a GeometryPartitioner that will do the job
277  GeometryPartitioner* part = nullptr;
278  switch(m_partitioningMethod)
279  {
281  CEPS_SAYS("Start reading and partitioning meshes with PtScotch");
282  part = ceps::getNew<PtscotchPartitioner>(this);
283  break;
284  default:
285  CEPS_ABORT("Unknown partitioning method");
286  }
287  CepsUInt err = part->computePartition();
288 
289  // Now get some data and share it if needed
290 
291  // Update max connectivity
294 
295  // Update the number of halo nodes
296  CepsUInt gridSize = ceps::getGridSize();
297  if ((gridSize>1) && (m_nbHaloNodes==0))
298  {
299  // each process gets its local nb halo nodes
300  CepsUInt localHaloNodes = this->getNbHaloNodesLocal();
301 
302  // exchange data with MPI
303  CepsUInt globalHaloNodes = 0U;
304 
305  MPI_Allreduce(&localHaloNodes,&globalHaloNodes,1,CEPS_MPI_UINT,MPI_SUM, ceps::getCommunicator());
306 
307  m_nbHaloNodes = globalHaloNodes;
308  }
309 
310  CepsUInt* cells = ceps::newArray<CepsUInt>(gridSize);
311  CepsUInt* boundary = ceps::newArray<CepsUInt>(gridSize);
312  CepsUInt* nodes = ceps::newArray<CepsUInt>(gridSize);
313  CepsUInt* haloNodes = ceps::newArray<CepsUInt>(gridSize);
314  if (ceps::isProfiling())
315  {
316  // Print repartition of data
317  this->getGlobalDistribution(cells,boundary,nodes,haloNodes);
318 
319  if (ceps::isDebug())
320  this->printDataDistribution(cells,boundary,nodes,haloNodes,ceps::debugLog());
321  if (ceps::isVerbose())
322  this->printDataDistribution(cells,boundary,nodes,haloNodes,std::cout);
323  this->printDataDistribution(cells,boundary,nodes,haloNodes,ceps::profilingLog());
324  }
325 
326  #ifdef CEPS_DEBUG_ENABLED
327  // Safety checks
328  // this->getGlobalDistribution(cells,boundary,nodes,haloNodes);
329  // CepsUInt nbCells = this->getNbCells();
330  // CepsUInt nbNodes = this->getNbNodes();
331  // CepsUInt i;
332  // if (ceps::isMaster())
333  // {
334  // CepsUInt sum = 0;
335  // // Sum of all nodes should be equal to total nb nodes
336  // for (i = 0; i<gridSize; i++)
337  // sum += nodes[i];
338  // CEPS_ABORT_IF (sum!=nbNodes,
339  // "Sum of local nodes on all process ("<< sum << ")" <<
340  // " differs from total nodes in geometry (" << nbNodes << ")."
341  // );
342  // // Check overlaping:
343  // sum = 0;
344  // for (i = 0; i < gridSize; i++)
345  // sum += cells[i];
346  // CEPS_ABORT_IF(sum<nbCells,
347  // "Invalid Geometry partitioning: incorrect nb cells per process."
348  // );
349  // }
350  #endif // CEPS_DEBUG_ENABLED
351  ceps::destroyTabular(cells );
352  ceps::destroyTabular(boundary );
353  ceps::destroyTabular(nodes );
354  ceps::destroyTabular(haloNodes);
355  ceps::destroyObject (part );
356 
357  CEPS_SAYS("Information");
358  CEPS_SAYS(" Number of nodes " << m_nbNodes );
359  CEPS_SAYS(" Total number of cells " << m_nbCells + m_nbBoundaryCells);
360  CEPS_SAYS(" Number of interior cells " << m_nbCells);
361  CEPS_SAYS(" Number of boundary cells " << m_nbBoundaryCells);
362  CEPS_SAYS("Geometry and partition set");
363 
364  return err;
365 }
366 
367 // ---------------------------------------------------------------------------
368 // Number of nodes/cells
369 
370 CepsUInt
372 {
373  return m_nbCells;
374 }
375 
376 CepsUInt
378 {
379  return m_nbBoundaryCells;
380 }
381 
382 CepsUInt
384 {
385  return m_nbNodes;
386 }
387 
388 CepsUInt
390 {
391  return m_nbHaloNodes;
392 }
393 
394 CepsUInt
396 {
397  CepsUInt nbNodes = 0;
398  for (CepsUInt dim=1; dim<=3; dim++)
399  if (hasMeshOfDim (dim))
400  nbNodes += m_meshes[dim-1]->getLocalNbNodes();
401  return nbNodes;
402 }
403 
404 CepsUInt
406 {
407  CepsUInt nbHaloNodes = 0;
408  for (CepsUInt dim=1; dim<=3; dim++)
409  if (hasMeshOfDim(dim))
410  nbHaloNodes += m_meshes[dim-1]->getLocalNbHaloNodes();
411 
412  return nbHaloNodes;
413 }
414 
415 CepsUInt
417 {
419 }
420 
421 CepsUInt
423 {
424  CepsUInt nbCells = 0;
425  for (CepsUInt dim=1; dim<=3; dim++)
426  if (hasMeshOfDim (dim))
427  nbCells += m_meshes[dim-1]->getLocalNbCells();
428 
429  return nbCells;
430 }
431 
432 CepsUInt
434 {
435  CepsUInt nbBoundary = 0;
436  for (CepsUInt dim=1; dim<=3; dim++)
437  if (hasMeshOfDim(dim))
438  nbBoundary += m_meshes[dim-1]->getLocalNbBoundaryCells();
439 
440  return nbBoundary;
441 }
442 
443 CepsUInt
445 {
446  return m_maxNodeConnectivity;
447 }
448 
449 CepsReal
451 {
452  return m_maxCellDiameter;
453 }
454 
455 // ---------------------------------------------------------------------------
456 // Access to cellary entities
457 
458 GeomNode*
460 {
461  GeomNode* node = nullptr;
462  CepsUInt dim=1u;
463  while (ceps::isNullPtr(node) and dim<=3)
464  {
465  if (hasMeshOfDim(dim))
466  {
467  if (ownedOnly)
468  node = getMeshOfDim(dim)->getNode(globalID);
469  else
470  node = getMeshOfDim(dim)->getNodeOrHaloNode(globalID);
471  }
472  dim++;
473  }
474  return node;
475 }
476 
477 GeomCell*
479 {
480  GeomCell* elem = nullptr;
481  for (CepsUInt dim=1; dim<=3; dim++)
482  if (hasMeshOfDim(dim) and ceps::isNullPtr(elem))
483  {
484  elem = getMeshOfDim(dim)->getCell(globalID);
485  if (ceps::isNullPtr(elem))
486  elem = getMeshOfDim(dim)->getBoundaryCell(globalID);
487 
488  if (ceps::isValidPtr(elem))
489  break;
490  }
491  return elem;
492 }
493 
494 void
495 Geometry::print(std::ostream &os) const
496 {
497  if (ceps::isMaster())
498  {
499  os << " Geometry" << std::endl;
500  os << " ~~~~~~~~" << std::endl;
501  }
502 
504  {
505  os << "Process " << ceps::getRank () << " :" << std::endl;
506 
507  for (CepsUInt dim = 1; dim <= 3; dim++)
508  if (hasMeshOfDim (dim))
509  {
510  os << " " << dim << "D Mesh" << std::endl;
511  os << " -------" << std::endl;
512  os << *getMeshOfDim (dim) << std::endl;
513  os << std::endl;
514  }
515  }
517 
518  if (ceps::isMaster())
519  os << CEPS_STRING_SEPARATOR << std::endl;
520  return;
521 }
522 
523 std::ostream& operator<<
524 (std::ostream &os, const Geometry &g)
525 {
526  g.print(os);
527  return os;
528 }
529 
530 // ---------------------------------------------------------------------------
531 // Data distribution
532 
533 void
535  CepsUInt* boundary,
536  CepsUInt* nodes,
537  CepsUInt* haloNodes,
538  std::ostream& os) const
539 {
540  if (ceps::isMaster())
541  {
542  CepsUInt gridSize = ceps::getGridSize();
543  CepsUInt i;
544 
545  CepsUInt totalCells = this->getNbCells();
546  CepsUInt totalBoundary = this->getNbBoundaryCells();
547  CepsUInt totalNodes = this->getNbNodes();
548  CepsUInt totalHaloNodes = this->getNbHaloNodes();
549 
550  // compute global overlapping
551  CepsUInt sumCells = 0.0;
552  for (i = 0; i < gridSize; i++)
553  sumCells += cells[i];
554 
555  CepsReal ratHaloNodes = 100. * totalHaloNodes / (CepsReal) totalNodes;
556  CepsReal overlapping = 100 * (sumCells - totalCells) / (CepsReal) totalCells;
557 
558  os << "# " << CEPS_STRING_SEPARATOR << std::endl
559  << "# Data Distribution" << std::endl
560  << "# " << CEPS_STRING_SEPARATOR << std::endl
561  << "# Global data:" << std::endl
562  << "#\t- Number of nodes: " << totalNodes << std::endl
563  << "#\t- Halo nodes: " << totalHaloNodes << " (" << ratHaloNodes << "% of nodes)" << std::endl
564  << "#\t- Cells: " << totalCells << std::endl
565  << "#\t- Boundary cells: " << totalBoundary << std::endl
566  << "#\t- Theoretical optimum nodes per process: " << 100.0 / gridSize << "%" << std::endl
567  << "#\t- Cell overlapping: " << overlapping << "%" << std::endl;
568 
569  // Avoid 0 division
570  if (totalHaloNodes == 0)
571  totalHaloNodes = 1;
572 
573  // CPU-wise info
574  for (i = 0; i < gridSize; i++)
575  {
576  os << "# Process [" << i << "]" << std::endl;
577  os << "#\t- Owned Nodes: " << nodes[i] << " (" << (nodes[i] / (CepsReal) totalNodes) * 100 << "%)" << std::endl;
578  os << "#\t- Halo Nodes: " << haloNodes[i] << " (" << (haloNodes[i] / (CepsReal) totalHaloNodes) * 100 << "%)"
579  << std::endl;
580  os << "#\t- Cells: " << cells[i] << " (" << (cells[i] / (CepsReal) totalCells) * 100 << "%)"
581  << std::endl;
582  os << "#\t- Boundary Cells: " << boundary[i] << " (" << (boundary[i] / (CepsReal) totalBoundary) * 100 << "%)"
583  << std::endl;
584  }
585  os << "# " << CEPS_STRING_SEPARATOR << std::endl;
586  }
587  return;
588 }
589 
590 void
592  CepsUInt* nbBoundaryCells,
593  CepsUInt* nbNodes,
594  CepsUInt* nbHaloNodes) const
595 {
596  *nbCells = this->getNbCellsLocal ();
597  *nbBoundaryCells = this->getNbBoundaryCellsLocal();
598  *nbNodes = this->getNbOwnedNodesLocal ();
599  *nbHaloNodes = this->getNbHaloNodesLocal ();
600  return;
601 }
602 
603 void
605  CepsUInt* boundary,
606  CepsUInt* nodes,
607  CepsUInt* haloNodes) const
608 {
609  // Fill array with local information
610  CepsUInt nbCells, nbBdryCells, nbNodes, nbHaloNodes;
611  getLocalDistribution(&nbCells, &nbBdryCells, &nbNodes, &nbHaloNodes);
612 
613  CepsUInt rank = ceps::getRank();
614  cells [rank] = nbCells;
615  boundary [rank] = nbBdryCells;
616  nodes [rank] = nbNodes;
617  haloNodes[rank] = nbHaloNodes;
618 
619  // Share
620  MPI_Gather(&nbCells ,1,CEPS_MPI_UINT,cells ,1,CEPS_MPI_UINT,0,ceps::getCommunicator());
621  MPI_Gather(&nbBdryCells,1,CEPS_MPI_UINT,boundary ,1,CEPS_MPI_UINT,0,ceps::getCommunicator());
622  MPI_Gather(&nbNodes ,1,CEPS_MPI_UINT,nodes ,1,CEPS_MPI_UINT,0,ceps::getCommunicator());
623  MPI_Gather(&nbHaloNodes,1,CEPS_MPI_UINT,haloNodes,1,CEPS_MPI_UINT,0,ceps::getCommunicator());
624  return;
625 }
626 
627 // ---------------------------------------------------------------------------
628 // Indexing
629 
632 {
633  return m_nodesToSend;
634 }
635 
638 {
639  return m_nodesToReceive;
640 }
641 
644 {
645  return m_nodePartitionMap;
646 }
647 
650 {
651  return m_cellPartitionMap;
652 }
653 
656 {
657  return m_cellOffsetPerMesh;
658 }
659 
662 {
663  return m_nodeOffsetPerMesh;
664 }
665 
668 {
669  return m_coupledNodes;
670 }
671 
672 // ---------------------------------------------------------------------------
673 // Coordinates
674 
675 void
677 {
678  if (ceps::approxEquals (scaleFactor, 0.e0, 1.e-20))
679  std::cout << "\033[1m\033[34mWARNING. \033[0mGeometry scale: scaling factor " << scaleFactor
680  << " too small! Will not scale at all." << std::endl;
681  else
682  {
683  // call scaling method on all available domains
684  for (CepsUInt dim=1; dim<=3;dim++)
685  if (hasMeshOfDim(dim))
686  getMeshOfDim (dim)->scale(scaleFactor);
687  }
688 }
689 
690 // ---------------------------------------------------------------------------=
691 // PROTECTED
692 // ---------------------------------------------------------------------------=
693 
694 CepsUInt
696 {
697  if (not m_maxNodeConnectivity)
698  {
699  CepsUInt mymax = 0U;
700  for (CepsUInt dim=1;dim<=3;dim++)
701  if (hasMeshOfDim(dim))
702  mymax = std::max(mymax,getMeshOfDim(dim)->getMaxNodeConnectivity());
703  MPI_Allreduce(&mymax,&m_maxNodeConnectivity,1,CEPS_MPI_UINT,
704  MPI_MAX,ceps::getCommunicator());
705  }
706  return m_maxNodeConnectivity;
707 }
708 
709 CepsReal
711 {
712  if (m_maxCellDiameter<0.)
713  {
714  CepsReal mymax = -1.;
715  for (CepsUInt dim=1;dim<=3;dim++)
716  if (hasMeshOfDim(dim))
717  mymax = std::max(mymax,getMeshOfDim(dim)->getMaxCellDiameter());
718  MPI_Allreduce(&mymax,&m_maxCellDiameter,1,CEPS_MPI_REAL,
719  MPI_MAX,ceps::getCommunicator());
720  }
721  return m_maxCellDiameter;
722 }
723 
724 // ---------------------------------------------------------------------------=
725 // PRIVATE
726 // ---------------------------------------------------------------------------=
727 
728 void
730 {
731  m_parameters = nullptr;
732  m_nbNodes = 0;
733  m_nbHaloNodes = 0;
734  m_nbCells = 0;
736  m_maxCellDiameter = -1.;
737  m_nbBoundaryCells = 0;
738  m_hasCoupledNodes = false;
740 
741  m_meshes = {nullptr,nullptr,nullptr};
742  m_hasMeshOfDim = {false ,false ,false };
743 }
744 
745 void
747 {
748  CepsVector<CepsString> spairs = ceps::split(s,",");
749  for (CepsString spair: spairs)
750  {
751  std::istringstream iss(spair);
752  CepsString em = "Impossible to read number of unknowns in region with given attribute\n";
753  em += " The entry should be a comma separated list of pairs <attr,number>.\n";
754  em += " Got instead:\n ";
755  em += s;
756  CepsAttribute a = ceps::readInt(iss,em);
757  CepsUInt n = ceps::readInt(iss,em);
758  m_partitionWeights.insert(std::make_pair(a,n));
759  }
760 }
761 
762 void
764 {
765  // Get local info
766  Mesh *mesh = getMeshOfDim(dim);
767 
768  if (mesh)
769  {
770  CepsUInt nNSCells = mesh->getLocalNbCells ();
771  CepsUInt nNSBdCells = mesh->getLocalNbBoundaryCells();
772  CepsUInt nOwnedNodes = mesh->getLocalNbNodes ();
773 
774  // Share
775  CepsUInt gnNSCells(0U), gnNSBdCells(0U), gnOwnedNodes(0U);
776  MPI_Allreduce(&nNSCells ,&gnNSCells ,1,CEPS_MPI_UINT,MPI_SUM,ceps::getCommunicator());
777  MPI_Allreduce(&nNSBdCells ,&gnNSBdCells ,1,CEPS_MPI_UINT,MPI_SUM,ceps::getCommunicator());
778  MPI_Allreduce(&nOwnedNodes,&gnOwnedNodes,1,CEPS_MPI_UINT,MPI_SUM,ceps::getCommunicator());
779 
780  // Udpate mesh info
781  mesh->setNbCells (gnNSCells );
782  mesh->setNbBoundaryCells(gnNSBdCells );
783  mesh->setNbNodes (gnOwnedNodes);
784  }
785  return;
786 }
787 
788 void
790 {
791  for (CepsUInt dim=1; dim<=3;dim++)
792  if (hasMeshOfDim(dim))
793  updateMeshInfo(dim);
794  return;
795 }
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
#define CEPS_SAYS(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
#define CEPS_STRING_SEPARATOR
CepsString used as separator.
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
#define CEPS_MPI_REAL
Definition: CepsTypes.hpp:315
CepsInt CepsAttribute
Used to define regions.
Definition: CepsTypes.hpp:215
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
#define CEPS_MPI_UINT
Definition: CepsTypes.hpp:325
std::unordered_multimap< _Key, _Tp, _Hash, _KeyEqual, _Alloc > CepsMultiMap
C++ multimap.
Definition: CepsTypes.hpp:205
PartitioningMethod
Enum only meant to hold the method typedef.
@ PTScotchNode
GeomNode SCOTCH partitioning using primal graph.
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.
virtual CepsUInt computePartition()=0
Calls the partitioning method specified in the Geometry.
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
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
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
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.
CepsBool hasKey(const keyType &key) const
Tells if key exists in input file.
CepsString getString(const keyType &key) const
Reads a CepsString from configuration.
CepsReal getReal(const keyType &key) const
Reads a floating point value from configuration.
Geometrical information of 1,2 or 3D distributed cells.
Definition: Mesh.hpp:57
CepsUInt getLocalNbCells() const
Number of non-boundary cells stored on this process.
Definition: Mesh.cpp:246
void setNbCells(CepsUInt n)
Set the total number of cells of this mesh.
Definition: Mesh.cpp:145
void setNbNodes(CepsUInt n)
Set the total number of nodes of this mesh.
Definition: Mesh.cpp:156
void scale(CepsReal scaleFactor)
Each node coordinate is scaled by scaleFactor.
Definition: Mesh.cpp:296
CepsUInt getLocalNbNodes() const
Number of nodes stored on this process.
Definition: Mesh.cpp:258
CepsUInt getLocalNbBoundaryCells() const
Number of boundary cells stored on this process.
Definition: Mesh.cpp:252
GeomCell * getCell(CepsCellGlobalIndex geomIndex) const
pointer on requested cell, nullptr if not owned
Definition: Mesh.cpp:192
GeomCell * getBoundaryCell(CepsCellGlobalIndex geomIndex) const
pointer on requested boundary cell, nullptr if not owned
Definition: Mesh.cpp:198
GeomNode * getNodeOrHaloNode(CepsNodeGlobalIndex geomIndex) const
Get node referenced by geom index.
Definition: Mesh.cpp:174
void setNbBoundaryCells(CepsUInt n)
Set the total number of boundary cells of this mesh.
Definition: Mesh.cpp:151
GeomNode * getNode(CepsNodeGlobalIndex globalIndex) const
Get node referenced by global index.
Definition: Mesh.cpp:162
CepsUInt getRank()
Returns current processor rank.
CepsString toString(_Tp value)
Convert a given value to a string (input has to be compatible with std::to_string)
Definition: CepsString.hpp:409
void destroyTabular(_Type &)
Destroy[delete] any type.
Definition: CepsMemory.hpp:149
CepsBool isVerbose()
Check if the verbosity is enabled on the master proc (always false on slave procs).
Definition: CepsFlags.cpp:263
MPI_Comm getCommunicator()
Get the communicator.
CepsBool approxEquals(CepsReal a, CepsReal b, CepsReal epsilon)
Approximate equality with epsilon tolerance.
Definition: Precision.hpp:67
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
Definition: CepsMemory.hpp:61
std::ofstream & debugLog()
Get the DebugLog used in Ceps.
Definition: CepsFlags.cpp:245
const _Type & max(const CepsVector< _Type, _Alloc > &vec)
Returns the maximum of the vector, const version.
Definition: CepsVector.hpp:464
CepsUInt getGridSize()
Returns the number of process on the computing grid.
CepsInt readInt(std::istream &file, const CepsString &errorMessage="")
Reads an integral number from an istream, aborts if conversion fails advances the stream by 1 word.
Definition: CepsString.cpp:677
CepsBool isNullPtr(_Type *ptr)
Tells if passed pointer is null.
Definition: CepsMemory.hpp:45
void beginSequential()
Begins a sequential block.
CepsVector< CepsString > split(const CepsString &s, const CepsString &delimiters=CepsString(" \t"))
Splits a string using mulitple delimiters in a single string.
Definition: CepsString.cpp:38
CepsBool isMaster()
Is calling process the master ?
CepsBool isDebug()
Check if we enable the debug on the master proc (always false on slave procs).
Definition: CepsFlags.cpp:275
CepsString toUpper(const CepsString &s)
Switches all characters to upper case.
Definition: CepsString.cpp:124
std::ofstream & profilingLog()
Get the ProfilingLog used in Ceps.
Definition: CepsFlags.cpp:251
CepsBool equals(CepsReal a, CepsReal b, CepsReal error=1.0)
CepsReal equality up to machine precision.
Definition: Precision.hpp:54
void endSequential()
End a sequential block.
CepsBool isProfiling()
Check if we are currently profiling on the master proc (always false on slave procs).
Definition: CepsFlags.cpp:257
void destroyObject(_Type &)
Destroy[delete] any type.
Definition: CepsMemory.hpp:116