v0.9.1
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  */
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.
237  *
238  * List of materials/solution procedures
239 
240  * Block name / Number of attributes / (1) Attribute 1, (2) Attribute 2 etc.
241  *
242  * MAT_ELASTIC / 10 / (1) Young's modulus
243  * (2) Poisson's ratio
244  * (3) User attribute 8
245  * ...
246  * (10) User attribute 8
247  *
248  * MAT_ELASTIC_TRANSISO / 5 / (1) Young's modulus in xy plane (Ep)
249  * (2) Young's modulus in z-direction (Ez)
250  * (3) Poisson's ratio in xy plane (vp)
251  * (4) Poisson's ratio in z-direction (vpz)
252  * (5) Shear modulus in z-direction (Gzp)
253  *
254  * MAT_INTERF / 1 / (1) Elastic modulus multiplier
255  *
256  * To be extended as appropriate
257  */
258  std::string getName() const;
259 
260  /**
261  * \brief print name of block, sideset etc. (this is set in Cubit setting
262  * properties)
263  *
264  * e.g. it->printName(cout), i.e. printing to standard output
265  * e.g it->printName(std::cerr), i.e. printing to standard error output
266  */
267  MoFEMErrorCode printName(std::ostream &os) const;
268 
269  /**
270  * \brief fill data structure with data saved on meshset
271  */
272  template <class ATTRIBUTE_TYPE>
273  MoFEMErrorCode getAttributeDataStructure(ATTRIBUTE_TYPE &data) const {
275 
276  if ((cubitBcType & data.getType()).none()) {
277  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
278  "attributes are not for ATTRIBUTE_TYPE structure");
279  }
280  std::vector<double> attributes;
281  ierr = getAttributes(attributes);
282  CHKERRG(ierr);
283  ierr = data.fill_data(attributes);
284  CHKERRG(ierr);
286  }
287 
288  /**
289  * \brief fill meshset data with data on structure
290  */
291  template <class ATTRIBUTE_TYPE>
292  MoFEMErrorCode setAttributeDataStructure(const ATTRIBUTE_TYPE &data) {
294 
295  if ((cubitBcType & data.getType()).none()) {
296  SETERRQ(PETSC_COMM_SELF, 1,
297  "attributes are not for ATTRIBUTE_TYPE structure");
298  }
299  double *ptr = const_cast<double *>(tag_block_attributes);
300  ierr = data.set_data(ptr, 8 * tag_block_attributes_size);
301  CHKERRG(ierr);
303  }
304 
305  template <class CUBIT_BC_DATA_TYPE>
306  MoFEMErrorCode getBcDataStructure(CUBIT_BC_DATA_TYPE &data) const {
308 
309  if ((cubitBcType & data.tYpe).none()) {
310  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
311  "bc_data are not for CUBIT_BC_DATA_TYPE structure");
312  }
313  std::vector<char> bc_data;
314  getBcData(bc_data);
315  ierr = data.fill_data(bc_data);
316  CHKERRG(ierr);
318  }
319 
320  template <class CUBIT_BC_DATA_TYPE>
321  MoFEMErrorCode setBcDataStructure(CUBIT_BC_DATA_TYPE &data) {
323 
324  char *ptr = const_cast<char *>(tag_bc_data);
325  ierr = data.set_data(ptr, tag_bc_size);
326  CHKERRG(ierr);
328  }
329 
330  friend std::ostream &operator<<(std::ostream &os, const CubitMeshSets &e);
331 
334 
336 };
337 
338 /**
339  * \typedef CubitMeshSet_multiIndex
340  * \brief Stores data about meshsets (see CubitMeshSets) storing data about
341  * boundary conditions, interfaces, sidesets, nodests, blocksets
342  *
343  * \param Meshset_mi_tag index by meshset handle
344  * \param CubitMeshSets_mi_tag index by bc type, see CubitBC
345  * \param CubitMeshSets_mask_meshset_mi_tag index by NODESET, SIDESET, BLOCKSET
346  * only
347  *
348  * \param CubitMeshSets_name index by meshset name
349  *
350  * \param Composite_Cubit_msId_And_MeshSetType_mi_tag index by meshset id and
351  * type NODESET, SIDESET or BLOCKSET
352  *
353  * Example:
354  * \code
355  * MeshsetsManager *m_mng;
356  * CHKERR m_field.getInterface(m_mng);
357  * auto &index = m_mng->getMeshsetsMultindex();
358  *
359  *
360  * auto mit =
361  * index.get<CubitMeshSets_mask_meshset_mi_tag>().lower_bound(BLOCKSET); auto
362  * hi_mit =
363  * index.get<CubitMeshSets_mask_meshset_mi_tag>().upper_bound(BLOCKSET);
364  *
365  * // Make a loop over all BLOCKSET
366  * for(;mit!=hi_mit;mit++) {
367  * int id = mit->getMeshsetId(); // get blockset id
368  * EntityHandle handle = mit->getMeshset(); // get block meshset
369  * std::vector< double > attributes;
370  * // get block attributes
371  * auto mit->getAttributes(attributes);
372  * // do something
373  * }
374  * \endcode
375  *
376  */
377 typedef multi_index_container<
379  indexed_by<
380  hashed_unique<tag<Meshset_mi_tag>, member<CubitMeshSets, EntityHandle,
382  ordered_non_unique<tag<CubitMeshSets_mi_tag>,
383  const_mem_fun<CubitMeshSets, unsigned long int,
385  ordered_non_unique<tag<CubitMeshSets_mask_meshset_mi_tag>,
386  const_mem_fun<CubitMeshSets, unsigned long int,
388  ordered_non_unique<
389  tag<CubitMeshSets_name>,
390  const_mem_fun<CubitMeshSets, std::string, &CubitMeshSets::getName>>,
391  hashed_unique<
392  tag<Composite_Cubit_msId_And_MeshSetType_mi_tag>,
393  composite_key<
395  const_mem_fun<CubitMeshSets, int, &CubitMeshSets::getMeshsetId>,
396  const_mem_fun<CubitMeshSets, unsigned long int,
399 
400 /** \brief change meshset type
401  */
405  : bIt(bit){};
406  void operator()(CubitMeshSets &e);
407 };
408 
409 /**
410  * \brief change meshset name
411  */
414  std::string nAme;
415  CubitMeshSets_change_name(Interface &moab, const std::string &name)
416  : mOab(moab), nAme(name){};
417  void operator()(CubitMeshSets &e);
418 };
419 
420 /**
421  * change meshset attributes
422  */
425  const std::vector<double> &aTtr;
427  const std::vector<double> &attr)
428  : mOab(moab), aTtr(attr) {}
429  void operator()(CubitMeshSets &e);
430 };
431 
432 /**
433  * change meshset attributes for material data structure
434  */
439  Interface &moab, const GenericAttributeData &attr)
440  : mOab(moab), aTtr(attr) {}
441  void operator()(CubitMeshSets &e);
442 };
443 
444 /**
445  * change meshset attributes for material data structure
446  */
451  const GenericCubitBcData &bc_data)
452  : mOab(moab), bcData(bc_data) {}
453  void operator()(CubitMeshSets &e);
454 };
455 
456 } // namespace MoFEM
457 
458 #endif // __BCMULTIINDICES_HPP__
459 
460 /**
461  * \defgroup mofem_bc Boundary conditions
462  * \ingroup mofem
463  */
Generic bc data structure.
Definition: BCData.hpp:31
MoFEMErrorCode printBcData(std::ostream &os) const
print bc_data int stream given by os
Deprecated interface functions.
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:506
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:549
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:513
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 getTagsHandlers(Interface &moab)
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:62
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1791
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)