MueLu  Version of the Day
MueLu_RefMaxwell_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef MUELU_REFMAXWELL_DECL_HPP
47 #define MUELU_REFMAXWELL_DECL_HPP
48 
49 #include "MueLu.hpp"
50 #include "MueLu_ConfigDefs.hpp"
51 #include "MueLu_BaseClass.hpp"
52 #include "MueLu_Utilities.hpp"
53 #include "MueLu_SaPFactory.hpp"
54 #include "MueLu_TentativePFactory.hpp"
55 #include "MueLu_SmootherFactory.hpp"
56 #include "MueLu_CoalesceDropFactory.hpp"
57 #include "MueLu_UncoupledAggregationFactory.hpp"
58 #include "MueLu_TrilinosSmoother.hpp"
59 
60 #if defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_IFPACK2)
61 
62 #include "Tpetra_Operator.hpp"
63 #include "Tpetra_CrsMatrix.hpp"
64 #include "Tpetra_MultiVector_decl.hpp"
65 #include "MatrixMarket_Tpetra.hpp"
66 #include "Xpetra_Matrix.hpp"
67 #include "Xpetra_MatrixFactory.hpp"
68 #include "Xpetra_CrsMatrixWrap.hpp"
69 #include "Xpetra_BlockedCrsMatrix.hpp"
70 #include "Xpetra_TpetraMultiVector.hpp"
71 #include "Xpetra_ExportFactory.hpp"
72 
73 namespace MueLu {
74 
87  template <class Scalar =
88  Tpetra::Operator<>::scalar_type,
89  class LocalOrdinal =
90  typename Tpetra::Operator<Scalar>::local_ordinal_type,
91  class GlobalOrdinal =
92  typename Tpetra::Operator<Scalar, LocalOrdinal>::global_ordinal_type,
93  class Node =
94  typename Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal>::node_type>
95  class RefMaxwell : public Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
96 
97 #undef MUELU_REFMAXWELL_SHORT
98 #include "MueLu_UseShortNames.hpp"
99 
100  public:
101 
102  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> TMap;
103  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> TCRS;
104  typedef Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> TROW;
105  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
106  typedef Xpetra::Map<LocalOrdinal,GlobalOrdinal,Node> XMap;
107  typedef Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> XMV;
108  typedef Xpetra::TpetraMultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> XTMV;
109  typedef Xpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> XCRS;
110  typedef Xpetra::TpetraCrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> XTCRS;
111  typedef Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> XMat;
112  typedef Xpetra::CrsMatrixWrap<Scalar,LocalOrdinal,GlobalOrdinal,Node> XCrsWrap;
113 
116  Hierarchy11_(Teuchos::null),
117  Hierarchy22_(Teuchos::null),
118  disable_addon_(true),
119  mode_("additive")
120  {
121  }
122 
124  RefMaxwell(Teuchos::RCP<Hierarchy> H11, Teuchos::RCP<Hierarchy> H22) :
125  Hierarchy11_(H11),
126  Hierarchy22_(H22),
127  disable_addon_(false),
128  mode_("additive")
129  {
130  }
131 
143  RefMaxwell(const Teuchos::RCP<TCRS> & SM_Matrix,
144  const Teuchos::RCP<TCRS> & D0_Matrix,
145  const Teuchos::RCP<TCRS> & M0inv_Matrix,
146  const Teuchos::RCP<TCRS> & M1_Matrix,
147  const Teuchos::RCP<TMV> & Nullspace,
148  const Teuchos::RCP<TMV> & Coords,
149  Teuchos::ParameterList& List,
150  bool ComputePrec = true)
151  {
152  initialize(D0_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
153 
154  resetMatrix(SM_Matrix);
155 
156  // compute preconditioner (optionally)
157  if(ComputePrec)
158  compute();
159  }
160 
170  RefMaxwell(const Teuchos::RCP<TCRS> & D0_Matrix,
171  const Teuchos::RCP<TCRS> & M0inv_Matrix,
172  const Teuchos::RCP<TCRS> & M1_Matrix,
173  const Teuchos::RCP<TMV> & Nullspace,
174  const Teuchos::RCP<TMV> & Coords,
175  Teuchos::ParameterList& List)
176  {
177  initialize(D0_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
178  }
179 
190  RefMaxwell(const Teuchos::RCP<TCRS> & SM_Matrix,
191  const Teuchos::RCP<TCRS> & D0_Matrix,
192  const Teuchos::RCP<TCRS> & M1_Matrix,
193  const Teuchos::RCP<TMV> & Nullspace,
194  const Teuchos::RCP<TMV> & Coords,
195  Teuchos::ParameterList& List,
196  bool ComputePrec = true)
197  {
198  initialize(D0_Matrix,Teuchos::null,M1_Matrix,Nullspace,Coords,List);
199 
200  resetMatrix(SM_Matrix);
201 
202  // compute preconditioner (optionally)
203  if(ComputePrec)
204  compute();
205  }
206 
215  RefMaxwell(const Teuchos::RCP<TCRS> & D0_Matrix,
216  const Teuchos::RCP<TCRS> & M1_Matrix,
217  const Teuchos::RCP<TMV> & Nullspace,
218  const Teuchos::RCP<TMV> & Coords,
219  Teuchos::ParameterList& List)
220  {
221  initialize(D0_Matrix,Teuchos::null,M1_Matrix,Nullspace,Coords,List);
222  }
223 
225  virtual ~RefMaxwell() {}
226 
228  Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > getDomainMap() const;
229 
231  Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > getRangeMap() const;
232 
234  void setParameters(Teuchos::ParameterList& list);
235 
237  void compute();
238 
240  void buildProlongator();
241 
243  void formCoarseMatrix();
244 
246  void resetMatrix(Teuchos::RCP<TCRS> SM_Matrix_new);
247 
249  void applyInverseAdditive(const XTMV& RHS, XTMV& X) const;
250 
252  void applyInverse121(const XTMV& RHS, XTMV& X) const;
253 
255  void applyInverse212(const XTMV& RHS, XTMV& X) const;
256 
260  void apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
261  Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
262  Teuchos::ETransp mode = Teuchos::NO_TRANS,
263  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
264  Scalar beta = Teuchos::ScalarTraits<Scalar>::one()) const;
265 
267  bool hasTransposeApply() const;
268 
269  template <class NewNode>
270  Teuchos::RCP< RefMaxwell<Scalar, LocalOrdinal, GlobalOrdinal, NewNode> >
271  clone (const RCP<NewNode>& new_node) const {
273  (Hierarchy11_->template clone<NewNode> (new_node),
274  Hierarchy22_->template clone<NewNode> (new_node)));
275  }
276 
277  private:
278 
288  void initialize(const Teuchos::RCP<TCRS> & D0_Matrix,
289  const Teuchos::RCP<TCRS> & M0inv_Matrix,
290  const Teuchos::RCP<TCRS> & M1_Matrix,
291  const Teuchos::RCP<TMV> & Nullspace,
292  const Teuchos::RCP<TMV> & Coords,
293  Teuchos::ParameterList& List);
294 
296  Teuchos::RCP<Hierarchy> Hierarchy11_, Hierarchy22_, HierarchySmoother_;
298  Teuchos::RCP<Level> TopLevel_;
301  Teuchos::RCP<XMat> TMT_Matrix_, TMT_Agg_Matrix_, P11_, A11_, A22_;
303  std::vector<LocalOrdinal> BCrows_, BCcols_;
305  Teuchos::RCP<XMV> Nullspace_, Coords_;
310  std::string mode_;
311 
312  };
313 
314 } // namespace
315 
316 #endif //ifdef HAVE_MUELU_TPETRA
317 
318 #define MUELU_REFMAXWELL_SHORT
319 #endif // MUELU_REFMAXWELL_DECL_HPP
RefMaxwell(Teuchos::RCP< Hierarchy > H11, Teuchos::RCP< Hierarchy > H22)
Constructor with Hierarchies.
Teuchos::RCP< XMat > Ms_Matrix_
RefMaxwell(const Teuchos::RCP< TCRS > &D0_Matrix, const Teuchos::RCP< TCRS > &M0inv_Matrix, const Teuchos::RCP< TCRS > &M1_Matrix, const Teuchos::RCP< TMV > &Nullspace, const Teuchos::RCP< TMV > &Coords, Teuchos::ParameterList &List)
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > XCRS
Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > XMV
Teuchos::RCP< XMat > M0inv_Matrix_
Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > TROW
std::vector< LocalOrdinal > BCcols_
Teuchos::ParameterList smootherList_
Teuchos::RCP< XMat > TMT_Matrix_
RefMaxwell(const Teuchos::RCP< TCRS > &SM_Matrix, const Teuchos::RCP< TCRS > &D0_Matrix, const Teuchos::RCP< TCRS > &M0inv_Matrix, const Teuchos::RCP< TCRS > &M1_Matrix, const Teuchos::RCP< TMV > &Nullspace, const Teuchos::RCP< TMV > &Coords, Teuchos::ParameterList &List, bool ComputePrec=true)
std::vector< LocalOrdinal > BCrows_
Vectors for BCs.
Teuchos::RCP< Hierarchy > HierarchySmoother_
Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > XMat
void apply(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::one()) const
RefMaxwell(const Teuchos::RCP< TCRS > &D0_Matrix, const Teuchos::RCP< TCRS > &M1_Matrix, const Teuchos::RCP< TMV > &Nullspace, const Teuchos::RCP< TMV > &Coords, Teuchos::ParameterList &List)
Namespace for MueLu classes and methods.
Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > TMap
Teuchos::RCP< XMat > A22_
void setParameters(Teuchos::ParameterList &list)
Set parameters.
void buildProlongator()
Setup the prolongator for the (1,1)-block.
Teuchos::RCP< XMat > D0_Matrix_
Xpetra::TpetraMultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > XTMV
Preconditioner (wrapped as a Tpetra::Operator) for Maxwell&#39;s equations in curl-curl form...
Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > XMap
Teuchos::ParameterList precList11_
Xpetra::CrsMatrixWrap< Scalar, LocalOrdinal, GlobalOrdinal, Node > XCrsWrap
void compute()
Setup the preconditioner.
Teuchos::RCP< XMat > SM_Matrix_
Various matrices.
Teuchos::RCP< XMat > A11_
Teuchos::RCP< Hierarchy > Hierarchy22_
void applyInverse212(const XTMV &RHS, XTMV &X) const
apply 2-1-2 algorithm for 2x2 solve
Teuchos::RCP< RefMaxwell< Scalar, LocalOrdinal, GlobalOrdinal, NewNode > > clone(const RCP< NewNode > &new_node) const
Teuchos::RCP< XMat > TMT_Agg_Matrix_
Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > TCRS
void applyInverse121(const XTMV &RHS, XTMV &X) const
apply 1-2-1 algorithm for 2x2 solve
Teuchos::RCP< Hierarchy > Hierarchy11_
Two hierarchies: one for the (1,1)-block, another for the (2,2)-block.
bool disable_addon_
Some options.
Teuchos::RCP< Level > TopLevel_
Top Level.
virtual ~RefMaxwell()
Destructor.
Teuchos::ParameterList parameterList_
Parameter lists.
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > TMV
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
Teuchos::RCP< XMat > P11_
void initialize(const Teuchos::RCP< TCRS > &D0_Matrix, const Teuchos::RCP< TCRS > &M0inv_Matrix, const Teuchos::RCP< TCRS > &M1_Matrix, const Teuchos::RCP< TMV > &Nullspace, const Teuchos::RCP< TMV > &Coords, Teuchos::ParameterList &List)
Teuchos::RCP< XMV > Coords_
RefMaxwell(const Teuchos::RCP< TCRS > &SM_Matrix, const Teuchos::RCP< TCRS > &D0_Matrix, const Teuchos::RCP< TCRS > &M1_Matrix, const Teuchos::RCP< TMV > &Nullspace, const Teuchos::RCP< TMV > &Coords, Teuchos::ParameterList &List, bool ComputePrec=true)
Xpetra::TpetraCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > XTCRS
void formCoarseMatrix()
Compute P11^{T}*A*P11 efficiently.
Teuchos::RCP< XMat > M1_Matrix_
void resetMatrix(Teuchos::RCP< TCRS > SM_Matrix_new)
Reset system matrix.
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Teuchos::ParameterList precList22_
Teuchos::RCP< XMV > Nullspace_
Nullspace.
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
void applyInverseAdditive(const XTMV &RHS, XTMV &X) const
apply additive algorithm for 2x2 solve