v0.14.0
nonlinear_poisson_2d.hpp
Go to the documentation of this file.
1 #ifndef __NONLINEARPOISSON2D_HPP__
2 #define __NONLINEARPOISSON2D_HPP__
3 
4 #include <stdlib.h>
5 #include <MoFEM.hpp>
6 using namespace MoFEM;
7 
13 
14 
18  PETSC>::LinearForm<GAUSS>::OpBaseTimesScalar<1>;
20  PETSC>::LinearForm<GAUSS>::OpSource<1, 1>;
21 
22 
23 using AssemblyDomainEleOp =
27 
28 
30 
32 
34 
35 typedef boost::function<double(const double, const double, const double)>
37 
38 
40 public:
42  std::string row_field_name, std::string col_field_name,
43  boost::shared_ptr<VectorDouble> field_vec,
44  boost::shared_ptr<MatrixDouble> field_grad_mat)
45  : AssemblyDomainEleOp(row_field_name, col_field_name,
46  DomainEleOp::OPROWCOL),
47  fieldVec(field_vec), fieldGradMat(field_grad_mat) {}
48 
50  EntData &col_data) {
52 
53  auto &locLhs = AssemblyDomainEleOp::locMat;
54 
55  const int nb_row_dofs = row_data.getIndices().size();
56  const int nb_col_dofs = col_data.getIndices().size();
57  // get element area
58  const double area = getMeasure();
59 
60  // get number of integration points
61  const int nb_integration_points = getGaussPts().size2();
62  // get integration weights
63  auto t_w = getFTensor0IntegrationWeight();
64  // get solution (field value) at integration points
65  auto t_field = getFTensor0FromVec(*fieldVec);
66  // get gradient of field at integration points
67  auto t_field_grad = getFTensor1FromMat<2>(*fieldGradMat);
68 
69  // get base functions on row
70  auto t_row_base = row_data.getFTensor0N();
71  // get derivatives of base functions on row
72  auto t_row_diff_base = row_data.getFTensor1DiffN<2>();
73 
74  // START THE LOOP OVER INTEGRATION POINTS TO CALCULATE LOCAL MATRIX
75  for (int gg = 0; gg != nb_integration_points; gg++) {
76  const double a = t_w * area;
77 
78  for (int rr = 0; rr != nb_row_dofs; ++rr) {
79  // get base functions on column
80  auto t_col_base = col_data.getFTensor0N(gg, 0);
81  // get derivatives of base functions on column
82  auto t_col_diff_base = col_data.getFTensor1DiffN<2>(gg, 0);
83 
84  for (int cc = 0; cc != nb_col_dofs; cc++) {
85  locLhs(rr, cc) += (((1 + t_field * t_field) * t_row_diff_base(i) *
86  t_col_diff_base(i)) +
87  (2.0 * t_field * t_field_grad(i) *
88  t_row_diff_base(i) * t_col_base)) *
89  a;
90 
91  // move to the next base functions on column
92  ++t_col_base;
93  // move to the derivatives of the next base function on column
94  ++t_col_diff_base;
95  }
96 
97  // move to the next base function on row
98  ++t_row_base;
99  // move to the derivatives of the next base function on row
100  ++t_row_diff_base;
101  }
102 
103  // move to the weight of the next integration point
104  ++t_w;
105  // move to the solution (field value) at the next integration point
106  ++t_field;
107  // move to the gradient of field value at the next integration point
108  ++t_field_grad;
109  }
110 
112  }
113 
114 private:
115  boost::shared_ptr<VectorDouble> fieldVec;
116  boost::shared_ptr<MatrixDouble> fieldGradMat;
117 };
118 
120 public:
122  std::string field_name, ScalarFunc source_term_function,
123  boost::shared_ptr<VectorDouble> field_vec,
124  boost::shared_ptr<MatrixDouble> field_grad_mat)
126  sourceTermFunc(source_term_function), fieldVec(field_vec),
127  fieldGradMat(field_grad_mat) {}
128 
131 
132  auto &nf = AssemblyDomainEleOp::locF;
133 
134 
135  // get element area
136  const double area = getMeasure();
137 
138  // get number of integration points
139  const int nb_integration_points = getGaussPts().size2();
140  // get integration weights
141  auto t_w = getFTensor0IntegrationWeight();
142  // get coordinates of the integration point
143  auto t_coords = getFTensor1CoordsAtGaussPts();
144  // get solution (field value) at integration point
145  auto t_field = getFTensor0FromVec(*fieldVec);
146  // get gradient of field value of integration point
147  auto t_field_grad = getFTensor1FromMat<2>(*fieldGradMat);
148 
149  // get base function
150  auto t_base = data.getFTensor0N();
151  // get derivatives of base function
152  auto t_grad_base = data.getFTensor1DiffN<2>();
153 
154  // START THE LOOP OVER INTEGRATION POINTS TO CALCULATE LOCAL VECTOR
155  for (int gg = 0; gg != nb_integration_points; gg++) {
156  const double a = t_w * area;
157  double body_source =
158  sourceTermFunc(t_coords(0), t_coords(1), t_coords(2));
159 
160  // calculate the local vector
161  for (int rr = 0; rr != AssemblyDomainEleOp::nbRows; rr++) {
162  nf[rr] +=
163  (-t_base * body_source +
164  t_grad_base(i) * t_field_grad(i) * (1 + t_field * t_field)) *
165  a;
166 
167  // move to the next base function
168  ++t_base;
169  // move to the derivatives of the next base function
170  ++t_grad_base;
171  }
172 
173  // move to the weight of the next integration point
174  ++t_w;
175  // move to the coordinates of the next integration point
176  ++t_coords;
177  // move to the solution (field value) at the next integration point
178  ++t_field;
179  // move to the gradient of field value at the next integration point
180  ++t_field_grad;
181 
182  }
183 
185  }
186 
187 private:
189  boost::shared_ptr<VectorDouble> fieldVec;
190  boost::shared_ptr<MatrixDouble> fieldGradMat;
191 
192 };
193 
194 }; // namespace NonlinearPoissonOps
195 
196 #endif //__NONLINEARPOISSON2D_HPP__
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:128
BoundaryEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
Definition: child_and_parent.cpp:39
MoFEM::OpBaseImpl::locMat
MatrixDouble locMat
local entity block matrix
Definition: FormsIntegrators.hpp:249
OpBoundaryRhs
FormsIntegrators< BoundaryEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpBaseTimesScalar< 1 > OpBoundaryRhs
Definition: nonlinear_poisson_2d.hpp:18
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::PETSC
@ PETSC
Definition: FormsIntegrators.hpp:105
NonlinearPoissonOps::OpDomainRhs::fieldGradMat
boost::shared_ptr< MatrixDouble > fieldGradMat
Definition: nonlinear_poisson_2d.hpp:190
MoFEM.hpp
NonlinearPoissonOps
Definition: nonlinear_poisson_2d.hpp:31
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
MoFEM::PipelineManager::EdgeEle
MoFEM::EdgeElementForcesAndSourcesCore EdgeEle
Definition: PipelineManager.hpp:36
MoFEM::OpBaseImpl::locF
VectorDouble locF
local entity vector
Definition: FormsIntegrators.hpp:251
MoFEM::PostProcBrokenMeshInMoab
Definition: PostProcBrokenMeshInMoabBase.hpp:667
NonlinearPoissonOps::OpDomainRhs::iNtegrate
MoFEMErrorCode iNtegrate(EntData &data)
Class dedicated to integrate operator.
Definition: nonlinear_poisson_2d.hpp:129
MoFEM::OpBaseImpl
Definition: FormsIntegrators.hpp:178
NonlinearPoissonOps::OpDomainLhs::iNtegrate
MoFEMErrorCode iNtegrate(EntData &row_data, EntData &col_data)
Integrate grad-grad operator.
Definition: nonlinear_poisson_2d.hpp:49
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
a
constexpr double a
Definition: approx_sphere.cpp:30
BoundaryEleOp
OpBoundaryRhsSource
FormsIntegrators< BoundaryEleOp >::Assembly< PETSC >::LinearForm< GAUSS >::OpSource< 1, 1 > OpBoundaryRhsSource
Definition: nonlinear_poisson_2d.hpp:20
double
MoFEM::PipelineManager::FaceEle
MoFEM::FaceElementForcesAndSourcesCore FaceEle
Definition: PipelineManager.hpp:35
MoFEM::FormsIntegrators::Assembly
Assembly methods.
Definition: FormsIntegrators.hpp:317
MoFEM::getFTensor0FromVec
static auto getFTensor0FromVec(ublas::vector< T, A > &data)
Get tensor rank 0 (scalar) form data vector.
Definition: Templates.hpp:135
NonlinearPoissonOps::OpDomainLhs::OpDomainLhs
OpDomainLhs(std::string row_field_name, std::string col_field_name, boost::shared_ptr< VectorDouble > field_vec, boost::shared_ptr< MatrixDouble > field_grad_mat)
Definition: nonlinear_poisson_2d.hpp:41
NonlinearPoissonOps::i
FTensor::Index< 'i', 2 > i
Definition: nonlinear_poisson_2d.hpp:33
MoFEM::EntitiesFieldData::EntData::getIndices
const VectorInt & getIndices() const
Get global indices of dofs on entity.
Definition: EntitiesFieldData.hpp:1214
NonlinearPoissonOps::OpDomainRhs::fieldVec
boost::shared_ptr< VectorDouble > fieldVec
Definition: nonlinear_poisson_2d.hpp:189
NonlinearPoissonOps::OpDomainRhs::OpDomainRhs
OpDomainRhs(std::string field_name, ScalarFunc source_term_function, boost::shared_ptr< VectorDouble > field_vec, boost::shared_ptr< MatrixDouble > field_grad_mat)
Definition: nonlinear_poisson_2d.hpp:121
OpBoundaryLhs
FormsIntegrators< BoundaryEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, 1 > OpBoundaryLhs
Definition: nonlinear_poisson_2d.hpp:16
NonlinearPoissonOps::OpDomainRhs
Definition: nonlinear_poisson_2d.hpp:119
NonlinearPoissonOps::OpDomainLhs::fieldVec
boost::shared_ptr< VectorDouble > fieldVec
Definition: nonlinear_poisson_2d.hpp:115
NonlinearPoissonOps::OpDomainLhs
Definition: nonlinear_poisson_2d.hpp:39
BiLinearForm
EntData
EntitiesFieldData::EntData EntData
Definition: nonlinear_poisson_2d.hpp:29
field_name
constexpr auto field_name
Definition: poisson_2d_homogeneous.cpp:13
FTensor::Index< 'i', 2 >
NonlinearPoissonOps::OpDomainLhs::fieldGradMat
boost::shared_ptr< MatrixDouble > fieldGradMat
Definition: nonlinear_poisson_2d.hpp:116
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
MoFEM::OpBaseImpl::nbRows
int nbRows
number of dofs on rows
Definition: FormsIntegrators.hpp:236
NonlinearPoissonOps::OpDomainRhs::sourceTermFunc
ScalarFunc sourceTermFunc
Definition: nonlinear_poisson_2d.hpp:188
UserDataOperator
ForcesAndSourcesCore::UserDataOperator UserDataOperator
Definition: HookeElement.hpp:75
DomainEle
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
Definition: child_and_parent.cpp:34
NonlinearPoissonOps::ScalarFunc
boost::function< double(const double, const double, const double)> ScalarFunc
Definition: nonlinear_poisson_2d.hpp:36
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359