v0.14.0
Loading...
Searching...
No Matches
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>
17using 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
22template <int DIM>
25using DomainEleOp = DomainEle::UserDataOperator;
26
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
37typedef boost::function<double(const double, const double, const double)>
39
41public:
42 OpDomainLhsMatrixK(std::string row_field_name, std::string col_field_name)
43 : AssemblyDomainEleOp(row_field_name, col_field_name,
44 DomainEleOp::OPROWCOL) {}
45
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
95public:
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
143private:
145};
146
147}; // namespace Poisson2DHomogeneousOperators
148
149#endif //__POISSON_2D_HOMOGENEOUS_HPP__
constexpr double a
constexpr int SPACE_DIM
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
[Define dimension]
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
boost::function< double(const double, const double, const double)> ScalarFunc
FTensor::Index< 'i', SPACE_DIM > i
constexpr auto field_name
OpBaseImpl< PETSC, EdgeEleOp > OpBase
Definition radiation.cpp:29
Data on single entity (This is passed as argument to DataOperator::doWork)
FTensor::Tensor1< FTensor::PackPtr< double *, Tensor_Dim >, Tensor_Dim > getFTensor1DiffN(const FieldApproximationBase base)
Get derivatives of base functions.
FTensor::Tensor0< FTensor::PackPtr< double *, 1 > > getFTensor0N(const FieldApproximationBase base)
Get base function as Tensor0.
const VectorInt & getIndices() const
Get global indices of dofs on entity.
MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
OpDomainLhsMatrixK(std::string row_field_name, std::string col_field_name)
MoFEMErrorCode iNtegrate(EntitiesFieldData::EntData &data)
OpDomainRhsVectorF(std::string field_name, ScalarFunc source_term_function)
FormsIntegrators< DomainEleOp >::Assembly< A >::OpBase AssemblyDomainEleOp