Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
PrecBlock2x2_def.hpp
1#ifndef PrecBlock2x2_DEF_hpp
2#define PrecBlock2x2_DEF_hpp
3#include "PrecBlock2x2_decl.hpp"
4#include <Thyra_TpetraMultiVector_decl.hpp>
5#include <Teuchos_VerboseObject.hpp>
14
15namespace FEDD {
16using namespace Thyra;
17
18// Constructors
19
20template<class SC, class LO, class GO, class NO>
21PrecBlock2x2<SC,LO,GO,NO>::PrecBlock2x2()
22:PreconditionerOperator<SC,LO,GO,NO>()
23{
24// TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Still a problem for FaCSI, cant be used yet.");
25}
26
27template<class SC, class LO, class GO, class NO>
28PrecBlock2x2<SC,LO,GO,NO>::PrecBlock2x2( CommConstPtr_Type comm )
29:PreconditionerOperator<SC,LO,GO,NO>()
30{
31 comm_=comm;
32// TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Still a problem for FaCSI, cant be used yet.");
33}
34
35template<class SC, class LO, class GO, class NO>
37 ThyraLinOpPtr_Type velocityInv,
38 ThyraLinOpPtr_Type pressureInv
39 ){
40 setVeloctiyInv(velocityInv);
41
42 setPressureInv(pressureInv);
43
44 setType("Diagonal");
45
46 initialize();
47}
48
49template<class SC, class LO, class GO, class NO>
50void PrecBlock2x2<SC,LO,GO,NO>::setTriangular(
51 ThyraLinOpPtr_Type velocityInv,
52 ThyraLinOpPtr_Type pressureInv,
53 ThyraLinOpPtr_Type BT
54 ){
55 setVeloctiyInv(velocityInv);
56
57 setPressureInv(pressureInv);
58
59 setType("Triangular");
60
61 BT_ = BT;
62
63 initialize();
64}
65
66template<class SC, class LO, class GO, class NO>
67void PrecBlock2x2<SC,LO,GO,NO>::setVeloctiyInv(ThyraLinOpPtr_Type velocityInv){
68 velocityInv_ = velocityInv;
69}
70
71template<class SC, class LO, class GO, class NO>
72void PrecBlock2x2<SC,LO,GO,NO>::setPressureInv(ThyraLinOpPtr_Type pressureInv){
73 pressureInv_ = pressureInv;
74}
75
76template<class SC, class LO, class GO, class NO>
77void PrecBlock2x2<SC,LO,GO,NO>::setType(std::string type){
78 type_ = type;
79}
80
81template<class SC, class LO, class GO, class NO>
82void PrecBlock2x2<SC,LO,GO,NO>::initialize(){
83 TEUCHOS_TEST_FOR_EXCEPTION(velocityInv_.is_null(), std::runtime_error,"Can not initialize Block2x2 preconditioner: 1 preconditioner not set.");
84 TEUCHOS_TEST_FOR_EXCEPTION(pressureInv_.is_null(), std::runtime_error,"Can not initialize Block2x2 preconditioner: 2 preconditioner not set.");
85 Teuchos::Array< Teuchos::RCP< const Thyra::VectorSpaceBase< SC > > > vectorSpacesRange( 2 );
86 Teuchos::Array< Teuchos::RCP< const Thyra::VectorSpaceBase< SC > > > vectorSpacesDomain( 2 );
87 vectorSpacesRange[0] = velocityInv_->range();
88 vectorSpacesRange[1] = pressureInv_->domain();
89
90 vectorSpacesDomain[0] = velocityInv_->domain();
91 vectorSpacesDomain[1] = pressureInv_->domain();
92
93 Teuchos::RCP<const Thyra::DefaultProductVectorSpace<SC> > pR = Thyra::productVectorSpace<SC>( vectorSpacesRange );
94 Teuchos::RCP<const Thyra::DefaultProductVectorSpace<SC> > pD = Thyra::productVectorSpace<SC>( vectorSpacesDomain );
95
96 this->defaultProductRange_ = pR;
97 this->defaultProductDomain_ = pD;
98}
99
100template<class SC, class LO, class GO, class NO>
101void PrecBlock2x2<SC,LO,GO,NO>::applyIt(
102 const EOpTransp M_trans,
103 const MultiVectorBase<SC> &X_in,
104 const Ptr<MultiVectorBase<SC> > &Y_inout,
105 const SC alpha,
106 const SC beta
107 ) const
108{
109 applyImpl(M_trans, X_in, Y_inout, alpha, beta);
110
111}
112
113template<class SC, class LO, class GO, class NO>
115 const EOpTransp M_trans,
116 const MultiVectorBase<SC> &X_in,
117 const Ptr<MultiVectorBase<SC> > &Y_inout,
118 const SC alpha,
119 const SC beta
120 ) const
121{
122 // alpha and beta are ignored!
123 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
124
125 using Teuchos::rcpFromRef;
126 typedef Teuchos::ScalarTraits<SC> ST;
127 typedef RCP<MultiVectorBase<SC> > MultiVectorPtr;
128 typedef RCP<const MultiVectorBase<SC> > ConstMultiVectorPtr;
129 typedef RCP<const LinearOpBase<SC> > ConstLinearOpPtr;
130
131 int rank = comm_->getRank();
132
133 Teuchos::RCP<const Thyra::ProductMultiVectorBase<SC> > X
134 = Teuchos::rcp_dynamic_cast<const Thyra::ProductMultiVectorBase<SC> > ( rcpFromRef(X_in) );
135
136 Teuchos::RCP< Thyra::ProductMultiVectorBase<SC> > Y
137 = Teuchos::rcp_dynamic_cast< Thyra::ProductMultiVectorBase<SC> > ( rcpFromPtr(Y_inout) );
138
139 Teuchos::RCP< const MultiVectorBase< SC > > X_0 = X->getMultiVectorBlock(0);
140 Teuchos::RCP< MultiVectorBase< SC > > Y_0 = Y->getNonconstMultiVectorBlock(0);
141
142 Teuchos::RCP< const MultiVectorBase< SC > > X_1 = X->getMultiVectorBlock(1);
143 Teuchos::RCP< MultiVectorBase< SC > > Y_1 = Y->getNonconstMultiVectorBlock(1);
144
145 if (type_ == "Diagonal"){
146 velocityInv_->apply(NOTRANS, *X_0, Y_0.ptr(), 1., 0.);
147
148 pressureInv_->apply(NOTRANS, *X_1, Y_1.ptr(), 1., 0.);
149 }
150 else if (type_ == "Triangular"){
151
152 pressureInv_->apply(NOTRANS, *X_1, Y_1.ptr(), 1., 0.);
153
154 Teuchos::RCP< MultiVectorBase< SC > > Z_0 = X_0->clone_mv();
155
156 BT_->apply(NOTRANS, *Y_1, Z_0.ptr(), -1., 1.); //Z0= BT*Y1 + X0
157
158 velocityInv_->apply(NOTRANS, *Z_0, Y_0.ptr(), 1., 0.);
159
160 }
161 else{
162 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,"Unknow 2x2 block preconditioner type. Select Diagonal or Triangular.");
163 }
164}
165}
166
167#endif
virtual void applyImpl(const Thyra::EOpTransp M_trans, const Thyra::MultiVectorBase< SC > &X, const Teuchos::Ptr< Thyra::MultiVectorBase< SC > > &Y, const SC alpha, const SC beta) const
Definition PrecBlock2x2_def.hpp:114
void setDiagonal(ThyraLinOpPtr_Type velocityInv, ThyraLinOpPtr_Type pressureInv)
Definition PrecBlock2x2_def.hpp:36
Definition PreconditionerOperator_decl.hpp:23
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement.cpp:5