KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
communicator.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 // Riccardo Rossi
12 //
13 //
14 
15 
16 
17 #if !defined(KRATOS_COMMUNICATOR_H_INCLUDED )
18 #define KRATOS_COMMUNICATOR_H_INCLUDED
19 
20 
21 
22 // System includes
23 #include <string>
24 #include <iostream>
25 #include <sstream>
26 #include <cstddef>
27 
28 
29 // External includes
30 
31 // Project includes
32 #include "includes/define.h"
33 #include "includes/condition.h"
34 #include "includes/element.h"
35 #include "includes/mesh.h"
36 
37 namespace Kratos
38 {
39 
42 
46 
50 
54 
58 
59 // Forward declaration of DataCommunicator
60 class DataCommunicator;
61 
63 
66 class KRATOS_API(KRATOS_CORE) Communicator
67 {
68 public:
71 
72 
76 
79 
80  typedef unsigned int IndexType;
81 
82  typedef unsigned int SizeType;
83 
84  typedef Node NodeType;
85 
87 
89 
91 
93 
95 
97 
100 
106 
112 
120 
126 
132 
140 
146 
152 
155 
161 
167 
171 
173  Communicator();
174 
176 
180  Communicator(const DataCommunicator& rDataCommunicator);
181 
183  Communicator(Communicator const& rOther);
184 
186  virtual ~Communicator() = default;
187 
188  virtual Communicator::Pointer Create(const DataCommunicator& rDataCommunicator) const;
189 
190  Communicator::Pointer Create() const;
191 
195 
197  Communicator & operator=(Communicator const& rOther) = delete;
198 
202 
203  virtual bool IsDistributed() const;
204 
205  virtual int MyPID() const;
206 
207  virtual int TotalProcesses() const;
208 
209  SizeType GlobalNumberOfNodes() const;
210 
211  SizeType GlobalNumberOfElements() const;
212 
213  SizeType GlobalNumberOfConditions() const;
214 
215  SizeType GlobalNumberOfMasterSlaveConstraints() const;
216 
217  SizeType GetNumberOfColors() const;
218 
219  void SetNumberOfColors(SizeType NewNumberOfColors);
220 
221  void AddColors(SizeType NumberOfAddedColors);
222 
223  NeighbourIndicesContainerType& NeighbourIndices();
224 
225  NeighbourIndicesContainerType const& NeighbourIndices() const;
226 
228  void SetLocalMesh(MeshType::Pointer pGivenMesh);
229 
231  MeshType::Pointer pLocalMesh();
232 
234  MeshType::Pointer pGhostMesh();
235 
237  MeshType::Pointer pInterfaceMesh();
238 
240  const MeshType::Pointer pLocalMesh() const;
241 
243  const MeshType::Pointer pGhostMesh() const;
244 
246  const MeshType::Pointer pInterfaceMesh() const;
247 
248  MeshType::Pointer pLocalMesh(IndexType ThisIndex);
249 
250  MeshType::Pointer pGhostMesh(IndexType ThisIndex);
251 
252  MeshType::Pointer pInterfaceMesh(IndexType ThisIndex);
253 
254  const MeshType::Pointer pLocalMesh(IndexType ThisIndex) const;
255 
256  const MeshType::Pointer pGhostMesh(IndexType ThisIndex) const;
257 
258  const MeshType::Pointer pInterfaceMesh(IndexType ThisIndex) const;
259 
261  MeshType& LocalMesh();
262 
264  MeshType& GhostMesh();
265 
267  MeshType& InterfaceMesh();
268 
270  MeshType const& LocalMesh() const;
271 
273  MeshType const& GhostMesh() const;
274 
276  MeshType const& InterfaceMesh() const;
277 
278  MeshType& LocalMesh(IndexType ThisIndex);
279 
280  MeshType& GhostMesh(IndexType ThisIndex);
281 
282  MeshType& InterfaceMesh(IndexType ThisIndex);
283 
284  MeshType const& LocalMesh(IndexType ThisIndex) const;
285 
286  MeshType const& GhostMesh(IndexType ThisIndex) const;
287 
288  MeshType const& InterfaceMesh(IndexType ThisIndex) const;
289 
290  MeshesContainerType& LocalMeshes();
291 
292  MeshesContainerType& GhostMeshes();
293 
294  MeshesContainerType& InterfaceMeshes();
295 
296  MeshesContainerType const& LocalMeshes() const;
297 
298  MeshesContainerType const& GhostMeshes() const;
299 
300  MeshesContainerType const& InterfaceMeshes() const;
301 
302  virtual const DataCommunicator& GetDataCommunicator() const;
303 
307 
308  virtual bool SynchronizeNodalSolutionStepsData();
309 
310  virtual bool SynchronizeDofs();
311 
312  virtual bool SynchronizeVariable(Variable<int> const& rThisVariable);
313 
314  virtual bool SynchronizeVariable(Variable<double> const& rThisVariable);
315 
316  virtual bool SynchronizeVariable(Variable<bool> const& rThisVariable);
317 
318  virtual bool SynchronizeVariable(Variable<array_1d<double, 3 > > const& rThisVariable);
319 
320  virtual bool SynchronizeVariable(Variable<array_1d<double, 4 > > const& rThisVariable);
321 
322  virtual bool SynchronizeVariable(Variable<array_1d<double, 6 > > const& rThisVariable);
323 
324  virtual bool SynchronizeVariable(Variable<array_1d<double, 9 > > const& rThisVariable);
325 
326  virtual bool SynchronizeVariable(Variable<Vector> const& rThisVariable);
327 
328  virtual bool SynchronizeVariable(Variable<Matrix> const& rThisVariable);
329 
330  virtual bool SynchronizeVariable(Variable<Quaternion<double>> const& rThisVariable);
331 
332  virtual bool SynchronizeNonHistoricalVariable(Variable<int> const& rThisVariable);
333 
334  virtual bool SynchronizeNonHistoricalVariable(Variable<double> const& rThisVariable);
335 
336  virtual bool SynchronizeNonHistoricalVariable(Variable<bool> const& rThisVariable);
337 
338  virtual bool SynchronizeNonHistoricalVariable(Variable<array_1d<double, 3 > > const& rThisVariable);
339 
340  virtual bool SynchronizeNonHistoricalVariable(Variable<array_1d<double, 4 > > const& rThisVariable);
341 
342  virtual bool SynchronizeNonHistoricalVariable(Variable<array_1d<double, 6 > > const& rThisVariable);
343 
344  virtual bool SynchronizeNonHistoricalVariable(Variable<array_1d<double, 9 > > const& rThisVariable);
345 
346  virtual bool SynchronizeNonHistoricalVariable(Variable<Vector> const& rThisVariable);
347 
348  virtual bool SynchronizeNonHistoricalVariable(Variable<Matrix> const& rThisVariable);
349 
350  virtual bool SynchronizeNonHistoricalVariable(Variable<Quaternion<double>> const& rThisVariable);
351 
356  virtual bool SynchronizeCurrentDataToMax(Variable<double> const& ThisVariable);
357 
362  virtual bool SynchronizeNonHistoricalDataToMax(Variable<double> const& ThisVariable);
363 
368  virtual bool SynchronizeCurrentDataToAbsMax(Variable<double> const& ThisVariable);
369 
374  virtual bool SynchronizeNonHistoricalDataToAbsMax(Variable<double> const& ThisVariable);
375 
380  virtual bool SynchronizeCurrentDataToMin(Variable<double> const& ThisVariable);
381 
386  virtual bool SynchronizeNonHistoricalDataToMin(Variable<double> const& ThisVariable);
387 
392  virtual bool SynchronizeCurrentDataToAbsMin(Variable<double> const& ThisVariable);
393 
398  virtual bool SynchronizeNonHistoricalDataToAbsMin(Variable<double> const& ThisVariable);
399 
400  virtual bool SynchronizeElementalFlags();
401 
402  virtual bool AssembleCurrentData(Variable<int> const& ThisVariable);
403 
404  virtual bool AssembleCurrentData(Variable<double> const& ThisVariable);
405 
406  virtual bool AssembleCurrentData(Variable<array_1d<double, 3 > > const& ThisVariable);
407 
408  virtual bool AssembleCurrentData(Variable<Vector> const& ThisVariable);
409 
410  virtual bool AssembleCurrentData(Variable<Matrix> const& ThisVariable);
411 
412  virtual bool AssembleNonHistoricalData(Variable<int> const& ThisVariable);
413 
414  virtual bool AssembleNonHistoricalData(Variable<double> const& ThisVariable);
415 
416  virtual bool AssembleNonHistoricalData(Variable<array_1d<double, 3 > > const& ThisVariable);
417 
418  virtual bool AssembleNonHistoricalData(Variable<DenseVector<array_1d<double,3> > > const& ThisVariable);
419 
420  virtual bool AssembleNonHistoricalData(Variable<Vector> const& ThisVariable);
421 
422  virtual bool AssembleNonHistoricalData(Variable<Matrix> const& ThisVariable);
423 
424  virtual bool SynchronizeElementalNonHistoricalVariable(Variable<int> const& ThisVariable);
425 
426  virtual bool SynchronizeElementalNonHistoricalVariable(Variable<double> const& ThisVariable);
427 
428  virtual bool SynchronizeElementalNonHistoricalVariable(Variable<array_1d<double, 3 > > const& ThisVariable);
429 
430  virtual bool SynchronizeElementalNonHistoricalVariable(Variable<DenseVector<array_1d<double,3> > > const& ThisVariable);
431 
432  virtual bool SynchronizeElementalNonHistoricalVariable(Variable<DenseVector<int> > const& ThisVariable);
433 
434  virtual bool SynchronizeElementalNonHistoricalVariable(Variable<Vector> const& ThisVariable);
435 
436  virtual bool SynchronizeElementalNonHistoricalVariable(Variable<Matrix> const& ThisVariable);
437 
438  virtual bool TransferObjects(std::vector<NodesContainerType>& SendObjects, std::vector<NodesContainerType>& RecvObjects);
439 
440  virtual bool TransferObjects(std::vector<ElementsContainerType>& SendObjects, std::vector<ElementsContainerType>& RecvObjects);
441 
442  virtual bool TransferObjects(std::vector<ConditionsContainerType>& SendObjects, std::vector<ConditionsContainerType>& RecvObjects);
443 
444  virtual bool TransferObjects(std::vector<NodesContainerType>& SendObjects, std::vector<NodesContainerType>& RecvObjects,Kratos::Serializer& particleSerializer);
445 
446  virtual bool TransferObjects(std::vector<ElementsContainerType>& SendObjects, std::vector<ElementsContainerType>& RecvObjects,Kratos::Serializer& particleSerializer);
447 
448  virtual bool TransferObjects(std::vector<ConditionsContainerType>& SendObjects, std::vector<ConditionsContainerType>& RecvObjects,Kratos::Serializer& particleSerializer);
449 
450  virtual bool SynchronizeOrNodalFlags(const Flags& TheFlags);
451 
452  virtual bool SynchronizeAndNodalFlags(const Flags& TheFlags);
453 
454  virtual bool SynchronizeNodalFlags();
455 
456  void Clear();
457 
461 
463  virtual std::string Info() const;
464 
466  virtual void PrintInfo(std::ostream& rOStream) const;
467 
469  virtual void PrintData(std::ostream& rOStream, std::string const& rPrefixString="") const;
470 
474 
478 
479 
481 
482 protected:
485 
486 
491 
493 
494  // To store all local entities
495  MeshType::Pointer mpLocalMesh;
496 
497  // To store all ghost entities
498  MeshType::Pointer mpGhostMesh;
499 
500  // To store all interface entities
501  MeshType::Pointer mpInterfaceMesh;
502 
503  // To store interfaces local entities
505 
506  // To store interfaces ghost entities
508 
509  // To store interfaces ghost+local entities
511 
512  // Interface to MPI communication
514 
518 
519 
523 
524 
528 
529 
533 
534 
538 
539 
541 
542 private:
545 
546 
550 
551 
552 
553 
557 
558 
562 
563 
567 
568 
572 
573 
577 
578 
580 
581 }; // Class Communicator
582 
584 
587 
588 
592 
593 
595 inline std::istream & operator >>(std::istream& rIStream,
596  Communicator& rThis);
597 
599 
600 inline std::ostream & operator <<(std::ostream& rOStream,
601  const Communicator& rThis)
602 {
603  rThis.PrintInfo(rOStream);
604  rOStream << std::endl;
605  rThis.PrintData(rOStream);
606 
607  return rOStream;
608 }
610 
611 
612 } // namespace Kratos.
613 
614 #endif // KRATOS_COMMUNICATOR_H_INCLUDED defined
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
The Commmunicator class manages communication for distributed ModelPart instances.
Definition: communicator.h:67
PointerVector< MeshType > MeshesContainerType
Definition: communicator.h:96
MeshesContainerType mInterfaceMeshes
Definition: communicator.h:510
MeshType::PropertiesConstantIterator PropertiesConstantIterator
Definition: communicator.h:131
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: communicator.h:139
KRATOS_CLASS_POINTER_DEFINITION(Communicator)
Pointer definition of Communicator.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: communicator.cpp:657
MeshType::Pointer mpInterfaceMesh
Definition: communicator.h:501
Mesh< NodeType, PropertiesType, ElementType, ConditionType > MeshType
Definition: communicator.h:94
MeshType::ConditionConstantIterator ConditionConstantIterator
Definition: communicator.h:166
MeshesContainerType mLocalMeshes
Definition: communicator.h:504
SizeType mNumberOfColors
Definition: communicator.h:490
Communicator & operator=(Communicator const &rOther)=delete
Assignment operator.
const DataCommunicator & mrDataCommunicator
Definition: communicator.h:513
MeshType::NodeConstantIterator NodeConstantIterator
Definition: communicator.h:111
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: communicator.h:99
Condition ConditionType
Definition: communicator.h:90
MeshType::Pointer mpGhostMesh
Definition: communicator.h:498
MeshesContainerType mGhostMeshes
Definition: communicator.h:507
Element ElementType
Definition: communicator.h:88
MeshType::PropertiesContainerType PropertiesContainerType
Properties container. Which is a vector set of Properties with their Id's as key.
Definition: communicator.h:119
Node NodeType
Definition: communicator.h:84
MeshType::ElementIterator ElementIterator
Definition: communicator.h:145
MeshType::ElementConstantIterator ElementConstantIterator
Definition: communicator.h:151
Properties PropertiesType
Definition: communicator.h:86
NeighbourIndicesContainerType mNeighbourIndices
Definition: communicator.h:492
DenseVector< int > NeighbourIndicesContainerType
Definition: communicator.h:92
virtual ~Communicator()=default
Destructor.
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: communicator.h:154
MeshType::PropertiesIterator PropertiesIterator
Definition: communicator.h:125
MeshType::ConditionIterator ConditionIterator
Definition: communicator.h:160
unsigned int IndexType
Definition: communicator.h:80
virtual void PrintData(std::ostream &rOStream, std::string const &rPrefixString="") const
Print object's data.
Definition: communicator.cpp:662
MeshType::NodeIterator NodeIterator
Definition: communicator.h:105
unsigned int SizeType
Definition: communicator.h:82
MeshType::Pointer mpLocalMesh
Definition: communicator.h:495
Base class for all Conditions.
Definition: condition.h:59
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
Base class for all Elements.
Definition: element.h:60
Definition: flags.h:58
Definition: amatrix_interface.h:41
typename NodesContainerType::const_iterator NodeConstantIterator
Const iterator for nodes in the container. Provides direct references to nodes.
Definition: mesh.h:117
typename PropertiesContainerType::iterator PropertiesIterator
Iterator for properties in the container. Provides direct references to properties.
Definition: mesh.h:123
typename ConditionsContainerType::iterator ConditionIterator
Iterator for conditions in the container. Provides direct references to conditions.
Definition: mesh.h:153
typename NodesContainerType::iterator NodeIterator
Iterator for nodes in the container. Provides direct references to nodes.
Definition: mesh.h:114
typename ConditionsContainerType::const_iterator ConditionConstantIterator
Const iterator for conditions in the container. Provides direct references to conditions.
Definition: mesh.h:156
typename ElementsContainerType::const_iterator ElementConstantIterator
Const iterator for elements in the container. Provides direct references to elements.
Definition: mesh.h:141
typename ElementsContainerType::iterator ElementIterator
Iterator for elements in the container. Provides direct references to elements.
Definition: mesh.h:138
typename PropertiesContainerType::const_iterator PropertiesConstantIterator
Const iterator for properties in the container. Provides direct references to properties.
Definition: mesh.h:126
This class defines the node.
Definition: node.h:65
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
Properties encapsulates data shared by different Elements or Conditions. It can store any type of dat...
Definition: properties.h:69
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
Modeler::Pointer Create(const std::string &ModelerName, Model &rModel, const Parameters ModelParameters)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:30
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432