v0.13.0
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 *tagBcData;
38  int tagBcSize;
39  unsigned int *tagBlockHeaderData;
42  char *tagName;
44 
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 & meshsetsMask).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 tagBlockHeaderData[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  */
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  if ((cubitBcType & data.getType()).none()) {
276  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
277  "attributes are not for ATTRIBUTE_TYPE structure");
278  }
279  std::vector<double> attributes;
280  CHKERR getAttributes(attributes);
281  CHKERR data.fill_data(attributes);
283  }
284 
285  /**
286  * \brief fill meshset data with data on structure
287  */
288  template <class ATTRIBUTE_TYPE>
289  MoFEMErrorCode setAttributeDataStructure(const ATTRIBUTE_TYPE &data) {
291  if ((cubitBcType & data.getType()).none()) {
292  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
293  "attributes are not for ATTRIBUTE_TYPE structure");
294  }
295  double *ptr = const_cast<double *>(tagBlockAttributes);
296  CHKERR data.set_data(ptr, 8 * tagBlockAttributesSize);
298  }
299 
300  template <class CUBIT_BC_DATA_TYPE>
301  MoFEMErrorCode getBcDataStructure(CUBIT_BC_DATA_TYPE &data) const {
303 
304  if ((cubitBcType & data.tYpe).none()) {
305  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
306  "bc_data are not for CUBIT_BC_DATA_TYPE structure");
307  }
308  std::vector<char> bc_data;
309  getBcData(bc_data);
310  ierr = data.fill_data(bc_data);
311  CHKERRG(ierr);
313  }
314 
315  template <class CUBIT_BC_DATA_TYPE>
316  MoFEMErrorCode setBcDataStructure(CUBIT_BC_DATA_TYPE &data) {
318 
319  char *ptr = const_cast<char *>(tagBcData);
320  ierr = data.set_data(ptr, tagBcSize);
321  CHKERRG(ierr);
323  }
324 
325  friend std::ostream &operator<<(std::ostream &os, const CubitMeshSets &e);
326 
329 
331 };
332 
333 /**
334  * \typedef CubitMeshSet_multiIndex
335  * \brief Stores data about meshsets (see CubitMeshSets) storing data about
336  * boundary conditions, interfaces, sidesets, nodests, blocksets
337  *
338  * \param Meshset_mi_tag index by meshset handle
339  * \param CubitMeshsetType_mi_tag index by bc type, see CubitBC
340  * \param CubitMeshsetMaskedType_mi_tag index by NODESET, SIDESET, BLOCKSET
341  * only
342  *
343  * \param CubitMeshsets_name index by meshset name
344  *
345  * \param Composite_Cubit_msId_And_MeshsetType_mi_tag index by meshset id and
346  * type NODESET, SIDESET or BLOCKSET
347  *
348  * Example:
349  * \code
350  * MeshsetsManager *m_mng;
351  * CHKERR m_field.getInterface(m_mng);
352  * auto &index = m_mng->getMeshsetsMultindex();
353  *
354  *
355  * auto mit =
356  * index.get<CubitMeshsetMaskedType_mi_tag>().lower_bound(BLOCKSET); auto
357  * hi_mit =
358  * index.get<CubitMeshsetMaskedType_mi_tag>().upper_bound(BLOCKSET);
359  *
360  * // Make a loop over all BLOCKSET
361  * for(;mit!=hi_mit;mit++) {
362  * int id = mit->getMeshsetId(); // get blockset id
363  * EntityHandle handle = mit->getMeshset(); // get block meshset
364  * std::vector< double > attributes;
365  * // get block attributes
366  * auto mit->getAttributes(attributes);
367  * // do something
368  * }
369  * \endcode
370  *
371  */
372 typedef multi_index_container<
374  indexed_by<
375  hashed_unique<tag<Meshset_mi_tag>, member<CubitMeshSets, EntityHandle,
377  ordered_non_unique<tag<CubitMeshsetType_mi_tag>,
378  const_mem_fun<CubitMeshSets, unsigned long int,
380  ordered_non_unique<tag<CubitMeshsetMaskedType_mi_tag>,
381  const_mem_fun<CubitMeshSets, unsigned long int,
383  ordered_non_unique<
384  tag<CubitMeshsets_name>,
385  const_mem_fun<CubitMeshSets, std::string, &CubitMeshSets::getName>>,
386  hashed_unique<
387  tag<Composite_Cubit_msId_And_MeshsetType_mi_tag>,
388  composite_key<
390  const_mem_fun<CubitMeshSets, int, &CubitMeshSets::getMeshsetId>,
391  const_mem_fun<CubitMeshSets, unsigned long int,
394 
395 /** \brief change meshset type
396  */
400  : bIt(bit){};
401  void operator()(CubitMeshSets &e);
402 };
403 
404 /**
405  * \brief change meshset name
406  */
409  std::string nAme;
410  CubitMeshSets_change_name(Interface &moab, const std::string &name)
411  : mOab(moab), nAme(name){};
412  void operator()(CubitMeshSets &e);
413 };
414 
415 /**
416  * change meshset attributes
417  */
420  const std::vector<double> &aTtr;
422  const std::vector<double> &attr)
423  : mOab(moab), aTtr(attr) {}
424  void operator()(CubitMeshSets &e);
425 };
426 
427 /**
428  * change meshset attributes for material data structure
429  */
434  Interface &moab, const GenericAttributeData &attr)
435  : mOab(moab), aTtr(attr) {}
436  void operator()(CubitMeshSets &e);
437 };
438 
439 /**
440  * change meshset attributes for material data structure
441  */
446  const GenericCubitBcData &bc_data)
447  : mOab(moab), bcData(bc_data) {}
448  void operator()(CubitMeshSets &e);
449 };
450 
451 } // namespace MoFEM
452 
453 #endif // __BCMULTIINDICES_HPP__
454 
455 /**
456  * \defgroup mofem_bc Boundary conditions
457  * \ingroup mofem
458  */
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:460
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:496
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:44
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
#define CHKERR
Inline error check.
Definition: definitions.h:548
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:453
auto bit
set bit
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:87
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
std::bitset< 32 > CubitBCType
Definition: Types.hpp:63
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
multi_index_container< CubitMeshSets, indexed_by< hashed_unique< tag< Meshset_mi_tag >, member< CubitMeshSets, EntityHandle, &CubitMeshSets::meshset > >, ordered_non_unique< tag< CubitMeshsetType_mi_tag >, const_mem_fun< CubitMeshSets, unsigned long int, &CubitMeshSets::getBcTypeULong > >, ordered_non_unique< tag< CubitMeshsetMaskedType_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,...
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1965
CubitMeshSets_change_add_bit_to_cubit_bc_type(const CubitBCType &bit)
CubitMeshSets_change_attributes_data_structure(Interface &moab, const GenericAttributeData &attr)
const std::vector< double > & aTtr
CubitMeshSets_change_attributes(Interface &moab, const std::vector< double > &attr)
CubitMeshSets_change_bc_data_structure(Interface &moab, const GenericCubitBcData &bc_data)
void operator()(CubitMeshSets &e)
CubitMeshSets_change_name(Interface &moab, const std::string &name)
this struct keeps basic methods for moab meshset about material and boundary conditions
MoFEMErrorCode getAttributes(std::vector< double > &attributes) const
get Cubit block attributes
unsigned long int getBcTypeULong() const
get bc meshset type
MoFEMErrorCode getBcData(std::vector< char > &bc_data) const
get bc_data vector from MoFEM database
MoFEMErrorCode printName(std::ostream &os) const
print name of block, sideset etc. (this is set in Cubit setting properties)
MoFEMErrorCode printAttributes(std::ostream &os) const
print the attributes vector
unsigned int * tagBlockHeaderData
MoFEMErrorCode getAttributeDataStructure(ATTRIBUTE_TYPE &data) const
fill data structure with data saved on meshset
MoFEMErrorCode getTypeFromName(const std::string &name, CubitBCType &type) const
Function that returns the CubitBCType type of the block name, sideset name etc.
MoFEMErrorCode setBcDataStructure(CUBIT_BC_DATA_TYPE &data)
CubitMeshSets(Interface &moab, const EntityHandle meshset)
friend std::ostream & operator<<(std::ostream &os, const CubitMeshSets &e)
MoFEMErrorCode getMeshsetIdEntitiesByDimension(Interface &moab, Range &entities, const bool recursive=false) const
get entities form meshset
MoFEMErrorCode setAttributes(moab::Interface &moab, const std::vector< double > &attributes)
cet Cubit block attributes
MoFEMErrorCode getBlockHeaderData(std::vector< unsigned int > &material_data) const
get block_headers vector from MoFEM database
MoFEMErrorCode getBcDataStructure(CUBIT_BC_DATA_TYPE &data) const
unsigned int getMeshsetEntitiesDimension() const
Get the meshset entities dimension.
CubitMeshSets(Interface &moab, const CubitBCType cubit_bc_type, const int msId)
MoFEMErrorCode printBcData(std::ostream &os) const
print bc_data int stream given by os
CubitBCType getBcType() const
get type of meshset
MoFEMErrorCode getMeshsetIdEntitiesByDimension(Interface &moab, const int dimension, Range &entities, const bool recursive=false) const
get entities form meshset
std::string getName() const
get name of block, sideset etc. (this is set in Cubit block properties)
std::vector< Tag > tag_handles
vector of tag handles to types of data passed from cubit
EntityHandle getMeshset() const
get bc meshset
MoFEMErrorCode setAttributeDataStructure(const ATTRIBUTE_TYPE &data)
fill meshset data with data on structure
MoFEMErrorCode getTagsHandlers(Interface &moab)
int * msId
cubit meshset ID
const CubitBCType meshsetsMask
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.
unsigned long int getMaksedBcTypeULong() const
get meshset type and mask
int getMeshsetId() const
get meshset id as it set in preprocessing software
MoFEMErrorCode printBlockHeaderData(std::ostream &os) const
print material_data int stream given by os
Deprecated interface functions.
Generic attribute data structure.
Generic bc data structure.
Definition: BCData.hpp:31