v0.14.0
poisson_2d_homogeneous.hpp
Go to the documentation of this file.
1 /**
2  * \file poisson_2d_homogeneous.hpp
3  * \example poisson_2d_homogeneous.hpp
4  *
5  * Solution of poisson equation. Direct implementation of User Data Operators
6  * for teaching proposes.
7  *
8  * \note In practical application we suggest use form integrators to generalise
9  * and simplify code. However, here we like to expose user to ways how to
10  * implement data operator from scratch.
11  */
12 
13 // Define name if it has not been defined yet
14 #ifndef __POISSON_2D_HOMOGENEOUS_HPP__
15 #define __POISSON_2D_HOMOGENEOUS_HPP__
16 #include <MoFEM.hpp>
17 using namespace MoFEM;
18 // Use of alias for some specific functions
19 // We are solving Poisson's equation in 2D so Face element is used
21 
22 template <int DIM>
26 
27 using AssemblyDomainEleOp =
29 
30 // Namespace that contains necessary UDOs, will be included in the main program
32 
33 // Declare FTensor index for 2D problem
35 
36 //function type
37 typedef boost::function<double(const double, const double, const double)>
39 
41 public:
42  OpDomainLhsMatrixK(std::string row_field_name, std::string col_field_name)
43  : AssemblyDomainEleOp(row_field_name, col_field_name,
44  DomainEleOp::OPROWCOL) {}
45 
47  EntitiesFieldData::EntData &col_data) {
49 
50  const int nb_row_dofs = row_data.getIndices().size();
51  const int nb_col_dofs = col_data.getIndices().size();
52 
53  this->locMat.resize(nb_row_dofs, nb_col_dofs, false);
54  this->locMat.clear();
55 
56  // get element area
57  const double area = getMeasure();
58 
59  // get number of integration points
60  const int nb_integration_points = getGaussPts().size2();
61  // get integration weights
62  auto t_w = getFTensor0IntegrationWeight();
63 
64  // get derivatives of base functions on row
65  auto t_row_diff_base = row_data.getFTensor1DiffN<SPACE_DIM>();
66 
67  // START THE LOOP OVER INTEGRATION POINTS TO CALCULATE LOCAL MATRIX
68  for (int gg = 0; gg != nb_integration_points; gg++) {
69  const double a = t_w * area;
70 
71  for (int rr = 0; rr != nb_row_dofs; ++rr) {
72  // get derivatives of base functions on column
73  auto t_col_diff_base = col_data.getFTensor1DiffN<SPACE_DIM>(gg, 0);
74 
75  for (int cc = 0; cc != nb_col_dofs; cc++) {
76  this->locMat(rr, cc) += t_row_diff_base(i) * t_col_diff_base(i) * a;
77 
78  // move to the derivatives of the next base functions on column
79  ++t_col_diff_base;
80  }
81 
82  // move to the derivatives of the next base functions on row
83  ++t_row_diff_base;
84  }
85 
86  // move to the weight of the next integration point
87  ++t_w;
88  }
89 
91  }
92 };
93 
95 public:
96  OpDomainRhsVectorF(std::string field_name, ScalarFunc source_term_function)
98  sourceTermFunc(source_term_function) {}
99 
102 
103  const int nb_dofs = data.getIndices().size();
104 
105  this->locF.resize(nb_dofs, false);
106  this->locF.clear();
107 
108  // get element area
109  const double area = getMeasure();
110 
111  // get number of integration points
112  const int nb_integration_points = getGaussPts().size2();
113  // get integration weights
114  auto t_w = getFTensor0IntegrationWeight();
115  auto t_coords = getFTensor1CoordsAtGaussPts();
116 
117  // get base function
118  auto t_base = data.getFTensor0N();
119 
120  // START THE LOOP OVER INTEGRATION POINTS TO CALCULATE LOCAL VECTOR
121  for (int gg = 0; gg != nb_integration_points; gg++) {
122  const double a = t_w * area;
123 
124  // get source term at the integration point coordinates
125  double body_source =
126  sourceTermFunc(t_coords(0), t_coords(1), t_coords(2));
127  for (int rr = 0; rr != nb_dofs; rr++) {
128  this->locF[rr] += t_base * body_source * a;
129 
130  // move to the next base function
131  ++t_base;
132  }
133 
134  // move to the weight of the next integration point
135  ++t_w;
136  // move to the coordinates of the next integration point
137  ++t_coords;
138  }
139 
141  }
142 
143 private:
145 };
146 
147 }; // namespace Poisson2DHomogeneousOperators
148 
149 #endif //__POISSON_2D_HOMOGENEOUS_HPP__
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:128
Poisson2DHomogeneousOperators::OpDomainRhsVectorF
Definition: poisson_2d_homogeneous.hpp:94
Poisson2DHomogeneousOperators::OpDomainLhsMatrixK::iNtegrate
MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
Integrate grad-grad operator.
Definition: poisson_2d_homogeneous.hpp:46
MoFEM::PipelineManager::ElementsAndOpsByDim
Definition: PipelineManager.hpp:38
Poisson2DHomogeneousOperators::ScalarFunc
boost::function< double(const double, const double, const double)> ScalarFunc
Definition: poisson_2d_homogeneous.hpp:38
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::PETSC
@ PETSC
Definition: FormsIntegrators.hpp:105
Poisson2DHomogeneousOperators::i
FTensor::Index< 'i', SPACE_DIM > i
Definition: poisson_2d_homogeneous.hpp:34
MoFEM.hpp
Poisson2DHomogeneousOperators::OpDomainRhsVectorF::sourceTermFunc
ScalarFunc sourceTermFunc
Definition: poisson_2d_homogeneous.hpp:144
OpBase
OpBaseImpl< PETSC, EdgeEleOp > OpBase
Definition: radiation.cpp:29
MoFEM::EntitiesFieldData::EntData::getFTensor0N
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0N(const FieldApproximationBase base)
Get base function as Tensor0.
Definition: EntitiesFieldData.hpp:1502
Poisson2DHomogeneousOperators::OpDomainLhsMatrixK
Definition: poisson_2d_homogeneous.hpp:40
MoFEM::OpBaseImpl
Definition: FormsIntegrators.hpp:178
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
SPACE_DIM
constexpr int SPACE_DIM
Definition: child_and_parent.cpp:16
a
constexpr double a
Definition: approx_sphere.cpp:30
Poisson2DHomogeneousOperators::OpDomainRhsVectorF::OpDomainRhsVectorF
OpDomainRhsVectorF(std::string field_name, ScalarFunc source_term_function)
Definition: poisson_2d_homogeneous.hpp:96
double
MoFEM::FormsIntegrators::Assembly
Assembly methods.
Definition: FormsIntegrators.hpp:317
MoFEM::EntitiesFieldData::EntData::getIndices
const VectorInt & getIndices() const
Get global indices of dofs on entity.
Definition: EntitiesFieldData.hpp:1214
Poisson2DHomogeneousOperators::OpDomainLhsMatrixK::OpDomainLhsMatrixK
OpDomainLhsMatrixK(std::string row_field_name, std::string col_field_name)
Definition: poisson_2d_homogeneous.hpp:42
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
FTensor::Index< 'i', SPACE_DIM >
EntData
EntitiesFieldData::EntData EntData
Definition: poisson_2d_homogeneous.hpp:20
ElementsAndOps
Definition: child_and_parent.cpp:18
DomainEleOp
MoFEM::EntitiesFieldData::EntData::getFTensor1DiffN
FTensor::Tensor1< FTensor::PackPtr< double *, Tensor_Dim >, Tensor_Dim > getFTensor1DiffN(const FieldApproximationBase base)
Get derivatives of base functions.
Definition: EntitiesFieldData.cpp:526
Poisson2DHomogeneousOperators
Definition: poisson_2d_homogeneous.hpp:31
UserDataOperator
ForcesAndSourcesCore::UserDataOperator UserDataOperator
Definition: HookeElement.hpp:75
DomainEle
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
Definition: child_and_parent.cpp:34
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
Poisson2DHomogeneousOperators::OpDomainRhsVectorF::iNtegrate
MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &data)
Class dedicated to integrate operator.
Definition: poisson_2d_homogeneous.hpp:100
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359