From 654f9c165b20454130aa2b3605abf356f0405308 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Wed, 10 Jan 2024 20:52:52 -0800 Subject: [PATCH 1/4] formatting --- fdtd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fdtd.py b/fdtd.py index 6f9638c..e311c0b 100644 --- a/fdtd.py +++ b/fdtd.py @@ -230,9 +230,9 @@ def main(): Ectr[t] = sim.E[ind].get() u[t] = pyopencl.array.sum(sim.E * sim.E * sim.eps + h_old * sim.H).get() * dx * dx * dx ui[t] = (sim.E * sim.E * sim.eps + h_old * sim.H).reshape(epsilon.shape).get()[:, pml_thickness+m:-pml_thickness-m, :, - pml_thickness+m:-pml_thickness-m].sum() * dx * dx * dx + pml_thickness+m:-pml_thickness-m].sum() * dx * dx * dx # ui[t] = (sim.E * sim.E * sim.eps + h_old * sim.H).reshape(epsilon.shape).get()[:, pml_thickness+m:-pml_thickness-m, -# pml_thickness+m:-pml_thickness-m, :].sum() * dx * dx * dx +# pml_thickness+m:-pml_thickness-m, :].sum() * dx * dx * dx if t % 100 == 0: avg = (t + 1) / (time.perf_counter() - start) From d0011cb1f97a395e1619d1f27c34d930c90b0b47 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Wed, 10 Jan 2024 20:54:12 -0800 Subject: [PATCH 2/4] type modernization --- opencl_fdtd/simulation.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/opencl_fdtd/simulation.py b/opencl_fdtd/simulation.py index f2ef309..31e017a 100644 --- a/opencl_fdtd/simulation.py +++ b/opencl_fdtd/simulation.py @@ -2,7 +2,7 @@ Class for constructing and holding the basic FDTD operations and fields """ -from typing import List, Dict, Callable, Type, Union, Optional, Sequence +from typing import Callable, Type, Sequence from collections import OrderedDict import numpy from numpy.typing import NDArray @@ -62,29 +62,29 @@ class Simulation(object): S: pyopencl.array.Array eps: pyopencl.array.Array dt: float - inv_dxes: List[pyopencl.array.Array] + inv_dxes: list[pyopencl.array.Array] arg_type: Type context: pyopencl.Context queue: pyopencl.CommandQueue - update_E: Callable[[List[pyopencl.Event]], pyopencl.Event] - update_H: Callable[[List[pyopencl.Event]], pyopencl.Event] - update_S: Callable[[List[pyopencl.Event]], pyopencl.Event] - update_J: Callable[[List[pyopencl.Event]], pyopencl.Event] - sources: Dict[str, str] + update_E: Callable[[list[pyopencl.Event]], pyopencl.Event] + update_H: Callable[[list[pyopencl.Event]], pyopencl.Event] + update_S: Callable[[list[pyopencl.Event]], pyopencl.Event] + update_J: Callable[[list[pyopencl.Event]], pyopencl.Event] + sources: dict[str, str] def __init__( self, epsilon: NDArray, - pmls: Sequence[Dict[str, float]], - bloch_boundaries: Sequence[Dict[str, float]] = (), - dxes: Union[List[List[NDArray]], float, None] = None, - dt: Optional[float] = None, - initial_fields: Optional[Dict[str, NDArray]] = None, - context: Optional[pyopencl.Context] = None, - queue: Optional[pyopencl.CommandQueue] = None, + pmls: Sequence[dict[str, float]], + bloch_boundaries: Sequence[dict[str, float]] = (), + dxes: list[list[NDArray]] | float | None = None, + dt: float | None = None, + initial_fields: dict[str, NDArray] | None = None, + context: pyopencl.Context | None = None, + queue: pyopencl.CommandQueue | None = None, float_type: Type = numpy.float32, do_poynting: bool = True, do_fieldsrc: bool = False, @@ -331,8 +331,8 @@ class Simulation(object): def _create_context( self, - context: Optional[pyopencl.Context] = None, - queue: Optional[pyopencl.CommandQueue] = None, + context: pyopencl.Context | None = None, + queue: pyopencl.CommandQueue | None = None, ) -> None: if context is None: self.context = pyopencl.create_some_context() @@ -353,7 +353,7 @@ class Simulation(object): raise Exception(f'Epsilon shape mismatch. Expected {self.shape}, got {epsilon[0].shape}') self.eps = pyopencl.array.to_device(self.queue, vec(epsilon).astype(self.arg_type)) - def _create_field(self, initial_value: Optional[NDArray] = None) -> pyopencl.array.Array: + def _create_field(self, initial_value: NDArray | None = None) -> pyopencl.array.Array: if initial_value is None: return pyopencl.array.zeros_like(self.eps) else: From 5b1e758c27de93430e7d468a1b928f6fa974cb2c Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Wed, 10 Jan 2024 20:57:23 -0800 Subject: [PATCH 3/4] typo fix --- opencl_fdtd/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencl_fdtd/__init__.py b/opencl_fdtd/__init__.py index f6596ad..0dcc446 100644 --- a/opencl_fdtd/__init__.py +++ b/opencl_fdtd/__init__.py @@ -1,5 +1,5 @@ from .simulation import Simulation, type_to_C __author__ = 'Jan Petykiewicz' -__vesion__ = '0.4' +__version__ = '0.4' version = __version__ From b703f1ee20576dcc899df67824586662f0e4a29e Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Wed, 10 Jan 2024 20:57:40 -0800 Subject: [PATCH 4/4] drop object superclass --- opencl_fdtd/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencl_fdtd/simulation.py b/opencl_fdtd/simulation.py index 31e017a..fbd282a 100644 --- a/opencl_fdtd/simulation.py +++ b/opencl_fdtd/simulation.py @@ -23,7 +23,7 @@ __author__ = 'Jan Petykiewicz' jinja_env = jinja2.Environment(loader=jinja2.PackageLoader(__name__.split('.')[0], 'kernels')) -class Simulation(object): +class Simulation: r""" Constructs and holds the basic FDTD operations and related fields