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
41
42using namespace Nektar;
43
44/**
45 * @brief EquationSystem wrapper to handle virtual function calls in @c
46 * EquationSystem and its subclasses.
47 */
48template <class T> struct EquationSystemWrap : public T, public py::wrapper<T>
49{
50 /**
51 * @brief Constructor, which is identical to Filter.
52 *
53 * @param field Input field.
54 */
57 : T(session, graph), py::wrapper<T>()
58 {
59 }
60
61 void v_InitObject(bool declareField) override
62 {
63 if (py::override f = this->get_override("InitObject")(declareField))
64 {
65 f();
66 }
67 else
68 {
69 T::v_InitObject();
70 }
71 }
72
73 void Default_v_InitObject(bool declareField)
74 {
75 return this->T::v_InitObject(declareField);
76 }
77
78 void v_DoInitialise(bool dumpInitialConditions) override
79 {
80 if (py::override f = this->get_override("DoInitialise"))
81 {
82 f(dumpInitialConditions);
83 }
84 else
85 {
86 T::v_DoInitialise(dumpInitialConditions);
87 }
88 }
89
90 void Default_v_DoInitialise(bool dumpInitialConditions)
91 {
92 this->T::v_DoInitialise(dumpInitialConditions);
93 }
94
95 void v_DoSolve() override
96 {
97 if (py::override f = this->get_override("DoSolve"))
98 {
99 f();
100 }
101 else
102 {
103 T::v_DoSolve();
104 }
105 }
106
108 {
109 this->T::v_DoSolve();
110 }
111
113 bool dumpInitialConditions,
114 const int domain) override
115 {
116 if (py::override f = this->get_override("SetInitialConditions"))
117 {
118 f(initialtime, dumpInitialConditions, domain);
119 }
120 else
121 {
122 T::v_SetInitialConditions(initialtime, dumpInitialConditions,
123 domain);
124 }
125 }
126
128 bool dumpInitialConditions,
129 const int domain)
130 {
131 this->T::v_SetInitialConditions(initialtime, dumpInitialConditions,
132 domain);
133 }
134
136 const NekDouble time)
137 {
138 if (py::override f = this->get_override("EvaluateExactSolution"))
139 {
140 py::object tmpPy = f(field, time);
142 py::extract<Array<OneD, NekDouble>>(tmpPy);
143 return tmp;
144 }
145 else
146 {
147 Array<OneD, NekDouble> outfield(
148 this->m_fields[field]->GetNpoints());
149 T::v_EvaluateExactSolution(field, outfield, time);
150 return outfield;
151 }
152 }
153
155 const NekDouble time)
156 {
157 Array<OneD, NekDouble> outfield(this->m_fields[field]->GetNpoints());
158 this->T::v_EvaluateExactSolution(field, outfield, time);
159 return outfield;
160 }
161
163 {
164 if (py::override f = this->get_override("LinfError"))
165 {
166 return f(field);
167 }
168
169 return T::v_LinfError(field);
170 }
171
173 {
174 return this->T::v_LinfError(field);
175 }
176
178 {
179 if (py::override f = this->get_override("L2Error"))
180 {
181 return f(field);
182 }
183
184 return T::v_L2Error(field);
185 }
186
188 {
189 return this->T::v_L2Error(field);
190 }
191};
192
193#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.
void v_DoSolve() override
Array< OneD, NekDouble > v_EvaluateExactSolution(unsigned int field, const NekDouble time)
EquationSystemWrap(LibUtilities::SessionReaderSharedPtr session, SpatialDomains::MeshGraphSharedPtr graph)
Constructor, which is identical to Filter.
NekDouble v_L2Error(unsigned int field)
Array< OneD, NekDouble > Default_v_EvaluateExactSolution(unsigned int field, const NekDouble time)
void v_DoInitialise(bool dumpInitialConditions) override
void Default_v_SetInitialConditions(NekDouble initialtime, bool dumpInitialConditions, const int domain)
NekDouble Default_v_LinfError(unsigned int field)
void v_SetInitialConditions(NekDouble initialtime, bool dumpInitialConditions, const int domain) override
NekDouble Default_v_L2Error(unsigned int field)
NekDouble v_LinfError(unsigned int field)
void v_InitObject(bool declareField) override
void Default_v_InitObject(bool declareField)
void Default_v_DoInitialise(bool dumpInitialConditions)