From 6a72588ea130c0179ad30e761039c04b99b1208b Mon Sep 17 00:00:00 2001 From: Hideousmon Date: Mon, 11 Sep 2023 19:02:41 +0800 Subject: [PATCH] Version 0.5.2 --- history.md | 5 ++++- splayout/__init__.py | 2 +- splayout/adjointmethod/adjointmultitoopt.py | 16 ++++++++++++++-- splayout/adjointmethod/adjointtopologyopt.py | 16 ++++++++++++++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/history.md b/history.md index 0e8a9e3..ab31ab9 100644 --- a/history.md +++ b/history.md @@ -207,4 +207,7 @@ ### Version 0.5.1 (Sep 6, 2023) * Fix the format for call_fom and call_grad for the user-defined fom. -* Add api reference for ScalableToOptRegion3D and AdjointForMultiTO. \ No newline at end of file +* Add api reference for ScalableToOptRegion3D and AdjointForMultiTO. + +### Version 0.5.2 (Sep 11, 2023) +* Enable backward direction calculations for monitors in the adjoint method. \ No newline at end of file diff --git a/splayout/__init__.py b/splayout/__init__.py index b94bf99..f0bda5a 100644 --- a/splayout/__init__.py +++ b/splayout/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.5.1" +__version__ = "0.5.2" ## Submodules from . import utils diff --git a/splayout/adjointmethod/adjointmultitoopt.py b/splayout/adjointmethod/adjointmultitoopt.py index 5b48e90..1bb0d3a 100644 --- a/splayout/adjointmethod/adjointmultitoopt.py +++ b/splayout/adjointmethod/adjointmultitoopt.py @@ -29,9 +29,11 @@ class AdjointForMultiTO: Whether set y-axis antisymmetric in the simulation(default: 0). if_default_fom : Bool or Int `Whether use the default figure of merit(default: 1). + backward_T_monitor_names : String or List of String + Monitor names for deriving FoM which need to calculate in the backward direction. """ def __init__(self,fdtd_engine, T_monitor_names, target_T, design_regions, forward_source_names, backward_source_names, - sim_name = "Adjoint", y_antisymmetric = 0, if_default_fom = 1): + sim_name = "Adjoint", y_antisymmetric = 0, if_default_fom = 1, backward_T_monitor_names = None): self.fdtd_engine = fdtd_engine self.design_regions = design_regions self.design_region_num = len(design_regions) @@ -55,6 +57,10 @@ def __init__(self,fdtd_engine, T_monitor_names, target_T, design_regions, forwar self.y_antisymmetric = y_antisymmetric self.multi_target_flag = 0 self.if_default_fom = if_default_fom + if backward_T_monitor_names is None: + self.backward_T_monitor_names = [] + else: + self.backward_T_monitor_names = np.array([backward_T_monitor_names]).flatten() def get_total_source_power(self, source_names): """ @@ -80,7 +86,13 @@ def get_forward_transmission_properties(self): """ mode_coefficients = [] for i in range(0, np.shape(self.T_monitor_names)[0]): - mode_coefficients.append(self.fdtd_engine.get_mode_coefficient(expansion_name=str(self.T_monitor_names[i]))) + if self.T_monitor_names[i] in self.backward_T_monitor_names: + mode_coefficients.append( + self.fdtd_engine.get_mode_coefficient(expansion_name=str(self.T_monitor_names[i]), + direction=BACKWARD)) + else: + mode_coefficients.append( + self.fdtd_engine.get_mode_coefficient(expansion_name=str(self.T_monitor_names[i]))) mode_coefficients = np.array(mode_coefficients) forward_source_power = self.get_total_source_power(self.forward_source_names) self.T_fwd_vs_wavelengths = np.real(mode_coefficients * mode_coefficients.conj() / forward_source_power) diff --git a/splayout/adjointmethod/adjointtopologyopt.py b/splayout/adjointmethod/adjointtopologyopt.py index fde9195..e715ca0 100644 --- a/splayout/adjointmethod/adjointtopologyopt.py +++ b/splayout/adjointmethod/adjointtopologyopt.py @@ -29,9 +29,11 @@ class AdjointForTO: Whether set y-axis antisymmetric in the simulation(default: 0). if_default_fom : Bool or Int `Whether use the default figure of merit(default: 1). + backward_T_monitor_names : String or List of String + Monitor names for deriving FoM which need to calculate in the backward direction. """ def __init__(self,fdtd_engine, T_monitor_names, target_T, design_region, forward_source_names, backward_source_names, - sim_name = "Adjoint", y_antisymmetric = 0, if_default_fom = 1): + sim_name = "Adjoint", y_antisymmetric = 0, if_default_fom = 1, backward_T_monitor_names = None): self.fdtd_engine = fdtd_engine self.design_region = design_region self.T_monitor_names = np.array([T_monitor_names]).flatten() @@ -42,6 +44,10 @@ def __init__(self,fdtd_engine, T_monitor_names, target_T, design_region, forward self.y_antisymmetric = y_antisymmetric self.multi_target_flag = 0 self.if_default_fom = if_default_fom + if backward_T_monitor_names is None: + self.backward_T_monitor_names = [] + else: + self.backward_T_monitor_names = np.array([backward_T_monitor_names]).flatten() def get_total_source_power(self, source_names): """ @@ -67,7 +73,13 @@ def get_forward_transmission_properties(self): """ mode_coefficients = [] for i in range(0, np.shape(self.T_monitor_names)[0]): - mode_coefficients.append(self.fdtd_engine.get_mode_coefficient(expansion_name=str(self.T_monitor_names[i]))) + if self.T_monitor_names[i] in self.backward_T_monitor_names: + mode_coefficients.append( + self.fdtd_engine.get_mode_coefficient(expansion_name=str(self.T_monitor_names[i]), + direction=BACKWARD)) + else: + mode_coefficients.append( + self.fdtd_engine.get_mode_coefficient(expansion_name=str(self.T_monitor_names[i]))) mode_coefficients = np.array(mode_coefficients) forward_source_power = self.get_total_source_power(self.forward_source_names) self.T_fwd_vs_wavelengths = np.real(mode_coefficients * mode_coefficients.conj() / forward_source_power)