Skip to content

Commit

Permalink
Merge branch 'development' into package-demos
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklovell committed Apr 6, 2023
2 parents 55705a1 + 9ae5a3e commit 49861bf
Show file tree
Hide file tree
Showing 19 changed files with 1,127 additions and 38 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Release 1.5.0 (TBD)

New:
* Support Raysect 0.8
* Add PeriodicTransformXD and VectorPeriodicTransformXD functions to support the data simulated with periodic boundary conditions. (#387)
* Add CylindricalTransform and VectorCylindricalTransform to transform functions from cylindrical to Cartesian coordinates. (#387)


Release 1.4.0 (3 Feb 2023)
Expand All @@ -16,7 +18,6 @@ API changes:
* Support for Python 3.6 is dropped. It may still work, but is no longer actively tested.

Bug fixes:
* Fixed generomak plasma edge data paths.
* Fix and improve OpenCL utility functions. (#358)
* Fixed Bremsstrahlung trapezium evaluation (#384).

Expand Down
1 change: 1 addition & 0 deletions cherab/core/math/__init__.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ from cherab.core.math.clamp cimport *
from cherab.core.math.mappers cimport *
from cherab.core.math.mask cimport *
from cherab.core.math.slice cimport *
from cherab.core.math.transform cimport *
13 changes: 9 additions & 4 deletions cherab/core/math/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2016-2018 Euratom
# Copyright 2016-2018 United Kingdom Atomic Energy Authority
# Copyright 2016-2018 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas
# Copyright 2016-2022 Euratom
# Copyright 2016-2022 United Kingdom Atomic Energy Authority
# Copyright 2016-2022 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");
Expand Down Expand Up @@ -31,6 +31,11 @@
from .caching import Caching1D, Caching2D, Caching3D
from .clamp import ClampOutput1D, ClampOutput2D, ClampOutput3D
from .clamp import ClampInput1D, ClampInput2D, ClampInput3D
from .mappers import IsoMapper2D, IsoMapper3D, Swizzle2D, Swizzle3D, AxisymmetricMapper, VectorAxisymmetricMapper
from .mappers import IsoMapper2D, IsoMapper3D
from .mappers import Swizzle2D, Swizzle3D
from .mappers import AxisymmetricMapper, VectorAxisymmetricMapper
from .mask import PolygonMask2D
from .slice import Slice2D, Slice3D
from .transform import CylindricalTransform, VectorCylindricalTransform
from .transform import PeriodicTransform1D, PeriodicTransform2D, PeriodicTransform3D
from .transform import VectorPeriodicTransform1D, VectorPeriodicTransform2D, VectorPeriodicTransform3D
23 changes: 6 additions & 17 deletions cherab/core/math/mappers.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2016-2018 Euratom
# Copyright 2016-2018 United Kingdom Atomic Energy Authority
# Copyright 2016-2018 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas
# Copyright 2016-2022 Euratom
# Copyright 2016-2022 United Kingdom Atomic Energy Authority
# Copyright 2016-2022 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");
Expand All @@ -16,8 +16,9 @@
# See the Licence for the specific language governing permissions and limitations
# under the Licence.

from cherab.core.math.function cimport Function1D, Function2D, Function3D, VectorFunction2D, VectorFunction3D
from raysect.core cimport Vector3D
from raysect.core.math.function.float cimport Function1D, Function2D, Function3D
from raysect.core.math.function.vector3d cimport Function2D as VectorFunction2D
from raysect.core.math.function.vector3d cimport Function3D as VectorFunction3D


cdef class IsoMapper2D(Function2D):
Expand All @@ -26,43 +27,31 @@ cdef class IsoMapper2D(Function2D):
readonly Function1D function1d
readonly Function2D function2d

cdef double evaluate(self, double x, double y) except? -1e999


cdef class IsoMapper3D(Function3D):

cdef:
readonly Function3D function3d
readonly Function1D function1d

cdef double evaluate(self, double x, double y, double z) except? -1e999


cdef class Swizzle2D(Function2D):

cdef readonly Function2D function2d

cdef double evaluate(self, double x, double y) except? -1e999


cdef class Swizzle3D(Function3D):

cdef:
readonly Function3D function3d
int shape[3]

cdef double evaluate(self, double x, double y, double z) except? -1e999


cdef class AxisymmetricMapper(Function3D):

cdef readonly Function2D function2d

cdef double evaluate(self, double x, double y, double z) except? -1e999


cdef class VectorAxisymmetricMapper(VectorFunction3D):

cdef readonly VectorFunction2D function2d

cdef Vector3D evaluate(self, double x, double y, double z)
13 changes: 5 additions & 8 deletions cherab/core/math/mappers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

from libc.math cimport sqrt, atan2, M_PI

from cherab.core.math.function cimport autowrap_function1d, autowrap_function2d, autowrap_function3d, autowrap_vectorfunction2d
from raysect.core.math cimport Vector3D
from raysect.core.math.function.float cimport autowrap_function1d, autowrap_function2d, autowrap_function3d
from raysect.core.math.function.vector3d cimport autowrap_function2d as autowrap_vectorfunction2d
from raysect.core cimport rotate_z
cimport cython

Expand Down Expand Up @@ -251,13 +253,10 @@ cdef class AxisymmetricMapper(Function3D):
def __init__(self, object function2d):

if not callable(function2d):
raise TypeError("Function3D is not callable.")
raise TypeError("Function2D is not callable.")

self.function2d = autowrap_function2d(function2d)

def __call__(self, double x, double y, double z):
return self.evaluate(x, y, z)

cdef double evaluate(self, double x, double y, double z) except? -1e999:
"""Return the value of function2d when it is y-axis symmetrically
extended to the 3D space."""
Expand Down Expand Up @@ -299,13 +298,11 @@ cdef class VectorAxisymmetricMapper(VectorFunction3D):

self.function2d = autowrap_vectorfunction2d(vectorfunction2d)

def __call__(self, double x, double y, double z):
return self.evaluate(x, y, z)

@cython.cdivision(True)
cdef Vector3D evaluate(self, double x, double y, double z):
"""Return the value of function2d when it is y-axis symmetrically
extended to the 3D space."""
cdef double r, phi

# convert to cylindrical coordinates
phi = atan2(y, x) / M_PI * 180
Expand Down
24 changes: 20 additions & 4 deletions cherab/core/math/tests/test_mappers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2016-2018 Euratom
# Copyright 2016-2018 United Kingdom Atomic Energy Authority
# Copyright 2016-2018 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas
# Copyright 2016-2022 Euratom
# Copyright 2016-2022 United Kingdom Atomic Energy Authority
# Copyright 2016-2022 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");
Expand All @@ -16,6 +16,7 @@
# See the Licence for the specific language governing permissions and limitations
# under the Licence.

from raysect.core.math import Vector3D
from cherab.core.math import mappers
import numpy as np
import unittest
Expand All @@ -35,6 +36,9 @@ def f2d(x, y): return x*np.sin(y)
def f3d(x, y, z): return x*x*np.exp(y)-2*z*y
self.function3d = f3d

def vecf2d(r, z): return Vector3D(0, r, z)
self.vectorfunction2d = vecf2d


def test_iso_mapper_2d(self):
"""Composition of a 1D and a 2D function."""
Expand Down Expand Up @@ -142,5 +146,17 @@ def test_axisymmetric_mapper_invalid_arg(self):
"""An error must be raised if the given argument is not callable."""
self.assertRaises(TypeError, mappers.AxisymmetricMapper, "blah")

def test_vector_axisymmetric_mapper(self):
"""Vector axisymmetric mapper."""
symm_func = mappers.VectorAxisymmetricMapper(self.vectorfunction2d)
vec1 = symm_func(1., 1., 1.)
vec2 = Vector3D(-1., 1., 1.)
np.testing.assert_almost_equal([vec1.x, vec1.y, vec1.z], [vec2.x, vec2.y, vec2.z], decimal=10)

def test_vector_axisymmetric_mapper_invalid_arg(self):
"""An error must be raised if the given argument is not callable."""
self.assertRaises(TypeError, mappers.VectorAxisymmetricMapper, "blah")


if __name__ == '__main__':
unittest.main()
unittest.main()
Loading

0 comments on commit 49861bf

Please sign in to comment.