v0.15.0
Loading...
Searching...
No Matches
CommInterface.hpp
Go to the documentation of this file.
1/** \file CommInterface.hpp
2 * \brief Interface for communication functions
3 * \ingroup mofem_comm
4 *
5 * Functions used to communicate, share entities, share data, etc.
6 *
7 */
8
9#ifndef __COMMINTERFACE_HPP__
10#define __COMMINTERFACE_HPP__
11
12#include "UnknownInterface.hpp"
13
14namespace MoFEM {
15
16/**
17 * \brief Managing BitRefLevels
18 * \ingroup mofem_bit_ref
19 * \nosubgrouping
20 */
22
23 inline static bool debug = false;
24 inline static Sev sev = Sev::verbose;
25
26 MoFEMErrorCode query_interface(boost::typeindex::type_index type_index,
27 UnknownInterface **iface) const;
28
30 bool dEbug;
31
32 CommInterface(const MoFEM::Core &core);
33
34 /**
35 * \brief Destructor
36 */
37 ~CommInterface() = default;
38
39 /** \name Make elemets multishared */
40
41 /**@{*/
42
43 /**
44 * \brief resolve shared entities for finite elements in the problem
45 * \ingroup mofem_problems
46
47 * @param problem_ptr problem pointer
48 * @param fe_name finite element name
49 * @param verb verbosity level
50 * @return error code
51 *
52 * This allows for tag reduction or tag exchange, f.e.
53
54 \code
55 CHKERR m_field.resolveSharedFiniteElements(problem_ptr,"SHELL_ELEMENT");
56 Tag th;
57 CHKERR mField.get_moab().tag_get_handle("ADAPT_ORDER",th);
58 CHKERR ParallelComm* pcomm =
59 ParallelComm::get_pcomm(&mField.get_moab(),MYPCOMM_INDEX);
60 CHKERR pcomm->exchange_tags(th,prisms);
61 \endcode
62
63 *
64 */
66 const std::string &fe_name,
67 int verb = DEFAULT_VERBOSITY);
68
69 /**
70 * \brief resolve shared entities for finite elements in the problem
71 * \ingroup mofem_problems
72
73 * @param name problem name
74 * @param fe_name finite element name
75 * @param verb verbosity level
76 * @return error code
77 *
78 * This allows for tag reduction or tag exchange, f.e.
79
80 \code
81 CHKERR m_field.resolveSharedFiniteElements(problem_ptr,"SHELL_ELEMENT");
82 Tag th;
83 CHKERR mField.get_moab().tag_get_handle("ADAPT_ORDER",th);
84 ParallelComm* pcomm =
85 ParallelComm::get_pcomm(&mField.get_moab(),MYPCOMM_INDEX);
86 // CHKERR pcomm->reduce_tags(th,MPI_SUM,prisms);
87 CHKERR pcomm->exchange_tags(th,prisms);
88 \endcode
89
90 *
91 */
92 MoFEMErrorCode resolveSharedFiniteElements(const std::string name,
93 const std::string &fe_name,
94 int verb = DEFAULT_VERBOSITY);
95
96 /** \name Make entities multishared */
97
98 /**
99 * @brief make entities from proc 0 shared on all proc
100 *
101 * \note collective - need tu be run on all processors in communicator
102 *
103 * @param entities
104 * @param num_entities
105 * @param my_proc default proc id to share from
106 * @param verb
107 * @return MoFEMErrorCode
108 */
110 const int num_entities,
111 const int owner_proc = 0,
112 int verb = DEFAULT_VERBOSITY);
113
114 /**
115 * @brief make entities from proc 0 shared on all proc
116 *
117 * \note collective - need tu be run on all processors in communicator
118 *
119 * @param entities
120 * @param my_proc default proc id to share from
121 * @param verb
122 * @return MoFEMErrorCode
123 */
125 const int owner_proc = 0,
126 int verb = DEFAULT_VERBOSITY);
127
128 /**
129 * @brief make field entities multi shared
130 *
131 * \note collective - need tu be run on all processors in communicator
132 *
133 * @param field_name
134 * @param owner_proc
135 * @param verb
136 * @return MoFEMErrorCode
137 */
139 const int owner_proc = 0,
140 int verb = DEFAULT_VERBOSITY);
141
142 /**
143 * @brief Exchange field data
144 *
145 * Exchange field for all shared and ghosted entities. This function should be
146 * called collectively over the communicator for this ParallelComm. If the
147 * entities vector is empty, all shared entities participate in the exchange.
148 * If a proc has no owned entities this function must still be called since it
149 * is collective.
150 *
151 * \note collective - need tu be run on all processors in communicator
152 *
153 * \todo It is not working if field has entities diffrent than vertices.
154 *
155 * @param verb
156 * @param field_name @return MoFEMErrorCode
157 */
159 int verb = DEFAULT_VERBOSITY);
160
161 /**@}*/
162
163 /** \name Synchronize entities (Following functions in future will be
164 * deprecated) */
165
166 /**@{*/
167
168 /** synchronize entity range on processors (collective)
169 *
170 * \note collective - need tu be run on all processors in communicator
171 *
172 */
173
174 /**
175 * @brief synchronize entity range on processors (collective)
176 *
177 * \note collective - need tu be run on all processors in communicator
178 *
179 * @param ent ents to send and received
180 * @param received_ents pointer to map with received entities
181 * @param verb
182 * @return MoFEMErrorCode
183 */
185 std::map<int, Range> *received_ents,
186 int verb = DEFAULT_VERBOSITY);
187
188 /**
189 * @brief synchronize entity range on processors (collective)
190 *
191 * \note collective - need tu be run on all processors in communicator
192 *
193 * @param ent ents to send and received
194 * @param verb
195 * @return MoFEMErrorCode
196 */
198
199 /** synchronize entity range on processors (collective)
200 * \ingroup mofem_field
201 *
202 * \note collective - need tu be run on all processors in communicator
203 *
204 * \param name field
205 * \param verbose level
206 *
207 */
208 MoFEMErrorCode synchroniseFieldEntities(const std::string name,
209 int verb = DEFAULT_VERBOSITY);
210
211 /**
212 * @brief Synchronise parent entities
213 *
214 * \note collective - need tu be run on all processors in communicator
215 *
216 * Exchange parent entity tag and bitref of entity. Note thar parent handle
217 * can be different on each processor.
218 *
219 * @param ent
220 * @param verb
221 * @return MoFEMErrorCode
222 */
224 int verb = DEFAULT_VERBOSITY);
225
226 /**@}*/
227
228 /**@*/
229
230 /** \name Read load and boradcoast */
231
232 /**
233 * \brief Set partition tag to each finite element in the problem
234 * \ingroup mofem_problems_manager
235 *
236 * This will use one of the mesh partitioning programs available from PETSc
237 * See
238 * <http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatPartitioningType.html>
239 *
240 * @param ents Entities to partition
241 * @param dim Dimension of entities to partition
242 * @param adj_dim Adjacency dimension
243 * @param n_parts Number of partitions
244 * @param verb Verbosity level
245 * @return Error code
246 */
247 MoFEMErrorCode partitionMesh(const Range &ents, const int dim,
248 const int adj_dim, const int n_parts,
249 Tag *th_vertex_weights = nullptr,
250 Tag *th_edge_weights = nullptr,
251 Tag *th_part_weights = nullptr,
252 int verb = VERBOSE, const bool debug = false);
253
254
255 /**@}*/
256
257 /**@{*/
258
259 /** \name Load file */
260
261 using LoadFileFun = std::function<std::array<Range, 4>(
262 std::array<Range, 4> &&, std::vector<const CubitMeshSets *> &&)>;
263
264 static std::array<Range, 4>
265 defaultProcSkinFun(std::array<Range, 4> &&proc_ents_skin,
266 std::vector<const CubitMeshSets *> &&vec_ptr) {
267 return proc_ents_skin;
268 }
269
270 /**
271 * @brief Root proc has whole mesh, other procs only part of it
272 *
273 * @param moab
274 * @param file_name
275 * @param dim
276 * @param proc_skin_fun
277 * @param options
278 * @return MoFEMErrorCode
279 */
281 moab::Interface &moab, const char *file_name, int dim,
282 LoadFileFun proc_skin_fun = defaultProcSkinFun,
283 const char *options = "PARALLEL=BCAST;PARTITION=");
284
285 static Range getPartEntities(moab::Interface &moab, int part);
286
287 /**@}*/
288 /**@*/
289
290 /** \name Functions when rooot proc have all entities */
291
293 std::pair<std::pair<Range, Range>, SmartPetscObj<Vec>>;
294
295 /**
296 * @brief Create a ghost vector for exchanging data
297 *
298 * @note Only works if loadFileRootProcAllRestDistributed function is used.
299 *
300 * @param comm
301 * @param moab
302 * @param dim dimension of partition entities
303 * @param adj_dim dimension of adjacent entities
304 * @param nb_coeffs number of coefficients
305 * @param sev
306 * @param root_rank
307 *
308 * @return std::pair<Range, SmartPetscObj<Vec>>
309 */
311 createEntitiesPetscVector(MPI_Comm comm, moab::Interface &moab, int dim,
312 const int nb_coeffs, Sev sev = Sev::verbose,
313 int root_rank = 0);
314
315 using UpdateGhosts = std::function<MoFEMErrorCode(Vec vec)>;
316
319 CHKERR VecAssemblyBegin(v);
320 CHKERR VecAssemblyEnd(v);
321 CHKERR VecGhostUpdateBegin(v, ADD_VALUES, SCATTER_REVERSE);
322 CHKERR VecGhostUpdateEnd(v, ADD_VALUES, SCATTER_REVERSE);
323 CHKERR VecGhostUpdateBegin(v, INSERT_VALUES, SCATTER_FORWARD);
324 CHKERR VecGhostUpdateEnd(v, INSERT_VALUES, SCATTER_FORWARD);
326 };
327
328 /**
329 * @brief Exchange data between vector and data
330 *
331 * @param tag
332 * @return MoFEMErrorCode
333 */
334 static MoFEMErrorCode
335 updateEntitiesPetscVector(moab::Interface &moab, EntitiesPetscVector &vec,
336 Tag tag,
337 UpdateGhosts update_gosts = defaultUpdateGhosts);
338
339 /**@}*/
340
341};
342} // namespace MoFEM
343
344#endif //__COMMINTERFACE_HPP__
345
346/**
347 * \defgroup mofem_comm Comm intrface
348 * \brief Comm interface
349 *
350 * \ingroup mofem
351 */
MoFEM interface.
@ DEFAULT_VERBOSITY
@ VERBOSE
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
MoFEMErrorCode synchroniseFieldEntities(const std::string name, int verb=DEFAULT_VERBOSITY)
SeverityLevel
Severity levels.
MoFEMErrorCode partitionMesh(const Range &ents, const int dim, const int adj_dim, const int n_parts, Tag *th_vertex_weights=nullptr, Tag *th_edge_weights=nullptr, Tag *th_part_weights=nullptr, int verb=VERBOSE, const bool debug=false)
Set partition tag to each finite element in the problem.
MoFEMErrorCode resolveSharedFiniteElements(const Problem *problem_ptr, const std::string &fe_name, int verb=DEFAULT_VERBOSITY)
resolve shared entities for finite elements in the problem
const double v
phase velocity of light in medium (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
constexpr auto field_name
Managing BitRefLevels.
static MoFEMErrorCode updateEntitiesPetscVector(moab::Interface &moab, EntitiesPetscVector &vec, Tag tag, UpdateGhosts update_gosts=defaultUpdateGhosts)
Exchange data between vector and data.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
std::function< MoFEMErrorCode(Vec vec)> UpdateGhosts
static Range getPartEntities(moab::Interface &moab, int part)
static EntitiesPetscVector createEntitiesPetscVector(MPI_Comm comm, moab::Interface &moab, int dim, const int nb_coeffs, Sev sev=Sev::verbose, int root_rank=0)
Create a ghost vector for exchanging data.
~CommInterface()=default
Destructor.
CommInterface(const MoFEM::Core &core)
static MoFEMErrorCode defaultUpdateGhosts(Vec v)
MoFEMErrorCode makeEntitiesMultishared(const EntityHandle *entities, const int num_entities, const int owner_proc=0, int verb=DEFAULT_VERBOSITY)
make entities from proc 0 shared on all proc
static std::array< Range, 4 > defaultProcSkinFun(std::array< Range, 4 > &&proc_ents_skin, std::vector< const CubitMeshSets * > &&vec_ptr)
std::pair< std::pair< Range, Range >, SmartPetscObj< Vec > > EntitiesPetscVector
static MoFEMErrorCode loadFileRootProcAllRestDistributed(moab::Interface &moab, const char *file_name, int dim, LoadFileFun proc_skin_fun=defaultProcSkinFun, const char *options="PARALLEL=BCAST;PARTITION=")
Root proc has whole mesh, other procs only part of it.
MoFEMErrorCode synchroniseEntities(Range &ent, std::map< int, Range > *received_ents, int verb=DEFAULT_VERBOSITY)
synchronize entity range on processors (collective)
MoFEMErrorCode makeFieldEntitiesMultishared(const std::string field_name, const int owner_proc=0, int verb=DEFAULT_VERBOSITY)
make field entities multi shared
MoFEMErrorCode resolveParentEntities(const Range &ent, int verb=DEFAULT_VERBOSITY)
Synchronise parent entities.
std::function< std::array< Range, 4 >( std::array< Range, 4 > &&, std::vector< const CubitMeshSets * > &&)> LoadFileFun
MoFEMErrorCode exchangeFieldData(const std::string field_name, int verb=DEFAULT_VERBOSITY)
Exchange field data.
Core (interface) class.
Definition Core.hpp:82
keeps basic data about problem
intrusive_ptr for managing petsc objects
base class for all interface classes