MueLu
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
MueLu_TwoLevelMatlabFactory_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_TWOLEVELMATLABFACTORY_DEF_HPP
11
#define MUELU_TWOLEVELMATLABFACTORY_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_TwoLevelMatlabFactory_decl.hpp
"
19
#include "
MueLu_MatlabUtils_decl.hpp
"
20
21
#include <iostream>
22
23
#ifdef HAVE_MUELU_MATLAB
24
25
namespace
MueLu
{
26
27
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
28
TwoLevelMatlabFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::TwoLevelMatlabFactory
()
29
:
hasDeclaredInput_
(false) {}
30
31
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
32
RCP<const ParameterList>
TwoLevelMatlabFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::GetValidParameterList
()
const
{
33
RCP<ParameterList> validParamList =
getInputParamList
();
34
validParamList->set<std::string>(
"Provides"
,
""
,
"A comma-separated list of objects provided on the coarse level by the TwoLevelMatlabFactory"
);
35
validParamList->set<std::string>(
"Needs Fine"
,
""
,
"A comma-separated list of objects needed on the fine level by the TwoLevelMatlabFactory"
);
36
validParamList->set<std::string>(
"Needs Coarse"
,
""
,
"A comma-separated list of objects needed on the coarse level by the TwoLevelMatlabFactory"
);
37
validParamList->set<std::string>(
"Function"
,
""
,
"The name of the Matlab MEX function to call for Build()"
);
38
return
validParamList;
39
}
40
41
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
42
void
TwoLevelMatlabFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::DeclareInput
(
Level
& fineLevel,
Level
& coarseLevel)
const
{
43
using namespace
std;
44
const
Teuchos::ParameterList& pL =
GetParameterList
();
45
// Get needs strings
46
const
std::string str_nf = pL.get<std::string>(
"Needs Fine"
);
47
const
std::string str_nc = pL.get<std::string>(
"Needs Coarse"
);
48
needsFine_
=
tokenizeList
(str_nf);
49
needsCoarse_
=
tokenizeList
(str_nc);
50
for
(
auto
fineNeed :
needsFine_
) {
51
if
(!
IsParamMuemexVariable
(fineNeed) && fineNeed !=
"Level"
)
52
this->
Input
(fineLevel, fineNeed);
53
}
54
for
(
auto
coarseNeed :
needsCoarse_
) {
55
if
(!
IsParamMuemexVariable
(coarseNeed) && coarseNeed !=
"Level"
)
56
this->
Input
(coarseLevel, coarseNeed);
57
}
58
hasDeclaredInput_
=
true
;
59
}
60
61
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
62
void
TwoLevelMatlabFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build
(
Level
& fineLevel,
Level
& coarseLevel)
const
{
63
FactoryMonitor
m(*
this
,
"Build"
, coarseLevel);
64
65
const
Teuchos::ParameterList& pL =
GetParameterList
();
66
using
Teuchos::rcp;
67
using
Teuchos::RCP;
68
using namespace
std;
69
string
needsFine = pL.get<
string
>(
"Needs Fine"
);
70
string
needsCoarse = pL.get<
string
>(
"Needs Coarse"
);
71
vector<RCP<MuemexArg>> InputArgs =
processNeeds<Scalar, LocalOrdinal, GlobalOrdinal, Node>
(
this
, needsFine, fineLevel);
72
vector<RCP<MuemexArg>> InputArgsCoarse =
processNeeds<Scalar, LocalOrdinal, GlobalOrdinal, Node>
(
this
, needsCoarse, coarseLevel);
73
// Add coarse args to the end of InputArgs
74
InputArgs.reserve(InputArgs.size() + InputArgsCoarse.size());
75
InputArgs.insert(InputArgs.begin(), InputArgsCoarse.begin(), InputArgsCoarse.end());
76
77
// Determine output
78
string
provides = pL.get<
string
>(
"Provides"
);
79
size_t
numProvides =
tokenizeList
(provides).size();
80
// Call mex function
81
string
matlabFunction = pL.get<
string
>(
"Function"
);
82
if
(!matlabFunction.length())
83
throw
runtime_error(
"Invalid matlab function name"
);
84
vector<RCP<MuemexArg>> mexOutput =
callMatlab
(matlabFunction, numProvides, InputArgs);
85
processProvides<Scalar, LocalOrdinal, GlobalOrdinal, Node>
(mexOutput,
this
, provides, coarseLevel);
86
}
87
88
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
89
std::string
TwoLevelMatlabFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::description
()
const
{
90
std::ostringstream out;
91
const
Teuchos::ParameterList& pL =
GetParameterList
();
92
out <<
"TwoLevelMatlabFactory["
<< pL.get<std::string>(
"Function"
) <<
"]"
;
93
return
out.str();
94
}
95
96
}
// namespace MueLu
97
98
#endif
// HAVE_MUELU_MATLAB
99
100
#endif
// MUELU_TWOLEVELMATLABFACTORY_DEF_HPP
MueLu_MatlabUtils_decl.hpp
MueLu_Monitor.hpp
MueLu_TwoLevelMatlabFactory_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::TwoLevelMatlabFactory::description
std::string description() const
@ name Description
Definition
MueLu_TwoLevelMatlabFactory_def.hpp:89
MueLu::TwoLevelMatlabFactory::needsCoarse_
std::vector< std::string > needsCoarse_
List of arguments to the MATLAB function, in order. These args must correspond to MueLu "Needs" objec...
Definition
MueLu_TwoLevelMatlabFactory_decl.hpp:86
MueLu::TwoLevelMatlabFactory::GetValidParameterList
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Definition
MueLu_TwoLevelMatlabFactory_def.hpp:32
MueLu::TwoLevelMatlabFactory::hasDeclaredInput_
bool hasDeclaredInput_
Definition
MueLu_TwoLevelMatlabFactory_decl.hpp:76
MueLu::TwoLevelMatlabFactory::TwoLevelMatlabFactory
TwoLevelMatlabFactory()
Definition
MueLu_TwoLevelMatlabFactory_def.hpp:28
MueLu::TwoLevelMatlabFactory::Build
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
Definition
MueLu_TwoLevelMatlabFactory_def.hpp:62
MueLu::TwoLevelMatlabFactory::needsFine_
std::vector< std::string > needsFine_
List of arguments to the MATLAB function, in order. These args must correspond to MueLu "Needs" objec...
Definition
MueLu_TwoLevelMatlabFactory_decl.hpp:83
MueLu::TwoLevelMatlabFactory::DeclareInput
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
Definition
MueLu_TwoLevelMatlabFactory_def.hpp:42
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_TwoLevelMatlabFactory_def.hpp
Generated by
1.17.0