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
38
39using namespace Nektar;
40using namespace Nektar::SolverUtils;
41
42std::shared_ptr<SessionFunction> SessionFunction_Init(
44 const MultiRegions::ExpListSharedPtr field, std::string functionName)
45{
47 functionName);
48}
49
50std::string SessionFunction_Describe(std::shared_ptr<SessionFunction> func,
51 std::string fieldName)
52{
53 return func->Describe(fieldName);
54}
55
57 std::shared_ptr<SessionFunction> func, std::vector<std::string> fieldNames,
59{
60 func->Evaluate(fieldNames, explists, time);
61 return explists;
62}
63
65 std::shared_ptr<SessionFunction> func, py::list fieldNames,
67{
68 std::vector<std::string> fields(py::len(fieldNames));
69
70 for (std::size_t i = 0; i < py::len(fieldNames); ++i)
71 {
72 fields[i] = py::extract<std::string>(fieldNames[i]);
73 }
74
75 if (explists.size() == 0)
76 {
77 throw new ErrorUtil::NekError("List of fields is empty");
78 }
79
80 // Check first entry in list to guess which version of this function needs
81 // to be called.
82 return SessionFunction_Evaluate_ExpList(func, fields, explists, time);
83}
84
86 std::shared_ptr<SessionFunction> func, py::list fieldNames,
88{
89 return SessionFunction_Evaluate(func, fieldNames, explists, 0.0);
90}
91
93{
94 py::class_<SessionFunction, std::shared_ptr<SessionFunction>,
95 boost::noncopyable>("SessionFunction", py::no_init)
96 .def("__init__", &SessionFunction_Init)
97 .def("Describe", &SessionFunction_Describe)
98 .def("Evaluate", &SessionFunction_Evaluate)
99 .def("Evaluate", &SessionFunction_Evaluate1);
100}
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()
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