Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
AssembleFE_Laplace_def.hpp
1#ifndef ASSEMBLEFE_LAPLACE_DEF_hpp
2#define ASSEMBLEFE_LAPLACE_DEF_hpp
3
4namespace FEDD {
5
6
16template <class SC, class LO, class GO, class NO>
17AssembleFE_Laplace<SC,LO,GO,NO>::AssembleFE_Laplace(int flag, vec2D_dbl_Type nodesRefConfig, ParameterListPtr_Type params,tuple_disk_vec_ptr_Type tuple):
18AssembleFE<SC,LO,GO,NO>(flag, nodesRefConfig, params,tuple)
19{
20
21}
22
30
31template <class SC, class LO, class GO, class NO>
33
34 int nodesElement = this->nodesRefConfig_.size();
35 int dofs = std::get<2>(this->diskTuple_->at(0));
36 int dofsElement = nodesElement*dofs;
37 SmallMatrixPtr_Type elementMatrix =Teuchos::rcp( new SmallMatrix_Type( dofsElement));
38
39 assemblyLaplacian(elementMatrix);
40
41 this->jacobian_ = elementMatrix ;
42}
43
51template <class SC, class LO, class GO, class NO>
52void AssembleFE_Laplace<SC,LO,GO,NO>::assemblyLaplacian(SmallMatrixPtr_Type &elementMatrix) {
53
54 int dim = this->getDim();
55 int numNodes= std::get<3>(this->diskTuple_->at(0));//this->getNodesRefConfig().size();
56 std::string FEType = std::get<1>(this->diskTuple_->at(0));
57 int dofs = std::get<2>(this->diskTuple_->at(0));
58
59 vec3D_dbl_ptr_Type dPhi;
60 vec_dbl_ptr_Type weights = Teuchos::rcp(new vec_dbl_Type(0));
61
62 // inner( grad(u) , grad(v) ) has twice the polyonimial degree than grad(u) or grad(v).
63 UN deg = 2*Helper::determineDegree(dim,FEType,Helper::Deriv1);
64 Helper::getDPhi(dPhi, weights, dim, FEType, deg);
65
66 SC detB;
67 SC absDetB;
68 SmallMatrix<SC> B(dim);
69 SmallMatrix<SC> Binv(dim);
70
71 buildTransformation(B);
72 detB = B.computeInverse(Binv);
73 absDetB = std::fabs(detB);
74
75 vec3D_dbl_Type dPhiTrans( dPhi->size(), vec2D_dbl_Type( dPhi->at(0).size(), vec_dbl_Type(dim,0.) ) );
76 applyBTinv( dPhi, dPhiTrans, Binv );
77 for (UN i=0; i < numNodes; i++) {
78 Teuchos::Array<SC> value( dPhiTrans[0].size(), 0. );
79 for (UN j=0; j < numNodes; j++) {
80 for (UN w=0; w<dPhiTrans.size(); w++) {
81 for (UN d=0; d<dim; d++){
82 value[j] += weights->at(w) * dPhiTrans[w][i][d] * dPhiTrans[w][j][d];
83 }
84 }
85 value[j] *= absDetB;
86
87 for (UN d=0; d<dofs; d++) {
88 (*elementMatrix)[i*dofs +d][j*dofs+d] = value[j];
89 }
90 }
91
92 }
93
94}
95
103template <class SC, class LO, class GO, class NO>
105
106
107 int dim = this->getDim();
108 int numNodes= std::get<3>(this->diskTuple_->at(0));//this->getNodesRefConfig().size();
109 std::string FEType = std::get<1>(this->diskTuple_->at(0));
110 vec_dbl_Type elementVector(numNodes);
111
112 vec2D_dbl_ptr_Type phi;
113 vec_dbl_ptr_Type weights = Teuchos::rcp(new vec_dbl_Type(0));
114
115 UN extraDegree = 1; // TODO: [JK] 2025/04 This should be user defined, based on the irregularity of f(x). Function parameter? Parameter list?
116 UN deg = Helper::determineDegree(dim,FEType,Helper::Deriv0) + extraDegree;
117 Helper::getPhi(phi, weights, dim, FEType, deg);
118
119 SC detB;
120 SC absDetB;
121 SmallMatrix<SC> B(dim);
122 SmallMatrix<SC> Binv(dim);
123
124 this->buildTransformation(B);
125 detB = B.computeInverse(Binv);
126 absDetB = std::fabs(detB);
127
128 std::vector<double> paras0(1);
129
130 double x;
131
132 SC value;
133
134 //for now just const!
135 std::vector<double> valueFunc(dim);
136 SC* paras = &(paras0[0]);
137
138 this->rhsFunc_( &x, &valueFunc[0], paras );
139
140 for (UN i=0; i < phi->at(0).size(); i++) {
141 value = Teuchos::ScalarTraits<SC>::zero();
142 for (UN w=0; w<weights->size(); w++){
143 value += weights->at(w) * phi->at(w).at(i);
144 }
145 value *= absDetB *valueFunc[0];
146 elementVector[i] += value;
147 }
148
149 (*this->rhsVec_) = elementVector;
150}
151
159
160template <class SC, class LO, class GO, class NO>
161void AssembleFE_Laplace<SC,LO,GO,NO>::buildTransformation(SmallMatrix<SC>& B){
162
163 TEUCHOS_TEST_FOR_EXCEPTION( (B.size()<2 || B.size()>3), std::logic_error, "Initialize SmallMatrix for transformation.");
164 UN index;
165 UN index0 = 0;
166 for (UN j=0; j<B.size(); j++) {
167 index = j+1;
168 for (UN i=0; i<B.size(); i++) {
169 B[i][j] = this->nodesRefConfig_.at(index).at(i) - this->nodesRefConfig_.at(index0).at(i);
170 }
171 }
172
173}
174
182
183template <class SC, class LO, class GO, class NO>
184void AssembleFE_Laplace<SC,LO,GO,NO>::applyBTinv( vec3D_dbl_ptr_Type& dPhiIn,
185 vec3D_dbl_Type& dPhiOut,
186 SmallMatrix<SC>& Binv){
187 UN dim = Binv.size();
188 for (UN w=0; w<dPhiIn->size(); w++){
189 for (UN i=0; i < dPhiIn->at(w).size(); i++) {
190 for (UN d1=0; d1<dim; d1++) {
191 for (UN d2=0; d2<dim; d2++) {
192 dPhiOut[w][i][d1] += dPhiIn->at(w).at(i).at(d2) * Binv[d2][d1];
193 }
194 }
195 }
196 }
197}
198
199}
200#endif
201
void assembleJacobian() override
Assemble the element Jacobian matrix.
Definition AssembleFE_Laplace_def.hpp:32
void assembleRHS() override
Assemble the element right hand side vector.
Definition AssembleFE_Laplace_def.hpp:104
AssembleFE_Laplace(int flag, vec2D_dbl_Type nodesRefConfig, ParameterListPtr_Type parameters, tuple_disk_vec_ptr_Type tuple)
Constructor for AssembleFE_Laplace.
Definition AssembleFE_Laplace_def.hpp:17
AssembleFE(int flag, vec2D_dbl_Type nodesRefConfig, ParameterListPtr_Type parameters, tuple_disk_vec_ptr_Type tuple)
Definition AssembleFE_def.hpp:8
vec2D_dbl_Type nodesRefConfig_
Definition AssembleFE_decl.hpp:255
static UN determineDegree(UN dim, std::string FEType, VarType orderOfDerivative)
Determine polynomial degree of a finite element basis function or its gradient that is required to se...
Definition Helper.cpp:68
@ Deriv0
order 0, f(x)
Definition Helper.hpp:27
@ Deriv1
order 1, gradient(f(x))
Definition Helper.hpp:28
static int getPhi(vec2D_dbl_ptr_Type &Phi, vec_dbl_ptr_Type &weightsPhi, int dim, std::string FEType, int Degree, std::string FETypeQuadPoints="")
Get basisfunction phi per quadrature point.
Definition Helper.cpp:921
static int getDPhi(vec3D_dbl_ptr_Type &DPhi, vec_dbl_ptr_Type &weightsDPhi, int Dimension, std::string FEType, int Degree)
Full matrix representation of gradient of a basis function for each quadrature point.
Definition Helper.cpp:215
This class represents a templated small Matrix of type T. Primarily created for 2x2 and 3x3 matrices....
Definition SmallMatrix.hpp:20
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36