Skip to content

Commit

Permalink
Version 0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hideousmon committed Sep 11, 2023
1 parent 9d62691 commit 6a72588
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
5 changes: 4 additions & 1 deletion history.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* Add api reference for ScalableToOptRegion3D and AdjointForMultiTO.

### Version 0.5.2 (Sep 11, 2023)
* Enable backward direction calculations for monitors in the adjoint method.
2 changes: 1 addition & 1 deletion splayout/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.1"
__version__ = "0.5.2"

## Submodules
from . import utils
Expand Down
16 changes: 14 additions & 2 deletions splayout/adjointmethod/adjointmultitoopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
"""
Expand All @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions splayout/adjointmethod/adjointtopologyopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
"""
Expand All @@ -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)
Expand Down

0 comments on commit 6a72588

Please sign in to comment.