def test_contains(self): s = Sphere(radius=1) assert s.contains((0.0, 0.0, 2.0)) == False assert s.contains((0.0, 0.0, 1.0)) == False assert s.contains((0.0, 0.0, 0.0)) == True
from pvtrace.geometry.cylinder import Cylinder from pvtrace.geometry.sphere import Sphere from pvtrace.scene.renderer import MeshcatRenderer from pvtrace.scene.scene import Scene from pvtrace.scene.node import Node from pvtrace.light.light import Light from pvtrace.algorithm import photon_tracer from pvtrace.material.dielectric import Dielectric import numpy as np import functools import sys import time # World node contains the simulation; large sphere filled with air world = Node(name="world (air)", geometry=Sphere(radius=10.0, material=Dielectric.air())) # A small cylinder shape made from glass cylinder = Node(name="cylinder (glass)", geometry=Cylinder(length=1.0, radius=1.0, material=Dielectric.glass()), parent=world) # A light source with 60-deg divergence light = Node(name="light (555nm laser)", light=Light(divergence_delegate=functools.partial( Light.cone_divergence, np.radians(60))), parent=world) light.translate((0.0, 0.0, -1.0))
def test_is_on_surface(self): s = Sphere(radius=1) assert s.is_on_surface((0.0, 0.0, 1.0)) == True assert s.is_on_surface((0.0, 0.0, 0.0)) == False
def test_is_entering_true(self): s = Sphere(radius=1) assert s.is_entering((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0)) == True
def test_is_entering_false(self): s = Sphere(radius=1) assert s.is_entering((-1.0, 0.0, 0.0), (-1.0, 0.0, 0.0)) == False
def test_normal(self): s = Sphere(radius=1) assert np.allclose(s.normal((0.0, 0.0, 1.0)), (0.0, 0.0, 1.0))
def test_intersection(self): s = Sphere(radius=1) ro = (-2.0, 0.0, 0.0) rd = (1.0, 0.0, 0.0) assert s.intersections(ro, rd) == ((-1.0, 0.0, 0.0), (1.0, 0.0, 0.0))
import logging # We want to see pvtrace logging here #logging.getLogger('pvtrace').setLevel(logging.CRITICAL) logging.getLogger('trimesh').setLevel(logging.CRITICAL) logging.getLogger('matplotlib').setLevel(logging.CRITICAL) wavelength_range = (200, 800) wavelength = np.linspace(*wavelength_range, 1000) lumogen = Lumophore.make_lumogen_f_red(wavelength, 1000, 1.0) linear_background = Lumophore.make_linear_background(wavelength, 1.0) # Make a world coordinate system world_node = Node(name='world') world_node.geometry = Sphere( radius=10.0, material=Dielectric.make_constant((300, 1000.0), 1.0) ) refractive_index = np.column_stack( (wavelength, np.ones(wavelength.shape) * 1.5) ) # Add LSC size = (1.0, 1.0, 0.02) lsc = Node(name="LSC", parent=world_node) lsc.geometry = Box( size, material=Host( refractive_index, # LSC refractive index [linear_background, lumogen] # LSC list of lumophore materials ) )