Nektar++
Python/EquationSystem.h
Go to the documentation of this file.
1//////////////////////////////////////////////////////////////////////////////
2//
3// File: EquationSystem.h
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 EquationSystem.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_LIBRARY_SOLVERUTILS_PYTHON_EQUATIONSYSTEM_H
36#define NEKTAR_LIBRARY_SOLVERUTILS_PYTHON_EQUATIONSYSTEM_H
37
42
43using namespace Nektar;
44using namespace Nektar::SolverUtils;
45
46/**
47 * @brief EquationSystem wrapper to handle virtual function calls in @c
48 * EquationSystem and its subclasses.
49 */
50#pragma GCC visibility push(hidden)
51template <typename T>
52struct EquationSystemWrap : public T, public py::trampoline_self_life_support
53{
54 /**
55 * @brief Constructor, which is identical to Filter.
56 *
57 * @param field Input field.
58 */
61 : T(session, graph)
62 {
63 }
64
65 void v_InitObject(bool declareField) override
66 {
67 PYBIND11_OVERRIDE_NAME(void, T, "InitObject", v_InitObject,
68 declareField);
69 }
70
71 void v_DoInitialise(bool dumpInitialConditions) override
72 {
73 PYBIND11_OVERRIDE_NAME(void, T, "DoInitialize", v_DoInitialise,
74 dumpInitialConditions);
75 }
76
77 void v_DoSolve() override
78 {
79 PYBIND11_OVERRIDE_NAME(void, T, "DoSolve", v_DoSolve, );
80 }
81
83 bool dumpInitialConditions,
84 const int domain) override
85 {
86 PYBIND11_OVERRIDE_NAME(void, T, "SetInitialConditions",
87 v_SetInitialConditions, initialtime,
88 dumpInitialConditions, domain);
89 }
90
92 std::shared_ptr<EquationSystemWrap> eqsys, unsigned int field,
93 const NekDouble time)
94 {
95 py::gil_scoped_acquire gil;
96 py::function override =
97 py::get_override(eqsys.get(), "EvaluateExactSolution");
98
99 if (override)
100 {
101 auto obj = override(field, time);
102 return py::cast<Array<OneD, NekDouble>>(obj);
103 }
104
105 Array<OneD, NekDouble> outfield(
106 eqsys->UpdateFields()[field]->GetNpoints());
107 eqsys->EquationSystemWrap<T>::v_EvaluateExactSolution(field, outfield,
108 time);
109 return outfield;
110 }
111
112 static NekDouble LinfError(std::shared_ptr<EquationSystemWrap> eqsys,
113 unsigned int field)
114 {
115 py::gil_scoped_acquire gil;
116 py::function override = py::get_override(eqsys.get(), "LinfError");
117
118 if (override)
119 {
120 return py::cast<NekDouble>(override(field));
121 }
122
123 return eqsys->EquationSystemWrap<T>::v_LinfError(field);
124 }
125
126 static NekDouble L2Error(std::shared_ptr<EquationSystemWrap> eqsys,
127 unsigned int field)
128 {
129 py::gil_scoped_acquire gil;
130 py::function override = py::get_override(eqsys.get(), "L2Error");
131
132 if (override)
133 {
134 return py::cast<NekDouble>(override(field));
135 }
136
137 return eqsys->EquationSystemWrap<T>::v_L2Error(field);
138 }
139
140 using T::v_EvaluateExactSolution;
141 using T::v_L2Error;
142 using T::v_LinfError;
143};
144#pragma GCC visibility pop
145
146template <class T> struct EquationSystemPublic : public T
147{
148public:
149 using T::v_DoInitialise;
150 using T::v_DoSolve;
151 using T::v_EvaluateExactSolution;
152 using T::v_InitObject;
153 using T::v_SetInitialConditions;
154};
155
156#endif
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
double NekDouble
EquationSystem wrapper to handle virtual function calls in EquationSystem and its subclasses.
static NekDouble L2Error(std::shared_ptr< EquationSystemWrap > eqsys, unsigned int field)
void v_DoSolve() override
EquationSystemWrap(LibUtilities::SessionReaderSharedPtr session, SpatialDomains::MeshGraphSharedPtr graph)
Constructor, which is identical to Filter.
static Array< OneD, NekDouble > EvaluateExactSolution(std::shared_ptr< EquationSystemWrap > eqsys, unsigned int field, const NekDouble time)
void v_DoInitialise(bool dumpInitialConditions) override
static NekDouble LinfError(std::shared_ptr< EquationSystemWrap > eqsys, unsigned int field)
void v_SetInitialConditions(NekDouble initialtime, bool dumpInitialConditions, const int domain) override
void v_InitObject(bool declareField) override