|
| 1 | +# cython: language_level=3 |
| 2 | + |
| 3 | +# Copyright 2016-2025 Euratom |
| 4 | +# Copyright 2016-2025 United Kingdom Atomic Energy Authority |
| 5 | +# Copyright 2016-2025 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas |
| 6 | +# |
| 7 | +# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the |
| 8 | +# European Commission - subsequent versions of the EUPL (the "Licence"); |
| 9 | +# You may not use this work except in compliance with the Licence. |
| 10 | +# You may obtain a copy of the Licence at: |
| 11 | +# |
| 12 | +# https://joinup.ec.europa.eu/software/page/eupl5 |
| 13 | +# |
| 14 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 15 | +# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR |
| 16 | +# CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +# |
| 18 | +# See the Licence for the specific language governing permissions and limitations |
| 19 | +# under the Licence. |
| 20 | + |
| 21 | +from raysect.core.math.function.float cimport Function1D, autowrap_function2d |
| 22 | + |
| 23 | + |
| 24 | +cdef class Integrator2D: |
| 25 | + """ |
| 26 | + Compute a definite integral of a two-dimensional function. |
| 27 | +
|
| 28 | + :ivar Function2D integrand: A 2D function to integrate. |
| 29 | + """ |
| 30 | + |
| 31 | + @property |
| 32 | + def integrand(self): |
| 33 | + """ |
| 34 | + A 2D function to integrate. |
| 35 | +
|
| 36 | + :rtype: int |
| 37 | + """ |
| 38 | + return self.function |
| 39 | + |
| 40 | + @integrand.setter |
| 41 | + def integrand(self, object func not None): |
| 42 | + |
| 43 | + self.function = autowrap_function2d(func) |
| 44 | + |
| 45 | + cdef double evaluate(self, double x_lower, double x_upper, Function1D y_lower, Function1D y_upper) except? -1e999: |
| 46 | + |
| 47 | + raise NotImplementedError("The evaluate() method has not been implemented.") |
| 48 | + |
| 49 | + def __call__(self, double x_lower, double x_upper, Function1D y_lower, Function1D y_upper): |
| 50 | + """ |
| 51 | + Integrates a two-dimensional function over a finite interval. |
| 52 | +
|
| 53 | + :param double x_lower: Lower limit of integration in the x dimension. |
| 54 | + :param double x_upper: Upper limit of integration in the x dimension. |
| 55 | + :param Function1D y_lower: Lower limit of integration in the y dimension. |
| 56 | + :param Function1D y_upper: Upper limit of integration in the y dimension. |
| 57 | +
|
| 58 | + :returns: Definite integral of a two-dimensional function. |
| 59 | + """ |
| 60 | + |
| 61 | + return self.evaluate(x_lower, x_upper, y_lower, y_upper) |
0 commit comments