MueLu Version of the Day
Loading...
Searching...
No Matches
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
60
61#include "MueLu_MasterList.hpp"
62#include "MueLu_FactoryManager.hpp"
67
72
79
83
84#include "Xpetra_Operator.hpp"
85#include "Xpetra_Map_fwd.hpp"
86#include "Xpetra_Matrix_fwd.hpp"
87#include "Xpetra_MatrixFactory_fwd.hpp"
88#include "Xpetra_MultiVectorFactory_fwd.hpp"
89#include "Xpetra_VectorFactory_fwd.hpp"
90#include "Xpetra_CrsMatrixWrap_fwd.hpp"
91
92namespace MueLu {
93
120 template <class Scalar,
121 class LocalOrdinal,
122 class GlobalOrdinal,
123 class Node>
124 class RefMaxwell : public VerboseObject, public Xpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
125
126#undef MUELU_REFMAXWELL_SHORT
128
129 public:
130
131 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitudeType;
132 typedef typename Teuchos::ScalarTraits<Scalar>::coordinateType coordinateType;
133 typedef typename Xpetra::MultiVector<coordinateType,LO,GO,NO> RealValuedMultiVector;
134
137 HierarchyH_(Teuchos::null),
138 Hierarchy22_(Teuchos::null),
139 disable_addon_(MasterList::getDefault<bool>("refmaxwell: disable addon")),
140 mode_(MasterList::getDefault<std::string>("refmaxwell: mode"))
141 {
142 }
143
145 RefMaxwell(Teuchos::RCP<Hierarchy> HH, Teuchos::RCP<Hierarchy> H22) :
146 HierarchyH_(HH),
147 Hierarchy22_(H22),
148 disable_addon_(MasterList::getDefault<bool>("refmaxwell: disable addon")),
149 mode_(MasterList::getDefault<std::string>("refmaxwell: mode"))
150 {
151 }
152
165 RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
166 const Teuchos::RCP<Matrix> & D0_Matrix,
167 const Teuchos::RCP<Matrix> & Ms_Matrix,
168 const Teuchos::RCP<Matrix> & M0inv_Matrix,
169 const Teuchos::RCP<Matrix> & M1_Matrix,
170 const Teuchos::RCP<MultiVector> & Nullspace,
171 const Teuchos::RCP<RealValuedMultiVector> & Coords,
172 Teuchos::ParameterList& List,
173 bool ComputePrec = true)
174 {
175 initialize(D0_Matrix,Ms_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
176 resetMatrix(SM_Matrix,ComputePrec);
177 }
178
190 RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
191 const Teuchos::RCP<Matrix> & D0_Matrix,
192 const Teuchos::RCP<Matrix> & M0inv_Matrix,
193 const Teuchos::RCP<Matrix> & M1_Matrix,
194 const Teuchos::RCP<MultiVector> & Nullspace,
195 const Teuchos::RCP<RealValuedMultiVector> & Coords,
196 Teuchos::ParameterList& List,
197 bool ComputePrec = true)
198 {
199 initialize(D0_Matrix,M1_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
200 resetMatrix(SM_Matrix,ComputePrec);
201 }
202
212 RefMaxwell(const Teuchos::RCP<Matrix> & D0_Matrix,
213 const Teuchos::RCP<Matrix> & M0inv_Matrix,
214 const Teuchos::RCP<Matrix> & M1_Matrix,
215 const Teuchos::RCP<MultiVector> & Nullspace,
216 const Teuchos::RCP<RealValuedMultiVector> & Coords,
217 Teuchos::ParameterList& List) : SM_Matrix_(Teuchos::null)
218 {
219 initialize(D0_Matrix,M1_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
220 }
221
232 RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
233 const Teuchos::RCP<Matrix> & D0_Matrix,
234 const Teuchos::RCP<Matrix> & M1_Matrix,
235 const Teuchos::RCP<MultiVector> & Nullspace,
236 const Teuchos::RCP<RealValuedMultiVector> & Coords,
237 Teuchos::ParameterList& List,
238 bool ComputePrec)
239 {
240 initialize(D0_Matrix,M1_Matrix,Teuchos::null,M1_Matrix,Nullspace,Coords,List);
241 resetMatrix(SM_Matrix,ComputePrec);
242 }
243
252 RefMaxwell(const Teuchos::RCP<Matrix> & D0_Matrix,
253 const Teuchos::RCP<Matrix> & M1_Matrix,
254 const Teuchos::RCP<MultiVector> & Nullspace,
255 const Teuchos::RCP<RealValuedMultiVector> & Coords,
256 Teuchos::ParameterList& List) : SM_Matrix_(Teuchos::null)
257 {
258 initialize(D0_Matrix,M1_Matrix,Teuchos::null,M1_Matrix,Nullspace,Coords,List);
259 }
260
267 RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
268 Teuchos::ParameterList& List,
269 bool ComputePrec = true)
270 {
271
272 RCP<MultiVector> Nullspace = List.get<RCP<MultiVector> >("Nullspace", Teuchos::null);
273 RCP<RealValuedMultiVector> Coords = List.get<RCP<RealValuedMultiVector> >("Coordinates", Teuchos::null);
274 RCP<Matrix> D0_Matrix = List.get<RCP<Matrix> >("D0");
275 RCP<Matrix> Ms_Matrix;
276 if (List.isType<RCP<Matrix> >("Ms"))
277 Ms_Matrix = List.get<RCP<Matrix> >("Ms");
278 else
279 Ms_Matrix = List.get<RCP<Matrix> >("M1");
280 RCP<Matrix> M1_Matrix = List.get<RCP<Matrix> >("M1");
281 RCP<Matrix> M0inv_Matrix = List.get<RCP<Matrix> >("M0inv", Teuchos::null);
282
283 initialize(D0_Matrix,Ms_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
284
285 if (SM_Matrix != Teuchos::null)
286 resetMatrix(SM_Matrix,ComputePrec);
287 }
288
290 virtual ~RefMaxwell() {}
291
293 Teuchos::RCP<const Map> getDomainMap() const;
294
296 Teuchos::RCP<const Map> getRangeMap() const;
297
299 const Teuchos::RCP<Matrix> & getJacobian() const {
300 return SM_Matrix_;
301 }
302
304 void setParameters(Teuchos::ParameterList& list);
305
307 void compute(bool reuse=false);
308
310 void buildProlongator();
311
313 void formCoarseMatrix();
314
316 void resetMatrix(Teuchos::RCP<Matrix> SM_Matrix_new, bool ComputePrec=true);
317
321 void apply (const MultiVector& X, MultiVector& Y,
322 Teuchos::ETransp mode = Teuchos::NO_TRANS,
323 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
324 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
325
327 bool hasTransposeApply() const;
328
329 void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_HIGH) const;
330
332 void residual(const MultiVector & X,
333 const MultiVector & B,
334 MultiVector & R) const {
335 using STS = Teuchos::ScalarTraits<Scalar>;
336 R.update(STS::one(),B,STS::zero());
337 this->apply (X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
338 }
339
340
341 private:
342
353 void initialize(const Teuchos::RCP<Matrix> & D0_Matrix,
354 const Teuchos::RCP<Matrix> & Ms_Matrix,
355 const Teuchos::RCP<Matrix> & M0inv_Matrix,
356 const Teuchos::RCP<Matrix> & M1_Matrix,
357 const Teuchos::RCP<MultiVector> & Nullspace,
358 const Teuchos::RCP<RealValuedMultiVector> & Coords,
359 Teuchos::ParameterList& List);
360
363
365 void applyInverseAdditive(const MultiVector& RHS, MultiVector& X) const;
366
368 void solveH(const MultiVector& RHS, MultiVector& X) const;
369
371 void solve22(const MultiVector& RHS, MultiVector& X) const;
372
374 void allocateMemory(int numVectors) const;
375
377 void dump(const Matrix& A, std::string name) const;
378
380 void dump(const MultiVector& X, std::string name) const;
381
383 void dumpCoords(const RealValuedMultiVector& X, std::string name) const;
384
386 void dump(const Teuchos::ArrayRCP<bool>& v, std::string name) const;
387
389 void dump(const Kokkos::View<bool*, typename Node::device_type>& v, std::string name) const;
390
392 Teuchos::RCP<Teuchos::TimeMonitor> getTimer(std::string name, RCP<const Teuchos::Comm<int> > comm=Teuchos::null) const;
393
394
396 Teuchos::RCP<Hierarchy> HierarchyH_, Hierarchy22_;
397 Teuchos::RCP<SmootherBase> PreSmoother_, PostSmoother_;
398 Teuchos::RCP<SmootherPrototype> PreSmootherData_, PostSmootherData_;
402 Teuchos::RCP<Matrix> A_nodal_Matrix_, P11_, R11_, AH_, A22_, Addon_Matrix_;
403 Teuchos::RCP<const Map> D0origDomainMap_;
404 Teuchos::RCP<const Import> D0origImporter_;
406 Kokkos::View<bool*, typename Node::device_type> BCrows_, BCcols_, BCdomain_;
409 Teuchos::RCP<MultiVector> Nullspace_;
411 Teuchos::RCP<RealValuedMultiVector> Coords_, CoordsH_;
413 Teuchos::RCP<MultiVector> NullspaceH_;
415 Teuchos::RCP<const Import> ImporterH_, Importer22_;
420 Teuchos::RCP<Teuchos::ParameterList> AH_AP_reuse_data_, AH_RAP_reuse_data_;
421 Teuchos::RCP<Teuchos::ParameterList> A22_AP_reuse_data_, A22_RAP_reuse_data_;
426 std::string mode_;
429 };
430
431
432} // namespace
433
434#define MUELU_REFMAXWELL_SHORT
435#endif // MUELU_REFMAXWELL_DECL_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
MueLu::DefaultNode Node
Static class that holds the complete list of valid MueLu parameters.
Teuchos::RCP< MultiVector > D0xSubComm_
Teuchos::RCP< MultiVector > NullspaceH_
Nullspace for (1,1) problem.
Teuchos::RCP< MultiVector > P11resTmp_
void dumpCoords(const RealValuedMultiVector &X, std::string name) const
dump out real-valued multivector
Teuchos::ScalarTraits< Scalar >::coordinateType coordinateType
Teuchos::RCP< SmootherBase > PreSmoother_
Teuchos::RCP< MultiVector > P11x_
Teuchos::RCP< MultiVector > residual_
Teuchos::RCP< Matrix > D0_Matrix_
Teuchos::RCP< const Import > D0origImporter_
Teuchos::RCP< Teuchos::ParameterList > A22_AP_reuse_data_
Teuchos::RCP< MultiVector > P11res_
Temporary memory.
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)
Xpetra::MultiVector< coordinateType, LO, GO, NO > RealValuedMultiVector
Teuchos::RCP< RealValuedMultiVector > Coords_
Coordinates.
void formCoarseMatrix()
Compute P11^{T}*A*P11 efficiently.
Teuchos::RCP< Matrix > AH_
Teuchos::RCP< Teuchos::TimeMonitor > getTimer(std::string name, RCP< const Teuchos::Comm< int > > comm=Teuchos::null) const
get a (synced) timer
void allocateMemory(int numVectors) const
allocate multivectors for solve
Teuchos::RCP< Matrix > M0inv_Matrix_
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< MultiVector > D0x_
Teuchos::RCP< Matrix > SM_Matrix_
Various matrices.
Teuchos::RCP< Teuchos::ParameterList > AH_AP_reuse_data_
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_HIGH) const
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)
Teuchos::RCP< Matrix > D0_T_Matrix_
Teuchos::ParameterList smootherList_
Teuchos::RCP< MultiVector > D0res_
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
Kokkos::View< bool *, typename Node::device_type > BCrows_
Vectors for BCs.
Teuchos::RCP< SmootherPrototype > PostSmootherData_
Teuchos::RCP< Teuchos::ParameterList > A22_RAP_reuse_data_
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
Teuchos::RCP< SmootherPrototype > PreSmootherData_
bool disable_addon_
Some options.
void solveH(const MultiVector &RHS, MultiVector &X) const
apply solve to 1-1 block only
Teuchos::ParameterList precList22_
Teuchos::RCP< const Import > ImporterH_
Importer to coarse (1,1) hierarchy.
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< Matrix > A22_
Teuchos::RCP< Matrix > R11_
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitudeType
const Teuchos::RCP< Matrix > & getJacobian() const
Returns Jacobian matrix SM.
Teuchos::RCP< const Import > Importer22_
void buildProlongator()
Setup the prolongator for the (1,1)-block.
Teuchos::RCP< Teuchos::ParameterList > AH_RAP_reuse_data_
Teuchos::RCP< Matrix > A_nodal_Matrix_
Teuchos::RCP< Matrix > P11_
RefMaxwell(Teuchos::RCP< Hierarchy > HH, Teuchos::RCP< Hierarchy > H22)
Constructor with Hierarchies.
Kokkos::View< bool *, typename Node::device_type > BCcols_
virtual ~RefMaxwell()
Destructor.
Teuchos::RCP< MultiVector > P11resSubComm_
Teuchos::RCP< MultiVector > P11xSubComm_
Teuchos::RCP< Hierarchy > Hierarchy22_
Teuchos::RCP< SmootherBase > PostSmoother_
Teuchos::RCP< MultiVector > D0resTmp_
Teuchos::RCP< Matrix > Addon_Matrix_
Teuchos::RCP< Matrix > M1_Matrix_
void setFineLevelSmoother()
Set the fine level smoother.
Teuchos::RCP< MultiVector > D0TR11Tmp_
void applyInverseAdditive(const MultiVector &RHS, MultiVector &X) const
apply additive algorithm for 2x2 solve
RefMaxwell(const Teuchos::RCP< Matrix > &SM_Matrix, Teuchos::ParameterList &List, bool ComputePrec=true)
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)
Teuchos::RCP< const Map > getRangeMap() const
Returns the Xpetra::Map object associated with the range of this operator.
Teuchos::RCP< RealValuedMultiVector > CoordsH_
void compute(bool reuse=false)
Setup the preconditioner.
Teuchos::RCP< Hierarchy > HierarchyH_
Two hierarchies: one for the coarse (1,1)-block, another for the (2,2)-block.
Teuchos::ParameterList precList11_
Teuchos::RCP< Matrix > Ms_Matrix_
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)
Teuchos::ParameterList parameterList_
Parameter lists.
Kokkos::View< bool *, typename Node::device_type > BCdomain_
Teuchos::RCP< MultiVector > D0resSubComm_
void resetMatrix(Teuchos::RCP< Matrix > SM_Matrix_new, bool ComputePrec=true)
Reset system matrix.
void setParameters(Teuchos::ParameterList &list)
Set parameters.
Teuchos::RCP< MultiVector > Nullspace_
Nullspace.
void dump(const Matrix &A, std::string name) const
dump out matrix
void solve22(const MultiVector &RHS, MultiVector &X) const
apply solve to 2-2 block only
Teuchos::RCP< const Map > D0origDomainMap_
Teuchos::RCP< const Map > getDomainMap() const
Returns the Xpetra::Map object associated with the domain of this operator.
void residual(const MultiVector &X, const MultiVector &B, MultiVector &R) const
Compute a residual R = B - (*this) * X.
Namespace for MueLu classes and methods.