v0.8.23
BCMultiIndices.hpp
Go to the documentation of this file.
1 /** \file BCMultiIndices.hpp
2  * \brief Multi-index containers, data boundary data structures and other
3  * low-level functions
4  *
5  * MoFEM is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation, either version 3 of the License, or (at your
8  * option) any later version.
9  *
10  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
17  */
18 
19 #ifndef __BCMULTIINDICES_HPP__
20 #define __BCMULTIINDICES_HPP__
21 
22 namespace MoFEM {
23 
24 /**
25  * \brief this struct keeps basic methods for moab meshset about material and
26  * boundary conditions \ingroup mofem_bc
27  *
28  */
29 struct CubitMeshSets {
30 
32  CubitBCType cubitBcType; ///< type of meshset from cubit NodeSet, BlockSet,
33  ///< SideSet and more
34  std::vector<Tag>
35  tag_handles; ///< vector of tag handles to types of data passed from cubit
36  int *msId; ///< cubit meshset ID
37  char *tag_bc_data;
39  unsigned int *tag_block_header_data;
42  char *tagName;
44 
45  CubitMeshSets(Interface &moab, const EntityHandle _meshset);
46  CubitMeshSets(Interface &moab, const CubitBCType _cubit_bc_type,
47  const int _msId);
48 
49  /**
50  * \brief get meshset id as it set in preprocessing software
51  * @return id of meshset
52  */
53  inline int getMeshsetId() const { return *msId; }
54 
55  // /** \deprecated use getMeshsetId() instead
56  // */
57  // DEPRECATED inline int get_msId() const { return getMeshsetId(); }
58 
59  /**
60  * \brief get type of meshset
61  *
62  * See CubitBC for set of types of meshsets.
63  *
64  * @return meshset type
65  */
66  inline CubitBCType getBcType() const { return cubitBcType; }
67 
68  /**
69  * \brief get bc meshset
70  * @return meshset entity handle
71  */
72  inline EntityHandle getMeshset() const { return meshset; }
73 
74  /**
75  * \brief get bc meshset type
76  * @return return type as unsigned int
77  */
78  inline unsigned long int getBcTypeULong() const {
79  return cubitBcType.to_ulong();
80  }
81 
82  /**
83  * \brief get meshset type and mask
84  * @return type is returned as unsigned integer
85  */
86  inline unsigned long int getMaksedBcTypeULong() const {
87  return (cubitBcType & meshsets_mask).to_ulong();
88  }
89 
90  /**
91  * @brief Get the meshset entities dimension
92  *
93  * \note If dimension is -1, then dimension for meshset ins undetermined.
94  *
95  * @return unsigned int
96  */
97  unsigned int getMeshsetEntitiesDimension() const {
99  return tag_block_header_data[2];
100  else
101  return -1;
102  }
103 
104  /**
105  * \brief get entities form meshset
106  * @param moab moab instance
107  * @param dimension dimension of entities
108  * @param entities range of returned entities
109  * @param recursive true if meshset should be searched recursively
110  * @return error code
111  */
113  getMeshsetIdEntitiesByDimension(Interface &moab, const int dimension,
114  Range &entities,
115  const bool recursive = false) const;
116 
117  /**
118  * \brief get entities form meshset
119  *
120  * Use if meshset have predefined dimension
121  *
122  * @param moab moab instance
123  * @param entities range of returned entities
124  * @param recursive true if meshset should be searched recursively
125  * @return error code
126  *
127  */
129  getMeshsetIdEntitiesByDimension(Interface &moab, Range &entities,
130  const bool recursive = false) const;
131 
132  /**
133  * \brief get entities by type
134  * @param moab moab instance
135  * @param type type of entity
136  * @param entities returned entities
137  * @param recursive true if meshset should be searched recursively
138  * @return error code
139  */
141  const EntityType type,
142  Range &entities,
143  const bool recursive = false) const;
144 
145  /**
146  * \brief Function that returns the CubitBCType type of the contents of
147  * bc_data
148  */
149  MoFEMErrorCode getTypeFromBcData(const std::vector<char> &bc_data,
150  CubitBCType &type) const;
151 
152  /**
153  * \brief Function that returns the CubitBCType type of the contents of
154  * bc_data
155  */
157 
158  /**
159  * \brief get bc_data vector from MoFEM database
160  *
161  * \param bc_data is the in/out vector were bc_data will be stored
162  */
163  MoFEMErrorCode getBcData(std::vector<char> &bc_data) const;
164 
165  /**
166  * \brief get block_headers vector from MoFEM database
167  *
168  * \param material_data is the in/out vector were the material data will be
169  * stored
170  */
172  getBlockHeaderData(std::vector<unsigned int> &material_data) const;
173 
174  /**
175  * \brief print material_data int stream given by os
176  *
177  * f.e. it->print_Cubit_material_data(cout), i.e. printing to standard output
178  * f.e. it->print_Cubit_material_data(std::cerr), i.e. printing to standard
179  * error output
180  */
181  MoFEMErrorCode printBlockHeaderData(std::ostream &os) const;
182 
183  /**
184  * \brief print bc_data int stream given by os
185  *
186  * f.e. it->printBcData(cout), i.e. printing to standard output
187  * f.e. it->printBcData(std::cerr), i.e. printing to standard error output
188  */
189  MoFEMErrorCode printBcData(std::ostream &os) const;
190 
191  /**
192  * \brief Function that returns the CubitBCType type of the block name,
193  * sideset name etc.
194  */
195  MoFEMErrorCode getTypeFromName(const std::string &name,
196  CubitBCType &type) const;
197 
198  /**
199  * \brief Function that returns the CubitBCType type of the block name,
200  * sideset name etc.
201  */
203 
204  /**
205  * \brief get Cubit block attributes
206  *
207  * \param attributes is the vector where the block attribute data will be
208  * stored
209  */
210  MoFEMErrorCode getAttributes(std::vector<double> &attributes) const;
211 
212  /**
213  * \brief cet Cubit block attributes
214  *
215  * \param attributes is the vector where the block attribute data will be
216  * stored
217  */
218  MoFEMErrorCode setAttributes(moab::Interface &moab,
219  const std::vector<double> &attributes);
220 
221  /**
222  * \brief print the attributes vector
223  *
224  * f.e. it->printAttributes(cout), i.e. printing to standard output
225  * f.e. it->printAttributes(std::cerr), i.e. printing to standard error output
226  */
227  MoFEMErrorCode printAttributes(std::ostream &os) const;
228 
229  /**
230  * \brief get name of block, sideset etc. (this is set in Cubit block
231  properties)
232  *
233  * Block Name Conventions:
234 
235  * Materials are defined with block names starting with MAT_
236  * e.g. MAT_ELASTIC_abcd, MAT_FRACTcdef etc.
237  * Solution procedures are defined with block names starting with SOL_ e.g.
238  * SOL_ELASTIC_xx, SOL_NLELASTICxx, SOL_FRACTabcd etc.
239  *
240  * List of materials/solution procedures
241 
242  * Block name / Number of attributes / (1) Attribute 1, (2) Attribute 2 etc.
243  *
244  * MAT_ELASTIC / 10 / (1) Young's modulus
245  * (2) Poisson's ratio
246  * (3) User attribute 8
247  * ...
248  * (10) User attribute 8
249  *
250  * MAT_ELASTIC_TRANSISO / 5 / (1) Young's modulus in xy plane (Ep)
251  * (2) Young's modulus in z-direction (Ez)
252  * (3) Poisson's ratio in xy plane (vp)
253  * (4) Poisson's ratio in z-direction (vpz)
254  * (5) Shear modulus in z-direction (Gzp)
255  *
256  * MAT_INTERF / 1 / (1) Elastic modulus multiplier
257  *
258  * To be extended as appropriate
259  */
260  std::string getName() const;
261 
262  /**
263  * \brief print name of block, sideset etc. (this is set in Cubit setting
264  * properties)
265  *
266  * e.g. it->printName(cout), i.e. printing to standard output
267  * e.g it->printName(std::cerr), i.e. printing to standard error output
268  */
269  MoFEMErrorCode printName(std::ostream &os) const;
270 
271  /**
272  * \brief fill data structure with data saved on meshset
273  */
274  template <class ATTRIBUTE_TYPE>
275  MoFEMErrorCode getAttributeDataStructure(ATTRIBUTE_TYPE &data) const {
277 
278  if ((cubitBcType & data.getType()).none()) {
279  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
280  "attributes are not for ATTRIBUTE_TYPE structure");
281  }
282  std::vector<double> attributes;
283  ierr = getAttributes(attributes);
284  CHKERRG(ierr);
285  ierr = data.fill_data(attributes);
286  CHKERRG(ierr);
288  }
289 
290  /**
291  * \brief fill meshset data with data on structure
292  */
293  template <class ATTRIBUTE_TYPE>
294  MoFEMErrorCode setAttributeDataStructure(const ATTRIBUTE_TYPE &data) {
296 
297  if ((cubitBcType & data.getType()).none()) {
298  SETERRQ(PETSC_COMM_SELF, 1,
299  "attributes are not for ATTRIBUTE_TYPE structure");
300  }
301  double *ptr = const_cast<double *>(tag_block_attributes);
302  ierr = data.set_data(ptr, 8 * tag_block_attributes_size);
303  CHKERRG(ierr);
305  }
306 
307  template <class CUBIT_BC_DATA_TYPE>
308  MoFEMErrorCode getBcDataStructure(CUBIT_BC_DATA_TYPE &data) const {
310 
311  if ((cubitBcType & data.tYpe).none()) {
312  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
313  "bc_data are not for CUBIT_BC_DATA_TYPE structure");
314  }
315  std::vector<char> bc_data;
316  getBcData(bc_data);
317  ierr = data.fill_data(bc_data);
318  CHKERRG(ierr);
320  }
321 
322  template <class CUBIT_BC_DATA_TYPE>
323  MoFEMErrorCode setBcDataStructure(CUBIT_BC_DATA_TYPE &data) {
325 
326  char *ptr = const_cast<char *>(tag_bc_data);
327  ierr = data.set_data(ptr, tag_bc_size);
328  CHKERRG(ierr);
330  }
331 
332  friend std::ostream &operator<<(std::ostream &os, const CubitMeshSets &e);
333 
336 
338 };
339 
340 /**
341  * \typedef CubitMeshSet_multiIndex
342  * \brief Stores data about meshsets (see CubitMeshSets) storing data about
343  * boundary conditions, interfaces, sidesets, nodests, blocksets
344  *
345  * \param Meshset_mi_tag index by meshset handle
346  * \param CubitMeshSets_mi_tag index by bc type, see CubitBC
347  * \param CubitMeshSets_mask_meshset_mi_tag index by NODESET, SIDESET, BLOCKSET
348  * only \param CubitMeshSets_name index by meshset name \param
349  * Composite_Cubit_msId_And_MeshSetType_mi_tag index by meshset id and type
350  * NODESET, SIDESET or BLOCKSET
351  *
352  * Example:
353  * \code
354  * MeshsetsManager *m_mng;
355  * ierr = m_field.getInterface(m_mng); CHKERRG(ierr);
356  * CubitMeshSet_multiIndex &meshsets_index = m_mng->etMeshsetsMultindex();
357  *
358  * CubitMeshSet_multiIndex::index<CubitMeshSets_mask_meshset_mi_tag>::type::iterator
359  * mit,hi_mit; mit =
360  * meshsets_index.get<CubitMeshSets_mask_meshset_mi_tag>().lower_bound(BLOCKSET);
361  * hi_mit =
362  * meshsets_index.get<CubitMeshSets_mask_meshset_mi_tag>().upper_bound(BLOCKSET);
363  * // Make a loop over all BLOCKSET
364  * for(;mit!=hi_mit;mit++) {
365  * int id = mit->getMeshsetId(); // get blockset id
366  * EntityHandle handle = mit->getMeshset(); // get block meshset
367  * std::vector< double > attributes;
368  * // get block attributes
369  * ierr = mit->getAttributes(attributes); CHKERRG(ierr);
370  * // do something
371  * }
372  * \endcode
373  *
374  */
375 typedef multi_index_container<
377  indexed_by<
378  hashed_unique<tag<Meshset_mi_tag>, member<CubitMeshSets, EntityHandle,
380  ordered_non_unique<tag<CubitMeshSets_mi_tag>,
381  const_mem_fun<CubitMeshSets, unsigned long int,
383  ordered_non_unique<tag<CubitMeshSets_mask_meshset_mi_tag>,
384  const_mem_fun<CubitMeshSets, unsigned long int,
386  ordered_non_unique<
387  tag<CubitMeshSets_name>,
388  const_mem_fun<CubitMeshSets, std::string, &CubitMeshSets::getName>>,
389  hashed_unique<
390  tag<Composite_Cubit_msId_And_MeshSetType_mi_tag>,
391  composite_key<
393  const_mem_fun<CubitMeshSets, int, &CubitMeshSets::getMeshsetId>,
394  const_mem_fun<CubitMeshSets, unsigned long int,
397 
398 /** \brief change meshset type
399  */
403  : bIt(bit){};
404  void operator()(CubitMeshSets &e);
405 };
406 
407 /**
408  * \brief change meshset name
409  */
412  std::string nAme;
413  CubitMeshSets_change_name(Interface &moab, const std::string &name)
414  : mOab(moab), nAme(name){};
415  void operator()(CubitMeshSets &e);
416 };
417 
418 /**
419  * change meshset attributes
420  */
423  const std::vector<double> &aTtr;
425  const std::vector<double> &attr)
426  : mOab(moab), aTtr(attr) {}
427  void operator()(CubitMeshSets &e);
428 };
429 
430 /**
431  * change meshset attributes for material data structure
432  */
437  Interface &moab, const GenericAttributeData &attr)
438  : mOab(moab), aTtr(attr) {}
439  void operator()(CubitMeshSets &e);
440 };
441 
442 /**
443  * change meshset attributes for material data structure
444  */
449  const GenericCubitBcData &bc_data)
450  : mOab(moab), bcData(bc_data) {}
451  void operator()(CubitMeshSets &e);
452 };
453 
454 } // namespace MoFEM
455 
456 #endif // __BCMULTIINDICES_HPP__
457 
458 /**
459  * \defgroup mofem_bc Boundary conditions
460  * \ingroup mofem
461  */
Generic bc data structure.
Definition: BCData.hpp:30
MoFEMErrorCode printBcData(std::ostream &os) const
print bc_data int stream given by os
friend std::ostream & operator<<(std::ostream &os, const CubitMeshSets &e)
MoFEMErrorCode printAttributes(std::ostream &os) const
print the attributes vector
unsigned long int getBcTypeULong() const
get bc meshset type
CubitMeshSets(Interface &moab, const EntityHandle _meshset)
const CubitBCType meshsets_mask
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:501
MoFEMErrorCode getAttributeDataStructure(ATTRIBUTE_TYPE &data) const
fill data structure with data saved on meshset
MoFEMErrorCode printBlockHeaderData(std::ostream &os) const
print material_data int stream given by os
MoFEMErrorCode getMeshsetIdEntitiesByDimension(Interface &moab, const int dimension, Range &entities, const bool recursive=false) const
get entities form meshset
this struct keeps basic methods for moab meshset about material and boundary conditions
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:544
MoFEMErrorCode getTagsHanlders(Interface &moab)
const std::vector< double > & aTtr
CubitMeshSets_change_add_bit_to_cubit_bc_type(const CubitBCType &bit)
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:508
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
std::vector< Tag > tag_handles
vector of tag handles to types of data passed from cubit
multi_index_container< CubitMeshSets, indexed_by< hashed_unique< tag< Meshset_mi_tag >, member< CubitMeshSets, EntityHandle, &CubitMeshSets::meshset > >, ordered_non_unique< tag< CubitMeshSets_mi_tag >, const_mem_fun< CubitMeshSets, unsigned long int, &CubitMeshSets::getBcTypeULong > >, ordered_non_unique< tag< CubitMeshSets_mask_meshset_mi_tag >, const_mem_fun< CubitMeshSets, unsigned long int, &CubitMeshSets::getMaksedBcTypeULong > >, ordered_non_unique< tag< CubitMeshSets_name >, const_mem_fun< CubitMeshSets, std::string, &CubitMeshSets::getName > >, hashed_unique< tag< Composite_Cubit_msId_And_MeshSetType_mi_tag >, composite_key< CubitMeshSets, const_mem_fun< CubitMeshSets, int, &CubitMeshSets::getMeshsetId >, const_mem_fun< CubitMeshSets, unsigned long int, &CubitMeshSets::getMaksedBcTypeULong > > > > > CubitMeshSet_multiIndex
Stores data about meshsets (see CubitMeshSets) storing data about boundary conditions,...
CubitBCType getBcType() const
get type of meshset
MoFEMErrorCode getBlockHeaderData(std::vector< unsigned int > &material_data) const
get block_headers vector from MoFEM database
MoFEMErrorCode setBcDataStructure(CUBIT_BC_DATA_TYPE &data)
MoFEMErrorCode getTypeFromName(const std::string &name, CubitBCType &type) const
Function that returns the CubitBCType type of the block name, sideset name etc.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:66
CubitMeshSets_change_attributes(Interface &moab, const std::vector< double > &attr)
std::string getName() const
get name of block, sideset etc. (this is set in Cubit block properties)
EntityHandle getMeshset() const
get bc meshset
unsigned long int getMaksedBcTypeULong() const
get meshset type and mask
MoFEMErrorCode getBcDataStructure(CUBIT_BC_DATA_TYPE &data) const
MoFEMErrorCode getAttributes(std::vector< double > &attributes) const
get Cubit block attributes
Generic attribute data structure.
CubitMeshSets_change_bc_data_structure(Interface &moab, const GenericCubitBcData &bc_data)
MoFEMErrorCode printName(std::ostream &os) const
print name of block, sideset etc. (this is set in Cubit setting properties)
MoFEMErrorCode getMeshsetIdEntitiesByType(Interface &moab, const EntityType type, Range &entities, const bool recursive=false) const
get entities by type
unsigned int getMeshsetEntitiesDimension() const
Get the meshset entities dimension.
MoFEMErrorCode getTypeFromBcData(const std::vector< char > &bc_data, CubitBCType &type) const
Function that returns the CubitBCType type of the contents of bc_data.
std::bitset< 32 > CubitBCType
Definition: Types.hpp:63
void operator()(CubitMeshSets &e)
unsigned int * tag_block_header_data
CubitMeshSets_change_name(Interface &moab, const std::string &name)
int getMeshsetId() const
get meshset id as it set in preprocessing software
int * msId
cubit meshset ID
MoFEMErrorCode setAttributes(moab::Interface &moab, const std::vector< double > &attributes)
cet Cubit block attributes
MoFEMErrorCode setAttributeDataStructure(const ATTRIBUTE_TYPE &data)
fill meshset data with data on structure
MoFEMErrorCode getBcData(std::vector< char > &bc_data) const
get bc_data vector from MoFEM database
CubitMeshSets_change_attributes_data_structure(Interface &moab, const GenericAttributeData &attr)