MueLu Version of the Day
Loading...
Searching...
No Matches
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
19#include "MueLu_Level_fwd.hpp"
25
26#include "Xpetra_Map_fwd.hpp"
27#include "Xpetra_Matrix_fwd.hpp"
28#include "Xpetra_MatrixFactory_fwd.hpp"
29#include "Xpetra_MultiVectorFactory_fwd.hpp"
30#include "Xpetra_VectorFactory_fwd.hpp"
31#include "Xpetra_CrsMatrixWrap_fwd.hpp"
32
33namespace MueLu {
34
41template <class Scalar,
42 class LocalOrdinal,
43 class GlobalOrdinal,
44 class Node>
45class Maxwell1 : public VerboseObject, public Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
46#undef MUELU_MAXWELL1_SHORT
48
49 public:
50 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitudeType;
51 typedef typename Teuchos::ScalarTraits<Scalar>::coordinateType coordinateType;
52 typedef typename Xpetra::MultiVector<coordinateType, LO, GO, NO> RealValuedMultiVector;
53
56 : Hierarchy11_(Teuchos::null)
57 , Hierarchy22_(Teuchos::null)
58 , HierarchyGmhd_(Teuchos::null)
60 }
61
63 Maxwell1(Teuchos::RCP<Hierarchy> H11, Teuchos::RCP<Hierarchy> H22)
64 : Hierarchy11_(H11)
65 , Hierarchy22_(H22)
66 , HierarchyGmhd_(Teuchos::null)
68 }
69
79 Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
80 const Teuchos::RCP<Matrix>& D0_Matrix,
81 const Teuchos::RCP<MultiVector>& Nullspace,
82 const Teuchos::RCP<RealValuedMultiVector>& Coords,
83 Teuchos::ParameterList& List,
84 bool ComputePrec = true)
86 RCP<Matrix> Kn_Matrix;
87 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, Teuchos::null, 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,
104 const Teuchos::RCP<RealValuedMultiVector>& Coords,
105 Teuchos::ParameterList& List,
106 bool ComputePrec = true)
108 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, Teuchos::null, List);
109 resetMatrix(SM_Matrix, ComputePrec);
110 }
111
121 Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
122 const Teuchos::RCP<Matrix>& D0_Matrix,
123 const Teuchos::RCP<Matrix>& Kn_Matrix,
124 const Teuchos::RCP<MultiVector>& Nullspace,
125 const Teuchos::RCP<RealValuedMultiVector>& Coords,
126 const Teuchos::RCP<MultiVector>& Material,
127 Teuchos::ParameterList& List,
128 bool ComputePrec = true)
130 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, Material, List);
131 resetMatrix(SM_Matrix, ComputePrec);
132 }
133
144 Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
145 const Teuchos::RCP<Matrix>& D0_Matrix,
146 const Teuchos::RCP<Matrix>& Kn_Matrix,
147 const Teuchos::RCP<MultiVector>& Nullspace,
148 const Teuchos::RCP<RealValuedMultiVector>& Coords,
149 Teuchos::ParameterList& List, const Teuchos::RCP<Matrix>& GmhdA_Matrix,
150 bool ComputePrec = true)
152 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, Teuchos::null, List);
153 resetMatrix(SM_Matrix, ComputePrec);
154 GmhdA_Matrix_ = GmhdA_Matrix;
155 HierarchyGmhd_ = rcp(new Hierarchy("HierarchyGmhd"));
156 GMHDSetupHierarchy(List);
157 }
158
165 Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
166 Teuchos::ParameterList& List,
167 bool ComputePrec = true)
169 RCP<MultiVector> Nullspace = List.get<RCP<MultiVector> >("Nullspace", Teuchos::null);
170 RCP<RealValuedMultiVector> Coords = List.get<RCP<RealValuedMultiVector> >("Coordinates", Teuchos::null);
171 RCP<Matrix> D0_Matrix = List.get<RCP<Matrix> >("D0");
172 RCP<Matrix> Kn_Matrix;
173 if (List.isType<RCP<Matrix> >("Kn"))
174 Kn_Matrix = List.get<RCP<Matrix> >("Kn");
175
176 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, Teuchos::null, List);
177
178 if (SM_Matrix != Teuchos::null)
179 resetMatrix(SM_Matrix, ComputePrec);
180 }
181
183 virtual ~Maxwell1() {}
184
186 const Teuchos::RCP<const Map> getDomainMap() const;
187
189 const Teuchos::RCP<const Map> getRangeMap() const;
190
192 const Teuchos::RCP<Matrix>& getJacobian() const {
193 return SM_Matrix_;
194 }
195
197 void setParameters(Teuchos::ParameterList& list);
198
200 void compute(bool reuse = false);
201
203 void resetMatrix(Teuchos::RCP<Matrix> SM_Matrix_new, bool ComputePrec = true);
204
208 void apply(const MultiVector& X, MultiVector& Y,
209 Teuchos::ETransp mode = Teuchos::NO_TRANS,
210 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
211 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
212
214 bool hasTransposeApply() const;
215
216 void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_HIGH) const;
217
219 void residual(const MultiVector& X,
220 const MultiVector& B,
221 MultiVector& R) const {
222 using STS = Teuchos::ScalarTraits<Scalar>;
223 R.update(STS::one(), B, STS::zero());
224 this->apply(X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
225 }
226
227 private:
229 Teuchos::RCP<Matrix> generate_kn() const;
230
232 void GMHDSetupHierarchy(Teuchos::ParameterList& List) const;
233
243 void initialize(const Teuchos::RCP<Matrix>& D0_Matrix,
244 const Teuchos::RCP<Matrix>& Kn_Matrix,
245 const Teuchos::RCP<MultiVector>& Nullspace,
246 const Teuchos::RCP<RealValuedMultiVector>& Coords,
247 const Teuchos::RCP<MultiVector>& Material,
248 Teuchos::ParameterList& List);
249
251 void applyInverseRefMaxwellAdditive(const MultiVector& RHS, MultiVector& X) const;
252
254 void applyInverseStandard(const MultiVector& RHS, MultiVector& X) const;
255
257 void allocateMemory(int numVectors) const;
258
260 void dump(const Matrix& A, std::string name) const;
261
263 void dump(const MultiVector& X, std::string name) const;
264
266 void dumpCoords(const RealValuedMultiVector& X, std::string name) const;
267
269 void dump(const Teuchos::ArrayRCP<bool>& v, std::string name) const;
270
272 void dump(const Kokkos::View<bool*, typename Node::device_type>& v, std::string name) const;
273
275 Teuchos::RCP<Teuchos::TimeMonitor> getTimer(std::string name, RCP<const Teuchos::Comm<int> > comm = Teuchos::null) const;
276
278 mutable Teuchos::ParameterList parameterList_, precList11_, precList22_;
279
281 Teuchos::RCP<Hierarchy> Hierarchy11_, Hierarchy22_, HierarchyGmhd_;
282
285
287 Kokkos::View<bool*, typename Node::device_type::memory_space> BCrowsKokkos_, BCcolsKokkos_, BCdomainKokkos_;
289 Teuchos::ArrayRCP<bool> BCrows_, BCcols_, BCdomain_;
291 Teuchos::RCP<MultiVector> Nullspace_;
293 Teuchos::RCP<RealValuedMultiVector> Coords_;
295 Teuchos::RCP<MultiVector> Material_;
299
301 typedef enum { MODE_STANDARD = 0,
306
308 RCP<Matrix> P11_;
309 mutable Teuchos::RCP<MultiVector> residualFine_, residual11c_, residual22_, update11c_, update22_;
310};
311
312} // namespace MueLu
313
314#define MUELU_MAXWELL1_SHORT
315#endif // MUELU_MAXWELL1_DECL_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
MueLu::DefaultNode Node
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
const Teuchos::RCP< const Map > getDomainMap() const
Returns the Xpetra::Map object associated with the domain of this operator.
Teuchos::ScalarTraits< Scalar >::coordinateType coordinateType
bool useKokkos_
Some options.
Teuchos::RCP< Matrix > generate_kn() const
Generates the Kn matrix.
Teuchos::RCP< Hierarchy > Hierarchy11_
Two hierarchies: one for the (1,1)-block, another for the (2,2)-block.
Teuchos::RCP< Hierarchy > HierarchyGmhd_
Teuchos::RCP< MultiVector > residualFine_
Teuchos::ArrayRCP< bool > BCcols_
virtual ~Maxwell1()
Destructor.
Teuchos::ArrayRCP< bool > BCrows_
Teuchos::RCP< Matrix > SM_Matrix_
Various matrices.
Teuchos::RCP< Hierarchy > Hierarchy22_
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)
Kokkos::View< bool *, typename Node::device_type::memory_space > BCrowsKokkos_
Vectors for BCs.
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)
void compute(bool reuse=false)
Setup the preconditioner.
void GMHDSetupHierarchy(Teuchos::ParameterList &List) const
Sets up hiearchy for GMHD matrices that include generalized Ohms law equations.
mode_type
Execution modes.
void initialize(const Teuchos::RCP< Matrix > &D0_Matrix, const Teuchos::RCP< Matrix > &Kn_Matrix, const Teuchos::RCP< MultiVector > &Nullspace, const Teuchos::RCP< RealValuedMultiVector > &Coords, const Teuchos::RCP< MultiVector > &Material, Teuchos::ParameterList &List)
Teuchos::ParameterList parameterList_
ParameterLists.
Teuchos::RCP< MultiVector > residual22_
Kokkos::View< bool *, typename Node::device_type::memory_space > BCdomainKokkos_
Teuchos::RCP< RealValuedMultiVector > Coords_
Coordinates.
Teuchos::RCP< Matrix > D0_Matrix_
const Teuchos::RCP< const Map > getRangeMap() const
Returns the Xpetra::Map object associated with the range of this operator.
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitudeType
void applyInverseRefMaxwellAdditive(const MultiVector &RHS, MultiVector &X) const
apply RefMaxwell additive 2x2 style cycle
Teuchos::RCP< MultiVector > Nullspace_
Nullspace.
Teuchos::RCP< MultiVector > update11c_
Maxwell1(Teuchos::RCP< Hierarchy > H11, Teuchos::RCP< Hierarchy > H22)
Constructor with Hierarchies.
void applyInverseStandard(const MultiVector &RHS, MultiVector &X) const
apply standard Maxwell1 cycle
RCP< Matrix > P11_
Temporary memory (cached vectors for RefMaxwell-style).
Xpetra::MultiVector< coordinateType, LO, GO, NO > RealValuedMultiVector
Teuchos::RCP< MultiVector > Material_
Material.
void dumpCoords(const RealValuedMultiVector &X, std::string name) const
dump out real-valued multivector
Teuchos::RCP< MultiVector > update22_
Teuchos::ArrayRCP< bool > BCdomain_
Teuchos::ParameterList precList11_
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 residual(const MultiVector &X, const MultiVector &B, MultiVector &R) const
Compute a residual R = B - (*this) * X.
const Teuchos::RCP< Matrix > & getJacobian() const
Returns Jacobian matrix SM.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_HIGH) const
Teuchos::RCP< Matrix > GmhdA_Matrix_
void dump(const Matrix &A, std::string name) const
dump out matrix
Maxwell1(const Teuchos::RCP< Matrix > &SM_Matrix, Teuchos::ParameterList &List, bool ComputePrec=true)
Teuchos::ParameterList precList22_
void resetMatrix(Teuchos::RCP< Matrix > SM_Matrix_new, bool ComputePrec=true)
Reset system matrix.
Teuchos::RCP< Matrix > Kn_Matrix_
Teuchos::RCP< MultiVector > residual11c_
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Teuchos::RCP< Teuchos::TimeMonitor > getTimer(std::string name, RCP< const Teuchos::Comm< int > > comm=Teuchos::null) const
get a (synced) timer
Kokkos::View< bool *, typename Node::device_type::memory_space > BCcolsKokkos_
void setParameters(Teuchos::ParameterList &list)
Set parameters.
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, const Teuchos::RCP< MultiVector > &Material, Teuchos::ParameterList &List, bool ComputePrec=true)
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 allocateMemory(int numVectors) const
allocate multivectors for solve
Namespace for MueLu classes and methods.