MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_RefMaxwellSmoother_def.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_REFMAXWELLSMOOTHER_DEF_HPP
47#define MUELU_REFMAXWELLSMOOTHER_DEF_HPP
48
49#include "MueLu_ConfigDefs.hpp"
50
51#include <Teuchos_ParameterList.hpp>
52
53#include <Xpetra_CrsMatrix.hpp>
54#include <Xpetra_Matrix.hpp>
55#include <Xpetra_MultiVectorFactory.hpp>
56
58#include "MueLu_Level.hpp"
60#include "MueLu_Utilities.hpp"
61#include "MueLu_Monitor.hpp"
62
63
64
65namespace MueLu {
66
67 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
68 RefMaxwellSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::RefMaxwellSmoother(const std::string type, const Teuchos::ParameterList& paramList)
69 : type_(type)
70 {
71 const bool solverSupported = (type_ == "RefMaxwell");
72 this->declareConstructionOutcome(!solverSupported, "RefMaxwellSmoother does not provide the smoother '" + type_ + "'.");
73 if (solverSupported)
74 SetParameterList(paramList);
75 }
76
77 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
81
82 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
84 this->Input(currentLevel, "A");
85 this->Input(currentLevel, "D0");
86 this->Input(currentLevel, "M1");
87 this->Input(currentLevel, "Ms");
88 this->Input(currentLevel, "M0inv");
89 this->Input(currentLevel, "Coordinates");
90 }
91
92 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
94 FactoryMonitor m(*this, "Setup Smoother", currentLevel);
95
96 SetupRefMaxwell(currentLevel);
98 this->GetOStream(Statistics1) << description() << std::endl;
99 }
100
101
102 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
104
105 using coordinateType = typename Teuchos::ScalarTraits<Scalar>::coordinateType;
106 using RealValuedMultiVector = Xpetra::MultiVector<coordinateType,LO,GO,NO>;
107
108 auto SM = currentLevel.Get<RCP<Matrix> >("A");
109 auto D0 = currentLevel.Get<RCP<Matrix> >("D0");
110 auto M1 = currentLevel.Get<RCP<Matrix> >("M1");
111 auto Ms = currentLevel.Get<RCP<Matrix> >("Ms");
112 auto M0inv = currentLevel.Get<RCP<Matrix> >("M0inv");
113 auto coords = currentLevel.Get<RCP<RealValuedMultiVector> >("Coordinates");
114 auto params = this->GetParameterList();
115
117 Teuchos::null, coords,
118 params));
119 std::ostringstream oss;
120 op_->describe(*Teuchos::fancyOStream(Teuchos::rcpFromRef(oss)));
121 cachedDescription_ = oss.str();
122 }
123
124 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
125 void RefMaxwellSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero) const {
126 TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() == false, Exceptions::RuntimeError, "MueLu::RefMaxwellSmoother::Apply(): Setup() has not been called");
127
128 if (InitialGuessIsZero) {
129 X.putScalar(0.0);
130 }
131 op_->apply(B, X);
132 }
133
134 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
135 RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> > RefMaxwellSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Copy() const {
136 RCP<RefMaxwellSmoother> smoother = rcp(new RefMaxwellSmoother(*this) );
137 smoother->SetParameterList(this->GetParameterList());
138 return smoother;
139 }
140
141 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
143 std::ostringstream out;
145 out << op_->description();
146 out << std::endl << std::endl;
147 // out << cachedDescription_;
148 } else {
149 out << "RefMaxwell";
150 }
151 return out.str();
152 }
153
154 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
155 void RefMaxwellSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::print(Teuchos::FancyOStream &out, const VerbLevel verbLevel) const {
157
158 if (verbLevel & Parameters1) {
159 out0 << "Parameter list: " << std::endl;
160 Teuchos::OSTab tab2(out);
161 out << this->GetParameterList();
162 }
163
164 if (verbLevel & External) {
165 if (op_ != Teuchos::null) {
166 Teuchos::OSTab tab2(out);
167 out << *op_ << std::endl << std::endl;
168 }
169 }
170
171 // if (verbLevel & Debug) {
172 // out0 << "IsSetup: " << Teuchos::toString(SmootherPrototype::IsSetup()) << std::endl
173 // << "-" << std::endl
174 // << "RCP<solver_>: " << tSolver_ << std::endl;
175 // }
176 }
177
178 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
180 return Teuchos::OrdinalTraits<size_t>::invalid();
181 }
182
183
184} // namespace MueLu
185
186#endif // MUELU_REFMAXWELLSMOOTHER_DEF_HPP
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
Exception throws to report errors in the internal logical of the program.
Timer to be used in factories. Similar to Monitor but with additional timers.
void Input(Level &level, const std::string &varName) const
Class that holds all level-specific information.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
virtual const Teuchos::ParameterList & GetParameterList() const
virtual void SetParameterList(const Teuchos::ParameterList &paramList)=0
Set parameters from a parameter list and return with default values.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
void SetupRefMaxwell(Level &currentLevel)
void Setup(Level &currentLevel)
Set up the smoother.
RCP< Operator > op_
matrix, used in apply if solving residual equation
void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
void DeclareInput(Level &currentLevel) const
Input.
RefMaxwellSmoother(const std::string type, const Teuchos::ParameterList &paramList)
Constructor.
std::string description() const
Return a simple one-line description of this object.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the preconditioner.
RCP< SmootherPrototype > Copy() const
Preconditioner (wrapped as a Xpetra::Operator) for Maxwell's equations in curl-curl form.
void declareConstructionOutcome(bool fail, std::string msg)
bool IsSetup() const
Get the state of a smoother prototype.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
Namespace for MueLu classes and methods.
@ Statistics1
Print more statistics.
@ External
Print external lib objects.
@ Parameters1
Print class parameters (more parameters, more verbose)