MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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_ConfigDefs.hpp"
50 #include "MueLu_BaseClass.hpp"
51 
57 #include "MueLu_SaPFactory_fwd.hpp"
60 #include "MueLu_Utilities_fwd.hpp"
61 
62 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
70 #endif
71 
78 
80 #include "MueLu_TrilinosSmoother.hpp"
81 #include "MueLu_Hierarchy.hpp"
82 
83 #include "Xpetra_Map_fwd.hpp"
84 #include "Xpetra_Matrix_fwd.hpp"
85 #include "Xpetra_MatrixFactory_fwd.hpp"
86 #include "Xpetra_MultiVectorFactory_fwd.hpp"
87 #include "Xpetra_VectorFactory_fwd.hpp"
88 #include "Xpetra_CrsMatrixWrap_fwd.hpp"
89 
90 #if defined(HAVE_MUELU_IFPACK2) && (!defined(HAVE_MUELU_EPETRA))
91 #define MUELU_REFMAXWELL_CAN_USE_HIPTMAIR
93 #include "Ifpack2_Hiptmair.hpp"
94 #endif
95 
96 namespace MueLu {
97 
124  template <class Scalar,
125  class LocalOrdinal,
126  class GlobalOrdinal,
127  class Node>
128  class RefMaxwell : public VerboseObject, public Xpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
129 
130 #undef MUELU_REFMAXWELL_SHORT
131 #include "MueLu_UseShortNames.hpp"
132 
133  public:
134 
137  typedef typename Xpetra::MultiVector<coordinateType,LO,GO,NO> RealValuedMultiVector;
138 
141  HierarchyH_(Teuchos::null),
142  Hierarchy22_(Teuchos::null),
143  disable_addon_(MasterList::getDefault<bool>("refmaxwell: disable addon")),
144  mode_(MasterList::getDefault<std::string>("refmaxwell: mode"))
145  {
146  }
147 
150  HierarchyH_(HH),
151  Hierarchy22_(H22),
152  disable_addon_(MasterList::getDefault<bool>("refmaxwell: disable addon")),
153  mode_(MasterList::getDefault<std::string>("refmaxwell: mode"))
154  {
155  }
156 
169  RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
170  const Teuchos::RCP<Matrix> & D0_Matrix,
171  const Teuchos::RCP<Matrix> & Ms_Matrix,
172  const Teuchos::RCP<Matrix> & M0inv_Matrix,
173  const Teuchos::RCP<Matrix> & M1_Matrix,
174  const Teuchos::RCP<MultiVector> & Nullspace,
177  bool ComputePrec = true)
178  {
179  initialize(D0_Matrix,Ms_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
180  resetMatrix(SM_Matrix,ComputePrec);
181  }
182 
194  RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
195  const Teuchos::RCP<Matrix> & D0_Matrix,
196  const Teuchos::RCP<Matrix> & M0inv_Matrix,
197  const Teuchos::RCP<Matrix> & M1_Matrix,
198  const Teuchos::RCP<MultiVector> & Nullspace,
201  bool ComputePrec = true)
202  {
203  initialize(D0_Matrix,M1_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
204  resetMatrix(SM_Matrix,ComputePrec);
205  }
206 
216  RefMaxwell(const Teuchos::RCP<Matrix> & D0_Matrix,
217  const Teuchos::RCP<Matrix> & M0inv_Matrix,
218  const Teuchos::RCP<Matrix> & M1_Matrix,
219  const Teuchos::RCP<MultiVector> & Nullspace,
221  Teuchos::ParameterList& List) : SM_Matrix_(Teuchos::null)
222  {
223  initialize(D0_Matrix,M1_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
224  }
225 
236  RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
237  const Teuchos::RCP<Matrix> & D0_Matrix,
238  const Teuchos::RCP<Matrix> & M1_Matrix,
239  const Teuchos::RCP<MultiVector> & Nullspace,
242  bool ComputePrec)
243  {
244  initialize(D0_Matrix,M1_Matrix,Teuchos::null,M1_Matrix,Nullspace,Coords,List);
245  resetMatrix(SM_Matrix,ComputePrec);
246  }
247 
256  RefMaxwell(const Teuchos::RCP<Matrix> & D0_Matrix,
257  const Teuchos::RCP<Matrix> & M1_Matrix,
258  const Teuchos::RCP<MultiVector> & Nullspace,
260  Teuchos::ParameterList& List) : SM_Matrix_(Teuchos::null)
261  {
262  initialize(D0_Matrix,M1_Matrix,Teuchos::null,M1_Matrix,Nullspace,Coords,List);
263  }
264 
271  RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
273  bool ComputePrec = true)
274  {
275 
276  RCP<MultiVector> Nullspace = List.get<RCP<MultiVector> >("Nullspace", Teuchos::null);
277  RCP<RealValuedMultiVector> Coords = List.get<RCP<RealValuedMultiVector> >("Coordinates", Teuchos::null);
278  RCP<Matrix> D0_Matrix = List.get<RCP<Matrix> >("D0");
279  RCP<Matrix> Ms_Matrix;
280  if (List.isType<RCP<Matrix> >("Ms"))
281  Ms_Matrix = List.get<RCP<Matrix> >("Ms");
282  else
283  Ms_Matrix = List.get<RCP<Matrix> >("M1");
284  RCP<Matrix> M1_Matrix = List.get<RCP<Matrix> >("M1");
285  RCP<Matrix> M0inv_Matrix = List.get<RCP<Matrix> >("M0inv", Teuchos::null);
286 
287  initialize(D0_Matrix,Ms_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
288 
289  if (SM_Matrix != Teuchos::null)
290  resetMatrix(SM_Matrix,ComputePrec);
291  }
292 
294  virtual ~RefMaxwell() {}
295 
298 
301 
304  return SM_Matrix_;
305  }
306 
309 
311  void compute(bool reuse=false);
312 
314  void buildProlongator();
315 
317  void formCoarseMatrix();
318 
320  void resetMatrix(Teuchos::RCP<Matrix> SM_Matrix_new, bool ComputePrec=true);
321 
325  void apply (const MultiVector& X, MultiVector& Y,
329 
331  bool hasTransposeApply() const;
332 
334 
336  void residual(const MultiVector & X,
337  const MultiVector & B,
338  MultiVector & R) const {
339  using STS = Teuchos::ScalarTraits<Scalar>;
340  R.update(STS::one(),B,STS::zero());
341  this->apply (X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
342  }
343 
344 
345  private:
346 
357  void initialize(const Teuchos::RCP<Matrix> & D0_Matrix,
358  const Teuchos::RCP<Matrix> & Ms_Matrix,
359  const Teuchos::RCP<Matrix> & M0inv_Matrix,
360  const Teuchos::RCP<Matrix> & M1_Matrix,
361  const Teuchos::RCP<MultiVector> & Nullspace,
363  Teuchos::ParameterList& List);
364 
366  void applyInverseAdditive(const MultiVector& RHS, MultiVector& X) const;
367 
369  void applyInverse121(const MultiVector& RHS, MultiVector& X) const;
370 
372  void applyInverse212(const MultiVector& RHS, MultiVector& X) const;
373 
375  void solveH(const MultiVector& RHS, MultiVector& X) const;
376 
378  void solve22(const MultiVector& RHS, MultiVector& X) const;
379 
381  void allocateMemory(int numVectors) const;
382 
384  void dump(const Matrix& A, std::string name) const;
385 
387  void dump(const MultiVector& X, std::string name) const;
388 
390  void dumpCoords(const RealValuedMultiVector& X, std::string name) const;
391 
393  void dump(const Teuchos::ArrayRCP<bool>& v, std::string name) const;
394 
395 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
396  void dump(const Kokkos::View<bool*, typename Node::device_type>& v, std::string name) const;
398 #endif
399 
401  Teuchos::RCP<Teuchos::TimeMonitor> getTimer(std::string name, RCP<const Teuchos::Comm<int> > comm=Teuchos::null) const;
402 
404  void setMatvecParams(Matrix& A, RCP<ParameterList> matvecParams) {
405  RCP<const Import> xpImporter = A.getCrsGraph()->getImporter();
406  if (!xpImporter.is_null())
407  xpImporter->setDistributorParameters(matvecParams);
408  RCP<const Export> xpExporter = A.getCrsGraph()->getExporter();
409  if (!xpExporter.is_null())
410  xpExporter->setDistributorParameters(matvecParams);
411  }
412 
416 #if defined(MUELU_REFMAXWELL_CAN_USE_HIPTMAIR)
417  Teuchos::RCP<Ifpack2::Preconditioner<Scalar,LocalOrdinal,GlobalOrdinal,Node> > hiptmairPreSmoother_, hiptmairPostSmoother_;
418 #endif
424 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
425  Kokkos::View<bool*, typename Node::device_type> BCrowsKokkos_, BCcolsKokkos_, BCdomainKokkos_;
426 #endif
443  std::string mode_;
446  };
447 
448 } // namespace
449 
450 #define MUELU_REFMAXWELL_SHORT
451 #endif // MUELU_REFMAXWELL_DECL_HPP
const Teuchos::RCP< Matrix > & getJacobian() const
Returns Jacobian matrix SM.
Teuchos::RCP< SmootherBase > PostSmoother_
Teuchos::RCP< const Import > Importer22_
void setMatvecParams(Matrix &A, RCP< ParameterList > matvecParams)
set parameters
Teuchos::RCP< Matrix > D0_T_Matrix_
MueLu::DefaultLocalOrdinal LocalOrdinal
void solve22(const MultiVector &RHS, MultiVector &X) const
apply solve to 2-2 block only
Teuchos::RCP< Teuchos::ParameterList > A22_RAP_reuse_data_
int BCedges_
Vectors for BCs.
Teuchos::RCP< Matrix > Ms_Matrix_
Teuchos::RCP< MultiVector > D0xTmp_
RefMaxwell(const Teuchos::RCP< Matrix > &SM_Matrix, const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< Matrix > &M0inv_Matrix, const Teuchos::RCP< Matrix > &M1_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, Teuchos::ParameterList &List, bool ComputePrec=true)
Teuchos::RCP< const Map > getDomainMap() const
Returns the Xpetra::Map object associated with the domain of this operator.
Teuchos::RCP< Matrix > D0_Matrix_
T & get(const std::string &name, T def_value)
Teuchos::RCP< Matrix > SM_Matrix_
Various matrices.
Teuchos::RCP< MultiVector > D0res_
RefMaxwell(const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< Matrix > &M1_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, Teuchos::ParameterList &List)
Teuchos::ParameterList smootherList_
Teuchos::RCP< Matrix > A22_
Teuchos::RCP< MultiVector > D0resTmp_
Teuchos::RCP< MultiVector > D0TR11Tmp_
void solveH(const MultiVector &RHS, MultiVector &X) const
apply solve to 1-1 block only
Teuchos::RCP< Matrix > Addon_Matrix_
void setParameters(Teuchos::ParameterList &list)
Set parameters.
void dump(const Matrix &A, std::string name) const
dump out matrix
void buildProlongator()
Setup the prolongator for the (1,1)-block.
MueLu::DefaultNode Node
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitudeType
Teuchos::RCP< MultiVector > P11res_
Temporary memory.
Static class that holds the complete list of valid MueLu parameters.
Teuchos::RCP< Matrix > M0inv_Matrix_
void allocateMemory(int numVectors) const
allocate multivectors for solve
Teuchos::RCP< MultiVector > residual_
Teuchos::RCP< MultiVector > D0x_
void applyInverseAdditive(const MultiVector &RHS, MultiVector &X) const
apply additive algorithm for 2x2 solve
Teuchos::RCP< MultiVector > P11resTmp_
MueLu::DefaultScalar Scalar
void resetMatrix(Teuchos::RCP< Matrix > SM_Matrix_new, bool ComputePrec=true)
Reset system matrix.
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Teuchos::RCP< Teuchos::ParameterList > AH_AP_reuse_data_
Teuchos::ParameterList precList11_
RefMaxwell(const Teuchos::RCP< Matrix > &SM_Matrix, const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< Matrix > &M1_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, Teuchos::ParameterList &List, bool ComputePrec)
Teuchos::RCP< Matrix > P11_
Teuchos::RCP< Matrix > A_nodal_Matrix_
Teuchos::RCP< Hierarchy > Hierarchy22_
Teuchos::RCP< Teuchos::ParameterList > AH_RAP_reuse_data_
Teuchos::RCP< Matrix > M1_Matrix_
Teuchos::RCP< RealValuedMultiVector > CoordsH_
Teuchos::ArrayRCP< bool > BCrows_
Teuchos::ArrayRCP< bool > BCcols_
Xpetra::MultiVector< coordinateType, LO, GO, NO > RealValuedMultiVector
void applyInverse212(const MultiVector &RHS, MultiVector &X) const
apply 2-1-2 algorithm for 2x2 solve
Teuchos::RCP< SmootherBase > PreSmoother_
Teuchos::RCP< Teuchos::TimeMonitor > getTimer(std::string name, RCP< const Teuchos::Comm< int > > comm=Teuchos::null) const
get a (synced) timer
void applyInverse121(const MultiVector &RHS, MultiVector &X) const
apply 1-2-1 algorithm for 2x2 solve
void compute(bool reuse=false)
Setup the preconditioner.
Teuchos::ArrayRCP< bool > BCdomain_
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_HIGH) const
bool disable_addon_
Some options.
void initialize(const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< Matrix > &Ms_Matrix, const Teuchos::RCP< Matrix > &M0inv_Matrix, const Teuchos::RCP< Matrix > &M1_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, Teuchos::ParameterList &List)
virtual ~RefMaxwell()
Destructor.
Teuchos::ParameterList parameterList_
Parameter lists.
Teuchos::RCP< RealValuedMultiVector > Coords_
Coordinates.
RefMaxwell(const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< Matrix > &M0inv_Matrix, const Teuchos::RCP< Matrix > &M1_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, Teuchos::ParameterList &List)
void dumpCoords(const RealValuedMultiVector &X, std::string name) const
dump out real-valued multivector
bool isType(const std::string &name) const
Teuchos::RCP< MultiVector > P11x_
Teuchos::RCP< Matrix > R11_
Teuchos::RCP< const Map > getRangeMap() const
Returns the Xpetra::Map object associated with the range of this operator.
void apply(const MultiVector &X, MultiVector &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
void residual(const MultiVector &X, const MultiVector &B, MultiVector &R) const
Compute a residual R = B - (*this) * X.
Teuchos::RCP< Matrix > AH_
void formCoarseMatrix()
Compute P11^{T}*A*P11 efficiently.
Teuchos::RCP< MultiVector > P11xTmp_
Teuchos::ScalarTraits< Scalar >::coordinateType coordinateType
Teuchos::RCP< Hierarchy > HierarchyH_
Two hierarchies: one for the coarse (1,1)-block, another for the (2,2)-block.
RefMaxwell(Teuchos::RCP< Hierarchy > HH, Teuchos::RCP< Hierarchy > H22)
Constructor with Hierarchies.
Teuchos::RCP< Teuchos::ParameterList > A22_AP_reuse_data_
Teuchos::ParameterList precList22_
Teuchos::RCP< MultiVector > Nullspace_
Nullspace.
RefMaxwell(const Teuchos::RCP< Matrix > &SM_Matrix, Teuchos::ParameterList &List, bool ComputePrec=true)
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Teuchos::RCP< const Import > ImporterH_
Importer to coarse (1,1) hierarchy.
bool is_null() const
RefMaxwell(const Teuchos::RCP< Matrix > &SM_Matrix, const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< Matrix > &Ms_Matrix, const Teuchos::RCP< Matrix > &M0inv_Matrix, const Teuchos::RCP< Matrix > &M1_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, Teuchos::ParameterList &List, bool ComputePrec=true)