v0.13.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 /* MoFEM is distributed in the hope that it will be useful, but WITHOUT
8  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  * License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
14  */
15 
16 #ifndef __BCMANAGER_HPP__
17 #define __BCMANAGER_HPP__
18 
19 #include "UnknownInterface.hpp"
20 
21 namespace MoFEM {
22 
23 /**
24  * \brief Simple interface for fast problem set-up
25  * \ingroup mofem_simple_interface
26  */
27 struct BcManager : public UnknownInterface {
28 
29  MoFEMErrorCode query_interface(boost::typeindex::type_index type_index,
30  UnknownInterface **iface) const;
31 
32  BcManager(const MoFEM::Core &core);
33  virtual ~BcManager() = default;
34 
35  /**
36  * @brief Data structure storing bc markers and atributes
37  *
38  */
39  struct BCs : boost::enable_shared_from_this<BCs> {
40  Range bcEnts;
41  std::vector<double> bcAttributes;
42  std::vector<unsigned char> bcMarkers;
43 
44  /// \deprecated use getBcEntsPtr
45  DEPRECATED inline auto getBcEdgesPtr() {
46  return boost::shared_ptr<Range>(shared_from_this(), &bcEnts);
47  }
48 
49  inline auto getBcEntsPtr() {
50  return boost::shared_ptr<Range>(shared_from_this(), &bcEnts);
51  }
52 
53  inline auto getBcMarkersPtr() {
54  return boost::shared_ptr<std::vector<unsigned char>>(shared_from_this(),
55  &bcMarkers);
56  }
57  };
58 
59  /**
60  * \brief get options
61  * @return error code
62  */
64 
65  Range getAdjEnts(Range ents);
66 
67  /**
68  * @brief Remove DOFs from problem
69  *
70  * @param problem_name
71  * @param block_name
72  * @param field_name
73  * @param lo lowest coefficient
74  * @param hi highest coefficient
75  * @param get_low_dim_ents get lower dimension entities
76  * @return MoFEMErrorCode
77  */
78  MoFEMErrorCode removeBlockDOFsOnEntities(const std::string problem_name,
79  const std::string block_name,
80  const std::string field_name, int lo,
81  int hi,
82  bool get_low_dim_ents = true);
83 
84  /**
85  * @brief Mark block dofs
86  *
87  * @param problem_name
88  * @param block_name
89  * @param field_name
90  * @param lo lowest coefficient
91  * @param hi highest coefficient
92  * @param get_low_dim_ents get lower dimension entities
93  * @return MoFEMErrorCode
94  */
95  MoFEMErrorCode pushMarkDOFsOnEntities(const std::string problem_name,
96  const std::string block_name,
97  const std::string field_name, int lo,
98  int hi, bool get_low_dim_ents = true);
99 
100  /**
101  * @brief Get bc data and remove element
102  *
103  * @param block_name
104  * @return boost::shared_ptr<BCs>
105  */
106  boost::shared_ptr<BCs> popMarkDOFsOnEntities(const std::string block_name);
107 
108  /** \todo Add markers for standard BCs from cubit on Nodests and Sidesets used
109  * bu cubit for displacements, forces, etc. Also add function to add blockset
110  * by id and type.
111  */
112 
113  using BcMapByBlockName = std::map<string, boost::shared_ptr<BCs>>;
114 
115  using BcMarkerPtr = boost::shared_ptr<std::vector<char unsigned>>;
116  /**
117  * @brief Get the bc structure object
118  *
119  * @param block_name
120  * @return auto
121  */
122  inline auto getBcStructure(const std::string bc_id) {
123  return bcMapByBlockName.at(bc_id);
124  }
125 
126  /**
127  * @brief Get the bc map
128  *
129  * @return auto
130  */
132 
133  /**
134  * @brief Get the Merged Boundary Marker object
135  *
136  * @param bc_regex_vec boundary name regex vector
137  * @return boundaryMarker
138  */
139  BcMarkerPtr getMergedBlocksMarker(std::vector<std::regex> bc_regex_vec);
140  /**
141  * @brief Get the Merged Boundary Marker object
142  *
143  * @param bc_names vector of boundary names
144  * @return boundaryMarker
145  */
146  inline auto getMergedBlocksMarker(std::vector<string> bc_names) {
147  std::vector<std::regex> reg_vec(bc_names.size());
148  for (int i = 0; i != bc_names.size(); ++i) {
149  string full_name = string("(.*)_") + bc_names[i] + string("(.*)");
150  reg_vec[i] = std::regex(full_name);
151  }
152  return getMergedBlocksMarker(reg_vec);
153  }
154  /**
155  * @brief Get the Merged Blocks Marker object
156  *
157  * @param boundary_markers_ptr_vec vector of boundary markers to merge
158  * @return BcMarkerPtr
159  */
161  const std::vector<BcMarkerPtr> &boundary_markers_ptr_vec);
162  /**
163  * @brief check if given boundary condition name is in the map bc element
164  *
165  * @param bc element of the map
166  * @param reg bc regex
167  * @return auto
168  */
169  inline auto checkBlock(const std::pair<string, boost::shared_ptr<BCs>> &bc,
170  std::regex reg) {
171  return std::regex_match(bc.first, reg);
172  }
173  /**
174  * @brief check if given boundary condition name is in the map bc element
175  *
176  * @param bc element of the map
177  * @param name bc name
178  * @return auto
179  */
180  inline auto checkBlock(const std::pair<string, boost::shared_ptr<BCs>> &bc,
181  std::string name) {
182  string full_name = string("(.*)_") + name + string("(.*)");
183  return checkBlock(bc, std::regex(full_name));
184  }
185 
186  /**
187  * @brief Get block is
188  *
189  * @param block_prefix for hashmap
190  * @param block_name for hash map
191  * @param field_name for hash map and IS
192  * @param problem_name for IS
193  * @param lo
194  * @param hi
195  * @param is_expand is to extend
196  * @return SmartPetscObj<IS>
197  */
199  getBlockIS(const std::string block_prefix, const std::string block_name,
200  const std::string field_name, const std::string problem_name,
201  int lo, int hi, SmartPetscObj<IS> is_expand = SmartPetscObj<IS>());
202 
203  /**
204  * @brief Get block is
205  *
206  * @param problem_name
207  * @param block_name
208  * @param field_name
209  * @param lo
210  * @param hi
211  * @param is_expand is to extend
212  * @return SmartPetscObj<IS>
213  */
215  getBlockIS(const std::string problem_name, const std::string block_name,
216  const std::string field_name, int lo, int hi,
217  SmartPetscObj<IS> is_expand = SmartPetscObj<IS>());
218 
219 private:
221 
223 };
224 
225 } // namespace MoFEM
226 
227 #endif //__BCMANAGER_HPP__
228 
229 /**
230  * \defgroup bc_manager Manages boundary conditions
231  * \brief Implementation manages boundary conditions
232  *
233  * \ingroup mofem
234  **/
MoFEM interface.
#define DEPRECATED
Definition: definitions.h:30
FTensor::Index< 'i', SPACE_DIM > i
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
Data structure storing bc markers and atributes.
Definition: BcManager.hpp:39
std::vector< unsigned char > bcMarkers
Definition: BcManager.hpp:42
std::vector< double > bcAttributes
Definition: BcManager.hpp:41
DEPRECATED auto getBcEdgesPtr()
Definition: BcManager.hpp:45
Simple interface for fast problem set-up.
Definition: BcManager.hpp:27
boost::shared_ptr< std::vector< char unsigned > > BcMarkerPtr
Definition: BcManager.hpp:115
MoFEMErrorCode getOptions()
get options
Definition: BcManager.cpp:54
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)
Remove DOFs from problem.
Definition: BcManager.cpp:63
BcMarkerPtr getMergedBlocksMarker(std::vector< std::regex > bc_regex_vec)
Get the Merged Boundary Marker object.
Definition: BcManager.cpp:209
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:169
auto checkBlock(const std::pair< string, boost::shared_ptr< BCs >> &bc, std::string name)
check if given boundary condition name is in the map bc element
Definition: BcManager.hpp:180
BcMapByBlockName & getBcMapByBlockName()
Get the bc map.
Definition: BcManager.hpp:131
auto getMergedBlocksMarker(std::vector< string > bc_names)
Get the Merged Boundary Marker object.
Definition: BcManager.hpp:146
MoFEM::Core & cOre
Definition: BcManager.hpp:220
BcMapByBlockName bcMapByBlockName
Definition: BcManager.hpp:222
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:238
virtual ~BcManager()=default
std::map< string, boost::shared_ptr< BCs > > BcMapByBlockName
Definition: BcManager.hpp:113
BcManager(const MoFEM::Core &core)
Definition: BcManager.cpp:30
auto getBcStructure(const std::string bc_id)
Get the bc structure object.
Definition: BcManager.hpp:122
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Definition: BcManager.cpp:23
boost::shared_ptr< BCs > popMarkDOFsOnEntities(const std::string block_name)
Get bc data and remove element.
Definition: BcManager.cpp:198
Range getAdjEnts(Range ents)
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:121
Core (interface) class.
Definition: Core.hpp:92
base class for all interface classes