Skip to content

Commit

Permalink
Merge pull request #421 from Mateasek/fix/laser_material_update
Browse files Browse the repository at this point in the history
Fix update bug of LaserMaterial
  • Loading branch information
jacklovell authored Nov 30, 2023
2 parents 17cb93f + 7c987a5 commit 0e6a150
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ New:
* Add CylindricalTransform and VectorCylindricalTransform to transform functions from cylindrical to Cartesian coordinates. (#387)
* Add the kind attribute to RayTransferPipelineXD that determines whether the ray transfer matrix is multiplied by sensitivity ('power') or not ('radiance'). (#412)

Bug fixes:
* Fix deprecated transforms being cached in LaserMaterial after laser.transform update (#420)

Release 1.4.0 (3 Feb 2023)
-------------------
Expand Down
6 changes: 5 additions & 1 deletion cherab/core/laser/material.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the Licence.


from raysect.core.scenegraph._nodebase cimport _NodeBase
from raysect.core cimport Primitive
from raysect.core.math cimport AffineMatrix3D
from raysect.optical.material.emitter cimport InhomogeneousVolumeEmitter

Expand All @@ -28,4 +28,8 @@ cdef class LaserMaterial(InhomogeneousVolumeEmitter):

cdef:
AffineMatrix3D _laser_to_plasma, _laser_segment_to_laser_node
Primitive _primitive
Laser _laser
list _models

cdef void _cache_transforms(self)
26 changes: 21 additions & 5 deletions cherab/core/laser/material.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the Licence.


from raysect.core.scenegraph._nodebase cimport _NodeBase
from raysect.core cimport Primitive
from raysect.optical cimport World, Primitive, Ray, Spectrum, Point3D, Vector3D, AffineMatrix3D
from raysect.optical.material.emitter cimport InhomogeneousVolumeEmitter
from raysect.optical.material.emitter.inhomogeneous cimport VolumeIntegrator
Expand All @@ -28,12 +28,12 @@ from cherab.core.laser.model cimport LaserModel

cdef class LaserMaterial(InhomogeneousVolumeEmitter):

def __init__(self, Laser laser not None, _NodeBase laser_segment not None, list models, VolumeIntegrator integrator not None):
def __init__(self, Laser laser not None, Primitive laser_segment not None, list models, VolumeIntegrator integrator not None):

super().__init__(integrator)

self._laser_segment_to_laser_node = laser_segment.to(laser)
self._laser_to_plasma = laser_segment.to(laser.plasma)
self._laser = laser
self._primitive = laser_segment
self.importance = laser.importance

#validate and set models
Expand All @@ -54,6 +54,10 @@ cdef class LaserMaterial(InhomogeneousVolumeEmitter):
Point3D point_plasma, point_laser
Vector3D direction_plasma, direction_laser
LaserModel model

# cache the important transforms
if self._laser_segment_to_laser_node is None or self._laser_to_plasma is None:
self._cache_transforms()

point_laser = point.transform(self._laser_segment_to_laser_node)
direction_laser = direction.transform(self._laser_segment_to_laser_node) # observation vector in the laser frame
Expand All @@ -63,4 +67,16 @@ cdef class LaserMaterial(InhomogeneousVolumeEmitter):
for model in self._models:
spectrum = model.emission(point_plasma, direction_plasma, point_laser, direction_laser, spectrum)

return spectrum
return spectrum

cdef void _cache_transforms(self):
"""
cache transforms from laser primitive to laser and plasma
"""

# if transforms are cached, the material should be used only for one primitive for safety
if not len(self.primitives) == 1:
raise ValueError("LaserMaterial must be attached to exactly one primitive.")

self._laser_segment_to_laser_node = self._primitive.to(self._laser)
self._laser_to_plasma = self._primitive.to(self._laser.get_plasma())
4 changes: 3 additions & 1 deletion cherab/core/laser/node.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ cdef class Laser(Node):
list _geometry
VolumeIntegrator _integrator

cdef object __weakref__
cdef object __weakref__

cdef Plasma get_plasma(self)
6 changes: 6 additions & 0 deletions cherab/core/laser/node.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ cdef class Laser(Node):
self._plasma.notifier.add(self._plasma_changed)

self._configure_materials()

cdef Plasma get_plasma(self):
"""
Fast method to obtain laser's plasma reference.
"""
return self._plasma

@property
def importance(self):
Expand Down

0 comments on commit 0e6a150

Please sign in to comment.