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"
59#include "MueLu_Monitor.hpp"
60
61
62
63namespace MueLu {
64
65 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
66 RefMaxwellSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::RefMaxwellSmoother(const std::string type, const Teuchos::ParameterList& paramList)
67 : type_(type)
68 {
69 const bool solverSupported = (type_ == "RefMaxwell");
70 this->declareConstructionOutcome(!solverSupported, "RefMaxwellSmoother does not provide the smoother '" + type_ + "'.");
71 if (solverSupported)
72 SetParameterList(paramList);
73 }
74
75 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
79
80 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
82 this->Input(currentLevel, "A");
83 this->Input(currentLevel, "D0");
84 this->Input(currentLevel, "M1");
85 this->Input(currentLevel, "Ms");
86 this->Input(currentLevel, "M0inv");
87 this->Input(currentLevel, "Coordinates");
88 }
89
90 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
92 FactoryMonitor m(*this, "Setup Smoother", currentLevel);
93
94 SetupRefMaxwell(currentLevel);
96 this->GetOStream(Statistics1) << description() << std::endl;
97 }
98
99
100 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
102
103 using coordinateType = typename Teuchos::ScalarTraits<Scalar>::coordinateType;
104 using RealValuedMultiVector = Xpetra::MultiVector<coordinateType,LO,GO,NO>;
105
106 auto SM = currentLevel.Get<RCP<Matrix> >("A");
107 auto D0 = currentLevel.Get<RCP<Matrix> >("D0");
108 auto M1 = currentLevel.Get<RCP<Matrix> >("M1");
109 auto Ms = currentLevel.Get<RCP<Matrix> >("Ms");
110 auto M0inv = currentLevel.Get<RCP<Matrix> >("M0inv");
111 auto coords = currentLevel.Get<RCP<RealValuedMultiVector> >("Coordinates");
112 auto params = this->GetParameterList();
113
114 op_ = rcp(new MueLu::RefMaxwell<Scalar, LocalOrdinal, GlobalOrdinal, Node>(SM, D0, Ms, M0inv, M1,
115 Teuchos::null, coords,
116 params));
117 std::ostringstream oss;
118 op_->describe(*Teuchos::fancyOStream(Teuchos::rcpFromRef(oss)));
119 cachedDescription_ = oss.str();
120 }
121
122 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
123 void RefMaxwellSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero) const {
124 TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() == false, Exceptions::RuntimeError, "MueLu::RefMaxwellSmoother::Apply(): Setup() has not been called");
125
126 if (InitialGuessIsZero) {
127 X.putScalar(0.0);
128 }
129 op_->apply(B, X);
130 }
131
132 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
133 RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> > RefMaxwellSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Copy() const {
134 RCP<RefMaxwellSmoother> smoother = rcp(new RefMaxwellSmoother(*this) );
135 smoother->SetParameterList(this->GetParameterList());
136 return smoother;
137 }
138
139 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
141 std::ostringstream out;
143 out << op_->description();
144 out << std::endl << std::endl;
145 // out << cachedDescription_;
146 } else {
147 out << "RefMaxwell";
148 }
149 return out.str();
150 }
151
152 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
153 void RefMaxwellSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::print(Teuchos::FancyOStream &out, const VerbLevel verbLevel) const {
155
156 if (verbLevel & Parameters1) {
157 out0 << "Parameter list: " << std::endl;
158 Teuchos::OSTab tab2(out);
159 out << this->GetParameterList();
160 }
161
162 if (verbLevel & External) {
163 if (op_ != Teuchos::null) {
164 Teuchos::OSTab tab2(out);
165 out << *op_ << std::endl << std::endl;
166 }
167 }
168
169 // if (verbLevel & Debug) {
170 // out0 << "IsSetup: " << Teuchos::toString(SmootherPrototype::IsSetup()) << std::endl
171 // << "-" << std::endl
172 // << "RCP<solver_>: " << tSolver_ << std::endl;
173 // }
174 }
175
176 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
178 return Teuchos::OrdinalTraits<size_t>::invalid();
179 }
180
181
182} // namespace MueLu
183
184#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.
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 void SetParameterList(const Teuchos::ParameterList &paramList)=0
Set parameters from a parameter list and return with default values.
Class that encapsulates Operator smoothers.
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.
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.
Namespace for MueLu classes and methods.
@ Statistics1
Print more statistics.
@ External
Print external lib objects.
@ Parameters1
Print class parameters (more parameters, more verbose)