1#ifndef NAVIERSTOKESASSFE_def_hpp
2#define NAVIERSTOKESASSFE_def_hpp
3#include "NavierStokesAssFE_decl.hpp"
42template<
class SC,
class LO,
class GO,
class NO>
43NavierStokesAssFE<SC,LO,GO,NO>::NavierStokesAssFE(
const DomainConstPtr_Type &domainVelocity, std::string FETypeVelocity,
const DomainConstPtr_Type &domainPressure, std::string FETypePressure, ParameterListPtr_Type parameterList ):
46pressureIDsLoc(new vec_int_Type(2)),
52 this->nonLinearTolerance_ = this->parameterList_->sublist(
"Parameter").get(
"relNonLinTol",1.0e-6);
53 this->initNOXParameters();
55 this->addVariable( domainVelocity , FETypeVelocity ,
"u" , domainVelocity->getDimension());
56 this->addVariable( domainPressure , FETypePressure ,
"p" , 1);
57 this->dim_ = this->getDomain(0)->getDimension();
59 u_rep_ = Teuchos::rcp(
new MultiVector_Type( this->getDomain(0)->getMapVecFieldRepeated() ) );
61 p_rep_ = Teuchos::rcp(
new MultiVector_Type( this->getDomain(1)->getMapRepeated() ) );
63 if (parameterList->sublist(
"Parameter").get(
"Calculate Coefficients",
false)) {
64 vec2D_dbl_ptr_Type vectmpPointsPressure = domainPressure->getPointsUnique();
65 vec2D_dbl_Type::iterator it;
68 if (domainPressure->getDimension() == 2) {
69 it = find_if(vectmpPointsPressure->begin(), vectmpPointsPressure->end(),
70 [&] (
const std::vector<double>& a){
71 if (a.at(0) >= 0.15-1.e-12 && a.at(0) <= 0.15+1.e-12
72 && a.at(1) >= 0.2-1.e-12 && a.at(1) <= 0.2+1.e-12) {
80 if (it != vectmpPointsPressure->end()) {
81 front = distance(vectmpPointsPressure->begin(),it);
83 it = find_if(vectmpPointsPressure->begin(), vectmpPointsPressure->end(),
84 [&] (
const std::vector<double>& a){
85 if (a.at(0) >= 0.25-1.e-12 && a.at(0) <= 0.25+1.e-12
86 && a.at(1) >= 0.2-1.e-12 && a.at(1) <= 0.2+1.e-12) {
94 if (it != vectmpPointsPressure->end()) {
95 back = distance(vectmpPointsPressure->begin(),it);
97 pressureIDsLoc->at(0) = front;
98 pressureIDsLoc->at(1) = back;
100 else if(domainPressure->getDimension() == 3){
101#ifdef ASSERTS_WARNINGS
102 MYASSERT(
false,
"Not implemented to calc coefficients in 3D!");
109template<
class SC,
class LO,
class GO,
class NO>
110void NavierStokesAssFE<SC,LO,GO,NO>::info(){
112 this->infoNonlinProblem();
115template<
class SC,
class LO,
class GO,
class NO>
116void NavierStokesAssFE<SC,LO,GO,NO>::assemble( std::string type )
const{
120 std::cout <<
"-- Assembly Navier-Stokes ... " << std::endl;
122 assembleConstantMatrices();
125 std::cout <<
"done -- " << std::endl;
132template<
class SC,
class LO,
class GO,
class NO>
133void NavierStokesAssFE<SC,LO,GO,NO>::assembleConstantMatrices()
const{
136 std::cout <<
"-- Assembly constant matrices Navier-Stokes ... " << std::flush;
138 double viscosity = this->parameterList_->sublist(
"Parameter").get(
"Viscosity",1.);
139 double density = this->parameterList_->sublist(
"Parameter").get(
"Density",1.);
144 A_.reset(
new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getDimension() * this->getDomain(0)->getApproxEntriesPerRow() ) );
146 MapConstPtr_Type pressureMap;
147 if ( this->getDomain(1)->getFEType() ==
"P0" )
148 pressureMap = this->getDomain(1)->getElementMap();
150 pressureMap = this->getDomain(1)->getMapUnique();
152 if (this->system_.is_null())
153 this->system_.reset(
new BlockMatrix_Type(2));
155 if (this->residualVec_.is_null())
156 this->residualVec_.reset(
new BlockMultiVector_Type(2));
158 MatrixPtr_Type B(
new Matrix_Type( pressureMap, this->getDomain(0)->getDimension() * this->getDomain(0)->getApproxEntriesPerRow() ) );
159 MatrixPtr_Type BT(
new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(1)->getDimension() * this->getDomain(1)->getApproxEntriesPerRow() ) );
162 this->system_->addBlock(A_,0,0);
163 this->system_->addBlock(BT,0,1);
164 this->system_->addBlock(B,1,0);
166 this->feFactory_->assemblyNavierStokes(this->dim_, this->getDomain(0)->getFEType(), this->getDomain(1)->getFEType(), 2, this->dim_,1,u_rep_,p_rep_,this->system_,this->residualVec_,this->coeff_, this->parameterList_,
false,
"Jacobian",
true);
168 if ( !this->getFEType(0).compare(
"P1") ) {
169 MatrixPtr_Type C(
new Matrix_Type( this->getDomain(1)->getMapUnique(), this->getDomain(1)->getApproxEntriesPerRow() ) );
170 this->feFactory_->assemblyBDStabilization( this->dim_,
"P1", C,
true);
172 C->scale( -1. / ( viscosity * density ) );
173 C->fillComplete( pressureMap, pressureMap );
175 this->system_->addBlock( C, 1, 1 );
182 if ( !this->parameterList_->sublist(
"General").get(
"Preconditioner Method",
"Monolithic").compare(
"Teko") ) {
183 if (!this->parameterList_->sublist(
"General").get(
"Assemble Velocity Mass",
false)) {
184 MatrixPtr_Type Mvelocity(
new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getApproxEntriesPerRow() ) );
186 this->feFactory_->assemblyMass( this->dim_, this->domain_FEType_vec_.at(0),
"Vector", Mvelocity,
true );
188 this->getPreconditionerConst()->setVelocityMassMatrix( Mvelocity );
190 std::cout <<
"\nVelocity mass matrix for LSC block preconditioner is assembled." << std::endl;
193 std::cout <<
"\nVelocity mass matrix for LSC block preconditioner not assembled." << std::endl;
197 std::string precType = this->parameterList_->sublist(
"General").get(
"Preconditioner Method",
"Monolithic");
198 if ( precType ==
"Diagonal" || precType ==
"Triangular" ) {
199 MatrixPtr_Type Mpressure(
new Matrix_Type( this->getDomain(1)->getMapUnique(), this->getDomain(1)->getApproxEntriesPerRow() ) );
201 this->feFactory_->assemblyMass( this->dim_, this->domain_FEType_vec_.at(1),
"Scalar", Mpressure,
true );
202 SC kinVisco = this->parameterList_->sublist(
"Parameter").get(
"Viscosity",1.);
203 Mpressure->scale(-1./kinVisco);
204 this->getPreconditionerConst()->setPressureMassMatrix( Mpressure );
207 std::cout <<
"done -- " << std::endl;
211template<
class SC,
class LO,
class GO,
class NO>
212void NavierStokesAssFE<SC,LO,GO,NO>::reAssemble( MatrixPtr_Type& massmatrix, std::string type )
const
219template<
class SC,
class LO,
class GO,
class NO>
220void NavierStokesAssFE<SC,LO,GO,NO>::reAssemble(std::string type)
const {
224 std::cout <<
"-- Reassembly Navier-Stokes ("<< type <<
") ... " << std::flush;
226 double density = this->parameterList_->sublist(
"Parameter").get(
"Density",1.);
228 MatrixPtr_Type ANW = Teuchos::rcp(
new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getDimension() * this->getDomain(0)->getApproxEntriesPerRow() ) );
230 MultiVectorConstPtr_Type u = this->solution_->getBlock(0);
231 u_rep_->importFromVector(u,
true);
233 MultiVectorConstPtr_Type p = this->solution_->getBlock(1);
234 p_rep_->importFromVector(p,
true);
239 this->system_->addBlock(ANW,0,0);
241 this->feFactory_->assemblyNavierStokes(this->dim_, this->getDomain(0)->getFEType(), this->getDomain(1)->getFEType(), 2, this->dim_,1,u_rep_,p_rep_,this->system_, this->residualVec_,this->coeff_,this->parameterList_,
true,
"FixedPoint",
true);
242 this->feFactory_->assemblyNavierStokes(this->dim_, this->getDomain(0)->getFEType(), this->getDomain(1)->getFEType(), 2, this->dim_,1,u_rep_,p_rep_,this->system_, this->residualVec_,this->coeff_,this->parameterList_,
true,
"Rhs",
true);
245 else if (type==
"FixedPoint" ) {
247 this->system_->addBlock(ANW,0,0);
248 this->feFactory_->assemblyNavierStokes(this->dim_, this->getDomain(0)->getFEType(), this->getDomain(1)->getFEType(), 2, this->dim_,1,u_rep_,p_rep_,this->system_, this->residualVec_,this->coeff_,this->parameterList_,
true,
"FixedPoint",
true);
250 else if(type==
"Newton"){
252 this->system_->addBlock(ANW,0,0);
253 this->feFactory_->assemblyNavierStokes(this->dim_, this->getDomain(0)->getFEType(), this->getDomain(1)->getFEType(), 2, this->dim_,1,u_rep_,p_rep_,this->system_,this->residualVec_, this->coeff_,this->parameterList_,
true,
"Jacobian",
true);
257 this->system_->addBlock(ANW,0,0);
260 std::cout <<
"done -- " << std::endl;
266template<
class SC,
class LO,
class GO,
class NO>
267void NavierStokesAssFE<SC,LO,GO,NO>::calculateNonLinResidualVec(std::string type,
double time)
const{
270 this->reAssemble(
"Rhs");
273 if(this->getDomain(0)->getFEType() ==
"P1"){
275 MultiVectorPtr_Type residualPressureTmp = Teuchos::rcp(
new MultiVector_Type( this->getDomain(1)->getMapUnique() ));
277 this->system_->getBlock(1,1)->apply( *(this->solution_->getBlock(1)), *residualPressureTmp);
279 this->residualVec_->getBlockNonConst(1)->update(1.,*residualPressureTmp,1.);
291 if (!type.compare(
"standard")){
292 this->residualVec_->update(-1.,*this->rhs_,1.);
296 this->bcFactory_->setVectorMinusBC( this->residualVec_, this->solution_, time );
299 else if(!type.compare(
"reverse")){
300 this->residualVec_->update(1.,*this->rhs_,-1.);
304 this->bcFactory_->setBCMinusVector( this->residualVec_, this->solution_, time );
310template<
class SC,
class LO,
class GO,
class NO>
311void NavierStokesAssFE<SC,LO,GO,NO>::calculateNonLinResidualVecWithMeshVelo(std::string type,
double time, MultiVectorPtr_Type u_minus_w, MatrixPtr_Type P)
const{
319 this->system_->apply( *this->solution_, *this->residualVec_ );
322 if (!type.compare(
"standard")){
323 this->residualVec_->update(-1.,*this->rhs_,1.);
324 if ( !this->sourceTerm_.is_null() )
325 this->residualVec_->update(-1.,*this->sourceTerm_,1.);
327 else if(!type.compare(
"reverse")){
328 this->residualVec_->update(1.,*this->rhs_,-1.);
329 if ( !this->sourceTerm_.is_null() )
330 this->residualVec_->update(1.,*this->sourceTerm_,1.);
334 this->bcFactory_->setBCMinusVector( this->residualVec_, this->solution_, time );
377template<
class SC,
class LO,
class GO,
class NO>
378void NavierStokesAssFE<SC,LO,GO,NO>::reAssembleExtrapolation(BlockMultiVectorPtrArray_Type previousSolutions){
381 std::cout <<
"-- Reassembly Navier-Stokes (Extrapolation) ... " << std::flush;
384 double density = this->parameterList_->sublist(
"Parameter").get(
"Density",1.);
386 if (previousSolutions.size()>=2) {
388 MultiVectorPtr_Type extrapolatedVector = Teuchos::rcp(
new MultiVector_Type( previousSolutions[0]->getBlock(0) ) );
390 extrapolatedVector->update( -1., *previousSolutions[1]->getBlock(0), 2. );
392 u_rep_->importFromVector(extrapolatedVector,
true);
394 else if(previousSolutions.size()==1){
395 MultiVectorConstPtr_Type u = previousSolutions[0]->getBlock(0);
396 u_rep_->importFromVector(u,
true);
398 else if (previousSolutions.size()==0){
399 MultiVectorConstPtr_Type u = this->solution_->getBlock(0);
400 u_rep_->importFromVector(u,
true);
403 MatrixPtr_Type ANW = Teuchos::rcp(
new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getDimension() * this->getDomain(0)->getApproxEntriesPerRow() ) );
405 MatrixPtr_Type N = Teuchos::rcp(
new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getDimension() * this->getDomain(0)->getApproxEntriesPerRow() ) );
406 this->feFactory_->assemblyAdvectionVecField( this->dim_, this->domain_FEType_vec_.at(0), N, u_rep_,
true );
410 N->fillComplete( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getMapVecFieldUnique());
412 A_->addMatrix(1.,ANW,0.);
413 N->addMatrix(1.,ANW,1.);
415 ANW->fillComplete( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getMapVecFieldUnique() );
417 this->system_->addBlock( ANW, 0, 0 );
420 std::cout <<
"done -- " << std::endl;
429template<
class SC,
class LO,
class GO,
class NO>
430void NavierStokesAssFE<SC,LO,GO,NO>::computeSteadyPostprocessingViscosity_Solution() {
433 MultiVectorConstPtr_Type u = this->solution_->getBlock(0);
434 u_rep_->importFromVector(u,
true);
436 MultiVectorConstPtr_Type p = this->solution_->getBlock(1);
437 p_rep_->importFromVector(p,
true);
442 viscosity_element_ = Teuchos::rcp(
new MultiVector_Type( this->getDomain(0)->getElementMap() ) );
443 this->feFactory_->computeSteadyViscosityFE_CM(this->dim_, this->getDomain(0)->getFEType(), this->getDomain(1)->getFEType(), this->dim_,1,u_rep_,p_rep_,this->parameterList_);
445 Teuchos::RCP<const MultiVector<SC,LO,GO,NO>> exportSolutionViscosityAssFE = this->feFactory_->const_output_fields->getBlock(0);
446 viscosity_element_->importFromVector(exportSolutionViscosityAssFE,
true);
Definition NonLinearProblem_decl.hpp:24
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:33