Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-------------------
Expand Down
1 change: 1 addition & 0 deletions cherab/core/math/integrators/__init__.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
# under the Licence.

from cherab.core.math.integrators.integrators1d cimport Integrator1D, GaussianQuadrature
from cherab.core.math.integrators.integrators2d cimport Integrator2D

1 change: 1 addition & 0 deletions cherab/core/math/integrators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
# under the Licence.

from .integrators1d import Integrator1D, GaussianQuadrature
from .integrators2d import Integrator2D
27 changes: 27 additions & 0 deletions cherab/core/math/integrators/integrators2d.pxd
Original file line number Diff line number Diff line change
@@ -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
61 changes: 61 additions & 0 deletions cherab/core/math/integrators/integrators2d.pyx
Original file line number Diff line number Diff line change
@@ -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)
Loading