MueLu Version of the Day
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"
20
21#ifdef HAVE_MUELU_MATLAB
22
23namespace MueLu {
24
25template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
28
29template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
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
38template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
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
50template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
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
71template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
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
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
std::string description() const
@ name Description
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
void Build(Level &currentLevel) const
Build an object with this factory.
Namespace for MueLu classes and methods.
bool IsParamMuemexVariable(const std::string &name)
Teuchos::RCP< Teuchos::ParameterList > getInputParamList()
std::vector< RCP< MuemexArg > > callMatlab(std::string function, int numOutputs, std::vector< RCP< MuemexArg > > args)
std::vector< std::string > tokenizeList(const std::string &params)