v0.8.16
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 integer
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 entities form meshset
92  * @param moab moab instance
93  * @param dimension dimension of entities
94  * @param entities range of returned entities
95  * @param recursive true if meshset should be searched recursively
96  * @return error code
97  */
99  getMeshsetIdEntitiesByDimension(Interface &moab, const int dimension,
100  Range &entities,
101  const bool recursive = false) const;
102 
103  /**
104  * \brief get entities form meshset
105  *
106  * Use if meshset have predefined dimension
107  *
108  * @param moab moab instance
109  * @param entities range of returned entities
110  * @param recursive true if meshset should be searched recursively
111  * @return error code
112  *
113  */
116  const bool recursive = false) const;
117 
118  /**
119  * \brief get entities by type
120  * @param moab moab instance
121  * @param type type of entity
122  * @param entities returned entities
123  * @param recursive true if meshset should be searched recursively
124  * @return error code
125  */
127  const EntityType type,
128  Range &entities,
129  const bool recursive = false) const;
130 
131  /**
132  * \brief Function that returns the CubitBCType type of the contents of
133  * bc_data
134  */
135  MoFEMErrorCode getTypeFromBcData(const std::vector<char> &bc_data,
136  CubitBCType &type) const;
137 
138  /**
139  * \brief Function that returns the CubitBCType type of the contents of
140  * bc_data
141  */
143 
144  /**
145  * \brief get bc_data vector from MoFEM database
146  *
147  * \param bc_data is the in/out vector were bc_data will be stored
148  */
149  MoFEMErrorCode getBcData(std::vector<char> &bc_data) const;
150 
151  /**
152  * \brief get block_headers vector from MoFEM database
153  *
154  * \param material_data is the in/out vector were the material data will be
155  * stored
156  */
158  getBlockHeaderData(std::vector<unsigned int> &material_data) const;
159 
160  /**
161  * \brief print material_data int stream given by os
162  *
163  * f.e. it->print_Cubit_material_data(cout), i.e. printing to standard output
164  * f.e. it->print_Cubit_material_data(std::cerr), i.e. printing to standard
165  * error output
166  */
167  MoFEMErrorCode printBlockHeaderData(std::ostream &os) const;
168 
169  /**
170  * \brief print bc_data int stream given by os
171  *
172  * f.e. it->printBcData(cout), i.e. printing to standard output
173  * f.e. it->printBcData(std::cerr), i.e. printing to standard error output
174  */
175  MoFEMErrorCode printBcData(std::ostream &os) const;
176 
177  /**
178  * \brief Function that returns the CubitBCType type of the block name,
179  * sideset name etc.
180  */
181  MoFEMErrorCode getTypeFromName(const std::string &name,
182  CubitBCType &type) const;
183 
184  /**
185  * \brief Function that returns the CubitBCType type of the block name,
186  * sideset name etc.
187  */
189 
190  /**
191  * \brief get Cubit block attributes
192  *
193  * \param attributes is the vector where the block attribute data will be
194  * stored
195  */
196  MoFEMErrorCode getAttributes(std::vector<double> &attributes) const;
197 
198  /**
199  * \brief cet Cubit block attributes
200  *
201  * \param attributes is the vector where the block attribute data will be
202  * stored
203  */
204  MoFEMErrorCode setAttributes(moab::Interface &moab,
205  const std::vector<double> &attributes);
206 
207  /**
208  * \brief print the attributes vector
209  *
210  * f.e. it->printAttributes(cout), i.e. printing to standard output
211  * f.e. it->printAttributes(std::cerr), i.e. printing to standard error output
212  */
213  MoFEMErrorCode printAttributes(std::ostream &os) const;
214 
215  /**
216  * \brief get name of block, sideset etc. (this is set in Cubit block
217  properties)
218  *
219  * Block Name Conventions:
220 
221  * Materials are defined with block names starting with MAT_
222  * e.g. MAT_ELASTIC_abcd, MAT_FRACTcdef etc.
223  * Solution procedures are defined with block names starting with SOL_ e.g.
224  * SOL_ELASTIC_xx, SOL_NLELASTICxx, SOL_FRACTabcd etc.
225  *
226  * List of materials/solution procedures
227 
228  * Block name / Number of attributes / (1) Attribute 1, (2) Attribute 2 etc.
229  *
230  * MAT_ELASTIC / 10 / (1) Young's modulus
231  * (2) Poisson's ratio
232  * (3) User attribute 8
233  * ...
234  * (10) User attribute 8
235  *
236  * MAT_ELASTIC_TRANSISO / 5 / (1) Young's modulus in xy plane (Ep)
237  * (2) Young's modulus in z-direction (Ez)
238  * (3) Poisson's ratio in xy plane (vp)
239  * (4) Poisson's ratio in z-direction (vpz)
240  * (5) Shear modulus in z-direction (Gzp)
241  *
242  * MAT_INTERF / 1 / (1) Elastic modulus multiplier
243  *
244  * To be extended as appropriate
245  */
246  std::string getName() const;
247 
248  /**
249  * \brief print name of block, sideset etc. (this is set in Cubit setting
250  * properties)
251  *
252  * e.g. it->printName(cout), i.e. printing to standard output
253  * e.g it->printName(std::cerr), i.e. printing to standard error output
254  */
255  MoFEMErrorCode printName(std::ostream &os) const;
256 
257  /**
258  * \brief fill data structure with data saved on meshset
259  */
260  template <class ATTRIBUTE_TYPE>
261  MoFEMErrorCode getAttributeDataStructure(ATTRIBUTE_TYPE &data) const {
263 
264  if ((cubitBcType & data.getType()).none()) {
265  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
266  "attributes are not for ATTRIBUTE_TYPE structure");
267  }
268  std::vector<double> attributes;
269  ierr = getAttributes(attributes);
270  CHKERRG(ierr);
271  ierr = data.fill_data(attributes);
272  CHKERRG(ierr);
274  }
275 
276  /**
277  * \brief fill meshset data with data on structure
278  */
279  template <class ATTRIBUTE_TYPE>
280  MoFEMErrorCode setAttributeDataStructure(const ATTRIBUTE_TYPE &data) {
282 
283  if ((cubitBcType & data.getType()).none()) {
284  SETERRQ(PETSC_COMM_SELF, 1,
285  "attributes are not for ATTRIBUTE_TYPE structure");
286  }
287  double *ptr = const_cast<double *>(tag_block_attributes);
288  ierr = data.set_data(ptr, 8 * tag_block_attributes_size);
289  CHKERRG(ierr);
291  }
292 
293  template <class CUBIT_BC_DATA_TYPE>
294  MoFEMErrorCode getBcDataStructure(CUBIT_BC_DATA_TYPE &data) const {
296 
297  if ((cubitBcType & data.tYpe).none()) {
298  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
299  "bc_data are not for CUBIT_BC_DATA_TYPE structure");
300  }
301  std::vector<char> bc_data;
302  getBcData(bc_data);
303  ierr = data.fill_data(bc_data);
304  CHKERRG(ierr);
306  }
307 
308  template <class CUBIT_BC_DATA_TYPE>
309  MoFEMErrorCode setBcDataStructure(CUBIT_BC_DATA_TYPE &data) {
311 
312  char *ptr = const_cast<char *>(tag_bc_data);
313  ierr = data.set_data(ptr, tag_bc_size);
314  CHKERRG(ierr);
316  }
317 
318  friend std::ostream &operator<<(std::ostream &os, const CubitMeshSets &e);
319 
322 
324 };
325 
326 /**
327  * \typedef CubitMeshSet_multiIndex
328  * \brief Stores data about meshsets (see CubitMeshSets) storing data about
329  * boundary conditions, interfaces, sidesets, nodests, blocksets
330  *
331  * \param Meshset_mi_tag index by meshset handle
332  * \param CubitMeshSets_mi_tag index by bc type, see CubitBC
333  * \param CubitMeshSets_mask_meshset_mi_tag index by NODESET, SIDESET, BLOCKSET
334  * only \param CubitMeshSets_name index by meshset name \param
335  * Composite_Cubit_msId_And_MeshSetType_mi_tag index by meshset id and type
336  * NODESET, SIDESET or BLOCKSET
337  *
338  * Example:
339  * \code
340  * MeshsetsManager *m_mng;
341  * ierr = m_field.getInterface(m_mng); CHKERRG(ierr);
342  * CubitMeshSet_multiIndex &meshsets_index = m_mng->etMeshsetsMultindex();
343  *
344  * CubitMeshSet_multiIndex::index<CubitMeshSets_mask_meshset_mi_tag>::type::iterator
345  * mit,hi_mit; mit =
346  * meshsets_index.get<CubitMeshSets_mask_meshset_mi_tag>().lower_bound(BLOCKSET);
347  * hi_mit =
348  * meshsets_index.get<CubitMeshSets_mask_meshset_mi_tag>().upper_bound(BLOCKSET);
349  * // Make a loop over all BLOCKSET
350  * for(;mit!=hi_mit;mit++) {
351  * int id = mit->getMeshsetId(); // get blockset id
352  * EntityHandle handle = mit->getMeshset(); // get block meshset
353  * std::vector< double > attributes;
354  * // get block attributes
355  * ierr = mit->getAttributes(attributes); CHKERRG(ierr);
356  * // do something
357  * }
358  * \endcode
359  *
360  */
361 typedef multi_index_container<
363  indexed_by<
364  hashed_unique<tag<Meshset_mi_tag>, member<CubitMeshSets, EntityHandle,
366  ordered_non_unique<tag<CubitMeshSets_mi_tag>,
367  const_mem_fun<CubitMeshSets, unsigned long int,
369  ordered_non_unique<tag<CubitMeshSets_mask_meshset_mi_tag>,
370  const_mem_fun<CubitMeshSets, unsigned long int,
372  ordered_non_unique<
373  tag<CubitMeshSets_name>,
374  const_mem_fun<CubitMeshSets, std::string, &CubitMeshSets::getName>>,
375  hashed_unique<
376  tag<Composite_Cubit_msId_And_MeshSetType_mi_tag>,
377  composite_key<
379  const_mem_fun<CubitMeshSets, int, &CubitMeshSets::getMeshsetId>,
380  const_mem_fun<CubitMeshSets, unsigned long int,
383 
384 /** \brief change meshset type
385  */
389  : bIt(bit){};
390  void operator()(CubitMeshSets &e);
391 };
392 
393 /**
394  * \brief change meshset name
395  */
398  std::string nAme;
399  CubitMeshSets_change_name(Interface &moab, const std::string &name)
400  : mOab(moab), nAme(name){};
401  void operator()(CubitMeshSets &e);
402 };
403 
404 /**
405  * change meshset attributes
406  */
409  const std::vector<double> &aTtr;
411  const std::vector<double> &attr)
412  : mOab(moab), aTtr(attr) {}
413  void operator()(CubitMeshSets &e);
414 };
415 
416 /**
417  * change meshset attributes for material data structure
418  */
423  Interface &moab, const GenericAttributeData &attr)
424  : mOab(moab), aTtr(attr) {}
425  void operator()(CubitMeshSets &e);
426 };
427 
428 /**
429  * change meshset attributes for material data structure
430  */
435  const GenericCubitBcData &bc_data)
436  : mOab(moab), bcData(bc_data) {}
437  void operator()(CubitMeshSets &e);
438 };
439 
440 } // namespace MoFEM
441 
442 #endif // __BCMULTIINDICES_HPP__
443 
444 /***************************************************************************/ /**
445 * \defgroup mofem_bc Boundary conditions
446 * \ingroup mofem
447 ******************************************************************************/
Generic bc data structure.
Definition: BCData.hpp:30
MoFEMErrorCode printBcData(std::ostream &os) const
print bc_data int stream given by os
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Common.hpp:60
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:483
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:526
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:490
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, interfaces, sidesets, nodests, blocksets.
std::bitset< 32 > CubitBCType
Definition: Common.hpp:200
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Common.hpp:80
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.
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
MoFEMErrorCode getTypeFromBcData(const std::vector< char > &bc_data, CubitBCType &type) const
Function that returns the CubitBCType type of the contents of bc_data.
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)