multiWorldConnectionsObject.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) 2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::multiWorldConnections
28 
29 Description
30  Centralized handling of multi-world MPI connections.
31 
32 Note
33  This class may move to static only or a singleton in the future.
34 
35 SourceFiles
36  multiWorldConnectionsObject.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef meshObjects_multiWorldConnections_H
41 #define meshObjects_multiWorldConnections_H
42 
43 #include "MeshObject.H"
44 #include "EdgeMap.H"
45 #include "Time.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class multiWorldConnections Declaration
54 \*---------------------------------------------------------------------------*/
55 
57 :
58  public MeshObject
59  <
60  Time,
61  TopologicalMeshObject,
62  multiWorldConnections
63  >
64 {
65  // Private Typedefs
66 
67  typedef MeshObject
68  <
69  Time,
73 
74 
75  // Private Data
76 
77  //- Table of world/world connections to communicator label
78  EdgeMap<label> table_;
79 
80 
81  // Private Member Functions
82 
83  //- Pairing from myWorld to other world by ID
84  // \return invalid on any error or if non-parallel
85  static edge worldPair(const label otherWorld);
86 
87  //- Pairing from myWorld to other world by NAME.
88  // \return invalid on any error or if non-parallel
89  static edge worldPair(const word& otherWorld);
90 
91  //- Allocate a communicator between myWorld and other world
92  static label createCommunicator(const edge& worlds);
93 
94 
95 public:
96 
97  //- Run-time type information
98  TypeName("multiWorld");
99 
100 
101  // Constructors
102 
103  //- Construct
104  explicit multiWorldConnections(const Time& runTime);
105 
106 
107  // Selectors
108 
109  //- Access mesh object
110  static const multiWorldConnections& New(const Time& runTime);
111 
112 
113  //- Destructor
115 
116 
117  // Member Functions
118 
119  //- True if no world-to-world connections are defined
120  bool empty() const noexcept;
121 
122  //- Number of world-to-world connections defined.
123  label size() const noexcept;
124 
125  //- Create all communicators.
126  //- Low-level, not normally called directly
127  void createComms();
128 
129  //- Define a connection from myWorld to other world by ID
130  bool addConnectionById(const label otherWorld);
131 
132  //- Define a connection from myWorld to other world by NAME
133  bool addConnectionByName(const word& otherWorld);
134 
135  //- Get communicator for myWorld to other world connection by ID.
136  // Uses cached value, or creates a new communicator
137  label getCommById(const label otherWorld) const;
138 
139  //- Get communicator for myWorld to other world connection by NAME.
140  // Uses cached value, or creates a new communicator
141  label getCommByName(const word& otherWorld) const;
142 
143  //- Get communicators used for myWorld to other worlds in sorted order.
144  // \return worldComm if no world-to-world communicators in use.
145  labelList comms() const;
146 };
147 
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 } // End namespace Foam
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 #endif
156 
157 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::multiWorldConnections::addConnectionById
bool addConnectionById(const label otherWorld)
Define a connection from myWorld to other world by ID.
Definition: multiWorldConnectionsObject.C:305
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::multiWorldConnections::getCommById
label getCommById(const label otherWorld) const
Get communicator for myWorld to other world connection by ID.
Definition: multiWorldConnectionsObject.C:344
Foam::multiWorldConnections::~multiWorldConnections
~multiWorldConnections()
Destructor.
Definition: multiWorldConnectionsObject.C:199
Foam::multiWorldConnections::New
static const multiWorldConnections & New(const Time &runTime)
Access mesh object.
Definition: multiWorldConnectionsObject.C:191
Foam::multiWorldConnections::comms
labelList comms() const
Get communicators used for myWorld to other worlds in sorted order.
Definition: multiWorldConnectionsObject.C:425
Foam::multiWorldConnections::size
label size() const noexcept
Number of world-to-world connections defined.
Definition: multiWorldConnectionsObject.C:211
Foam::multiWorldConnections::getCommByName
label getCommByName(const word &otherWorld) const
Get communicator for myWorld to other world connection by NAME.
Definition: multiWorldConnectionsObject.C:385
Foam::multiWorldConnections::createComms
void createComms()
Definition: multiWorldConnectionsObject.C:217
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::multiWorldConnections::empty
bool empty() const noexcept
True if no world-to-world connections are defined.
Definition: multiWorldConnectionsObject.C:205
Time.H
Foam::EdgeMap< label >
Foam::multiWorldConnections
Centralized handling of multi-world MPI connections.
Definition: multiWorldConnectionsObject.H:55
Foam::List< label >
Foam::multiWorldConnections::multiWorldConnections
multiWorldConnections(const Time &runTime)
Construct.
Definition: multiWorldConnectionsObject.C:182
Foam::TopologicalMeshObject< Time >::TopologicalMeshObject
TopologicalMeshObject(const word &typeName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:189
EdgeMap.H
MeshObject.H
Foam::MeshObject
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:88
Foam::multiWorldConnections::TypeName
TypeName("multiWorld")
Run-time type information.
Foam::multiWorldConnections::addConnectionByName
bool addConnectionByName(const word &otherWorld)
Define a connection from myWorld to other world by NAME.
Definition: multiWorldConnectionsObject.C:324