v0.5.86
Common.hpp
Go to the documentation of this file.
1 /** \file Common.hpp
2  * \brief Basic structures and data
3  *
4  * MoFEM is free software: you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the
6  * Free Software Foundation, either version 3 of the License, or (at your
7  * option) any later version.
8  *
9  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12  * License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
16 */
17 
18 #ifndef __COMMON_HPP__
19 #define __COMMON_HPP__
20 
21 namespace MoFEM {
22 
23  typedef ErrorCode MoABErrorCode;
24 
25  static MoABErrorCode rval;
26  static PetscErrorCode ierr;
27 
28  typedef int DofIdx; ///< Index of DOF
29  typedef int FEIdx; ///< Index of the element
30  typedef int EntIdx; ///< Index of DOF on the entity
31  typedef int EntPart; ///< Partition owning entity
32  typedef double FieldData; ///< Field data type
33  typedef int ApproximationOrder; ///< Approximation on the entity
34  typedef int FieldCoefficientsNumber; ///< Number of field coefficients
36 
37  //typedef checked_uint128_t UId;
38  typedef uint128_t UId; ///< Unique Id
39  typedef int ShortId; ///< Unique Id in the field
40 
41  #define UID_DOF_MAK 0x1FF
42 
43  typedef std::bitset<BITREFEDGES_SIZE> BitRefEdges;
44 
45  /**
46  * \brief Bit structure attached to each entity identifying to what mesh entity is attached.
47  */
48  typedef std::bitset<BITREFLEVEL_SIZE> BitRefLevel;
49 
50  typedef std::bitset<BITFIELDID_SIZE> BitFieldId;
51  typedef std::bitset<BITFEID_SIZE> BitFEId;
52  typedef std::bitset<BITPROBLEMID_SIZE> BitProblemId;
53  typedef std::bitset<BITINTERFACEUID_SIZE> BitIntefaceId;
54 
55  //AUX STRUCTURES
56 
57  /* This small utility that cascades two key extractors will be
58  * used throughout the boost example
59  * http://www.boost.org/doc/libs/1_53_0/libs/multi_index/example/complex_structs.cpp
60  */
61  template<class KeyExtractor1,class KeyExtractor2>
62  struct KeyFromKey {
63  public:
64  typedef typename KeyExtractor1::result_type result_type;
65 
67  const KeyExtractor1& key1_=KeyExtractor1(),
68  const KeyExtractor2& key2_=KeyExtractor2()
69  ):
70  key1(key1_),
71  key2(key2_) {}
72 
73  template<typename Arg>
74  result_type operator()(Arg& arg) const {
75  return key1(key2(arg));
76  }
77 
78  private:
79  KeyExtractor1 key1;
80  KeyExtractor2 key2;
81  };
82 
83  template <typename id_type>
84  struct LtBit {
85  inline bool operator()(const id_type& valueA,const id_type& valueB) const {
86  return valueA.to_ulong()<valueB.to_ulong();
87  }
88  };
89 
90  template <typename id_type>
91  struct EqBit {
92  inline bool operator()(const id_type& valueA,const id_type& valueB) const {
93  return valueA.to_ulong() == valueB.to_ulong();
94  }
95  };
96 
97  template <typename id_type>
98  struct HashBit {
99  inline unsigned int operator()(const id_type& value) const {
100  return value.to_ulong();
101  }
102  };
103 
104  struct MoFEMException: public std::exception {
106  char errorMessage[255];
108  errorCode(error_code) {
109  strcpy(errorMessage,"Huston we have a problem, something is wrong");
110  }
111  MoFEMException(MoFEMErrorCodes error_code,const char error_message[]):
112  errorCode(error_code) {
113  strcpy(errorMessage,error_message);
114  }
115  const char* what() const throw() {
116  return errorMessage;
117  }
118  };
119 
120  /**
121  * \typedef CubitBCType
122  * bc & material meshsets
123  *
124  */
125  typedef std::bitset<32> CubitBCType;
126 
127  // array with std allocators (i.e. concept of capacity is useful here)
128  // typedef ublas::unbounded_array<int,std::allocator<int> > IntAllacator;
129  // typedef ublas::unbounded_array<double,std::allocator<double> > DoubleAllacator;
130  typedef std::vector<int,std::allocator<int> > IntAllacator;
131  typedef std::vector<double,std::allocator<double> > DoubleAllacator;
132 
133  // bounded vector
134  typedef ublas::vector<int,IntAllacator > VectorInt;
135  typedef ublas::vector<double,DoubleAllacator > VectorDouble;
136  typedef ublas::matrix<double,ublas::row_major, DoubleAllacator > MatrixDouble;
137  typedef ublas::matrix<double,ublas::row_major,ublas::bounded_array<double,9> > MatrixDouble3by3;
138  typedef ublas::vector<double,ublas::bounded_array<double,3> > VectorDouble3;
139  typedef ublas::vector<double,ublas::bounded_array<double,9> > VectorDouble9;
140 
141  // shallow adaptor classes
142  typedef ublas::vector<double,ublas::shallow_array_adaptor<double> > VectorAdaptor;
143  typedef ublas::matrix<double,ublas::row_major,ublas::shallow_array_adaptor<double> > MatrixAdaptor;
144  typedef ublas::vector<int,ublas::shallow_array_adaptor<int> > VectorIntAdaptor;
145 
146  typedef std::vector<boost::shared_ptr<MatrixDouble> > ShapeFunctionBasesVector;
147 
148  template<class X>
149  inline std::string toString(X x) {
150  std::ostringstream buffer;
151  buffer << x;
152  return buffer.str();
153  }
154 
155 }
156 
157 #endif //__COMMON_HPP__
158 
159 /***************************************************************************//**
160  * \defgroup mofem MoFEM
161  ******************************************************************************/
int ShortId
Unique Id in the field.
Definition: Common.hpp:39
int FieldCoefficientsNumber
Number of field coefficients.
Definition: Common.hpp:34
MoFEMErrorCodes errorCode
Definition: Common.hpp:105
std::vector< int, std::allocator< int > > IntAllacator
Definition: Common.hpp:130
static PetscErrorCode ierr
Definition: Common.hpp:26
static MoABErrorCode rval
Definition: Common.hpp:25
std::bitset< BITPROBLEMID_SIZE > BitProblemId
Definition: Common.hpp:52
double FieldData
Field data type.
Definition: Common.hpp:32
int EntPart
Partition owning entity.
Definition: Common.hpp:31
ublas::matrix< double, ublas::row_major, DoubleAllacator > MatrixDouble
Definition: Common.hpp:136
const EntityHandle no_handle
Definition: Common.hpp:35
MoFEMException(MoFEMErrorCodes error_code, const char error_message[])
Definition: Common.hpp:111
std::bitset< BITREFEDGES_SIZE > BitRefEdges
Definition: Common.hpp:43
std::bitset< BITFEID_SIZE > BitFEId
Definition: Common.hpp:51
KeyFromKey(const KeyExtractor1 &key1_=KeyExtractor1(), const KeyExtractor2 &key2_=KeyExtractor2())
Definition: Common.hpp:66
std::bitset< BITFIELDID_SIZE > BitFieldId
Definition: Common.hpp:50
int EntIdx
Index of DOF on the entity.
Definition: Common.hpp:30
uint128_t UId
Unique Id.
Definition: Common.hpp:38
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
KeyExtractor1 key1
Definition: Common.hpp:79
ErrorCode MoABErrorCode
Definition: Common.hpp:23
bool operator()(const id_type &valueA, const id_type &valueB) const
Definition: Common.hpp:92
std::bitset< 32 > CubitBCType
Definition: Common.hpp:125
KeyExtractor2 key2
Definition: Common.hpp:80
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Common.hpp:48
unsigned int operator()(const id_type &value) const
Definition: Common.hpp:99
int FEIdx
Index of the element.
Definition: Common.hpp:29
ublas::matrix< double, ublas::row_major, ublas::bounded_array< double, 9 > > MatrixDouble3by3
Definition: Common.hpp:137
std::vector< double, std::allocator< double > > DoubleAllacator
Definition: Common.hpp:131
ublas::matrix< double, ublas::row_major, ublas::shallow_array_adaptor< double > > MatrixAdaptor
Definition: Common.hpp:143
std::string toString(X x)
Definition: Common.hpp:149
bool operator()(const id_type &valueA, const id_type &valueB) const
Definition: Common.hpp:85
const char * what() const
Definition: Common.hpp:115
ublas::vector< int, IntAllacator > VectorInt
Definition: Common.hpp:134
ublas::vector< double, DoubleAllacator > VectorDouble
Definition: Common.hpp:135
ublas::vector< double, ublas::bounded_array< double, 9 > > VectorDouble9
Definition: Common.hpp:139
ublas::vector< double, ublas::shallow_array_adaptor< double > > VectorAdaptor
Definition: Common.hpp:142
int ApproximationOrder
Approximation on the entity.
Definition: Common.hpp:33
MoFEMException(MoFEMErrorCodes error_code)
Definition: Common.hpp:107
result_type operator()(Arg &arg) const
Definition: Common.hpp:74
std::bitset< BITINTERFACEUID_SIZE > BitIntefaceId
Definition: Common.hpp:53
MoFEMErrorCodes
Error handling.
Definition: definitions.h:108
int DofIdx
Index of DOF.
Definition: Common.hpp:28
KeyExtractor1::result_type result_type
Definition: Common.hpp:64
std::vector< boost::shared_ptr< MatrixDouble > > ShapeFunctionBasesVector
Definition: Common.hpp:146
ublas::vector< int, ublas::shallow_array_adaptor< int > > VectorIntAdaptor
Definition: Common.hpp:144
ublas::vector< double, ublas::bounded_array< double, 3 > > VectorDouble3
Definition: Common.hpp:138