1#ifndef ASSEMBLEFENAVIERSTOKES_DEF_hpp
2#define ASSEMBLEFENAVIERSTOKES_DEF_hpp
4#include "AssembleFENavierStokes_decl.hpp"
8template <
class SC,
class LO,
class GO,
class NO>
10AssembleFE<SC,LO,GO,NO>(flag, nodesRefConfig, params,tuple)
14 if(std::get<0>(this->diskTuple_->at(0))==
"Velocity"){
18 else if(std::get<0>(this->diskTuple_->at(1))==
"Velocity"){
23 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"No discretisation Information for Velocity in Navier Stokes Element." );
28 FETypeVelocity_ = std::get<1>(this->diskTuple_->at(locVelocity));
29 FETypePressure_ =std::get<1>(this->diskTuple_->at(locPressure));
32 dofsPressure_ =std::get<2>(this->diskTuple_->at(locPressure));
34 numNodesVelocity_ = std::get<3>(this->diskTuple_->at(locVelocity));
35 numNodesPressure_=std::get<3>(this->diskTuple_->at(locPressure));
38 dofsElementPressure_ = dofsPressure_*numNodesPressure_;
41 this->solutionVelocity_ = vec_dbl_Type(dofsElementVelocity_);
42 this->solutionPressure_ = vec_dbl_Type(dofsElementPressure_);
44 viscosity_ = this->params_->sublist(
"Parameter").get(
"Viscosity",1.);
45 density_ = this->params_->sublist(
"Parameter").get(
"Density",1.);
47 dofsElement_ = dofsElementVelocity_+ dofsElementPressure_;
49 SmallMatrix_Type coeff(2);
50 coeff[0][0]=1.; coeff[0][1] = 1.; coeff[1][0] = 1.; coeff[1][1] = 1.;
53 linearization_ = this->params_->sublist(
"General").get(
"Linearization",
"FixedPoint");
56template <
class SC,
class LO,
class GO,
class NO>
57void AssembleFENavierStokes<SC,LO,GO,NO>::setCoeff(SmallMatrix_Type coeff) {
66template <
class SC,
class LO,
class GO,
class NO>
69 SmallMatrixPtr_Type elementMatrixN =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
70 SmallMatrixPtr_Type elementMatrixW =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
72 if(this->newtonStep_ ==0){
74 SmallMatrixPtr_Type elementMatrixA =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
75 SmallMatrixPtr_Type elementMatrixB =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
77 constantMatrix_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
81 elementMatrixA->scale(viscosity_);
82 elementMatrixA->scale(density_);
84 constantMatrix_->add( (*elementMatrixA),(*constantMatrix_));
88 elementMatrixB->scale(-1.);
90 constantMatrix_->add( (*elementMatrixB),(*constantMatrix_));
93 ANB_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
94 ANB_->add( (*constantMatrix_),(*ANB_));
97 elementMatrixN->scale(density_);
98 ANB_->add( (*elementMatrixN),(*ANB_));
99 if(linearization_ !=
"FixedPoint"){
101 elementMatrixW->scale(density_);
105 this->jacobian_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
107 this->jacobian_->add((*ANB_),(*this->jacobian_));
109 if(linearization_ !=
"FixedPoint"){
110 this->jacobian_->add((*elementMatrixW),(*this->jacobian_));
114template <
class SC,
class LO,
class GO,
class NO>
117 SmallMatrixPtr_Type elementMatrixN =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
119 if(this->newtonStep_ ==0){
120 SmallMatrixPtr_Type elementMatrixA =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
121 SmallMatrixPtr_Type elementMatrixB =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
123 constantMatrix_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
127 elementMatrixA->scale(viscosity_);
128 elementMatrixA->scale(density_);
130 constantMatrix_->add( (*elementMatrixA),(*constantMatrix_));
134 elementMatrixB->scale(-1.);
136 constantMatrix_->add( (*elementMatrixB),(*constantMatrix_));
139 ANB_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
140 ANB_->add( (*constantMatrix_),(*ANB_));
143 elementMatrixN->scale(density_);
144 ANB_->add( (*elementMatrixN),(*ANB_));
149template <
class SC,
class LO,
class GO,
class NO>
153 int numNodes= numNodesVelocity_;
154 std::string FEType = FETypeVelocity_;
157 vec3D_dbl_ptr_Type dPhi;
158 vec_dbl_ptr_Type weights = Teuchos::rcp(
new vec_dbl_Type(0));
172 detB = B.computeInverse(Binv);
173 absDetB = std::fabs(detB);
175 vec3D_dbl_Type dPhiTrans( dPhi->size(), vec2D_dbl_Type( dPhi->at(0).size(), vec_dbl_Type(dim,0.) ) );
178 for (UN i=0; i < numNodes; i++) {
179 Teuchos::Array<SC> value( dPhiTrans[0].size(), 0. );
180 for (UN j=0; j < numNodes; j++) {
181 for (UN w=0; w<dPhiTrans.size(); w++) {
182 for (UN d=0; d<dim; d++){
183 value[j] += weights->at(w) * dPhiTrans[w][i][d] * dPhiTrans[w][j][d];
190 for (UN d=0; d<dofs; d++) {
191 (*elementMatrix)[i*dofs +d][j*dofs+d] = value[j];
199template <
class SC,
class LO,
class GO,
class NO>
202 SmallMatrixPtr_Type elementMatrixN =Teuchos::rcp(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
204 ANB_.reset(
new SmallMatrix_Type( dofsElementVelocity_+numNodesPressure_));
205 ANB_->add( (*constantMatrix_),(*ANB_));
208 elementMatrixN->scale(density_);
209 ANB_->add( (*elementMatrixN),(*ANB_));
211 this->rhsVec_.reset(
new vec_dbl_Type ( dofsElement_,0.) );
214 for(
int i=0 ; i< ANB_->size();i++){
215 if (i >= dofsElementVelocity_)
217 for(
int j=0; j < ANB_->size(); j++){
218 if(j >= dofsElementVelocity_)
220 (*this->rhsVec_)[i] += (*ANB_)[i][j]*(*this->solution_)[j]*coeff_[s][t];
227template <
class SC,
class LO,
class GO,
class NO>
231 int numNodes= numNodesVelocity_;
232 std::string FEType = FETypeVelocity_;
235 vec3D_dbl_ptr_Type dPhi;
236 vec2D_dbl_ptr_Type phi;
237 vec_dbl_ptr_Type weights = Teuchos::rcp(
new vec_dbl_Type(0));
243 UN deg = degPhi + degGradPhi + degPhi;
253 vec2D_dbl_Type uLoc( dim, vec_dbl_Type( weights->size() , -1. ) );
256 detB = B.computeInverse(Binv);
257 absDetB = std::fabs(detB);
259 vec3D_dbl_Type dPhiTrans( dPhi->size(), vec2D_dbl_Type( dPhi->at(0).size(), vec_dbl_Type(dim,0.) ) );
262 for (
int w=0; w<phi->size(); w++){
263 for (
int d=0; d<dim; d++) {
265 for (
int i=0; i < phi->at(0).size(); i++) {
266 LO index = dim * i + d;
267 uLoc[d][w] += (*this->solution_)[index] * phi->at(w).at(i);
273 for (UN i=0; i < phi->at(0).size(); i++) {
274 Teuchos::Array<SC> value( dPhiTrans[0].size(), 0. );
275 Teuchos::Array<GO> indices( dPhiTrans[0].size(), 0 );
276 for (UN j=0; j < value.size(); j++) {
277 for (UN w=0; w<dPhiTrans.size(); w++) {
278 for (UN d=0; d<dim; d++){
279 value[j] += weights->at(w) * uLoc[d][w] * (*phi)[w][i] * dPhiTrans[w][j][d];
290 for (UN d=0; d<dim; d++) {
291 for (UN j=0; j < indices.size(); j++)
292 (*elementMatrix)[i*dofs +d][j*dofs+d] = value[j];
301template <
class SC,
class LO,
class GO,
class NO>
305 int numNodes= numNodesVelocity_;
306 std::string FEType = FETypeVelocity_;
310 vec3D_dbl_ptr_Type dPhi;
311 vec2D_dbl_ptr_Type phi;
312 vec_dbl_ptr_Type weights = Teuchos::rcp(
new vec_dbl_Type(0));
318 UN deg = degPhi + degGradPhi + degPhi;
328 vec2D_dbl_Type uLoc( dim, vec_dbl_Type( weights->size() , -1. ) );
331 detB = B.computeInverse(Binv);
332 absDetB = std::fabs(detB);
334 vec3D_dbl_Type dPhiTrans( dPhi->size(), vec2D_dbl_Type( dPhi->at(0).size(), vec_dbl_Type(dim,0.) ) );
339 std::vector<SmallMatrix<SC> > duLoc( weights->size(),
SmallMatrix<SC>(dim) );
341 for (
int w=0; w<dPhiTrans.size(); w++){
342 for (
int d1=0; d1<dim; d1++) {
343 for (
int i=0; i < dPhiTrans[0].size(); i++) {
344 LO index = dim *i+ d1;
345 for (
int d2=0; d2<dim; d2++)
346 duLoc[w][d2][d1] += (*this->solution_)[index] * dPhiTrans[w][i][d2];
351 for (UN i=0; i < phi->at(0).size(); i++) {
352 for (UN d1=0; d1<dim; d1++) {
353 Teuchos::Array<SC> value( dim*phi->at(0).size(), 0. );
354 for (UN j=0; j < phi->at(0).size(); j++) {
355 for (UN d2=0; d2<dim; d2++){
356 for (UN w=0; w<phi->size(); w++) {
357 value[ dim * j + d2 ] += weights->at(w) * duLoc[w][d2][d1] * (*phi)[w][i] * (*phi)[w][j];
359 value[ dim * j + d2 ] *= absDetB;
362 for (UN j=0; j < phi->at(0).size(); j++){
363 for (UN d=0; d<dofs; d++) {
364 (*elementMatrix)[i*dofs +d1][j*dofs+d] = value[j*dofs+d];
374template <
class SC,
class LO,
class GO,
class NO>
377 vec3D_dbl_ptr_Type dPhi;
378 vec2D_dbl_ptr_Type phi;
379 vec_dbl_ptr_Type weights = Teuchos::rcp(
new vec_dbl_Type(0));
380 int dim = this->dim_;
386 UN deg = degGradPhi_vel + degPhi_pres;
392 if (FETypePressure_==
"P1-disc" && FETypeVelocity_==
"Q2" )
393 Helper::getPhi(phi, weights, dim, FETypePressure_, deg, FETypeVelocity_);
404 detB = B.computeInverse(Binv);
405 absDetB = std::fabs(detB);
407 vec3D_dbl_Type dPhiTrans( dPhi->size(), vec2D_dbl_Type( dPhi->at(0).size(), vec_dbl_Type(dim,0.) ) );
410 Teuchos::Array<GO> rowIndex( 1, 0 );
411 Teuchos::Array<SC> value(1, 0.);
414 for (UN i=0; i < phi->at(0).size(); i++) {
415 if (FETypePressure_==
"P0")
416 rowIndex[0] = GO ( 0 );
418 rowIndex[0] = GO ( i );
420 for (UN j=0; j < dPhiTrans[0].size(); j++) {
421 for (UN d=0; d<dim; d++){
423 for (UN w=0; w<dPhiTrans.size(); w++)
424 value[0] += weights->at(w) * phi->at(w)[i] * dPhiTrans[w][j][d];
477template <
class SC,
class LO,
class GO,
class NO>
480 TEUCHOS_TEST_FOR_EXCEPTION( (B.size()<2 || B.size()>3), std::logic_error,
"Initialize SmallMatrix for transformation.");
483 for (UN j=0; j<B.size(); j++) {
485 for (UN i=0; i<B.size(); i++) {
void assembleFixedPoint()
Assembly of FixedPoint- Matrix (System Matrix K with current u)
Definition AssembleFENavierStokes_def.hpp:115
int dofsVelocity_
Definition AssembleFENavierStokes_decl.hpp:110
void assembleJacobian() override
Assemble the element Jacobian matrix.
Definition AssembleFENavierStokes_def.hpp:67
void buildTransformation(SmallMatrix< SC > &B)
Building Transformation.
Definition AssembleFENavierStokes_def.hpp:478
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:200
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:9
int getDim()
Definition AssembleFE_def.hpp:137
AssembleFE(int flag, vec2D_dbl_Type nodesRefConfig, ParameterListPtr_Type parameters, tuple_disk_vec_ptr_Type tuple)
Definition AssembleFE_def.hpp:10
vec2D_dbl_Type nodesRefConfig_
Definition AssembleFE_decl.hpp:252
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:604
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:22
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement.cpp:5