diff --git a/CHANGELOG.md b/CHANGELOG.md index 36ef451f..6317375d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Release 1.6.0 (TBD) New: * Add e_field attribute to Plasma object for electric field vector. (#465) - +* Add Integrator2D base class for integration of two-dimensional functions. (#472) Release 1.5.0 (27 Aug 2024) ------------------- diff --git a/cherab/core/math/integrators/__init__.pxd b/cherab/core/math/integrators/__init__.pxd index db06ef43..c4eff464 100644 --- a/cherab/core/math/integrators/__init__.pxd +++ b/cherab/core/math/integrators/__init__.pxd @@ -17,4 +17,5 @@ # under the Licence. from cherab.core.math.integrators.integrators1d cimport Integrator1D, GaussianQuadrature +from cherab.core.math.integrators.integrators2d cimport Integrator2D diff --git a/cherab/core/math/integrators/__init__.py b/cherab/core/math/integrators/__init__.py index 86b7d58d..b1fa4516 100644 --- a/cherab/core/math/integrators/__init__.py +++ b/cherab/core/math/integrators/__init__.py @@ -17,3 +17,4 @@ # under the Licence. from .integrators1d import Integrator1D, GaussianQuadrature +from .integrators2d import Integrator2D diff --git a/cherab/core/math/integrators/integrators2d.pxd b/cherab/core/math/integrators/integrators2d.pxd new file mode 100644 index 00000000..62ba8667 --- /dev/null +++ b/cherab/core/math/integrators/integrators2d.pxd @@ -0,0 +1,27 @@ +# Copyright 2016-2025 Euratom +# Copyright 2016-2025 United Kingdom Atomic Energy Authority +# Copyright 2016-2025 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# +# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the +# European Commission - subsequent versions of the EUPL (the "Licence"); +# You may not use this work except in compliance with the Licence. +# You may obtain a copy of the Licence at: +# +# https://joinup.ec.europa.eu/software/page/eupl5 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. +# +# See the Licence for the specific language governing permissions and limitations +# under the Licence. + +from raysect.core.math.function.float cimport Function1D, Function2D + + +cdef class Integrator2D: + + cdef: + Function2D function + + cdef double evaluate(self,double x_lower, double x_upper, Function1D y_lower, Function1D y_upper) except? -1e999 diff --git a/cherab/core/math/integrators/integrators2d.pyx b/cherab/core/math/integrators/integrators2d.pyx new file mode 100644 index 00000000..58627afe --- /dev/null +++ b/cherab/core/math/integrators/integrators2d.pyx @@ -0,0 +1,61 @@ +# cython: language_level=3 + +# Copyright 2016-2025 Euratom +# Copyright 2016-2025 United Kingdom Atomic Energy Authority +# Copyright 2016-2025 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas +# +# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the +# European Commission - subsequent versions of the EUPL (the "Licence"); +# You may not use this work except in compliance with the Licence. +# You may obtain a copy of the Licence at: +# +# https://joinup.ec.europa.eu/software/page/eupl5 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. +# +# See the Licence for the specific language governing permissions and limitations +# under the Licence. + +from raysect.core.math.function.float cimport Function1D, autowrap_function2d + + +cdef class Integrator2D: + """ + Compute a definite integral of a two-dimensional function. + + :ivar Function2D integrand: A 2D function to integrate. + """ + + @property + def integrand(self): + """ + A 2D function to integrate. + + :rtype: int + """ + return self.function + + @integrand.setter + def integrand(self, object func not None): + + self.function = autowrap_function2d(func) + + cdef double evaluate(self, double x_lower, double x_upper, Function1D y_lower, Function1D y_upper) except? -1e999: + + raise NotImplementedError("The evaluate() method has not been implemented.") + + def __call__(self, double x_lower, double x_upper, Function1D y_lower, Function1D y_upper): + """ + Integrates a two-dimensional function over a finite interval. + + :param double x_lower: Lower limit of integration in the x dimension. + :param double x_upper: Upper limit of integration in the x dimension. + :param Function1D y_lower: Lower limit of integration in the y dimension. + :param Function1D y_upper: Upper limit of integration in the y dimension. + + :returns: Definite integral of a two-dimensional function. + """ + + return self.evaluate(x_lower, x_upper, y_lower, y_upper)