v0.14.0
BcManager.hpp
Go to the documentation of this file.
1 /** \file BcManager.hpp
2  * \brief Manage boundary conditions set to the problem
3  * \ingroup bc_manager
4  *
5  */
6 
7 #ifndef __BCMANAGER_HPP__
8 #define __BCMANAGER_HPP__
9 
10 #include "UnknownInterface.hpp"
11 
12 namespace MoFEM {
13 
14 template <CubitBC BC> struct BcMeshsetType {};
15 template <CubitBC BC> struct BcScalarMeshsetType {};
16 template <CubitBC BC> using BcTemperature = BcScalarMeshsetType<BC>;
17 template <CubitBC BC> struct BcDisplacementMeshsetType {};
18 template <CubitBC BC> struct BcForceMeshsetType {};
19 template <CubitBC BC> struct BcFluxMeshsetType {};
20 
21 /**
22  * \brief Simple interface for fast problem set-up
23  * \ingroup mofem_simple_interface
24  */
25 struct BcManager : public UnknownInterface {
26 
27  MoFEMErrorCode query_interface(boost::typeindex::type_index type_index,
28  UnknownInterface **iface) const;
29 
30  BcManager(const MoFEM::Core &core);
31  virtual ~BcManager() = default;
32 
33  /**
34  * @brief Data structure storing bc markers and atributes
35  *
36  */
37  struct BCs : boost::enable_shared_from_this<BCs> {
39  std::vector<double> bcAttributes;
40  std::vector<unsigned char> bcMarkers;
41 
42  boost::shared_ptr<DisplacementCubitBcData> dispBcPtr;
43  boost::shared_ptr<TemperatureCubitBcData> tempBcPtr;
44  boost::shared_ptr<HeatFluxCubitBcData> heatFluxBcPtr;
45  boost::shared_ptr<ForceCubitBcData> forceBcPtr;
46  boost::shared_ptr<MPCsType> mpcPtr;
47 
48  /// \deprecated use getBcEntsPtr
49  DEPRECATED inline auto getBcEdgesPtr() {
50  return boost::shared_ptr<Range>(shared_from_this(), &bcEnts);
51  }
52 
53  inline auto getBcEntsPtr() {
54  return boost::shared_ptr<Range>(shared_from_this(), &bcEnts);
55  }
56 
57  inline auto getBcMarkersPtr() {
58  return boost::shared_ptr<std::vector<unsigned char>>(shared_from_this(),
59  &bcMarkers);
60  }
61  };
62 
63  /**
64  * \brief get options
65  * @return error code
66  */
68  // FIXME: add functions to couple the dofs
69  MoFEMErrorCode addBlockDOFsToMPCs(const std::string problem_name,
70  const std::string field_name,
71  bool get_low_dim_ents = false,
72  bool block_name_field_prefix = false,
73  bool is_distributed_mesh = false);
74 
75  /**
76  * @brief Remove DOFs from problem
77  *
78  * @param problem_name
79  * @param block_name
80  * @param field_name
81  * @param lo lowest coefficient
82  * @param hi highest coefficient
83  * @param get_low_dim_ents get lower dimension entities
84  * @param is_distributed_mesh distributed mesh
85  * @return MoFEMErrorCode
86  */
87  MoFEMErrorCode removeBlockDOFsOnEntities(const std::string problem_name,
88  const std::string block_name,
89  const std::string field_name, int lo,
90  int hi, bool get_low_dim_ents = true,
91  bool is_distributed_mesh = true);
92 
93  /**
94  * @brief Mark block DOFs
95  *
96  * @param problem_name
97  * @param block_name
98  * @param field_name
99  * @param lo lowest coefficient
100  * @param hi highest coefficient
101  * @param get_low_dim_ents get lower dimension entities
102  * field name
103  * @return MoFEMErrorCode
104  */
105  MoFEMErrorCode pushMarkDOFsOnEntities(const std::string problem_name,
106  const std::string block_name,
107  const std::string field_name, int lo,
108  int hi, bool get_low_dim_ents = true);
109 
110  /**
111  * @brief Mark block DOFs
112  *
113  * @tparam BCSET
114  * @param problem_name
115  * @param field_name
116  * @param get_low_dim_ents
117  * @param is_distributed_mesh
118  * @param block_name_field_prefix
119  * @return MoFEMErrorCode
120  */
121  template <typename T>
122  MoFEMErrorCode removeBlockDOFsOnEntities(const std::string problem_name,
123  const std::string field_name,
124  bool get_low_dim_ents = true,
125  bool block_name_field_prefix = false,
126  bool is_distributed_mesh = true);
127 
128  /**
129  * @brief Mark block DOFs
130  *
131  * @param problem_name
132  * @param field_name
133  * @param get_low_dim_ents get lower dimension entities
134  * @param block_name_field_prefix
135  * @return MoFEMErrorCode
136  */
137  template <typename T>
138  MoFEMErrorCode pushMarkDOFsOnEntities(const std::string problem_name,
139  const std::string field_name,
140  bool get_low_dim_ents = true,
141  bool block_name_field_prefix = false);
142 
143  /**
144  * @brief Mark block DOFs
145  *
146  * @tparam BCSET
147  * @param problem_name
148  * @param field_name
149  * @param block_name
150  * @param get_low_dim_ents
151  * @param is_distributed_mesh
152  * @return MoFEMErrorCode
153  */
154  template <typename T>
155  MoFEMErrorCode removeBlockDOFsOnEntities(const std::string problem_name,
156  const std::string block_name,
157  const std::string field_name,
158  bool get_low_dim_ents = true,
159  bool is_distributed_mesh = true);
160 
161  /**
162  * @brief Mark block DOFs
163  *
164  * @param problem_name
165  * @param field_name
166  * @param block_name
167  * @param get_low_dim_ents get lower dimension entities
168  * @return MoFEMErrorCode
169  */
170  template <typename T>
171  MoFEMErrorCode pushMarkDOFsOnEntities(const std::string problem_name,
172  const std::string block_name,
173  const std::string field_name,
174  bool get_low_dim_ents = true);
175 
176  /**
177  * @brief Get bc data and remove element
178  *
179  * @param block_name
180  * @return boost::shared_ptr<BCs>
181  */
182  boost::shared_ptr<BCs> popMarkDOFsOnEntities(const std::string block_name);
183 
184  /** \todo Add markers for standard BCs from cubit on Nodests and Sidesets used
185  * bu cubit for displacements, forces, etc. Also add function to add blockset
186  * by id and type.
187  */
188 
189  using BcMapByBlockName = std::map<string, boost::shared_ptr<BCs>>;
190 
191  using BcMarkerPtr = boost::shared_ptr<std::vector<char unsigned>>;
192  /**
193  * @brief Get the bc structure object
194  *
195  * @param block_name
196  * @return auto
197  */
198  inline auto getBcStructure(const std::string bc_id) {
199  return bcMapByBlockName.at(bc_id);
200  }
201 
202  /**
203  * @brief Get the bc map
204  *
205  * @return auto
206  */
208 
209  /**
210  * @brief Merge block ranges
211  *
212  * @param bc_regex_vec
213  * @return Range
214  */
215  Range getMergedBlocksRange(std::vector<std::regex> bc_regex_vec);
216 
217  /**
218  * @brief Merge block ranges
219  *
220  * @param bc_names
221  * @return auto
222  */
223  inline auto getMergedBlocksRange(std::vector<string> bc_names) {
224  std::vector<std::regex> reg_vec(bc_names.size());
225  for (int i = 0; i != bc_names.size(); ++i) {
226  auto full_name = std::string("(.*)_") + bc_names[i] + std::string("(.*)");
227  reg_vec[i] = std::regex(full_name);
228  }
229  return getMergedBlocksRange(reg_vec);
230  }
231 
232  /**
233  * @brief Get the Merged Boundary Marker object
234  *
235  * @param bc_regex_vec boundary name regex vector
236  * @return boundaryMarker
237  */
238  BcMarkerPtr getMergedBlocksMarker(std::vector<std::regex> bc_regex_vec);
239  /**
240  * @brief Get the Merged Boundary Marker object
241  *
242  * @param bc_names vector of boundary names
243  * @return boundaryMarker
244  */
245  inline auto getMergedBlocksMarker(std::vector<string> bc_names) {
246  std::vector<std::regex> reg_vec(bc_names.size());
247  for (int i = 0; i != bc_names.size(); ++i) {
248  auto full_name = std::string("(.*)_") + bc_names[i] + std::string("(.*)");
249  reg_vec[i] = std::regex(full_name);
250  }
251  return getMergedBlocksMarker(reg_vec);
252  }
253  /**
254  * @brief Get the Merged Blocks Marker object
255  *
256  * @param boundary_markers_ptr_vec vector of boundary markers to merge
257  * @return BcMarkerPtr
258  */
260  const std::vector<BcMarkerPtr> &boundary_markers_ptr_vec);
261 
262  /**
263  * @brief check if given boundary condition name is in the map bc element
264  *
265  * @param bc element of the map
266  * @param reg bc regex
267  * @return auto
268  */
269  inline auto checkBlock(const std::pair<string, boost::shared_ptr<BCs>> &bc,
270  std::regex reg) {
271  return std::regex_match(bc.first, reg);
272  }
273  /**
274  * @brief check if given boundary condition name is in the map bc element
275  *
276  * @param bc element of the map
277  * @param name bc name
278  * @return auto
279  */
280  inline auto
281  checkBlock(const std::pair<std::string, boost::shared_ptr<BCs>> &bc,
282  std::string name) {
283  auto full_name = std::string("(.*)_") + name + std::string("(.*)");
284  return checkBlock(bc, std::regex(full_name));
285  }
286 
287  /**
288  * @brief Get block IS
289  *
290  * @param block_prefix for hashmap
291  * @param block_name for hash map
292  * @param field_name for hash map and IS
293  * @param problem_name for IS
294  * @param lo
295  * @param hi
296  * @param is_expand is to extend
297  * @return SmartPetscObj<IS>
298  */
300  getBlockIS(const std::string block_prefix, const std::string block_name,
301  const std::string field_name, const std::string problem_name,
302  int lo, int hi, SmartPetscObj<IS> is_expand = SmartPetscObj<IS>());
303 
304  /**
305  * @brief Get block IS
306  *
307  * @param problem_name
308  * @param block_name
309  * @param field_name
310  * @param lo
311  * @param hi
312  * @param is_expand is to extend
313  * @return SmartPetscObj<IS>
314  */
316  getBlockIS(const std::string problem_name, const std::string block_name,
317  const std::string field_name, int lo, int hi,
318  SmartPetscObj<IS> is_expand = SmartPetscObj<IS>());
319 
320  /**
321  * @brief Extract block name and block name form block id
322  *
323  * @param block_id
324  * @param prb_name
325  * @return std::pair<std::string, std::string>
326  */
327  static std::pair<std::string, std::string>
328  extractStringFromBlockId(const std::string block_id,
329  const std::string prb_name);
330 
331 private:
333 
335 };
336 
337 template <>
339 BcManager::removeBlockDOFsOnEntities<BcMeshsetType<DISPLACEMENTSET>>(
340  const std::string problem_name, const std::string field_name,
341  bool get_low_dim_ents, bool block_name_field_prefix,
342  bool is_distributed_mesh);
343 
344 template <>
346 BcManager::removeBlockDOFsOnEntities<BcMeshsetType<TEMPERATURESET>>(
347  const std::string problem_name, const std::string field_name,
348  bool get_low_dim_ents, bool block_name_field_prefix,
349  bool is_distributed_mesh);
350 
351 template <>
352 MoFEMErrorCode BcManager::removeBlockDOFsOnEntities<BcMeshsetType<HEATFLUXSET>>(
353  const std::string problem_name, const std::string field_name,
354  bool get_low_dim_ents, bool block_name_field_prefix,
355  bool is_distributed_mesh);
356 
357 template <>
359 BcManager::removeBlockDOFsOnEntities<BcDisplacementMeshsetType<BLOCKSET>>(
360  const std::string problem_name, const std::string field_name,
361  bool get_low_dim_ents, bool block_name_field_prefix,
362  bool is_distributed_mesh);
363 
364 template <>
366 BcManager::removeBlockDOFsOnEntities<BcScalarMeshsetType<BLOCKSET>>(
367  const std::string problem_name, const std::string block_name,
368  const std::string field_name, bool get_low_dim_ents,
369  bool is_distributed_mesh);
370 
371 template <>
373 BcManager::pushMarkDOFsOnEntities<BcMeshsetType<DISPLACEMENTSET>>(
374  const std::string problem_name, const std::string field_name,
375  bool get_low_dim_ents, bool block_name_field_prefix);
376 
377 template <>
378 MoFEMErrorCode BcManager::pushMarkDOFsOnEntities<BcMeshsetType<TEMPERATURESET>>(
379  const std::string problem_name, const std::string field_name,
380  bool get_low_dim_ents, bool block_name_field_prefix);
381 
382 template <>
383 MoFEMErrorCode BcManager::pushMarkDOFsOnEntities<BcMeshsetType<HEATFLUXSET>>(
384  const std::string problem_name, const std::string field_name,
385  bool get_low_dim_ents, bool block_name_field_prefix);
386 
387 template <>
389 BcManager::pushMarkDOFsOnEntities<BcDisplacementMeshsetType<BLOCKSET>>(
390  const std::string problem_name, const std::string field_name,
391  bool get_low_dim_ents, bool block_name_field_prefix);
392 
393 template <>
394 MoFEMErrorCode BcManager::pushMarkDOFsOnEntities<BcScalarMeshsetType<BLOCKSET>>(
395  const std::string problem_name, const std::string field_name,
396  const std::string block_name, bool get_low_dim_ents);
397 
398 template <>
399 MoFEMErrorCode BcManager::pushMarkDOFsOnEntities<DisplacementCubitBcData>(
400  const std::string problem_name, const std::string field_name,
401  bool get_low_dim_ents, bool block_name_field_prefix);
402 
403 template <>
404 MoFEMErrorCode BcManager::removeBlockDOFsOnEntities<DisplacementCubitBcData>(
405  const std::string problem_name, const std::string field_name,
406  bool get_low_dim_ents, bool block_name_field_prefix,
407  bool is_distributed_mesh);
408 
409 template <>
410 MoFEMErrorCode BcManager::pushMarkDOFsOnEntities<TemperatureCubitBcData>(
411  const std::string problem_name, const std::string field_name,
412  bool get_low_dim_ents, bool block_name_field_prefix);
413 
414 template <>
415 MoFEMErrorCode BcManager::removeBlockDOFsOnEntities<TemperatureCubitBcData>(
416  const std::string problem_name, const std::string field_name,
417  bool get_low_dim_ents, bool block_name_field_prefix,
418  bool is_distributed_mesh);
419 
420 template <>
421 MoFEMErrorCode BcManager::pushMarkDOFsOnEntities<HeatFluxCubitBcData>(
422  const std::string problem_name, const std::string field_name,
423  bool get_low_dim_ents, bool block_name_field_prefix);
424 
425 template <>
426 MoFEMErrorCode BcManager::removeBlockDOFsOnEntities<HeatFluxCubitBcData>(
427  const std::string problem_name, const std::string field_name,
428  bool get_low_dim_ents, bool block_name_field_prefix,
429  bool is_distributed_mesh);
430 
431 template <>
432 MoFEMErrorCode BcManager::pushMarkDOFsOnEntities<BcMeshsetType<FORCESET>>(
433  const std::string problem_name, const std::string field_name,
434  bool get_low_dim_ents, bool block_name_field_prefix);
435 
436 template <>
437 MoFEMErrorCode BcManager::pushMarkDOFsOnEntities<BcForceMeshsetType<BLOCKSET>>(
438  const std::string problem_name, const std::string field_name,
439  bool get_low_dim_ents, bool block_name_field_prefix);
440 
441 template <>
442 MoFEMErrorCode BcManager::pushMarkDOFsOnEntities<ForceCubitBcData>(
443  const std::string problem_name, const std::string field_name,
444  bool get_low_dim_ents, bool block_name_field_prefix);
445 
446 template <>
447 MoFEMErrorCode BcManager::removeBlockDOFsOnEntities<BcMeshsetType<FORCESET>>(
448  const std::string problem_name, const std::string field_name,
449  bool get_low_dim_ents, bool block_name_field_prefix,
450  bool is_distributed_mesh);
451 
452 template <>
454 BcManager::removeBlockDOFsOnEntities<BcForceMeshsetType<BLOCKSET>>(
455  const std::string problem_name, const std::string field_name,
456  bool get_low_dim_ents, bool block_name_field_prefix,
457  bool is_distributed_mesh);
458 
459 template <>
460 MoFEMErrorCode BcManager::removeBlockDOFsOnEntities<ForceCubitBcData>(
461  const std::string problem_name, const std::string field_name,
462  bool get_low_dim_ents, bool block_name_field_prefix,
463  bool is_distributed_mesh);
464 
465 } // namespace MoFEM
466 
467 #endif //__BCMANAGER_HPP__
468 
469 /**
470  * \defgroup bc_manager Manages boundary conditions
471  * \brief Implementation manages boundary conditions
472  *
473  * \ingroup mofem
474  **/
MoFEM::BcManager::BCs::getBcEntsPtr
auto getBcEntsPtr()
Definition: BcManager.hpp:53
MoFEM::BcManager::extractStringFromBlockId
static std::pair< std::string, std::string > extractStringFromBlockId(const std::string block_id, const std::string prb_name)
Extract block name and block name form block id.
Definition: BcManager.cpp:1389
MoFEM::BcManager::getMergedBlocksRange
auto getMergedBlocksRange(std::vector< string > bc_names)
Merge block ranges.
Definition: BcManager.hpp:223
MoFEM::BcManager::BCs::bcMarkers
std::vector< unsigned char > bcMarkers
Definition: BcManager.hpp:40
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
DEPRECATED
#define DEPRECATED
Definition: definitions.h:17
MoFEM::BcManager::popMarkDOFsOnEntities
boost::shared_ptr< BCs > popMarkDOFsOnEntities(const std::string block_name)
Get bc data and remove element.
Definition: BcManager.cpp:357
MoFEM::BcManager::query_interface
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Definition: BcManager.cpp:34
MoFEM::BcManager::checkBlock
auto checkBlock(const std::pair< std::string, boost::shared_ptr< BCs >> &bc, std::string name)
check if given boundary condition name is in the map bc element
Definition: BcManager.hpp:281
MoFEM::BcManager::BcManager
BcManager(const MoFEM::Core &core)
Definition: BcManager.cpp:41
MoFEM::BcManager::cOre
MoFEM::Core & cOre
Definition: BcManager.hpp:332
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::BcManager::BCs::getBcMarkersPtr
auto getBcMarkersPtr()
Definition: BcManager.hpp:57
MoFEM::BcManager::getOptions
MoFEMErrorCode getOptions()
get options
Definition: BcManager.cpp:65
MoFEM::BcManager::removeBlockDOFsOnEntities
MoFEMErrorCode removeBlockDOFsOnEntities(const std::string problem_name, const std::string block_name, const std::string field_name, int lo, int hi, bool get_low_dim_ents=true, bool is_distributed_mesh=true)
Remove DOFs from problem.
Definition: BcManager.cpp:73
MoFEM::BcManager::getMergedBlocksMarker
BcMarkerPtr getMergedBlocksMarker(std::vector< std::regex > bc_regex_vec)
Get the Merged Boundary Marker object.
Definition: BcManager.cpp:382
MoFEM::BcManager::BCs::bcEnts
Range bcEnts
Definition: BcManager.hpp:38
MoFEM::BcManager::pushMarkDOFsOnEntities
MoFEMErrorCode pushMarkDOFsOnEntities(const std::string problem_name, const std::string block_name, const std::string field_name, int lo, int hi, bool get_low_dim_ents=true)
Mark block DOFs.
Definition: BcManager.cpp:111
MoFEM::BcManager::BCs::tempBcPtr
boost::shared_ptr< TemperatureCubitBcData > tempBcPtr
Definition: BcManager.hpp:43
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::BcManager::BCs
Data structure storing bc markers and atributes.
Definition: BcManager.hpp:37
MoFEM::BcManager
Simple interface for fast problem set-up.
Definition: BcManager.hpp:25
MoFEM::BcManager::BCs::mpcPtr
boost::shared_ptr< MPCsType > mpcPtr
Definition: BcManager.hpp:46
MoFEM::BcManager::BCs::dispBcPtr
boost::shared_ptr< DisplacementCubitBcData > dispBcPtr
Definition: BcManager.hpp:42
MoFEM::BcManager::getBcMapByBlockName
BcMapByBlockName & getBcMapByBlockName()
Get the bc map.
Definition: BcManager.hpp:207
MoFEM::BcScalarMeshsetType
Definition: BcManager.hpp:15
MoFEM::BcManager::getBlockIS
SmartPetscObj< IS > getBlockIS(const std::string block_prefix, const std::string block_name, const std::string field_name, const std::string problem_name, int lo, int hi, SmartPetscObj< IS > is_expand=SmartPetscObj< IS >())
Get block IS.
Definition: BcManager.cpp:413
MoFEM::BcManager::checkBlock
auto checkBlock(const std::pair< string, boost::shared_ptr< BCs >> &bc, std::regex reg)
check if given boundary condition name is in the map bc element
Definition: BcManager.hpp:269
MoFEM::BcManager::BCs::heatFluxBcPtr
boost::shared_ptr< HeatFluxCubitBcData > heatFluxBcPtr
Definition: BcManager.hpp:44
MoFEM::BcFluxMeshsetType
Definition: BcManager.hpp:19
UnknownInterface.hpp
MoFEM interface.
MoFEM::BcManager::getMergedBlocksRange
Range getMergedBlocksRange(std::vector< std::regex > bc_regex_vec)
Merge block ranges.
Definition: BcManager.cpp:367
MoFEM::BcManager::BcMarkerPtr
boost::shared_ptr< std::vector< char unsigned > > BcMarkerPtr
Definition: BcManager.hpp:191
MoFEM::BcManager::BCs::forceBcPtr
boost::shared_ptr< ForceCubitBcData > forceBcPtr
Definition: BcManager.hpp:45
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
MoFEM::BcManager::addBlockDOFsToMPCs
MoFEMErrorCode addBlockDOFsToMPCs(const std::string problem_name, const std::string field_name, bool get_low_dim_ents=false, bool block_name_field_prefix=false, bool is_distributed_mesh=false)
Definition: BcManager.cpp:185
MoFEM::BcManager::BCs::getBcEdgesPtr
DEPRECATED auto getBcEdgesPtr()
Definition: BcManager.hpp:49
MoFEM::UnknownInterface
base class for all interface classes
Definition: UnknownInterface.hpp:34
MoFEM::BcManager::~BcManager
virtual ~BcManager()=default
Range
MoFEM::BcForceMeshsetType
Definition: BcManager.hpp:18
MoFEM::BcManager::getMergedBlocksMarker
auto getMergedBlocksMarker(std::vector< string > bc_names)
Get the Merged Boundary Marker object.
Definition: BcManager.hpp:245
MoFEM::BcManager::BCs::bcAttributes
std::vector< double > bcAttributes
Definition: BcManager.hpp:39
MoFEM::BcMeshsetType
Definition: BcManager.hpp:14
MoFEM::BcManager::bcMapByBlockName
BcMapByBlockName bcMapByBlockName
Definition: BcManager.hpp:334
MoFEM::BcManager::getBcStructure
auto getBcStructure(const std::string bc_id)
Get the bc structure object.
Definition: BcManager.hpp:198
MoFEM::SmartPetscObj< IS >
MoFEM::BcManager::BcMapByBlockName
std::map< string, boost::shared_ptr< BCs > > BcMapByBlockName
Definition: BcManager.hpp:189
MoFEM::BcDisplacementMeshsetType
Definition: BcManager.hpp:17