MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_Maxwell1_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_MAXWELL1_DECL_HPP
47#define MUELU_MAXWELL1_DECL_HPP
48
49#include "MueLu_ConfigDefs.hpp"
50#include "MueLu_BaseClass.hpp"
51
53
55#include "MueLu_Level_fwd.hpp"
60
61#include "Xpetra_Map_fwd.hpp"
62#include "Xpetra_Matrix_fwd.hpp"
63#include "Xpetra_MatrixFactory_fwd.hpp"
64#include "Xpetra_MultiVectorFactory_fwd.hpp"
65#include "Xpetra_VectorFactory_fwd.hpp"
66#include "Xpetra_CrsMatrixWrap_fwd.hpp"
67
68namespace MueLu {
69
76 template <class Scalar,
77 class LocalOrdinal,
78 class GlobalOrdinal,
79 class Node>
80 class Maxwell1 : public VerboseObject, public Xpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
81
82#undef MUELU_MAXWELL1_SHORT
84
85 public:
86
87 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitudeType;
88 typedef typename Teuchos::ScalarTraits<Scalar>::coordinateType coordinateType;
89 typedef typename Xpetra::MultiVector<coordinateType,LO,GO,NO> RealValuedMultiVector;
90
93 Hierarchy11_(Teuchos::null),
94 Hierarchy22_(Teuchos::null),
97 {
98 }
99
101 Maxwell1(Teuchos::RCP<Hierarchy> H11, Teuchos::RCP<Hierarchy> H22) :
102 Hierarchy11_(H11),
103 Hierarchy22_(H22),
104 HierarchyGmhd_(Teuchos::null),
106 {
107 }
108
118 Maxwell1(const Teuchos::RCP<Matrix> & SM_Matrix,
119 const Teuchos::RCP<Matrix> & D0_Matrix,
120 const Teuchos::RCP<MultiVector> & Nullspace,
121 const Teuchos::RCP<RealValuedMultiVector> & Coords,
122 Teuchos::ParameterList& List,
123 bool ComputePrec = true):
125 {
126 RCP<Matrix> Kn_Matrix;
127 initialize(D0_Matrix,Kn_Matrix,Nullspace,Coords,List);
128 resetMatrix(SM_Matrix,ComputePrec);
129 }
130
140 Maxwell1(const Teuchos::RCP<Matrix> & SM_Matrix,
141 const Teuchos::RCP<Matrix> & D0_Matrix,
142 const Teuchos::RCP<Matrix> & Kn_Matrix,
143 const Teuchos::RCP<MultiVector> & Nullspace,
144 const Teuchos::RCP<RealValuedMultiVector> & Coords,
145 Teuchos::ParameterList& List,
146 bool ComputePrec = true):
148 {
149 initialize(D0_Matrix,Kn_Matrix,Nullspace,Coords,List);
150 resetMatrix(SM_Matrix,ComputePrec);
151 }
152
163 Maxwell1(const Teuchos::RCP<Matrix> & SM_Matrix,
164 const Teuchos::RCP<Matrix> & D0_Matrix,
165 const Teuchos::RCP<Matrix> & Kn_Matrix,
166 const Teuchos::RCP<MultiVector> & Nullspace,
167 const Teuchos::RCP<RealValuedMultiVector> & Coords,
168 Teuchos::ParameterList& List, const Teuchos::RCP<Matrix> & GmhdA_Matrix,
169 bool ComputePrec = true):
171 {
172 initialize(D0_Matrix,Kn_Matrix,Nullspace,Coords,List);
173 resetMatrix(SM_Matrix,ComputePrec);
174 GmhdA_Matrix_ = GmhdA_Matrix;
175 HierarchyGmhd_ = rcp(new Hierarchy("HierarchyGmhd"));
176 GMHDSetupHierarchy(List);
177 }
178
185 Maxwell1(const Teuchos::RCP<Matrix> & SM_Matrix,
186 Teuchos::ParameterList& List,
187 bool ComputePrec = true):
189 {
190
191 RCP<MultiVector> Nullspace = List.get<RCP<MultiVector> >("Nullspace", Teuchos::null);
192 RCP<RealValuedMultiVector> Coords = List.get<RCP<RealValuedMultiVector> >("Coordinates", Teuchos::null);
193 RCP<Matrix> D0_Matrix = List.get<RCP<Matrix> >("D0");
194 RCP<Matrix> Kn_Matrix;
195 if (List.isType<RCP<Matrix> >("Kn"))
196 Kn_Matrix = List.get<RCP<Matrix> >("Kn");
197
198 initialize(D0_Matrix,Kn_Matrix,Nullspace,Coords,List);
199
200 if (SM_Matrix != Teuchos::null)
201 resetMatrix(SM_Matrix,ComputePrec);
202 }
203
205 virtual ~Maxwell1() {}
206
208 Teuchos::RCP<const Map> getDomainMap() const;
209
211 Teuchos::RCP<const Map> getRangeMap() const;
212
214 const Teuchos::RCP<Matrix> & getJacobian() const {
215 return SM_Matrix_;
216 }
217
219 void setParameters(Teuchos::ParameterList& list);
220
222 void compute(bool reuse=false);
223
225 void resetMatrix(Teuchos::RCP<Matrix> SM_Matrix_new, bool ComputePrec=true);
226
230 void apply (const MultiVector& X, MultiVector& Y,
231 Teuchos::ETransp mode = Teuchos::NO_TRANS,
232 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
233 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
234
236 bool hasTransposeApply() const;
237
238 void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_HIGH) const;
239
241 void residual(const MultiVector & X,
242 const MultiVector & B,
243 MultiVector & R) const {
244 using STS = Teuchos::ScalarTraits<Scalar>;
245 R.update(STS::one(),B,STS::zero());
246 this->apply (X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
247 }
248
249
250 private:
252 Teuchos::RCP<Matrix> generate_kn() const;
253
254
256 void GMHDSetupHierarchy(Teuchos::ParameterList& List) const;
257
266 void initialize(const Teuchos::RCP<Matrix> & D0_Matrix,
267 const Teuchos::RCP<Matrix> & Kn_Matrix,
268 const Teuchos::RCP<MultiVector> & Nullspace,
269 const Teuchos::RCP<RealValuedMultiVector> & Coords,
270 Teuchos::ParameterList& List);
271
272
274 void applyInverseRefMaxwellAdditive(const MultiVector& RHS, MultiVector& X) const;
275
277 void applyInverseStandard(const MultiVector& RHS, MultiVector& X) const;
278
280 void allocateMemory(int numVectors) const;
281
283 void dump(const Matrix& A, std::string name) const;
284
286 void dump(const MultiVector& X, std::string name) const;
287
289 void dumpCoords(const RealValuedMultiVector& X, std::string name) const;
290
292 void dump(const Teuchos::ArrayRCP<bool>& v, std::string name) const;
293
295 void dump(const Kokkos::View<bool*, typename Node::device_type>& v, std::string name) const;
296
298 Teuchos::RCP<Teuchos::TimeMonitor> getTimer(std::string name, RCP<const Teuchos::Comm<int> > comm=Teuchos::null) const;
299
301 mutable Teuchos::ParameterList parameterList_, precList11_, precList22_;
302
304 Teuchos::RCP<Hierarchy> Hierarchy11_, Hierarchy22_, HierarchyGmhd_;
305
308
310 Kokkos::View<bool*, typename Node::device_type> BCrowsKokkos_, BCcolsKokkos_, BCdomainKokkos_;
312 Teuchos::ArrayRCP<bool> BCrows_, BCcols_, BCdomain_;
314 Teuchos::RCP<MultiVector> Nullspace_;
316 Teuchos::RCP<RealValuedMultiVector> Coords_;
320
324
326 RCP<Matrix> P11_;
327 mutable Teuchos::RCP<MultiVector> residualFine_, residual11c_, residual22_, update11c_,update22_;
328
329 };
330
331
332
333
334} // namespace
335
336#define MUELU_MAXWELL1_SHORT
337#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.
Teuchos::ScalarTraits< Scalar >::coordinateType coordinateType
Xpetra::MultiVector< coordinateType, LO, GO, NO > RealValuedMultiVector
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)
Teuchos::RCP< const Map > getDomainMap() const
Returns the Xpetra::Map object associated with the domain of this 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< const Map > getRangeMap() const
Returns the Xpetra::Map object associated with the range of this operator.
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.
Teuchos::ParameterList parameterList_
ParameterLists.
Teuchos::RCP< MultiVector > residual22_
Teuchos::RCP< RealValuedMultiVector > Coords_
Coordinates.
Teuchos::RCP< Matrix > D0_Matrix_
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitudeType
void applyInverseRefMaxwellAdditive(const MultiVector &RHS, MultiVector &X) const
apply RefMaxwell additive 2x2 style cycle
Teuchos::RCP< MultiVector > Nullspace_
Nullspace.
Kokkos::View< bool *, typename Node::device_type > BCdomainKokkos_
Teuchos::RCP< MultiVector > update11c_
Kokkos::View< bool *, typename Node::device_type > BCcolsKokkos_
Maxwell1(Teuchos::RCP< Hierarchy > H11, Teuchos::RCP< Hierarchy > H22)
Constructor with Hierarchies.
void applyInverseStandard(const MultiVector &RHS, MultiVector &X) const
apply standard Maxwell1 cycle
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)
RCP< Matrix > P11_
Temporary memory (cached vectors for RefMaxwell-style).
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.
Kokkos::View< bool *, typename Node::device_type > BCrowsKokkos_
Vectors for BCs.
Teuchos::RCP< Teuchos::TimeMonitor > getTimer(std::string name, RCP< const Teuchos::Comm< int > > comm=Teuchos::null) const
get a (synced) timer
void setParameters(Teuchos::ParameterList &list)
Set parameters.
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.