Nektar++
Python/SessionFunction.cpp
Go to the documentation of this file.
1//////////////////////////////////////////////////////////////////////////////
2//
3// File: SessionFunction.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Python wrapper for SessionFunction.
32//
33///////////////////////////////////////////////////////////////////////////////
34
39
40using namespace Nektar;
41using namespace Nektar::SolverUtils;
42
43std::shared_ptr<SessionFunction> SessionFunction_Init(
45 const MultiRegions::ExpListSharedPtr field, std::string functionName)
46{
48 functionName);
49}
50
51std::string SessionFunction_Describe(std::shared_ptr<SessionFunction> func,
52 std::string fieldName)
53{
54 return func->Describe(fieldName);
55}
56
58 std::shared_ptr<SessionFunction> func, std::vector<std::string> fieldNames,
60{
61 func->Evaluate(fieldNames, explists, time);
62 return explists;
63}
64
66 std::shared_ptr<SessionFunction> func, py::list fieldNames,
68{
69 std::vector<std::string> fields(py::len(fieldNames));
70
71 for (std::size_t i = 0; i < py::len(fieldNames); ++i)
72 {
73 fields[i] = py::cast<std::string>(fieldNames[i]);
74 }
75
76 if (explists.size() == 0)
77 {
78 throw new ErrorUtil::NekError("List of fields is empty");
79 }
80
81 // Check first entry in list to guess which version of this function needs
82 // to be called.
83 return SessionFunction_Evaluate_ExpList(func, fields, explists, time);
84}
85
87 std::shared_ptr<SessionFunction> func, py::list fieldNames,
89{
90 return SessionFunction_Evaluate(func, fieldNames, explists, 0.0);
91}
92
93void export_SessionFunction(py::module &m)
94{
95 py::class_<SessionFunction, std::shared_ptr<SessionFunction>>(
96 m, "SessionFunction")
97 .def(py::init<>(&SessionFunction_Init))
98 .def("Describe", &SessionFunction_Describe)
99 .def("Evaluate", &SessionFunction_Evaluate)
100 .def("Evaluate", &SessionFunction_Evaluate1);
101}
Nektar::ErrorUtil::NekError NekError
std::string SessionFunction_Describe(std::shared_ptr< SessionFunction > func, std::string fieldName)
Array< OneD, MultiRegions::ExpListSharedPtr > SessionFunction_Evaluate1(std::shared_ptr< SessionFunction > func, py::list fieldNames, Array< OneD, MultiRegions::ExpListSharedPtr > explists)
std::shared_ptr< SessionFunction > SessionFunction_Init(const LibUtilities::SessionReaderSharedPtr session, const MultiRegions::ExpListSharedPtr field, std::string functionName)
void export_SessionFunction(py::module &m)
Array< OneD, MultiRegions::ExpListSharedPtr > SessionFunction_Evaluate(std::shared_ptr< SessionFunction > func, py::list fieldNames, Array< OneD, MultiRegions::ExpListSharedPtr > explists, NekDouble time)
Array< OneD, MultiRegions::ExpListSharedPtr > SessionFunction_Evaluate_ExpList(std::shared_ptr< SessionFunction > func, std::vector< std::string > fieldNames, Array< OneD, MultiRegions::ExpListSharedPtr > explists, NekDouble time)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
double NekDouble