Nektar++
Classes | Functions
Python/Filter.cpp File Reference
#include <LibUtilities/Python/BasicUtils/NekFactory.hpp>
#include <LibUtilities/Python/BasicUtils/SharedArray.hpp>
#include <LibUtilities/Python/NekPyConfig.hpp>
#include <MultiRegions/ContField.h>
#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...
 
struct  FilterPublic
 

Functions

FilterSharedPtr Filter_Create (py::args args, const py::kwargs &kwargs)
 Lightweight wrapper for Filter factory creation function. More...
 
void export_Filter (py::module &m)
 

Function Documentation

◆ export_Filter()

void export_Filter ( py::module &  m)

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

159{
161
162 // Wrapper for the Filter class. Note that since Filter contains a pure
163 // virtual function, we need the FilterWrap helper class to handle this for
164 // us. In the lightweight wrappers above, we therefore need to ensure we're
165 // passing std::shared_ptr<Filter> as the first argument, otherwise they
166 // won't accept objects constructed from Python.
167 py::classh<Filter, FilterWrap>(m, "Filter")
170
171 .def("Initialise", &FilterPublic::v_Initialise)
172 .def("Update", &FilterPublic::v_Update)
173 .def("Finalise", &FilterPublic::v_Finalise)
174 .def("IsTimeDependent", &FilterPublic::v_IsTimeDependent)
175
176 // Factory functions.
177 .def_static("Create", &Filter_Create)
178
179 .def_static("Register", [](std::string &filterName, py::object &obj) {
180 fac(filterName, obj, filterName);
181 });
182}
FilterSharedPtr Filter_Create(py::args args, const py::kwargs &kwargs)
Lightweight wrapper for Filter factory creation function.
virtual void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)=0
virtual void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)=0
virtual bool v_IsTimeDependent()=0
virtual void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)=0
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< EquationSystem > EquationSystemSharedPtr
A shared pointer to an EquationSystem object.
FilterFactory & GetFilterFactory()

References Filter_Create(), Nektar::SolverUtils::GetFilterFactory(), Nektar::SolverUtils::Filter::v_Finalise(), Nektar::SolverUtils::Filter::v_Initialise(), Nektar::SolverUtils::Filter::v_IsTimeDependent(), and Nektar::SolverUtils::Filter::v_Update().

Referenced by PYBIND11_MODULE().

◆ Filter_Create()

FilterSharedPtr Filter_Create ( py::args  args,
const py::kwargs &  kwargs 
)

Lightweight wrapper for Filter factory creation function.

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

107{
109
110 if (py::len(args) != 3)
111 {
112 throw NekError("Filter.Create() requires three arguments: "
113 "filter name, a SessionReader object and an "
114 "EquationSystem object.");
115 }
116
117 std::string filterName = py::cast<std::string>(args[0]);
118
121
122 try
123 {
124 session = py::cast<LibUtilities::SessionReaderSharedPtr>(args[1]);
125 }
126 catch (...)
127 {
128 throw NekError("Second argument to Create() should be a SessionReader "
129 "object.");
130 }
131
132 try
133 {
134 eqsys = py::cast<EquationSystemSharedPtr>(args[2]);
135 }
136 catch (...)
137 {
138 throw NekError("Second argument to Create() should be a EquationSystem "
139 "object.");
140 }
141
142 // Process keyword arguments.
143 Filter::ParamMap params;
144
145 for (auto &kwarg : kwargs)
146 {
147 std::string arg = py::cast<std::string>(kwarg.first);
148 std::string val = py::cast<std::string>(py::str(kwarg.second));
149 params[arg] = val;
150 }
151
152 std::shared_ptr<Filter> filter =
153 GetFilterFactory().CreateInstance(filterName, session, eqsys, params);
154
155 return filter;
156}
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:66

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

Referenced by export_Filter().