v0.12.1
VolumeElementForcesAndSourcesCore.hpp
Go to the documentation of this file.
1 /** \file VolumeElementForcesAndSourcesCore.hpp
2  \brief Volume element.
3 
4  Those element are inherited by user to implement specific implementation of
5  particular problem.
6 
7 */
8 
9 /* This file is part of MoFEM.
10  * MoFEM is free software: you can redistribute it and/or modify it under
11  * the terms of the GNU Lesser General Public License as published by the
12  * Free Software Foundation, either version 3 of the License, or (at your
13  * option) any later version.
14  *
15  * MoFEM is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
22 
23 #ifndef __VOLUMEELEMENTFORCESANDSOURCESCORE_HPP__
24 #define __VOLUMEELEMENTFORCESANDSOURCESCORE_HPP__
25 
26 using namespace boost::numeric;
27 
28 namespace MoFEM {
29 
30 /** \brief Volume finite element base
31  \ingroup mofem_forces_and_sources_volume_element
32 
33  User is implementing own operator at Gauss point level, by class
34  derived from VolumeElementForcesAndSourcesCore::UserDataOperator. Arbitrary
35  number of operator can be added by pushing objects to OpPtrVector
36 
37  */
39 
40  std::string meshPositionsFieldName; ///< \deprecated DO NOT USE!
41 
42  /** \brief default operator for TET element
43  * \ingroup mofem_forces_and_sources_volume_element
44  */
45  struct UserDataOperator;
46 
47  enum Switches {
48  NO_TRANSFORM = 1 << 1 | 1 << 2,
49  };
50 
51  template <int SWITCH> MoFEMErrorCode opSwitch();
52 
53 protected:
55  const EntityType type = MBTET);
56 
57  // Note that functions below could be overloaded by user to change default
58  // behavior of the element.
59 
60  /**
61  * \brief Set integration points
62  * @return Error code
63  */
64  virtual MoFEMErrorCode setIntegrationPts();
65 
66  /**
67  * \brief Calculate element volume and Jacobian
68  *
69  * Note that at that point is assumed that geometry is exclusively defined by
70  * corner nodes.
71  *
72  * @return Error code
73  */
74  virtual MoFEMErrorCode calculateVolumeAndJacobian();
75 
76  /**
77  * \brief Calculate coordinate at integration points
78  * @return Error code
79  */
80  virtual MoFEMErrorCode calculateCoordinatesAtGaussPts();
81 
82  /**
83  * \brief Determine approximation space and order of base functions
84  * @return Error code
85  */
86  virtual MoFEMErrorCode getSpaceBaseAndOrderOnElement();
87 
88  /**
89  * \brief Transform base functions based on geometric element Jacobian.
90  *
91  * This function apply transformation to base functions and its derivatives.
92  * For example when base functions for H-div are present the
93  * Piola-Transformarion is applied to base functions and their derivatives.
94  *
95  * @return Error code
96  */
97  virtual MoFEMErrorCode transformBaseFunctions();
98 
99 
103 
108 
109  double &vOlume;
110 
115 
116  friend class UserDataOperator;
117 };
118 
121 
123 
124  /** \brief get element number of nodes
125  */
126  inline int getNumNodes();
127 
128  /** \brief get element connectivity
129  */
130  inline const EntityHandle *getConn();
131 
132  /** \brief element volume (linear geometry)
133  */
134  inline double getVolume() const;
135 
136  /** \brief element volume (linear geometry)
137  */
138  inline double &getVolume();
139 
140  /**
141  * \brief get element Jacobian
142  */
143  inline FTensor::Tensor2<double *, 3, 3> &getJac();
144 
145  /**
146  * \brief get element inverse Jacobian
147  */
148  inline FTensor::Tensor2<double *, 3, 3> &getInvJac();
149 
150  /** \brief nodal coordinates
151  */
152  inline VectorDouble &getCoords();
153 
154  /** \brief return pointer to Generic Volume Finite Element object
155  */
156  inline VolumeElementForcesAndSourcesCoreBase *getVolumeFE() const;
157 
158 protected:
159  MoFEMErrorCode setPtrFE(ForcesAndSourcesCore *ptr);
160 };
161 
162 /**
163  * @brief Volume finite element with switches
164  *
165  * Using SWITCH to off functions
166  *
167  * @tparam SWITCH
168  */
169 template <int SWITCH>
172 
174  const EntityType type = MBTET)
175  : VolumeElementForcesAndSourcesCoreBase(m_field, MBTET) {}
178 
179  MoFEMErrorCode operator()();
180 };
181 
182 /** \brief Volume finite element default
183  \ingroup mofem_forces_and_sources_volume_element
184 
185  */
188 
189 template <int SWITCH>
190 MoFEMErrorCode VolumeElementForcesAndSourcesCoreBase::opSwitch() {
192 
193  const auto type = numeredEntFiniteElementPtr->getEntType();
194  if (type != lastEvaluatedElementEntityType) {
195  switch (type) {
196  case MBTET:
197  getElementPolynomialBase() =
198  boost::shared_ptr<BaseFunction>(new TetPolynomialBase());
199  break;
200  case MBHEX:
201  getElementPolynomialBase() =
202  boost::shared_ptr<BaseFunction>(new HexPolynomialBase());
203  break;
204  default:
206  }
207  CHKERR createDataOnElement();
208  }
209 
210  CHKERR calculateVolumeAndJacobian();
211  CHKERR getSpaceBaseAndOrderOnElement();
212  CHKERR setIntegrationPts();
213  if (gaussPts.size2() == 0)
215  CHKERR calculateCoordinatesAtGaussPts();
216  CHKERR calHierarchicalBaseFunctionsOnElement();
217  CHKERR calBernsteinBezierBaseFunctionsOnElement();
218 
219  if (!(NO_TRANSFORM & SWITCH))
220  CHKERR transformBaseFunctions();
221 
222  // Iterate over operators
223  CHKERR loopOverOperators();
224 
226 }
227 
228 template <int SWITCH>
230  return opSwitch<SWITCH>();
231 }
232 
233 int VolumeElementForcesAndSourcesCoreBase::UserDataOperator::getNumNodes() {
234  return static_cast<VolumeElementForcesAndSourcesCoreBase *>(ptrFE)->num_nodes;
235 }
236 
237 const EntityHandle *
238 VolumeElementForcesAndSourcesCoreBase::UserDataOperator::getConn() {
239  return static_cast<VolumeElementForcesAndSourcesCoreBase *>(ptrFE)->conn;
240 }
241 
242 double
243 VolumeElementForcesAndSourcesCoreBase::UserDataOperator::getVolume() const {
244  return static_cast<VolumeElementForcesAndSourcesCoreBase *>(ptrFE)->vOlume;
245 }
246 
247 double &VolumeElementForcesAndSourcesCoreBase::UserDataOperator::getVolume() {
248  return static_cast<VolumeElementForcesAndSourcesCoreBase *>(ptrFE)->vOlume;
249 }
250 
252 VolumeElementForcesAndSourcesCoreBase::UserDataOperator::getJac() {
253  return static_cast<VolumeElementForcesAndSourcesCoreBase *>(ptrFE)->tJac;
254 }
255 
257 VolumeElementForcesAndSourcesCoreBase::UserDataOperator::getInvJac() {
258  return static_cast<VolumeElementForcesAndSourcesCoreBase *>(ptrFE)->tInvJac;
259 }
260 
261 VectorDouble &
262 VolumeElementForcesAndSourcesCoreBase::UserDataOperator::getCoords() {
263  return static_cast<VolumeElementForcesAndSourcesCoreBase *>(ptrFE)->coords;
264 }
265 
267 VolumeElementForcesAndSourcesCoreBase::UserDataOperator::getVolumeFE() const {
268  return static_cast<VolumeElementForcesAndSourcesCoreBase *>(ptrFE);
269 }
270 
271 } // namespace MoFEM
272 
273 #endif //__VOLUMEELEMENTFORCESANDSOURCESCORE_HPP__
274 
275 /**
276  * \defgroup mofem_forces_and_sources_volume_element Volume Element
277  * \brief Implementation of general volume element.
278  *
279  * \ingroup mofem_forces_and_sources
280  **/
ForcesAndSourcesCore::UserDataOperator UserDataOperator
#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 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
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
UBlasVector< double > VectorDouble
Definition: Types.hpp:79
MatrixBoundedArray< double, 9 > MatrixDouble3by3
Definition: Types.hpp:116
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:21
Deprecated interface functions.
structure to get information form mofem into DataForcesAndSourcesCore
Calculate base functions on tetrahedral.
apply contravariant (Piola) transfer to Hdiv space
apply covariant transfer to Hcurl space
Transform local reference derivatives of shape function to global derivatives.
brief Transform local reference derivatives of shape function to global derivatives
Calculate base functions on tetrahedral.
VolumeElementForcesAndSourcesCoreSwitch(Interface &m_field, const EntityType type=MBTET)