MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
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 namespace MueLu {
62 
63 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
65  : type_(type) {
66  const bool solverSupported = (type_ == "RefMaxwell");
67  this->declareConstructionOutcome(!solverSupported, "RefMaxwellSmoother does not provide the smoother '" + type_ + "'.");
68  if (solverSupported)
69  SetParameterList(paramList);
70 }
71 
72 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
74  Factory::SetParameterList(paramList);
75 }
76 
77 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
79  const ParameterList& pL = this->GetParameterList();
80 
81  int spaceNumber = 1;
82  if (pL.isType<int>("refmaxwell: space number"))
83  spaceNumber = pL.get<int>("refmaxwell: space number");
84  this->Input(currentLevel, "A");
85  this->Input(currentLevel, "Dk_1");
86  if (spaceNumber > 1)
87  this->Input(currentLevel, "Dk_2");
88  this->Input(currentLevel, "D0");
89  this->Input(currentLevel, "Mk_one");
90  if (spaceNumber > 1)
91  this->Input(currentLevel, "Mk_1_one");
92  this->Input(currentLevel, "M1_beta");
93  if (spaceNumber > 1)
94  this->Input(currentLevel, "M1_alpha");
95  this->Input(currentLevel, "invMk_1_invBeta");
96  if (spaceNumber > 1)
97  this->Input(currentLevel, "invMk_2_invAlpha");
98  this->Input(currentLevel, "Coordinates");
99 }
100 
101 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
103  FactoryMonitor m(*this, "Setup Smoother", currentLevel);
104 
105  SetupRefMaxwell(currentLevel);
107  this->GetOStream(Statistics1) << description() << std::endl;
108 }
109 
110 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
112  using coordinateType = typename Teuchos::ScalarTraits<Scalar>::coordinateType;
113  using RealValuedMultiVector = Xpetra::MultiVector<coordinateType, LO, GO, NO>;
114 
115  ParameterList params = this->GetParameterList();
116  int spaceNumber = 1;
117  if (params.isType<int>("refmaxwell: space number"))
118  spaceNumber = params.get<int>("refmaxwell: space number");
119 
120  RCP<Matrix> SM, Dk_1, Dk_2, D0, Mk_one, Mk_1_one, M1_beta, M1_alpha, invMk_1_invBeta, invMk_2_invAlpha;
121 
122  SM = currentLevel.Get<RCP<Matrix> >("A");
123  Dk_1 = currentLevel.Get<RCP<Matrix> >("Dk_1");
124  if (spaceNumber > 1)
125  Dk_2 = currentLevel.Get<RCP<Matrix> >("Dk_2");
126  D0 = currentLevel.Get<RCP<Matrix> >("D0");
127  Mk_one = currentLevel.Get<RCP<Matrix> >("Mk_one");
128  if (spaceNumber > 1)
129  Mk_1_one = currentLevel.Get<RCP<Matrix> >("Mk_1_one");
130  M1_beta = currentLevel.Get<RCP<Matrix> >("M1_beta");
131  if (spaceNumber > 1)
132  M1_alpha = currentLevel.Get<RCP<Matrix> >("M1_alpha");
133  invMk_1_invBeta = currentLevel.Get<RCP<Matrix> >("invMk_1_invBeta");
134  if (spaceNumber > 1)
135  invMk_2_invAlpha = currentLevel.Get<RCP<Matrix> >("invMk_2_invAlpha");
136  auto coords = currentLevel.Get<RCP<RealValuedMultiVector> >("Coordinates");
137 
139  Dk_1, Dk_2, D0,
140  M1_beta, M1_alpha,
141  Mk_one, Mk_1_one,
142  invMk_1_invBeta, invMk_2_invAlpha,
143  Teuchos::null, Teuchos::null, coords,
144  params));
145  std::ostringstream oss;
146  op_->describe(*Teuchos::fancyOStream(Teuchos::rcpFromRef(oss)));
147  cachedDescription_ = oss.str();
148 }
149 
150 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
151 void RefMaxwellSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero) const {
152  TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() == false, Exceptions::RuntimeError, "MueLu::RefMaxwellSmoother::Apply(): Setup() has not been called");
153 
154  if (InitialGuessIsZero) {
155  X.putScalar(0.0);
156  }
157  op_->apply(B, X);
158 }
159 
160 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
162  RCP<RefMaxwellSmoother> smoother = rcp(new RefMaxwellSmoother(*this));
163  smoother->SetParameterList(this->GetParameterList());
164  return smoother;
165 }
166 
167 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
169  std::ostringstream out;
171  out << op_->description();
172  out << std::endl
173  << std::endl;
174  // out << cachedDescription_;
175  } else {
176  out << "RefMaxwell";
177  }
178  return out.str();
179 }
180 
181 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
184 
185  if (verbLevel & Parameters1) {
186  out0 << "Parameter list: " << std::endl;
187  Teuchos::OSTab tab2(out);
188  out << this->GetParameterList();
189  }
190 
191  if (verbLevel & External) {
192  if (op_ != Teuchos::null) {
193  Teuchos::OSTab tab2(out);
194  out << *op_ << std::endl
195  << std::endl;
196  }
197  }
198 
199  // if (verbLevel & Debug) {
200  // out0 << "IsSetup: " << Teuchos::toString(SmootherPrototype::IsSetup()) << std::endl
201  // << "-" << std::endl
202  // << "RCP<solver_>: " << tSolver_ << std::endl;
203  // }
204 }
205 
206 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
209 }
210 
211 } // namespace MueLu
212 
213 #endif // MUELU_REFMAXWELLSMOOTHER_DEF_HPP
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level-&gt;Get&lt; RCP&lt;Matrix&gt; &gt;(&quot;A&quot;, factory) if factory == NULL =&gt; use default factory.
RefMaxwellSmoother(const std::string type, const Teuchos::ParameterList &paramList)
Constructor.
RCP< SmootherPrototype > Copy() const
Print external lib objects.
void SetupRefMaxwell(Level &currentLevel)
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Print more statistics.
Preconditioner (wrapped as a Xpetra::Operator) for Maxwell&#39;s equations in curl-curl form...
virtual void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void declareConstructionOutcome(bool fail, std::string msg)
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:99
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
bool IsSetup() const
Get the state of a smoother prototype.
Class that encapsulates Operator smoothers.
std::string description() const
Return a simple one-line description of this object.
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
void DeclareInput(Level &currentLevel) const
Input.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the preconditioner.
bool isType(const std::string &name) const
Print class parameters (more parameters, more verbose)
Exception throws to report errors in the internal logical of the program.
void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
void Setup(Level &currentLevel)
Set up the smoother.