MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_Maxwell1_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_MAXWELL1_DECL_HPP
11 #define MUELU_MAXWELL1_DECL_HPP
12 
13 #include "MueLu_ConfigDefs.hpp"
14 #include "MueLu_BaseClass.hpp"
15 
17 
18 #include "MueLu_Utilities_fwd.hpp"
19 #include "MueLu_Level_fwd.hpp"
20 #include "MueLu_Hierarchy_fwd.hpp"
21 #include "MueLu_RAPFactory_fwd.hpp"
23 #include "MueLu_PerfUtils_fwd.hpp"
25 
26 #include "Xpetra_Map_fwd.hpp"
27 #include "Xpetra_Matrix_fwd.hpp"
32 
33 namespace MueLu {
34 
41 template <class Scalar,
42  class LocalOrdinal,
43  class GlobalOrdinal,
44  class Node>
45 class Maxwell1 : public VerboseObject, public Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
46 #undef MUELU_MAXWELL1_SHORT
47 #include "MueLu_UseShortNames.hpp"
48 
49  public:
53 
56  : Hierarchy11_(Teuchos::null)
57  , Hierarchy22_(Teuchos::null)
58  , HierarchyGmhd_(Teuchos::null)
59  , mode_(MODE_STANDARD) {
60  }
61 
64  : Hierarchy11_(H11)
65  , Hierarchy22_(H22)
66  , HierarchyGmhd_(Teuchos::null)
67  , mode_(MODE_STANDARD) {
68  }
69 
79  Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
80  const Teuchos::RCP<Matrix>& D0_Matrix,
81  const Teuchos::RCP<MultiVector>& Nullspace,
84  bool ComputePrec = true)
85  : mode_(MODE_STANDARD) {
86  RCP<Matrix> Kn_Matrix;
87  initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, List);
88  resetMatrix(SM_Matrix, ComputePrec);
89  }
90 
100  Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
101  const Teuchos::RCP<Matrix>& D0_Matrix,
102  const Teuchos::RCP<Matrix>& Kn_Matrix,
103  const Teuchos::RCP<MultiVector>& Nullspace,
106  bool ComputePrec = true)
107  : mode_(MODE_STANDARD) {
108  initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, List);
109  resetMatrix(SM_Matrix, ComputePrec);
110  }
111 
122  Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
123  const Teuchos::RCP<Matrix>& D0_Matrix,
124  const Teuchos::RCP<Matrix>& Kn_Matrix,
125  const Teuchos::RCP<MultiVector>& Nullspace,
127  Teuchos::ParameterList& List, const Teuchos::RCP<Matrix>& GmhdA_Matrix,
128  bool ComputePrec = true)
130  initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, List);
131  resetMatrix(SM_Matrix, ComputePrec);
132  GmhdA_Matrix_ = GmhdA_Matrix;
133  HierarchyGmhd_ = rcp(new Hierarchy("HierarchyGmhd"));
134  GMHDSetupHierarchy(List);
135  }
136 
143  Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
145  bool ComputePrec = true)
146  : mode_(MODE_STANDARD) {
147  RCP<MultiVector> Nullspace = List.get<RCP<MultiVector> >("Nullspace", Teuchos::null);
148  RCP<RealValuedMultiVector> Coords = List.get<RCP<RealValuedMultiVector> >("Coordinates", Teuchos::null);
149  RCP<Matrix> D0_Matrix = List.get<RCP<Matrix> >("D0");
150  RCP<Matrix> Kn_Matrix;
151  if (List.isType<RCP<Matrix> >("Kn"))
152  Kn_Matrix = List.get<RCP<Matrix> >("Kn");
153 
154  initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, List);
155 
156  if (SM_Matrix != Teuchos::null)
157  resetMatrix(SM_Matrix, ComputePrec);
158  }
159 
161  virtual ~Maxwell1() {}
162 
165 
167  const Teuchos::RCP<const Map> getRangeMap() const;
168 
171  return SM_Matrix_;
172  }
173 
176 
178  void compute(bool reuse = false);
179 
181  void resetMatrix(Teuchos::RCP<Matrix> SM_Matrix_new, bool ComputePrec = true);
182 
186  void apply(const MultiVector& X, MultiVector& Y,
190 
192  bool hasTransposeApply() const;
193 
195 
197  void residual(const MultiVector& X,
198  const MultiVector& B,
199  MultiVector& R) const {
200  using STS = Teuchos::ScalarTraits<Scalar>;
201  R.update(STS::one(), B, STS::zero());
202  this->apply(X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
203  }
204 
205  private:
208 
210  void GMHDSetupHierarchy(Teuchos::ParameterList& List) const;
211 
220  void initialize(const Teuchos::RCP<Matrix>& D0_Matrix,
221  const Teuchos::RCP<Matrix>& Kn_Matrix,
222  const Teuchos::RCP<MultiVector>& Nullspace,
224  Teuchos::ParameterList& List);
225 
227  void applyInverseRefMaxwellAdditive(const MultiVector& RHS, MultiVector& X) const;
228 
230  void applyInverseStandard(const MultiVector& RHS, MultiVector& X) const;
231 
233  void allocateMemory(int numVectors) const;
234 
236  void dump(const Matrix& A, std::string name) const;
237 
239  void dump(const MultiVector& X, std::string name) const;
240 
242  void dumpCoords(const RealValuedMultiVector& X, std::string name) const;
243 
245  void dump(const Teuchos::ArrayRCP<bool>& v, std::string name) const;
246 
248  void dump(const Kokkos::View<bool*, typename Node::device_type>& v, std::string name) const;
249 
251  Teuchos::RCP<Teuchos::TimeMonitor> getTimer(std::string name, RCP<const Teuchos::Comm<int> > comm = Teuchos::null) const;
252 
255 
258 
261 
263  Kokkos::View<bool*, typename Node::device_type::memory_space> BCrowsKokkos_, BCcolsKokkos_, BCdomainKokkos_;
273 
275  typedef enum { MODE_STANDARD = 0,
280 
284 };
285 
286 } // namespace MueLu
287 
288 #define MUELU_MAXWELL1_SHORT
289 #endif // MUELU_MAXWELL1_DECL_HPP
const Teuchos::RCP< Matrix > & getJacobian() const
Returns Jacobian matrix SM.
Teuchos::RCP< MultiVector > Nullspace_
Nullspace.
Teuchos::RCP< Matrix > GmhdA_Matrix_
Xpetra::MultiVector< coordinateType, LO, GO, NO > RealValuedMultiVector
const Teuchos::RCP< const Map > getDomainMap() const
Returns the Xpetra::Map object associated with the domain of this operator.
MueLu::DefaultLocalOrdinal LocalOrdinal
void dump(const Matrix &A, std::string name) const
dump out matrix
Maxwell1(const Teuchos::RCP< Matrix > &SM_Matrix, const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, Teuchos::ParameterList &List, bool ComputePrec=true)
Teuchos::RCP< Hierarchy > Hierarchy11_
Two hierarchies: one for the (1,1)-block, another for the (2,2)-block.
Kokkos::View< bool *, typename Node::device_type::memory_space > BCdomainKokkos_
Teuchos::RCP< Hierarchy > HierarchyGmhd_
T & get(const std::string &name, T def_value)
void resetMatrix(Teuchos::RCP< Matrix > SM_Matrix_new, bool ComputePrec=true)
Reset system matrix.
Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > MultiVector
void residual(const MultiVector &X, const MultiVector &B, MultiVector &R) const
Compute a residual R = B - (*this) * X.
bool useKokkos_
Some options.
void GMHDSetupHierarchy(Teuchos::ParameterList &List) const
Sets up hiearchy for GMHD matrices that include generalized Ohms law equations.
Teuchos::ArrayRCP< bool > BCcols_
Teuchos::RCP< Matrix > D0_Matrix_
void initialize(const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< Matrix > &Kn_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, Teuchos::ParameterList &List)
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Maxwell1(const Teuchos::RCP< Matrix > &SM_Matrix, const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< Matrix > &Kn_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, Teuchos::ParameterList &List, bool ComputePrec=true)
Teuchos::RCP< MultiVector > residual11c_
Teuchos::ParameterList precList22_
Kokkos::View< bool *, typename Node::device_type::memory_space > BCcolsKokkos_
MueLu::DefaultNode Node
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_HIGH) const
Teuchos::RCP< MultiVector > update22_
Verbose class for MueLu classes.
virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)=0
Preconditioner (wrapped as a Xpetra::Operator) for Maxwell&#39;s equations in curl-curl form...
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitudeType
Kokkos::View< bool *, typename Node::device_type::memory_space > BCrowsKokkos_
Vectors for BCs.
void setParameters(Teuchos::ParameterList &list)
Set parameters.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::ArrayRCP< bool > BCdomain_
Teuchos::ParameterList precList11_
Teuchos::RCP< Hierarchy > Hierarchy22_
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Teuchos::ScalarTraits< Scalar >::coordinateType coordinateType
Teuchos::RCP< Teuchos::TimeMonitor > getTimer(std::string name, RCP< const Teuchos::Comm< int > > comm=Teuchos::null) const
get a (synced) timer
mode_type
Execution modes.
void applyInverseRefMaxwellAdditive(const MultiVector &RHS, MultiVector &X) const
apply RefMaxwell additive 2x2 style cycle
void allocateMemory(int numVectors) const
allocate multivectors for solve
Teuchos::RCP< Matrix > Kn_Matrix_
Maxwell1()
Constructor.
RCP< Matrix > P11_
Temporary memory (cached vectors for RefMaxwell-style)
Teuchos::ArrayRCP< bool > BCrows_
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 applyInverseStandard(const MultiVector &RHS, MultiVector &X) const
apply standard Maxwell1 cycle
const Teuchos::RCP< const Map > getRangeMap() const
Returns the Xpetra::Map object associated with the range of this operator.
Maxwell1(Teuchos::RCP< Hierarchy > H11, Teuchos::RCP< Hierarchy > H22)
Constructor with Hierarchies.
Maxwell1(const Teuchos::RCP< Matrix > &SM_Matrix, const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< Matrix > &Kn_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, Teuchos::ParameterList &List, const Teuchos::RCP< Matrix > &GmhdA_Matrix, bool ComputePrec=true)
void compute(bool reuse=false)
Setup the preconditioner.
bool isType(const std::string &name) const
Teuchos::RCP< MultiVector > update11c_
Maxwell1(const Teuchos::RCP< Matrix > &SM_Matrix, Teuchos::ParameterList &List, bool ComputePrec=true)
virtual ~Maxwell1()
Destructor.
Teuchos::RCP< MultiVector > residual22_
Teuchos::RCP< Matrix > generate_kn() const
Generates the Kn matrix.
Teuchos::RCP< RealValuedMultiVector > Coords_
Coordinates.
void dumpCoords(const RealValuedMultiVector &X, std::string name) const
dump out real-valued multivector
Teuchos::RCP< Matrix > SM_Matrix_
Various matrices.
Teuchos::RCP< MultiVector > residualFine_
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Teuchos::ParameterList parameterList_
ParameterLists.