47#ifndef MUELU_MATLABSMOOTHER_DEF_HPP
48#define MUELU_MATLABSMOOTHER_DEF_HPP
51#if defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_MATLAB)
57 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
60 SetParameterList(paramList);
63 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67 ParameterList& pL =
const_cast<ParameterList&
>(this->GetParameterList());
68 setupFunction_ = pL.get(
"Setup Function",
"");
69 solveFunction_ = pL.get(
"Solve Function",
"");
70 solveDataSize_ = pL.get(
"Number of Solver Args", 0);
73 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
77 this->Input(currentLevel,
"A");
78 ParameterList& pL =
const_cast<ParameterList&
>(this->GetParameterList());
79 needsSetup_ = pL.get<
string>(
"Needs");
81 for(
size_t i = 0; i < needsList.size(); i++)
84 this->Input(currentLevel, needsList[i]);
88 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
93 if (this->IsSetup() ==
true)
94 this->GetOStream(
Warnings0) <<
"MueLu::MatlabSmoother::Setup(): Setup() has already been called";
95 vector<RCP<MuemexArg>> InputArgs = processNeeds<Scalar, LocalOrdinal, GlobalOrdinal, Node>(
this, needsSetup_, currentLevel);
96 A_ = Factory::Get<RCP<Matrix>>(currentLevel,
"A");
97 RCP<MuemexArg> AmatArg = rcp_implicit_cast<MuemexArg>(rcp(
new MuemexData<RCP<Matrix>>(A_)));
99 InputArgs.insert(InputArgs.begin(), AmatArg);
101 if(!setupFunction_.length())
102 throw runtime_error(
"Invalid matlab function name");
103 solveData_=
callMatlab(setupFunction_, solveDataSize_, InputArgs);
104 this->GetOStream(
Statistics1) << description() << endl;
108 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
112 "MueLu::MatlabSmoother::Apply(): Setup() has not been called");
115 if(InitialGuessIsZero)
118 vector<RCP<MuemexArg>> InputArgs;
119 InputArgs.push_back(rcp(
new MuemexData<RCP<Matrix>>(A_)));
121 RCP<MultiVector> Xrcp(&X,
false);
122 MultiVector* BPtrNonConst = (MultiVector*) &B;
123 RCP<MultiVector> Brcp = rcp<MultiVector>(BPtrNonConst,
false);
124 RCP<MuemexData<RCP<MultiVector>>> XData = rcp(
new MuemexData<RCP<MultiVector>>(Xrcp));
125 RCP<MuemexData<RCP<MultiVector>>> BData = rcp(
new MuemexData<RCP<MultiVector>>(Brcp));
126 InputArgs.push_back(XData);
127 InputArgs.push_back(BData);
128 for(
size_t i = 0; i < solveData_.size(); i++)
129 InputArgs.push_back(solveData_[i]);
130 if(!solveFunction_.length())
throw std::runtime_error(
"Invalid matlab function name");
131 vector<Teuchos::RCP<MuemexArg>> mexOutput =
callMatlab(solveFunction_, 1, InputArgs);
132 RCP<MuemexData<RCP<MultiVector>>> mydata = Teuchos::rcp_static_cast<MuemexData<RCP<MultiVector>>>(mexOutput[0]);
133 X = *(mydata->getData());
136 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
140 smoother->SetParameterList(this->GetParameterList());
144 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
146 std::ostringstream out;
148 out <<
"Matlab Smoother("<<setupFunction_<<
"/"<<solveFunction_<<
")";
155 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
160 out <<
"Matlab Smoother("<<setupFunction_<<
"/"<<solveFunction_<<
")";
163 out0 <<
"Parameter list: " << std::endl;
164 Teuchos::OSTab tab2(out);
165 out << this->GetParameterList();
168 if (verbLevel &
Debug) {
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
virtual std::string description() const
Return a simple one-line description of this object.
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.
void DeclareInput(Level ¤tLevel) const
Input.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
void Setup(Level ¤tLevel)
Set up the smoother.
RCP< SmootherPrototype > Copy() const
friend class MatlabSmoother
Constructor.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the preconditioner.
void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
std::string description() const
Return a simple one-line description of this object.
virtual void SetParameterList(const Teuchos::ParameterList ¶mList)=0
Set parameters from a parameter list and return with default values.
bool IsSetup() const
Get the state of a smoother prototype.
Namespace for MueLu classes and methods.
bool IsParamMuemexVariable(const std::string &name)
@ Warnings0
Important warning messages (one line)
@ Debug
Print additional debugging information.
@ Statistics1
Print more statistics.
@ Parameters0
Print class parameters.
@ Parameters1
Print class parameters (more parameters, more verbose)
std::vector< RCP< MuemexArg > > callMatlab(std::string function, int numOutputs, std::vector< RCP< MuemexArg > > args)
std::vector< std::string > tokenizeList(const std::string ¶ms)