MueLu
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
MueLu_SingleLevelMatlabFactory_def.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// MueLu: A package for multigrid based preconditioning
4
//
5
// Copyright 2012 NTESS and the MueLu contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#ifndef MUELU_SINGLELEVELMATLABFACTORY_DEF_HPP
11
#define MUELU_SINGLELEVELMATLABFACTORY_DEF_HPP
12
#include <Xpetra_Matrix.hpp>
13
#include <Xpetra_MultiVector.hpp>
14
15
#include "
MueLu_Monitor.hpp
"
16
#include "MueLu_Aggregates.hpp"
17
#include "MueLu_AmalgamationInfo.hpp"
18
#include "
MueLu_SingleLevelMatlabFactory_decl.hpp
"
19
#include "
MueLu_MatlabUtils_decl.hpp
"
20
21
#ifdef HAVE_MUELU_MATLAB
22
23
namespace
MueLu
{
24
25
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
26
SingleLevelMatlabFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::SingleLevelMatlabFactory
()
27
:
hasDeclaredInput_
(false) {}
28
29
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
30
RCP<const ParameterList>
SingleLevelMatlabFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::GetValidParameterList
()
const
{
31
RCP<ParameterList> validParamList =
getInputParamList
();
32
validParamList->set<std::string>(
"Provides"
,
""
,
"A comma-separated list of objects provided by the SingleLevelMatlabFactory"
);
33
validParamList->set<std::string>(
"Needs"
,
""
,
"A comma-separated list of objects needed by the SingleLevelMatlabFactory"
);
34
validParamList->set<std::string>(
"Function"
,
""
,
"The name of the Matlab MEX function to call for Build()"
);
35
return
validParamList;
36
}
37
38
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
39
void
SingleLevelMatlabFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::DeclareInput
(
Level
& currentLevel)
const
{
40
const
Teuchos::ParameterList& pL =
GetParameterList
();
41
needs_
=
tokenizeList
(pL.get<std::string>(
"Needs"
));
42
// Declare inputs
43
for
(
size_t
i = 0; i <
needs_
.size(); i++) {
44
if
(!
IsParamMuemexVariable
(
needs_
[i]) &&
needs_
[i] !=
"Level"
)
45
this->
Input
(currentLevel,
needs_
[i]);
46
}
47
hasDeclaredInput_
=
true
;
48
}
49
50
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
51
void
SingleLevelMatlabFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build
(
Level
& currentLevel)
const
{
52
FactoryMonitor
m(*
this
,
"Build"
, currentLevel);
53
54
const
Teuchos::ParameterList& pL =
GetParameterList
();
55
using
Teuchos::rcp;
56
using namespace
std;
57
// NOTE: mexOutput[0] is the "Provides." Might want to modify to allow for additional outputs
58
string
needsList = pL.get<
string
>(
"Needs"
);
59
vector<RCP<MuemexArg>> InputArgs =
processNeeds<Scalar, LocalOrdinal, GlobalOrdinal, Node>
(
this
, needsList, currentLevel);
60
string
providesList = pL.get<std::string>(
"Provides"
);
61
size_t
numProvides =
tokenizeList
(providesList).size();
62
// Call mex function
63
string
matlabFunction = pL.get<std::string>(
"Function"
);
64
if
(!matlabFunction.length())
65
throw
std::runtime_error(
"Invalid matlab function name"
);
66
vector<Teuchos::RCP<MuemexArg>> mexOutput =
callMatlab
(matlabFunction, numProvides, InputArgs);
67
// Set output in level
68
processProvides<Scalar, LocalOrdinal, GlobalOrdinal, Node>
(mexOutput,
this
, providesList, currentLevel);
69
}
70
71
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
72
std::string
SingleLevelMatlabFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::description
()
const
{
73
std::ostringstream out;
74
const
Teuchos::ParameterList& pL =
GetParameterList
();
75
out <<
"SingleLevelMatlabFactory["
<< pL.get<std::string>(
"Function"
) <<
"]"
;
76
return
out.str();
77
}
78
79
}
// namespace MueLu
80
81
#endif
// HAVE_MUELU_MATLAB
82
83
#endif
// MUELU_SINGLELEVELMATLABFACTORY_DEF_HPP
MueLu_MatlabUtils_decl.hpp
MueLu_Monitor.hpp
MueLu_SingleLevelMatlabFactory_decl.hpp
MueLu::Factory::Input
void Input(Level &level, const std::string &varName) const
Definition
MueLu_Factory.cpp:72
MueLu::FactoryMonitor
Timer to be used in factories. Similar to Monitor but with additional timers.
Definition
MueLu_Monitor.hpp:165
MueLu::Level
Class that holds all level-specific information.
Definition
MueLu_Level.hpp:63
MueLu::ParameterListAcceptorImpl::GetParameterList
virtual const Teuchos::ParameterList & GetParameterList() const
Definition
MueLu_ParameterListAcceptor.cpp:50
MueLu::SingleLevelMatlabFactory::hasDeclaredInput_
bool hasDeclaredInput_
Definition
MueLu_SingleLevelMatlabFactory_decl.hpp:72
MueLu::SingleLevelMatlabFactory::description
std::string description() const
@ name Description
Definition
MueLu_SingleLevelMatlabFactory_def.hpp:72
MueLu::SingleLevelMatlabFactory::SingleLevelMatlabFactory
SingleLevelMatlabFactory()
Definition
MueLu_SingleLevelMatlabFactory_def.hpp:26
MueLu::SingleLevelMatlabFactory::GetValidParameterList
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Definition
MueLu_SingleLevelMatlabFactory_def.hpp:30
MueLu::SingleLevelMatlabFactory::DeclareInput
void DeclareInput(Level ¤tLevel) const
Specifies the data that this class needs, and the factories that generate that data.
Definition
MueLu_SingleLevelMatlabFactory_def.hpp:39
MueLu::SingleLevelMatlabFactory::Build
void Build(Level ¤tLevel) const
Build an object with this factory.
Definition
MueLu_SingleLevelMatlabFactory_def.hpp:51
MueLu::SingleLevelMatlabFactory::needs_
std::vector< std::string > needs_
List of arguments to the MATLAB function, in order. These args must correspond to MueLu "Needs" objec...
Definition
MueLu_SingleLevelMatlabFactory_decl.hpp:79
MueLu
Namespace for MueLu classes and methods.
Definition
MueLu_BrickAggregationFactory_decl.hpp:42
MueLu::IsParamMuemexVariable
bool IsParamMuemexVariable(const std::string &name)
Definition
MueLu_Utilities.cpp:113
MueLu::getInputParamList
Teuchos::RCP< Teuchos::ParameterList > getInputParamList()
Definition
MueLu_MatlabUtils.cpp:276
MueLu::callMatlab
std::vector< RCP< MuemexArg > > callMatlab(std::string function, int numOutputs, std::vector< RCP< MuemexArg > > args)
Definition
MueLu_MatlabUtils.cpp:95
MueLu::processNeeds
std::vector< Teuchos::RCP< MuemexArg > > processNeeds(const Factory *factory, std::string &needsParam, Level &lvl)
Definition
MueLu_MatlabUtils_def.hpp:1197
MueLu::processProvides
void processProvides(std::vector< Teuchos::RCP< MuemexArg > > &mexOutput, const Factory *factory, std::string &providesParam, Level &lvl)
Definition
MueLu_MatlabUtils_def.hpp:1291
MueLu::tokenizeList
std::vector< std::string > tokenizeList(const std::string ¶ms)
Definition
MueLu_MatlabUtils.cpp:252
matlab
src
MueLu_SingleLevelMatlabFactory_def.hpp
Generated by
1.17.0