MueLu  Version of the Day
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 
57 #include "MueLu_SaPFactory_fwd.hpp"
60 #include "MueLu_Utilities_fwd.hpp"
61 
69 
76 
79 #include "MueLu_Hierarchy_fwd.hpp"
80 #include "MueLu_XpetraOperator.hpp"
81 
82 #include "Xpetra_Map_fwd.hpp"
83 #include "Xpetra_Matrix_fwd.hpp"
84 #include "Xpetra_MatrixFactory_fwd.hpp"
85 #include "Xpetra_MultiVectorFactory_fwd.hpp"
86 #include "Xpetra_VectorFactory_fwd.hpp"
87 #include "Xpetra_CrsMatrixWrap_fwd.hpp"
88 
89 namespace MueLu {
90 
117  template <class Scalar,
118  class LocalOrdinal,
119  class GlobalOrdinal,
120  class Node>
121  class RefMaxwell : public VerboseObject, public Xpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
122 
123 #undef MUELU_REFMAXWELL_SHORT
124 #include "MueLu_UseShortNames.hpp"
125 
126  public:
127 
128  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitudeType;
129  typedef typename Teuchos::ScalarTraits<Scalar>::coordinateType coordinateType;
130  typedef typename Xpetra::MultiVector<coordinateType,LO,GO,NO> RealValuedMultiVector;
131 
134  HierarchyH_(Teuchos::null),
135  Hierarchy22_(Teuchos::null),
136  disable_addon_(MasterList::getDefault<bool>("refmaxwell: disable addon")),
137  mode_(MasterList::getDefault<std::string>("refmaxwell: mode"))
138  {
139  }
140 
142  RefMaxwell(Teuchos::RCP<Hierarchy> HH, Teuchos::RCP<Hierarchy> H22) :
143  HierarchyH_(HH),
144  Hierarchy22_(H22),
145  disable_addon_(MasterList::getDefault<bool>("refmaxwell: disable addon")),
146  mode_(MasterList::getDefault<std::string>("refmaxwell: mode"))
147  {
148  }
149 
162  RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
163  const Teuchos::RCP<Matrix> & D0_Matrix,
164  const Teuchos::RCP<Matrix> & Ms_Matrix,
165  const Teuchos::RCP<Matrix> & M0inv_Matrix,
166  const Teuchos::RCP<Matrix> & M1_Matrix,
167  const Teuchos::RCP<MultiVector> & Nullspace,
168  const Teuchos::RCP<RealValuedMultiVector> & Coords,
169  Teuchos::ParameterList& List,
170  bool ComputePrec = true)
171  {
172  initialize(D0_Matrix,Ms_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
173  resetMatrix(SM_Matrix,ComputePrec);
174  }
175 
187  RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
188  const Teuchos::RCP<Matrix> & D0_Matrix,
189  const Teuchos::RCP<Matrix> & M0inv_Matrix,
190  const Teuchos::RCP<Matrix> & M1_Matrix,
191  const Teuchos::RCP<MultiVector> & Nullspace,
192  const Teuchos::RCP<RealValuedMultiVector> & Coords,
193  Teuchos::ParameterList& List,
194  bool ComputePrec = true)
195  {
196  initialize(D0_Matrix,M1_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
197  resetMatrix(SM_Matrix,ComputePrec);
198  }
199 
209  RefMaxwell(const Teuchos::RCP<Matrix> & D0_Matrix,
210  const Teuchos::RCP<Matrix> & M0inv_Matrix,
211  const Teuchos::RCP<Matrix> & M1_Matrix,
212  const Teuchos::RCP<MultiVector> & Nullspace,
213  const Teuchos::RCP<RealValuedMultiVector> & Coords,
214  Teuchos::ParameterList& List) : SM_Matrix_(Teuchos::null)
215  {
216  initialize(D0_Matrix,M1_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
217  }
218 
229  RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
230  const Teuchos::RCP<Matrix> & D0_Matrix,
231  const Teuchos::RCP<Matrix> & M1_Matrix,
232  const Teuchos::RCP<MultiVector> & Nullspace,
233  const Teuchos::RCP<RealValuedMultiVector> & Coords,
234  Teuchos::ParameterList& List,
235  bool ComputePrec)
236  {
237  initialize(D0_Matrix,M1_Matrix,Teuchos::null,M1_Matrix,Nullspace,Coords,List);
238  resetMatrix(SM_Matrix,ComputePrec);
239  }
240 
249  RefMaxwell(const Teuchos::RCP<Matrix> & D0_Matrix,
250  const Teuchos::RCP<Matrix> & M1_Matrix,
251  const Teuchos::RCP<MultiVector> & Nullspace,
252  const Teuchos::RCP<RealValuedMultiVector> & Coords,
253  Teuchos::ParameterList& List) : SM_Matrix_(Teuchos::null)
254  {
255  initialize(D0_Matrix,M1_Matrix,Teuchos::null,M1_Matrix,Nullspace,Coords,List);
256  }
257 
264  RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
265  Teuchos::ParameterList& List,
266  bool ComputePrec = true)
267  {
268 
269  RCP<MultiVector> Nullspace = List.get<RCP<MultiVector> >("Nullspace", Teuchos::null);
270  RCP<RealValuedMultiVector> Coords = List.get<RCP<RealValuedMultiVector> >("Coordinates", Teuchos::null);
271  RCP<Matrix> D0_Matrix = List.get<RCP<Matrix> >("D0");
272  RCP<Matrix> Ms_Matrix;
273  if (List.isType<RCP<Matrix> >("Ms"))
274  Ms_Matrix = List.get<RCP<Matrix> >("Ms");
275  else
276  Ms_Matrix = List.get<RCP<Matrix> >("M1");
277  RCP<Matrix> M1_Matrix = List.get<RCP<Matrix> >("M1");
278  RCP<Matrix> M0inv_Matrix = List.get<RCP<Matrix> >("M0inv", Teuchos::null);
279 
280  initialize(D0_Matrix,Ms_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
281 
282  if (SM_Matrix != Teuchos::null)
283  resetMatrix(SM_Matrix,ComputePrec);
284  }
285 
287  virtual ~RefMaxwell() {}
288 
290  Teuchos::RCP<const Map> getDomainMap() const;
291 
293  Teuchos::RCP<const Map> getRangeMap() const;
294 
296  const Teuchos::RCP<Matrix> & getJacobian() const {
297  return SM_Matrix_;
298  }
299 
301  void setParameters(Teuchos::ParameterList& list);
302 
304  void compute(bool reuse=false);
305 
307  void buildProlongator();
308 
310  void formCoarseMatrix();
311 
313  void resetMatrix(Teuchos::RCP<Matrix> SM_Matrix_new, bool ComputePrec=true);
314 
318  void apply (const MultiVector& X, MultiVector& Y,
319  Teuchos::ETransp mode = Teuchos::NO_TRANS,
320  Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
321  Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
322 
324  bool hasTransposeApply() const;
325 
326  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = Teuchos::VERB_HIGH) const;
327 
329  void residual(const MultiVector & X,
330  const MultiVector & B,
331  MultiVector & R) const {
332  using STS = Teuchos::ScalarTraits<Scalar>;
333  R.update(STS::one(),B,STS::zero());
334  this->apply (X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
335  }
336 
337 
338  private:
339 
350  void initialize(const Teuchos::RCP<Matrix> & D0_Matrix,
351  const Teuchos::RCP<Matrix> & Ms_Matrix,
352  const Teuchos::RCP<Matrix> & M0inv_Matrix,
353  const Teuchos::RCP<Matrix> & M1_Matrix,
354  const Teuchos::RCP<MultiVector> & Nullspace,
355  const Teuchos::RCP<RealValuedMultiVector> & Coords,
356  Teuchos::ParameterList& List);
357 
359  void setFineLevelSmoother();
360 
362  void applyInverseAdditive(const MultiVector& RHS, MultiVector& X) const;
363 
365  void solveH(const MultiVector& RHS, MultiVector& X) const;
366 
368  void solve22(const MultiVector& RHS, MultiVector& X) const;
369 
371  void allocateMemory(int numVectors) const;
372 
374  void dump(const Matrix& A, std::string name) const;
375 
377  void dump(const MultiVector& X, std::string name) const;
378 
380  void dumpCoords(const RealValuedMultiVector& X, std::string name) const;
381 
383  void dump(const Teuchos::ArrayRCP<bool>& v, std::string name) const;
384 
386  void dump(const Kokkos::View<bool*, typename Node::device_type>& v, std::string name) const;
387 
389  Teuchos::RCP<Teuchos::TimeMonitor> getTimer(std::string name, RCP<const Teuchos::Comm<int> > comm=Teuchos::null) const;
390 
391 
393  Teuchos::RCP<Hierarchy> HierarchyH_, Hierarchy22_;
394  Teuchos::RCP<SmootherBase> PreSmoother_, PostSmoother_;
395  Teuchos::RCP<SmootherPrototype> PreSmootherData_, PostSmootherData_;
399  Teuchos::RCP<Matrix> A_nodal_Matrix_, P11_, R11_, AH_, A22_, Addon_Matrix_;
400  Teuchos::RCP<const Map> D0origDomainMap_;
401  Teuchos::RCP<const Import> D0origImporter_;
403  Kokkos::View<bool*, typename Node::device_type> BCrowsKokkos_, BCcolsKokkos_, BCdomainKokkos_;
405  Teuchos::ArrayRCP<bool> BCrows_, BCcols_, BCdomain_;
407  Teuchos::RCP<MultiVector> Nullspace_;
409  Teuchos::RCP<RealValuedMultiVector> Coords_, CoordsH_;
411  Teuchos::RCP<MultiVector> NullspaceH_;
413  Teuchos::RCP<const Import> ImporterH_, Importer22_;
418  Teuchos::RCP<Teuchos::ParameterList> AH_AP_reuse_data_, AH_RAP_reuse_data_;
419  Teuchos::RCP<Teuchos::ParameterList> A22_AP_reuse_data_, A22_RAP_reuse_data_;
424  std::string mode_;
427  };
428 
429 
430 } // namespace
431 
432 #define MUELU_REFMAXWELL_SHORT
433 #endif // MUELU_REFMAXWELL_DECL_HPP
Teuchos::RCP< SmootherBase > PostSmoother_
Teuchos::RCP< const Import > Importer22_
Teuchos::RCP< Matrix > D0_T_Matrix_
MueLu::DefaultLocalOrdinal LocalOrdinal
Teuchos::RCP< Teuchos::ParameterList > A22_RAP_reuse_data_
void solveH(const MultiVector &RHS, MultiVector &X) const
apply solve to 1-1 block only
Teuchos::RCP< const Map > D0origDomainMap_
Teuchos::RCP< MultiVector > D0xSubComm_
Teuchos::RCP< Matrix > Ms_Matrix_
Teuchos::RCP< MultiVector > NullspaceH_
Nullspace for (1,1) problem.
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 > D0_Matrix_
Teuchos::RCP< SmootherPrototype > PostSmootherData_
Teuchos::RCP< Matrix > SM_Matrix_
Various matrices.
Teuchos::RCP< MultiVector > D0res_
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)
Teuchos::ParameterList smootherList_
Kokkos::View< bool *, typename Node::device_type > BCcolsKokkos_
Kokkos::View< bool *, typename Node::device_type > BCdomainKokkos_
void setFineLevelSmoother()
Set the fine level smoother.
Teuchos::RCP< Matrix > A22_
Teuchos::RCP< MultiVector > D0resTmp_
Teuchos::RCP< MultiVector > D0TR11Tmp_
Namespace for MueLu classes and methods.
Teuchos::RCP< Matrix > Addon_Matrix_
void setParameters(Teuchos::ParameterList &list)
Set parameters.
void applyInverseAdditive(const MultiVector &RHS, MultiVector &X) const
apply additive algorithm for 2x2 solve
void buildProlongator()
Setup the prolongator for the (1,1)-block.
MueLu::DefaultNode Node
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitudeType
Teuchos::RCP< MultiVector > P11res_
Temporary memory.
Verbose class for MueLu classes.
Static class that holds the complete list of valid MueLu parameters.
Teuchos::RCP< const Import > D0origImporter_
void allocateMemory(int numVectors) const
allocate multivectors for solve
Kokkos::View< bool *, typename Node::device_type > BCrowsKokkos_
Vectors for BCs.
Preconditioner (wrapped as a Xpetra::Operator) for Maxwell&#39;s equations in curl-curl form...
Teuchos::RCP< MultiVector > P11resSubComm_
Teuchos::RCP< Matrix > M0inv_Matrix_
Teuchos::RCP< MultiVector > residual_
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::VERB_HIGH) const
Teuchos::RCP< MultiVector > D0x_
Teuchos::RCP< MultiVector > P11resTmp_
void dumpCoords(const RealValuedMultiVector &X, std::string name) const
dump out real-valued multivector
MueLu::DefaultScalar Scalar
void resetMatrix(Teuchos::RCP< Matrix > SM_Matrix_new, bool ComputePrec=true)
Reset system matrix.
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Teuchos::RCP< Teuchos::ParameterList > AH_AP_reuse_data_
Teuchos::ParameterList precList11_
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 > D0resSubComm_
Teuchos::RCP< const Map > getRangeMap() const
Returns the Xpetra::Map object associated with the range of this operator.
Teuchos::RCP< Matrix > P11_
Teuchos::RCP< Matrix > A_nodal_Matrix_
Teuchos::RCP< Hierarchy > Hierarchy22_
Teuchos::RCP< Teuchos::ParameterList > AH_RAP_reuse_data_
Teuchos::RCP< Matrix > M1_Matrix_
Teuchos::RCP< RealValuedMultiVector > CoordsH_
Teuchos::ArrayRCP< bool > BCrows_
Teuchos::ArrayRCP< bool > BCcols_
Xpetra::MultiVector< coordinateType, LO, GO, NO > RealValuedMultiVector
RCP< Operator > thyraPrecOp22_
Teuchos::RCP< SmootherBase > PreSmoother_
void compute(bool reuse=false)
Setup the preconditioner.
Teuchos::RCP< MultiVector > P11xSubComm_
Teuchos::ArrayRCP< bool > BCdomain_
bool disable_addon_
Some options.
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)
virtual ~RefMaxwell()
Destructor.
Teuchos::ParameterList parameterList_
Parameter lists.
Teuchos::RCP< RealValuedMultiVector > Coords_
Coordinates.
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)
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
Teuchos::RCP< SmootherPrototype > PreSmootherData_
Teuchos::RCP< MultiVector > P11x_
Teuchos::RCP< Matrix > R11_
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 dump(const Matrix &A, std::string name) const
dump out matrix
Teuchos::RCP< Matrix > AH_
void formCoarseMatrix()
Compute P11^{T}*A*P11 efficiently.
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
RCP< Operator > thyraPrecOpH_
Teuchos::ScalarTraits< Scalar >::coordinateType coordinateType
Teuchos::RCP< Hierarchy > HierarchyH_
Two hierarchies: one for the coarse (1,1)-block, another for the (2,2)-block.
RefMaxwell(Teuchos::RCP< Hierarchy > HH, Teuchos::RCP< Hierarchy > H22)
Constructor with Hierarchies.
void solve22(const MultiVector &RHS, MultiVector &X) const
apply solve to 2-2 block only
Teuchos::RCP< Teuchos::ParameterList > A22_AP_reuse_data_
Teuchos::ParameterList precList22_
Teuchos::RCP< MultiVector > Nullspace_
Nullspace.
Teuchos::RCP< const Map > getDomainMap() const
Returns the Xpetra::Map object associated with the domain of this operator.
RefMaxwell(const Teuchos::RCP< Matrix > &SM_Matrix, Teuchos::ParameterList &List, bool ComputePrec=true)
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 > &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)