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"
15
17
19#include "MueLu_Level_fwd.hpp"
26
27#include "Xpetra_Operator.hpp"
28#include "Xpetra_Map_fwd.hpp"
29#include "Xpetra_Matrix_fwd.hpp"
30#include "Xpetra_MatrixFactory_fwd.hpp"
31#include "Xpetra_MultiVectorFactory_fwd.hpp"
32#include "Xpetra_VectorFactory_fwd.hpp"
33#include "Xpetra_CrsMatrixWrap_fwd.hpp"
34
35namespace MueLu {
36
43template <class Scalar,
44 class LocalOrdinal,
45 class GlobalOrdinal,
46 class Node>
47class Maxwell1 : public VerboseObject, public Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
48#undef MUELU_MAXWELL1_SHORT
50
51 public:
52 using magnitudeType = typename Teuchos::ScalarTraits<Scalar>::magnitudeType;
53 using coordinateType = typename Teuchos::ScalarTraits<Scalar>::coordinateType;
54 using RealValuedMultiVector = typename Xpetra::MultiVector<coordinateType, LO, GO, NO>;
55
58 : Hierarchy11_(Teuchos::null)
59 , Hierarchy22_(Teuchos::null)
60 , HierarchyGmhd_(Teuchos::null)
62 }
63
65 Maxwell1(Teuchos::RCP<Hierarchy> H11, Teuchos::RCP<Hierarchy> H22)
66 : Hierarchy11_(H11)
67 , Hierarchy22_(H22)
68 , HierarchyGmhd_(Teuchos::null)
70 }
71
81 Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
82 const Teuchos::RCP<Matrix>& D0_Matrix,
83 const Teuchos::RCP<MultiVector>& Nullspace,
84 const Teuchos::RCP<RealValuedMultiVector>& Coords,
85 Teuchos::ParameterList& List,
86 bool ComputePrec = true)
88 RCP<Matrix> Kn_Matrix = Teuchos::null;
89 RCP<Matrix> CurlCurl_Matrix = Teuchos::null;
90 RCP<MultiVector> Material = Teuchos::null;
91 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, CurlCurl_Matrix, Material, List);
92 resetMatrix(SM_Matrix, ComputePrec);
93 }
94
104 Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
105 const Teuchos::RCP<Matrix>& D0_Matrix,
106 const Teuchos::RCP<Matrix>& Kn_Matrix,
107 const Teuchos::RCP<MultiVector>& Nullspace,
108 const Teuchos::RCP<RealValuedMultiVector>& Coords,
109 Teuchos::ParameterList& List,
110 bool ComputePrec = true)
112 RCP<Matrix> CurlCurl_Matrix = Teuchos::null;
113 RCP<MultiVector> Material = Teuchos::null;
114 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, CurlCurl_Matrix, Material, List);
115 resetMatrix(SM_Matrix, ComputePrec);
116 }
117
127 Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
128 const Teuchos::RCP<Matrix>& D0_Matrix,
129 const Teuchos::RCP<Matrix>& Kn_Matrix,
130 const Teuchos::RCP<MultiVector>& Nullspace,
131 const Teuchos::RCP<RealValuedMultiVector>& Coords,
132 const Teuchos::RCP<MultiVector>& Material,
133 Teuchos::ParameterList& List,
134 bool ComputePrec = true)
136 RCP<Matrix> CurlCurl_Matrix = Teuchos::null;
137 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, CurlCurl_Matrix, Material, List);
138 resetMatrix(SM_Matrix, ComputePrec);
139 }
140
151 Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
152 const Teuchos::RCP<Matrix>& D0_Matrix,
153 const Teuchos::RCP<Matrix>& Kn_Matrix,
154 const Teuchos::RCP<MultiVector>& Nullspace,
155 const Teuchos::RCP<RealValuedMultiVector>& Coords,
156 const Teuchos::RCP<Matrix>& CurlCurl_Matrix,
157 const Teuchos::RCP<MultiVector>& Material,
158 Teuchos::ParameterList& List,
159 bool ComputePrec = true)
161 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, CurlCurl_Matrix, Material, List);
162 resetMatrix(SM_Matrix, ComputePrec);
163 }
164
175 Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
176 const Teuchos::RCP<Matrix>& D0_Matrix,
177 const Teuchos::RCP<Matrix>& Kn_Matrix,
178 const Teuchos::RCP<MultiVector>& Nullspace,
179 const Teuchos::RCP<RealValuedMultiVector>& Coords,
180 Teuchos::ParameterList& List, const Teuchos::RCP<Matrix>& GmhdA_Matrix,
181 bool ComputePrec = true)
183 RCP<Matrix> CurlCurl_Matrix = Teuchos::null;
184 RCP<MultiVector> Material = Teuchos::null;
185 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, CurlCurl_Matrix, Material, List);
186 resetMatrix(SM_Matrix, ComputePrec);
187 GmhdA_Matrix_ = GmhdA_Matrix;
188 HierarchyGmhd_ = rcp(new Hierarchy("HierarchyGmhd"));
189 GMHDSetupHierarchy(List);
190 }
191
198 Maxwell1(const Teuchos::RCP<Matrix>& SM_Matrix,
199 Teuchos::ParameterList& List,
200 bool ComputePrec = true)
202 auto& userData = List.sublist("user data");
203
204#define MUELU_MAXWELL1_GET_USER_DATA(TYPE, NAME, VAR) \
205 RCP<TYPE> VAR; \
206 if (List.isType<RCP<TYPE>>(NAME)) \
207 VAR = List.get<RCP<TYPE>>(NAME, Teuchos::null); \
208 if (userData.isType<RCP<TYPE>>(NAME)) \
209 VAR = userData.get<RCP<TYPE>>(NAME, Teuchos::null);
210
211 MUELU_MAXWELL1_GET_USER_DATA(MultiVector, "Nullspace", Nullspace);
213 MUELU_MAXWELL1_GET_USER_DATA(MultiVector, "Material", Material);
214 MUELU_MAXWELL1_GET_USER_DATA(Matrix, "D0", D0_Matrix);
215 MUELU_MAXWELL1_GET_USER_DATA(Matrix, "Kn", Kn_Matrix);
216 MUELU_MAXWELL1_GET_USER_DATA(Matrix, "CurlCurl", CurlCurl_Matrix);
217
218 initialize(D0_Matrix, Kn_Matrix, Nullspace, Coords, CurlCurl_Matrix, Material, List);
219
220 if (SM_Matrix != Teuchos::null)
221 resetMatrix(SM_Matrix, ComputePrec);
222
223 MUELU_MAXWELL1_GET_USER_DATA(Matrix, "GmhdA", GmhdA_Matrix);
224
225#undef MUELU_MAXWELL1_GET_USER_DATA
226
227 if (!GmhdA_Matrix.is_null()) {
229 GmhdA_Matrix_ = GmhdA_Matrix;
230 HierarchyGmhd_ = rcp(new Hierarchy("HierarchyGmhd"));
231 GMHDSetupHierarchy(List);
232 }
233 }
234
236 virtual ~Maxwell1() = default;
237
239 const Teuchos::RCP<const Map> getDomainMap() const;
240
242 const Teuchos::RCP<const Map> getRangeMap() const;
243
245 const Teuchos::RCP<Matrix>& getJacobian() const {
246 return SM_Matrix_;
247 }
248
250 void setParameters(Teuchos::ParameterList& list);
251
253 void compute(bool reuse = false);
254
256 void resetMatrix(Teuchos::RCP<Matrix> SM_Matrix_new, bool ComputePrec = true);
257
261 void apply(const MultiVector& RHS, MultiVector& X,
262 Teuchos::ETransp mode = Teuchos::NO_TRANS,
263 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
264 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
265
267 bool hasTransposeApply() const;
268
269 static std::pair<std::set<std::string>, std::set<std::string>> requiredAndOptionalUserData(const Teuchos::ParameterList& params);
270
271 void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_HIGH) const;
272
274 void residual(const MultiVector& X,
275 const MultiVector& B,
276 MultiVector& R) const {
277 using STS = Teuchos::ScalarTraits<Scalar>;
278 R.update(STS::one(), B, STS::zero());
279 this->apply(X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
280 }
281
282 private:
284 Teuchos::RCP<Matrix> generate_kn() const;
285
287 void GMHDSetupHierarchy(Teuchos::ParameterList& List) const;
288
298 void initialize(const Teuchos::RCP<Matrix>& D0_Matrix,
299 const Teuchos::RCP<Matrix>& Kn_Matrix,
300 const Teuchos::RCP<MultiVector>& Nullspace,
301 const Teuchos::RCP<RealValuedMultiVector>& Coords,
302 const Teuchos::RCP<Matrix>& CurlCurl_Matrix,
303 const Teuchos::RCP<MultiVector>& Material,
304 Teuchos::ParameterList& List);
305
307 void applyInverseRefMaxwellAdditive(const MultiVector& RHS, MultiVector& X) const;
308
310 void applyInverseStandard(const MultiVector& RHS, MultiVector& X) const;
311
313 void allocateMemory(int numVectors) const;
314
316 void dump(const Matrix& A, std::string name) const;
317
319 void dump(const MultiVector& X, std::string name) const;
320
322 void dumpCoords(const RealValuedMultiVector& X, std::string name) const;
323
325 void dump(const Teuchos::ArrayRCP<bool>& v, std::string name) const;
326
328 void dump(const Kokkos::View<bool*, typename Node::device_type>& v, std::string name) const;
329
331 Teuchos::RCP<Teuchos::TimeMonitor> getTimer(std::string name, RCP<const Teuchos::Comm<int>> comm = Teuchos::null) const;
332
334 mutable Teuchos::ParameterList parameterList_, precList11_, precList22_;
335
337 Teuchos::RCP<Hierarchy> Hierarchy11_, Hierarchy22_, HierarchyGmhd_;
338
341
343 Kokkos::View<bool*, typename Node::device_type::memory_space> BCrowsKokkos_, BCcolsKokkos_, BCdomainKokkos_;
345 Teuchos::ArrayRCP<bool> BCrows_, BCcols_, BCdomain_;
347 Teuchos::RCP<MultiVector> Nullspace_;
349 Teuchos::RCP<RealValuedMultiVector> Coords_;
351 Teuchos::RCP<MultiVector> Material_;
355
357 typedef enum { MODE_STANDARD = 0,
362
364 RCP<Matrix> P11_;
365 mutable Teuchos::RCP<MultiVector> residualFine_, residual11c_, residual22_, update11c_, update22_;
366};
367
368} // namespace MueLu
369
370#define MUELU_MAXWELL1_SHORT
371#endif // MUELU_MAXWELL1_DECL_HPP
#define MUELU_MAXWELL1_GET_USER_DATA(TYPE, NAME, VAR)
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
MueLu::DefaultNode Node
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Preconditioner (wrapped as a Xpetra::Operator) for Maxwell's equations in curl-curl form.
const Teuchos::RCP< const Map > getDomainMap() const
Returns the Xpetra::Map object associated with the domain of this operator.
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_
typename Teuchos::ScalarTraits< Scalar >::magnitudeType magnitudeType
Teuchos::ArrayRCP< bool > BCcols_
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.
typename Teuchos::ScalarTraits< Scalar >::coordinateType coordinateType
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_
virtual ~Maxwell1()=default
Destructor.
const Teuchos::RCP< const Map > getRangeMap() const
Returns the Xpetra::Map object associated with the range of this operator.
void applyInverseRefMaxwellAdditive(const MultiVector &RHS, MultiVector &X) const
apply RefMaxwell additive 2x2 style cycle
Teuchos::RCP< MultiVector > Nullspace_
Nullspace.
Teuchos::RCP< MultiVector > update11c_
void apply(const MultiVector &RHS, MultiVector &X, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
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)
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
typename Xpetra::MultiVector< coordinateType, LO, GO, NO > RealValuedMultiVector
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.
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< Matrix > &CurlCurl_Matrix, const Teuchos::RCP< MultiVector > &Material, Teuchos::ParameterList &List, bool ComputePrec=true)
static std::pair< std::set< std::string >, std::set< std::string > > requiredAndOptionalUserData(const Teuchos::ParameterList &params)
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 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< Matrix > &CurlCurl_Matrix, const Teuchos::RCP< MultiVector > &Material, Teuchos::ParameterList &List)
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 allocateMemory(int numVectors) const
allocate multivectors for solve
Verbose class for MueLu classes.
Namespace for MueLu classes and methods.