Nektar++
Classes | Functions
Python/Filter.cpp File Reference
#include <LibUtilities/Python/BasicUtils/NekFactory.hpp>
#include <LibUtilities/Python/NekPyConfig.hpp>
#include <SolverUtils/Filters/Filter.h>

Go to the source code of this file.

Classes

struct  FilterWrap
 Filter wrapper to handle virtual function calls in Filter and its subclasses. More...
 

Functions

FilterSharedPtr Filter_Create (py::tuple args, py::dict kwargs)
 Lightweight wrapper for Filter factory creation function. More...
 
void Filter_Initialise (std::shared_ptr< Filter > filter, Array< OneD, MultiRegions::ExpListSharedPtr > expLists, NekDouble time)
 
void Filter_Update (std::shared_ptr< Filter > filter, Array< OneD, MultiRegions::ExpListSharedPtr > expLists, NekDouble time)
 
void Filter_Finalise (std::shared_ptr< Filter > filter, Array< OneD, MultiRegions::ExpListSharedPtr > expLists, NekDouble time)
 
bool Filter_IsTimeDependent (std::shared_ptr< Filter > filter)
 
void export_Filter ()
 

Function Documentation

◆ export_Filter()

void export_Filter ( )

Definition at line 176 of file Python/Filter.cpp.

177{
179
180 // Define FilterWrap to be implicitly convertible to a Filter, since it
181 // seems that doesn't sometimes get picked up.
182 py::implicitly_convertible<std::shared_ptr<FilterWrap>,
183 std::shared_ptr<Filter>>();
184
185 // Wrapper for the Filter class. Note that since Filter contains a pure
186 // virtual function, we need the FilterWrap helper class to handle this for
187 // us. In the lightweight wrappers above, we therefore need to ensure we're
188 // passing std::shared_ptr<Filter> as the first argument, otherwise they
189 // won't accept objects constructed from Python.
190 py::class_<FilterWrap, std::shared_ptr<FilterWrap>, boost::noncopyable>(
191 "Filter", py::init<LibUtilities::SessionReaderSharedPtr,
193
194 .def("Initialise", &Filter_Initialise)
195 .def("Update", &Filter_Update)
196 .def("Finalise", &Filter_Finalise)
197 .def("IsTimeDependent", &Filter_IsTimeDependent)
198
199 // Factory functions.
200 .def("Create", py::raw_function(Filter_Create))
201 .staticmethod("Create")
202 .def("Register", [](std::string const &filterName,
203 py::object &obj) { fac(filterName, obj); })
204 .staticmethod("Register");
205
207}
FilterSharedPtr Filter_Create(py::tuple args, py::dict kwargs)
Lightweight wrapper for Filter factory creation function.
bool Filter_IsTimeDependent(std::shared_ptr< Filter > filter)
void Filter_Finalise(std::shared_ptr< Filter > filter, Array< OneD, MultiRegions::ExpListSharedPtr > expLists, NekDouble time)
void Filter_Initialise(std::shared_ptr< Filter > filter, Array< OneD, MultiRegions::ExpListSharedPtr > expLists, NekDouble time)
void Filter_Update(std::shared_ptr< Filter > filter, Array< OneD, MultiRegions::ExpListSharedPtr > expLists, NekDouble time)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< EquationSystem > EquationSystemSharedPtr
A shared pointer to an EquationSystem object.
FilterFactory & GetFilterFactory()
A helper class that for factory-based classes allows std::shared_ptr<T> as something that boost::pyth...

References Filter_Create(), Filter_Finalise(), Filter_Initialise(), Filter_IsTimeDependent(), Filter_Update(), and Nektar::SolverUtils::GetFilterFactory().

Referenced by BOOST_PYTHON_MODULE().

◆ Filter_Create()

FilterSharedPtr Filter_Create ( py::tuple  args,
py::dict  kwargs 
)

Lightweight wrapper for Filter factory creation function.

Definition at line 103 of file Python/Filter.cpp.

104{
106
107 if (py::len(args) != 3)
108 {
109 throw NekError("Filter.Create() requires three arguments: "
110 "filter name, a SessionReader object and an "
111 "EquationSystem object.");
112 }
113
114 std::string filterName = py::extract<std::string>(args[0]);
115
116 if (!py::extract<LibUtilities::SessionReaderSharedPtr>(args[1]).check())
117 {
118 throw NekError("Second argument to Create() should be a SessionReader "
119 "object.");
120 }
121
122 if (!py::extract<EquationSystemSharedPtr>(args[2]).check())
123 {
124 throw NekError("Second argument to Create() should be a EquationSystem "
125 "object.");
126 }
127
129 py::extract<LibUtilities::SessionReaderSharedPtr>(args[1]);
130 EquationSystemSharedPtr eqn = py::extract<EquationSystemSharedPtr>(args[2]);
131
132 // Process keyword arguments.
133 py::list items = kwargs.items();
134 Filter::ParamMap params;
135
136 for (int i = 0; i < py::len(items); ++i)
137 {
138 std::string arg = py::extract<std::string>(items[i][0]);
139 std::string val =
140 py::extract<std::string>(items[i][1].attr("__str__")());
141 params[arg] = val;
142 }
143
144 std::shared_ptr<Filter> filter =
145 GetFilterFactory().CreateInstance(filterName, session, eqn, params);
146
147 return filter;
148}
Nektar::ErrorUtil::NekError NekError
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
std::map< std::string, std::string > ParamMap
Definition: Filter.h:65

References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), and Nektar::SolverUtils::GetFilterFactory().

Referenced by export_Filter().

◆ Filter_Finalise()

void Filter_Finalise ( std::shared_ptr< Filter filter,
Array< OneD, MultiRegions::ExpListSharedPtr expLists,
NekDouble  time 
)

Definition at line 164 of file Python/Filter.cpp.

167{
168 filter->Finalise(expLists, time);
169}

Referenced by export_Filter().

◆ Filter_Initialise()

void Filter_Initialise ( std::shared_ptr< Filter filter,
Array< OneD, MultiRegions::ExpListSharedPtr expLists,
NekDouble  time 
)

Definition at line 150 of file Python/Filter.cpp.

153{
154 filter->Initialise(expLists, time);
155}

Referenced by export_Filter().

◆ Filter_IsTimeDependent()

bool Filter_IsTimeDependent ( std::shared_ptr< Filter filter)

Definition at line 171 of file Python/Filter.cpp.

172{
173 return filter->IsTimeDependent();
174}

Referenced by export_Filter().

◆ Filter_Update()

void Filter_Update ( std::shared_ptr< Filter filter,
Array< OneD, MultiRegions::ExpListSharedPtr expLists,
NekDouble  time 
)

Definition at line 157 of file Python/Filter.cpp.

160{
161 filter->Update(expLists, time);
162}

Referenced by export_Filter().