Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
Stokes_def.hpp
1#ifndef STOKES_def_hpp
2#define STOKES_def_hpp
3
12
13#include "feddlib/core/FE/Domain.hpp"
14#include "feddlib//core/FE/FE.hpp"
15#include "feddlib/problems/Solver/Preconditioner.hpp"
16
17namespace FEDD {
18void ZeroDirichlet(double* x, double* res, double t, double* parameters){
19
20 res[0] = 0.;
21
22 return;
23}
24
25double OneFunction(double* x, int* parameter)
26{
27 return 1.0;
28}
29
30template<class SC,class LO,class GO,class NO>
31Stokes<SC,LO,GO,NO>::Stokes(const DomainConstPtr_Type &domainVelocity, std::string FETypeVelocity, const DomainConstPtr_Type &domainPressure, std::string FETypePressure, ParameterListPtr_Type parameterList):
32Problem<SC,LO,GO,NO>(parameterList, domainVelocity->getComm())
33{
34
35 this->addVariable( domainVelocity , FETypeVelocity , "u" , domainVelocity->getDimension());
36 this->addVariable( domainPressure , FETypePressure , "p" , 1);
37
38 this->dim_ = this->getDomain(0)->getDimension();
39}
40
41template<class SC,class LO,class GO,class NO>
42Stokes<SC,LO,GO,NO>::~Stokes(){
43
44}
45
46template<class SC,class LO,class GO,class NO>
47void Stokes<SC,LO,GO,NO>::info(){
48 this->infoProblem();
49}
50
51template<class SC,class LO,class GO,class NO>
52void Stokes<SC,LO,GO,NO>::assemble( std::string type ) const{
53
54 if (this->verbose_)
55 std::cout << "-- Assembly ... " << std::flush;
56
57 double viscosity = this->parameterList_->sublist("Parameter").get("Viscosity",1.);
58
59 MatrixPtr_Type A(new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getApproxEntriesPerRow() ) );
60 MatrixPtr_Type BT(new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(1)->getDimension() * this->getDomain(1)->getApproxEntriesPerRow() ) );
61
62 MapConstPtr_Type pressureMap;
63 if ( this->getDomain(1)->getFEType() == "P0" )
64 pressureMap = this->getDomain(1)->getElementMap();
65 else
66 pressureMap = this->getDomain(1)->getMapUnique();
67
68 MatrixPtr_Type B(new Matrix_Type( pressureMap, this->getDomain(0)->getDimension() * this->getDomain(0)->getApproxEntriesPerRow() ) );
69
70 MatrixPtr_Type C;
71 if (this->verbose_)
72 std::cout << " A ... " << std::flush;
73 int* dummy;
74 if ( this->parameterList_->sublist("Parameter").get("Symmetric gradient",false) )
75 this->feFactory_->assemblyStress(this->dim_, this->domain_FEType_vec_.at(0), A, OneFunction, dummy, true);
76 else
77 this->feFactory_->assemblyLaplaceVecField(this->dim_, this->domain_FEType_vec_.at(0), 2, A, true);
78
79 if (this->verbose_)
80 std::cout << "B and B^T ... " << std::flush;
81
82 this->feFactory_->assemblyDivAndDivT(this->dim_, this->getFEType(0), this->getFEType(1), 2, B, BT, this->getDomain(0)->getMapVecFieldUnique(), pressureMap, true );
83
84 A->resumeFill();
85 B->resumeFill();
86 BT->resumeFill();
87
88 A->scale(viscosity);
89 B->scale(-1.);
90 BT->scale(-1.);
91
92 A->fillComplete( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getMapVecFieldUnique());
93 B->fillComplete( this->getDomain(0)->getMapVecFieldUnique(), pressureMap );
94 BT->fillComplete( pressureMap, this->getDomain(0)->getMapVecFieldUnique() );
95
96 this->system_.reset(new BlockMatrix_Type(2));
97
98 this->system_->addBlock( A, 0, 0 );
99 this->system_->addBlock( BT, 0, 1 );
100 this->system_->addBlock( B, 1, 0 );
101
102// this->initializeVectors();
103
104 if ( !this->getFEType(0).compare("P1") ) {
105 C.reset(new Matrix_Type( this->getDomain(1)->getMapUnique(), this->getDomain(1)->getApproxEntriesPerRow() ) );
106 this->feFactory_->assemblyBDStabilization( this->dim_, "P1", C, true);
107 C->resumeFill();
108 C->scale( -1./viscosity );
109 C->fillComplete( pressureMap, pressureMap );
110 this->system_->addBlock( C, 1, 1 );
111 }
112#ifdef FEDD_HAVE_TEKO
113 if ( !this->parameterList_->sublist("General").get("Preconditioner Method","Monolithic").compare("Teko") ) {
114 if (!this->parameterList_->sublist("General").get("Assemble Velocity Mass",false)) {
115 MatrixPtr_Type Mvelocity(new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getApproxEntriesPerRow() ) );
116 //
117 this->feFactory_->assemblyMass( this->dim_, this->domain_FEType_vec_.at(0), "Vector", Mvelocity, true );
118 //
119 this->getPreconditionerConst()->setVelocityMassMatrix( Mvelocity );
120 if (this->verbose_)
121 std::cout << "\nVelocity mass matrix for LSC block preconditioner is assembled." << std::endl;
122 } else {
123 if (this->verbose_)
124 std::cout << "\nVelocity mass matrix for LSC block preconditioner not assembled." << std::endl;
125 }
126 }
127#endif
128 std::string precType = this->parameterList_->sublist("General").get("Preconditioner Method","Monolithic");
129 if ( precType == "Diagonal" || precType == "Triangular" ) {
130 MatrixPtr_Type Mpressure(new Matrix_Type( this->getDomain(1)->getMapUnique(), this->getDomain(1)->getApproxEntriesPerRow() ) );
131
132 this->feFactory_->assemblyMass( this->dim_, this->domain_FEType_vec_.at(1), "Scalar", Mpressure, true );
133
134 Mpressure->resumeFill();
135 Mpressure->scale(-1./viscosity);
136 Mpressure->fillComplete( pressureMap, pressureMap );
137 this->getPreconditionerConst()->setPressureMassMatrix( Mpressure );
138 }
139
140 this->assembleSourceTerm( 0. );
141 this->addToRhs( this->sourceTerm_ );
142 //this->rhs_->print();
143
144 if (this->verbose_)
145 std::cout << "done -- " << std::endl;
146
147}
148
149}
150#endif
Definition Problem_decl.hpp:42
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36