Skip to content

Commit 89945ba

Browse files
authored
Merge pull request #473 from Mateasek/feature/integrate2d
Add Integrator2D base class
2 parents 2018dd9 + c6fbe5e commit 89945ba

5 files changed

Lines changed: 91 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Release 1.6.0 (TBD)
66

77
New:
88
* Add e_field attribute to Plasma object for electric field vector. (#465)
9-
9+
* Add Integrator2D base class for integration of two-dimensional functions. (#472)
1010

1111
Release 1.5.0 (27 Aug 2024)
1212
-------------------

cherab/core/math/integrators/__init__.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
# under the Licence.
1818

1919
from cherab.core.math.integrators.integrators1d cimport Integrator1D, GaussianQuadrature
20+
from cherab.core.math.integrators.integrators2d cimport Integrator2D
2021

cherab/core/math/integrators/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
# under the Licence.
1818

1919
from .integrators1d import Integrator1D, GaussianQuadrature
20+
from .integrators2d import Integrator2D
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2016-2025 Euratom
2+
# Copyright 2016-2025 United Kingdom Atomic Energy Authority
3+
# Copyright 2016-2025 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas
4+
#
5+
# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the
6+
# European Commission - subsequent versions of the EUPL (the "Licence");
7+
# You may not use this work except in compliance with the Licence.
8+
# You may obtain a copy of the Licence at:
9+
#
10+
# https://joinup.ec.europa.eu/software/page/eupl5
11+
#
12+
# Unless required by applicable law or agreed to in writing, software distributed
13+
# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR
14+
# CONDITIONS OF ANY KIND, either express or implied.
15+
#
16+
# See the Licence for the specific language governing permissions and limitations
17+
# under the Licence.
18+
19+
from raysect.core.math.function.float cimport Function1D, Function2D
20+
21+
22+
cdef class Integrator2D:
23+
24+
cdef:
25+
Function2D function
26+
27+
cdef double evaluate(self,double x_lower, double x_upper, Function1D y_lower, Function1D y_upper) except? -1e999
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)