1#ifndef ASSEMBLEFENAVIERSTOKES_DEF_hpp
2#define ASSEMBLEFENAVIERSTOKES_DEF_hpp
6template <
class SC,
class LO,
class GO,
class NO>
8AssembleFE<SC,LO,GO,NO>(flag, nodesRefConfig, params,tuple)
12 if(std::get<0>(this->diskTuple_->at(0))==
"Velocity"){
16 else if(std::get<0>(this->diskTuple_->at(1))==
"Velocity"){
21 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"No discretisation Information for Velocity in Navier Stokes Element." );
26 FETypeVelocity_ = std::get<1>(this->diskTuple_->at(locVelocity));
27 FETypePressure_ =std::get<1>(this->diskTuple_->at(locPressure));
29 dofsVelocity_ = std::get<2>(this->diskTuple_->at(locVelocity));
30 dofsPressure_ =std::get<2>(this->diskTuple_->at(locPressure));
32 numNodesVelocity_ = std::get<3>(this->diskTuple_->at(locVelocity));
33 numNodesPressure_=std::get<3>(this->diskTuple_->at(locPressure));
36 dofsElementPressure_ = dofsPressure_*numNodesPressure_;
39 this->solutionVelocity_ = vec_dbl_Type(dofsElementVelocity_);
40 this->solutionPressure_ = vec_dbl_Type(dofsElementPressure_);
42 viscosity_ = this->params_->sublist(
"Parameter").get(
"Viscosity",1.);
43 density_ = this->params_->sublist(
"Parameter").get(
"Density",1.);
45 dofsElement_ = dofsElementVelocity_+ dofsElementPressure_;
47 SmallMatrix_Type coeff(2);
48 coeff[0][0]=1.; coeff[0][1] = 1.; coeff[1][0] = 1.; coeff[1][1] = 1.;
52 if(this->params_->sublist(
"General").get(
"Linearization",
"FixedPoint") ==
"FixedPointNewton")
54 this->linearization_ = this->params_->sublist(
"General").get(
"Initial_Linearization",
"FixedPoint");
58 this->linearization_ = this->params_->sublist(
"General").get(
"Linearization",
"FixedPoint");
62template <
class SC,
class LO,
class GO,
class NO>
63void AssembleFENavierStokes<SC,LO,GO,NO>::setCoeff(SmallMatrix_Type coeff) {
72template <
class SC,
class LO,
class GO,
class NO>
75 SmallMatrixPtr_Type elementMatrixN =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
76 SmallMatrixPtr_Type elementMatrixW =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
78 if(this->newtonStep_ ==0){
80 SmallMatrixPtr_Type elementMatrixA =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
81 SmallMatrixPtr_Type elementMatrixB =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
83 constantMatrix_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
87 elementMatrixA->scale(viscosity_);
88 elementMatrixA->scale(density_);
90 constantMatrix_->add( (*elementMatrixA),(*constantMatrix_));
94 elementMatrixB->scale(-1.);
96 constantMatrix_->add( (*elementMatrixB),(*constantMatrix_));
99 ANB_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
100 ANB_->add( (*constantMatrix_),(*ANB_));
103 elementMatrixN->scale(density_);
104 ANB_->add( (*elementMatrixN),(*ANB_));
105 if(this->linearization_ !=
"FixedPoint"){
107 elementMatrixW->scale(density_);
111 this->jacobian_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
113 this->jacobian_->add((*ANB_),(*this->jacobian_));
115 if(this->linearization_ !=
"FixedPoint"){
116 this->jacobian_->add((*elementMatrixW),(*this->jacobian_));
120template <
class SC,
class LO,
class GO,
class NO>
123 SmallMatrixPtr_Type elementMatrixN =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
125 if(this->newtonStep_ ==0){
126 SmallMatrixPtr_Type elementMatrixA =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
127 SmallMatrixPtr_Type elementMatrixB =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
129 constantMatrix_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
133 elementMatrixA->scale(viscosity_);
134 elementMatrixA->scale(density_);
136 constantMatrix_->add( (*elementMatrixA),(*constantMatrix_));
140 elementMatrixB->scale(-1.);
142 constantMatrix_->add( (*elementMatrixB),(*constantMatrix_));
145 ANB_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
146 ANB_->add( (*constantMatrix_),(*ANB_));
149 elementMatrixN->scale(density_);
150 ANB_->add( (*elementMatrixN),(*ANB_));
155template <
class SC,
class LO,
class GO,
class NO>
159 int numNodes= numNodesVelocity_;
160 std::string FEType = FETypeVelocity_;
163 vec3D_dbl_ptr_Type dPhi;
164 vec_dbl_ptr_Type weights = Teuchos::rcp(
new vec_dbl_Type(0));
178 detB = B.computeInverse(Binv);
179 absDetB = std::fabs(detB);
181 vec3D_dbl_Type dPhiTrans( dPhi->size(), vec2D_dbl_Type( dPhi->at(0).size(), vec_dbl_Type(dim,0.) ) );
184 for (UN i=0; i < numNodes; i++) {
185 Teuchos::Array<SC> value( dPhiTrans[0].size(), 0. );
186 for (UN j=0; j < numNodes; j++) {
187 for (UN w=0; w<dPhiTrans.size(); w++) {
188 for (UN d=0; d<dim; d++){
189 value[j] += weights->at(w) * dPhiTrans[w][i][d] * dPhiTrans[w][j][d];
196 for (UN d=0; d<dofs; d++) {
197 (*elementMatrix)[i*dofs +d][j*dofs+d] = value[j];
205template <
class SC,
class LO,
class GO,
class NO>
208 SmallMatrixPtr_Type elementMatrixN =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
210 ANB_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
211 ANB_->add( (*constantMatrix_),(*ANB_));
214 elementMatrixN->scale(density_);
215 ANB_->add( (*elementMatrixN),(*ANB_));
217 this->rhsVec_.reset(
new vec_dbl_Type ( dofsElement_,0.) );
220 for(
int i=0 ; i< ANB_->size();i++){
221 if (i >= dofsElementVelocity_)
223 for(
int j=0; j < ANB_->size(); j++){
224 if(j >= dofsElementVelocity_)
226 (*this->rhsVec_)[i] += (*ANB_)[i][j]*(*this->solution_)[j]*coeff_[s][t];
233template <
class SC,
class LO,
class GO,
class NO>
237 int numNodes= numNodesVelocity_;
238 std::string FEType = FETypeVelocity_;
241 vec3D_dbl_ptr_Type dPhi;
242 vec2D_dbl_ptr_Type phi;
243 vec_dbl_ptr_Type weights = Teuchos::rcp(
new vec_dbl_Type(0));
249 UN deg = degPhi + degGradPhi + degPhi;
259 vec2D_dbl_Type uLoc( dim, vec_dbl_Type( weights->size() , -1. ) );
262 detB = B.computeInverse(Binv);
263 absDetB = std::fabs(detB);
265 vec3D_dbl_Type dPhiTrans( dPhi->size(), vec2D_dbl_Type( dPhi->at(0).size(), vec_dbl_Type(dim,0.) ) );
268 for (
int w=0; w<phi->size(); w++){
269 for (
int d=0; d<dim; d++) {
271 for (
int i=0; i < phi->at(0).size(); i++) {
272 LO index = dim * i + d;
273 uLoc[d][w] += (*this->solution_)[index] * phi->at(w).at(i);
279 for (UN i=0; i < phi->at(0).size(); i++) {
280 Teuchos::Array<SC> value( dPhiTrans[0].size(), 0. );
281 Teuchos::Array<GO> indices( dPhiTrans[0].size(), 0 );
282 for (UN j=0; j < value.size(); j++) {
283 for (UN w=0; w<dPhiTrans.size(); w++) {
284 for (UN d=0; d<dim; d++){
285 value[j] += weights->at(w) * uLoc[d][w] * (*phi)[w][i] * dPhiTrans[w][j][d];
296 for (UN d=0; d<dim; d++) {
297 for (UN j=0; j < indices.size(); j++)
298 (*elementMatrix)[i*dofs +d][j*dofs+d] = value[j];
307template <
class SC,
class LO,
class GO,
class NO>
311 int numNodes= numNodesVelocity_;
312 std::string FEType = FETypeVelocity_;
316 vec3D_dbl_ptr_Type dPhi;
317 vec2D_dbl_ptr_Type phi;
318 vec_dbl_ptr_Type weights = Teuchos::rcp(
new vec_dbl_Type(0));
324 UN deg = degPhi + degGradPhi + degPhi;
334 vec2D_dbl_Type uLoc( dim, vec_dbl_Type( weights->size() , -1. ) );
337 detB = B.computeInverse(Binv);
338 absDetB = std::fabs(detB);
340 vec3D_dbl_Type dPhiTrans( dPhi->size(), vec2D_dbl_Type( dPhi->at(0).size(), vec_dbl_Type(dim,0.) ) );
345 std::vector<SmallMatrix<SC> > duLoc( weights->size(),
SmallMatrix<SC>(dim) );
347 for (
int w=0; w<dPhiTrans.size(); w++){
348 for (
int d1=0; d1<dim; d1++) {
349 for (
int i=0; i < dPhiTrans[0].size(); i++) {
350 LO index = dim *i+ d1;
351 for (
int d2=0; d2<dim; d2++)
352 duLoc[w][d2][d1] += (*this->solution_)[index] * dPhiTrans[w][i][d2];
357 for (UN i=0; i < phi->at(0).size(); i++) {
358 for (UN d1=0; d1<dim; d1++) {
359 Teuchos::Array<SC> value( dim*phi->at(0).size(), 0. );
360 for (UN j=0; j < phi->at(0).size(); j++) {
361 for (UN d2=0; d2<dim; d2++){
362 for (UN w=0; w<phi->size(); w++) {
363 value[ dim * j + d2 ] += weights->at(w) * duLoc[w][d2][d1] * (*phi)[w][i] * (*phi)[w][j];
365 value[ dim * j + d2 ] *= absDetB;
368 for (UN j=0; j < phi->at(0).size(); j++){
369 for (UN d=0; d<dofs; d++) {
370 (*elementMatrix)[i*dofs +d1][j*dofs+d] = value[j*dofs+d];
380template <
class SC,
class LO,
class GO,
class NO>
383 vec3D_dbl_ptr_Type dPhi;
384 vec2D_dbl_ptr_Type phi;
385 vec_dbl_ptr_Type weights = Teuchos::rcp(
new vec_dbl_Type(0));
386 int dim = this->dim_;
392 UN deg = degGradPhi_vel + degPhi_pres;
398 if (FETypePressure_==
"P1-disc" && FETypeVelocity_==
"Q2" )
399 Helper::getPhi(phi, weights, dim, FETypePressure_, deg, FETypeVelocity_);
410 detB = B.computeInverse(Binv);
411 absDetB = std::fabs(detB);
413 vec3D_dbl_Type dPhiTrans( dPhi->size(), vec2D_dbl_Type( dPhi->at(0).size(), vec_dbl_Type(dim,0.) ) );
416 Teuchos::Array<GO> rowIndex( 1, 0 );
417 Teuchos::Array<SC> value(1, 0.);
420 for (UN i=0; i < phi->at(0).size(); i++) {
421 if (FETypePressure_==
"P0")
422 rowIndex[0] = GO ( 0 );
424 rowIndex[0] = GO ( i );
426 for (UN j=0; j < dPhiTrans[0].size(); j++) {
427 for (UN d=0; d<dim; d++){
429 for (UN w=0; w<dPhiTrans.size(); w++)
430 value[0] += weights->at(w) * phi->at(w)[i] * dPhiTrans[w][j][d];
483template <
class SC,
class LO,
class GO,
class NO>
486 TEUCHOS_TEST_FOR_EXCEPTION( (B.size()<2 || B.size()>3), std::logic_error,
"Initialize SmallMatrix for transformation.");
489 for (UN j=0; j<B.size(); j++) {
491 for (UN i=0; i<B.size(); i++) {
void assembleFixedPoint()
Assembly of FixedPoint- Matrix (System Matrix K with current u)
Definition AssembleFENavierStokes_def.hpp:121
int dofsVelocity_
Definition AssembleFENavierStokes_decl.hpp:110
void assembleJacobian() override
Assemble the element Jacobian matrix.
Definition AssembleFENavierStokes_def.hpp:73
void buildTransformation(SmallMatrix< SC > &B)
Building Transformation.
Definition AssembleFENavierStokes_def.hpp:484
void assemblyDivAndDivT(SmallMatrixPtr_Type &elementMatrix)
void assemblyAdvectionInU(SmallMatrixPtr_Type &elementMatrix)
void assemblyAdvection(SmallMatrixPtr_Type &elementMatrix)
void assembleRHS() override
Assemble the element right hand side vector.
Definition AssembleFENavierStokes_def.hpp:206
void assemblyLaplacian(SmallMatrixPtr_Type &elementMatrix)
AssembleFENavierStokes(int flag, vec2D_dbl_Type nodesRefConfig, ParameterListPtr_Type parameters, tuple_disk_vec_ptr_Type tuple)
Constructor for AssembleFEAceNavierStokes.
Definition AssembleFENavierStokes_def.hpp:7
int getDim()
Definition AssembleFE_def.hpp:135
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
static void applyBTinv(vec3D_dbl_ptr_Type &dPhiIn, vec3D_dbl_Type &dPhiOut, const SmallMatrix< SC > &Binv)
Applying the transformation matriX B to the gradient of phi, as is done in when transforming the grad...
Definition Helper.cpp:200
@ 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