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 <<
" Call Reassemble FixedPoint and Newton to allocate the Matrix pattern " << std::endl;
210 this->reAssemble(
"Newton");
213 std::cout <<
"done -- " << std::endl;
218template<
class SC,
class LO,
class GO,
class NO>
219void NavierStokesAssFE<SC,LO,GO,NO>::reAssemble( MatrixPtr_Type& massmatrix, std::string type )
const
226template<
class SC,
class LO,
class GO,
class NO>
227void NavierStokesAssFE<SC,LO,GO,NO>::reAssemble(std::string type)
const {
231 std::cout <<
"-- Reassembly Navier-Stokes ("<< type <<
") ... " << std::flush;
233 double density = this->parameterList_->sublist(
"Parameter").get(
"Density",1.);
235 MatrixPtr_Type ANW = Teuchos::rcp(
new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getDimension() * this->getDomain(0)->getApproxEntriesPerRow() ) );
237 MultiVectorConstPtr_Type u = this->solution_->getBlock(0);
238 u_rep_->importFromVector(u,
true);
240 MultiVectorConstPtr_Type p = this->solution_->getBlock(1);
241 p_rep_->importFromVector(p,
true);
246 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);
249 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);
252 else if (type==
"FixedPoint" ) {
254 this->system_->addBlock(ANW,0,0);
255 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);
257 else if(type==
"Newton"){
259 this->system_->addBlock(ANW,0,0);
260 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);
264 this->system_->addBlock(ANW,0,0);
267 std::cout <<
"done -- " << std::endl;
273template<
class SC,
class LO,
class GO,
class NO>
274void NavierStokesAssFE<SC,LO,GO,NO>::calculateNonLinResidualVec(std::string type,
double time)
const{
277 this->reAssemble(
"Rhs");
280 if(this->getDomain(0)->getFEType() ==
"P1"){
282 MultiVectorPtr_Type residualPressureTmp = Teuchos::rcp(
new MultiVector_Type( this->getDomain(1)->getMapUnique() ));
284 this->system_->getBlock(1,1)->apply( *(this->solution_->getBlock(1)), *residualPressureTmp);
286 this->residualVec_->getBlockNonConst(1)->update(1.,*residualPressureTmp,1.);
298 if (!type.compare(
"standard")){
299 this->residualVec_->update(-1.,*this->rhs_,1.);
303 this->bcFactory_->setVectorMinusBC( this->residualVec_, this->solution_, time );
306 else if(!type.compare(
"reverse")){
307 this->residualVec_->update(1.,*this->rhs_,-1.);
311 this->bcFactory_->setBCMinusVector( this->residualVec_, this->solution_, time );
317template<
class SC,
class LO,
class GO,
class NO>
318void NavierStokesAssFE<SC,LO,GO,NO>::calculateNonLinResidualVecWithMeshVelo(std::string type,
double time, MultiVectorPtr_Type u_minus_w, MatrixPtr_Type P)
const{
326 this->system_->apply( *this->solution_, *this->residualVec_ );
329 if (!type.compare(
"standard")){
330 this->residualVec_->update(-1.,*this->rhs_,1.);
331 if ( !this->sourceTerm_.is_null() )
332 this->residualVec_->update(-1.,*this->sourceTerm_,1.);
334 else if(!type.compare(
"reverse")){
335 this->residualVec_->update(1.,*this->rhs_,-1.);
336 if ( !this->sourceTerm_.is_null() )
337 this->residualVec_->update(1.,*this->sourceTerm_,1.);
341 this->bcFactory_->setBCMinusVector( this->residualVec_, this->solution_, time );
384template<
class SC,
class LO,
class GO,
class NO>
385void NavierStokesAssFE<SC,LO,GO,NO>::reAssembleExtrapolation(BlockMultiVectorPtrArray_Type previousSolutions){
388 std::cout <<
"-- Reassembly Navier-Stokes (Extrapolation) ... " << std::flush;
391 double density = this->parameterList_->sublist(
"Parameter").get(
"Density",1.);
393 if (previousSolutions.size()>=2) {
395 MultiVectorPtr_Type extrapolatedVector = Teuchos::rcp(
new MultiVector_Type( previousSolutions[0]->getBlock(0) ) );
397 extrapolatedVector->update( -1., *previousSolutions[1]->getBlock(0), 2. );
399 u_rep_->importFromVector(extrapolatedVector,
true);
401 else if(previousSolutions.size()==1){
402 MultiVectorConstPtr_Type u = previousSolutions[0]->getBlock(0);
403 u_rep_->importFromVector(u,
true);
405 else if (previousSolutions.size()==0){
406 MultiVectorConstPtr_Type u = this->solution_->getBlock(0);
407 u_rep_->importFromVector(u,
true);
410 MatrixPtr_Type ANW = Teuchos::rcp(
new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getDimension() * this->getDomain(0)->getApproxEntriesPerRow() ) );
412 MatrixPtr_Type N = Teuchos::rcp(
new Matrix_Type( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getDimension() * this->getDomain(0)->getApproxEntriesPerRow() ) );
413 this->feFactory_->assemblyAdvectionVecField( this->dim_, this->domain_FEType_vec_.at(0), N, u_rep_,
true );
417 N->fillComplete( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getMapVecFieldUnique());
419 A_->addMatrix(1.,ANW,0.);
420 N->addMatrix(1.,ANW,1.);
422 ANW->fillComplete( this->getDomain(0)->getMapVecFieldUnique(), this->getDomain(0)->getMapVecFieldUnique() );
424 this->system_->addBlock( ANW, 0, 0 );
427 std::cout <<
"done -- " << std::endl;
436template<
class SC,
class LO,
class GO,
class NO>
437void NavierStokesAssFE<SC,LO,GO,NO>::computeSteadyPostprocessingViscosity_Solution() {
440 MultiVectorConstPtr_Type u = this->solution_->getBlock(0);
441 u_rep_->importFromVector(u,
true);
443 MultiVectorConstPtr_Type p = this->solution_->getBlock(1);
444 p_rep_->importFromVector(p,
true);
449 viscosity_element_ = Teuchos::rcp(
new MultiVector_Type( this->getDomain(0)->getElementMap() ) );
450 this->feFactory_->computeSteadyViscosityFE_CM(this->dim_, this->getDomain(0)->getFEType(), this->getDomain(1)->getFEType(), this->dim_,1,u_rep_,p_rep_,this->parameterList_);
452 Teuchos::RCP<const MultiVector<SC,LO,GO,NO>> exportSolutionViscosityAssFE = this->feFactory_->const_output_fields->getBlock(0);
453 viscosity_element_->importFromVector(exportSolutionViscosityAssFE,
true);
Definition NonLinearProblem_decl.hpp:24
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:33