Skip to content

Commit

Permalink
Near2far fix for 2D Cylinder
Browse files Browse the repository at this point in the history
Normalization to power density

delete some unuseful comments

delete a wrong commnet in def integrate_2d

something

fix rcs

near2far fix

delete compute2d

format changes

format issues

fix

fix

format
  • Loading branch information
QimingFlex committed May 22, 2024
1 parent cd7bb00 commit d595088
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/faq
Submodule faq updated 227 files
2 changes: 1 addition & 1 deletion docs/notebooks
Submodule notebooks updated 71 files
+2 −2 .github/workflows/sync-to-proxy-repo.yaml
+3 −0 .gitignore
+4 −4 AdjointPlugin10YBranchLevelSet.ipynb
+23 −16 AdjointPlugin11CircuitMZI.ipynb
+62 −64 AdjointPlugin12LightExtractor.ipynb
+1,746 −0 AdjointPlugin13Metasurface.ipynb
+2,953 −0 AdjointPlugin14PreFab.ipynb
+10 −14 AdjointPlugin3InverseDesign.ipynb
+4 −2 AdjointPlugin5BoundaryGradients.ipynb
+11 −12 AdjointPlugin6GratingCoupler.ipynb
+5 −3 AdjointPlugin7Metalens.ipynb
+4 −2 AdjointPlugin8WaveguideBend.ipynb
+115 −327 AdjointPlugin9WDM.ipynb
+2,242 −0 AllDielectricStructuralColor.ipynb
+63,798 −19,370 AnimationTutorial.ipynb
+1 −1 BullseyeCavityPSO.ipynb
+1,945 −2,809 Design.ipynb
+4 −52 Dispersion.ipynb
+2,089 −0 EffectiveIndexApproximation.ipynb
+16 −16 Fitting.ipynb
+595 −1 GDSExport.ipynb
+8 −8 GeometryTransformations.ipynb
+1 −0 MIMResonator.ipynb
+8 −2 MetalHeaterPhaseShifter.ipynb
+215 −216 ParameterScan.ipynb
+19 −108 PhotonicCrystalWaveguidePolarizationFilter.ipynb
+2,996 −1 ResonanceFinder.ipynb
+242 −356 StripToSlotConverters.ipynb
+5 −1 ThermallyTunedRingResonator.ipynb
+4,887 −0 ThermoOpticDopedModulator.ipynb
+113 −113 TimeModulationTutorial.ipynb
+3,113 −0 WaveguideGratingAntenna.ipynb
+157 −182 WaveguideToRingCoupling.ipynb
+73 −705 XarrayTutorial.ipynb
+104 −2,414 YJunction.ipynb
+3 −1 docs/case_studies/metamaterials_gratings_periodic.rst
+2 −2 docs/case_studies/photonic_opt.rst
+2 −0 docs/case_studies/pic.rst
+1 −0 docs/case_studies/pic_active.rst
+5 −3 docs/features/adjoint.rst
+2 −1 docs/features/medium.rst
+1 −1 docs/features/parameter_sweep.rst
+ img/adjoint_11.png
+ img/adjoint_12.png
+ img/adjoint_13.png
+ img/adjoint_3.png
+ img/adjoint_5.png
+ img/adjoint_6.png
+ img/adjoint_7.png
+ img/adjoint_8.png
+ img/adjoint_9.png
+ img/all_dielectric.png
+ img/doped_silicon_heater.png
+ img/effective_index_approximation.png
+ img/mim.png
+ img/ppp_junction.png
+ img/prefab_intro.png
+ img/prefab_target.png
+ img/thermally_tuned_waveguide.png
+ img/wga_schematic.png
+ img/wga_schematic_2.png
+0 −16 metadata/description_length_checker.py
+0 −681 metadata/metadata.txt
+0 −16 metadata/title_length_checker.py
+0 −30 metadata/update_notebook_metadata.py
+ misc/grating_coupler_history_no_penalty.pkl
+1 −1 misc/import_file_mapping.json
+ misc/logo.png
+22 −0 misc/my_medium.json
+ misc/prefab_base_sim.hdf5
+ misc/prefab_gc.gds
1 change: 1 addition & 0 deletions pythonocc-documentation
Submodule pythonocc-documentation added at d5eb78
40 changes: 40 additions & 0 deletions tidy3d/components/data/monitor_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,20 @@ def propagation_phase(dist: Union[float, None], k: complex) -> complex:
return 1.0
return -1j * k * np.exp(1j * k * dist) / (4 * np.pi * dist)

@staticmethod
def propagation_phase_2d(dist: Union[float, None], k: complex) -> complex:
"""Phase associated with propagation of a distance with a given wavenumber."""
if dist is None:
return 1.0
return -np.exp(1j * k * dist) * np.sqrt(1j * k / (8 * np.pi * dist))

@staticmethod
def propagation_phase_3d(dist: Union[float, None], k: complex) -> complex:
"""Phase associated with propagation of a distance with a given wavenumber."""
if dist is None:
return 1.0
return -1j * k * np.exp(1j * k * dist) / (4 * np.pi * dist)

@property
def fields_spherical(self) -> xr.Dataset:
"""Get all field components in spherical coordinates relative to the monitor's
Expand Down Expand Up @@ -1973,6 +1987,32 @@ def radar_cross_section(self) -> xr.DataArray:

return self.make_data_array(data=rcs_data)

@property
def radar_cross_section_2d(self) -> xr.DataArray:
"""Radar cross section in units of incident power."""

_, index_k = self.nk
if not np.all(index_k == 0):
raise SetupError("Can't compute RCS for a lossy background medium.")

k = self.k[None, None, None, ...]
eta = self.eta[None, None, None, ...]

# 2D constant
constant = k**2 / (16 * np.pi * eta)

# normalize fields by the distance-based phase factor
coords_sph = self.coords_spherical
if coords_sph["r"] is None:
phase = 1.0
else:
phase = self.propagation_phase_2d(dist=coords_sph["r"][..., None], k=k)
Etheta = self.Etheta.values / phase
Ephi = self.Ephi.values / phase
rcs_data = constant * (np.abs(Etheta) ** 2 + np.abs(Ephi) ** 2)

return self.make_data_array(data=rcs_data)


class FieldProjectionAngleData(AbstractFieldProjectionData):
"""Data associated with a :class:`.FieldProjectionAngleMonitor`: components of projected fields.
Expand Down
74 changes: 55 additions & 19 deletions tidy3d/components/field_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ def _resample_surface_currents(
currents = currents.colocate(*colocation_points)
return currents

def integrate_1d(
self,
function: np.ndarray,
phase: np.ndarray,
pts_u: np.ndarray,
):
"""Trapezoidal integration in two dimensions."""
return np.trapz(np.squeeze(function) * np.squeeze(phase), pts_u, axis=0)

def integrate_2d(
self,
function: np.ndarray,
Expand Down Expand Up @@ -397,7 +406,6 @@ def _far_fields_for_surface(

theta = np.atleast_1d(theta)
phi = np.atleast_1d(phi)

sin_theta = np.sin(theta)
cos_theta = np.cos(theta)
sin_phi = np.sin(phi)
Expand All @@ -421,21 +429,38 @@ def integrate_for_one_theta(i_th: int):

phase_ij = phase[idx_u][:, None] * phase[idx_v][None, :] * phase[idx_w]

J[idx_u, i_th, j_ph] = self.integrate_2d(
currents_f[f"E{cmp_1}"].values, phase_ij, pts[idx_u], pts[idx_v]
)
if self.is_3d_simulation():
J[idx_u, i_th, j_ph] = self.integrate_2d(
currents_f[f"E{cmp_1}"].values, phase_ij, pts[idx_u], pts[idx_v]
)

J[idx_v, i_th, j_ph] = self.integrate_2d(
currents_f[f"E{cmp_2}"].values, phase_ij, pts[idx_u], pts[idx_v]
)
J[idx_v, i_th, j_ph] = self.integrate_2d(
currents_f[f"E{cmp_2}"].values, phase_ij, pts[idx_u], pts[idx_v]
)

M[idx_u, i_th, j_ph] = self.integrate_2d(
currents_f[f"H{cmp_1}"].values, phase_ij, pts[idx_u], pts[idx_v]
)
M[idx_u, i_th, j_ph] = self.integrate_2d(
currents_f[f"H{cmp_1}"].values, phase_ij, pts[idx_u], pts[idx_v]
)

M[idx_v, i_th, j_ph] = self.integrate_2d(
currents_f[f"H{cmp_2}"].values, phase_ij, pts[idx_u], pts[idx_v]
)
M[idx_v, i_th, j_ph] = self.integrate_2d(
currents_f[f"H{cmp_2}"].values, phase_ij, pts[idx_u], pts[idx_v]
)
else:
J[idx_u, i_th, j_ph] = self.integrate_1d(
currents_f[f"E{cmp_1}"].values, phase_ij, pts[idx_u]
)

J[idx_v, i_th, j_ph] = self.integrate_1d(
currents_f[f"E{cmp_2}"].values, phase_ij, pts[idx_u]
)

M[idx_u, i_th, j_ph] = self.integrate_1d(
currents_f[f"H{cmp_1}"].values, phase_ij, pts[idx_u]
)

M[idx_v, i_th, j_ph] = self.integrate_1d(
currents_f[f"H{cmp_2}"].values, phase_ij, pts[idx_u]
)

if len(theta) < 2:
integrate_for_one_theta(0)
Expand Down Expand Up @@ -534,6 +559,10 @@ def project_fields(
return self._project_fields_cartesian(proj_monitor)
return self._project_fields_kspace(proj_monitor)

def is_3d_simulation(self) -> bool:
"""Determine if the simulation is 2D or 3D based on the size attribute."""
return self.sim_data.simulation.size[2] != 0.01

def _project_fields_angular(
self, monitor: FieldProjectionAngleMonitor
) -> FieldProjectionAngleData:
Expand All @@ -554,17 +583,24 @@ def _project_fields_angular(
theta = np.atleast_1d(monitor.theta)
phi = np.atleast_1d(monitor.phi)

# compute projected fields for the dataset associated with each monitor
medium = monitor.medium if monitor.medium else self.medium
k = AbstractFieldProjectionData.wavenumber(medium=medium, frequency=freqs)

field_names = ("Er", "Etheta", "Ephi", "Hr", "Htheta", "Hphi")
fields = [
np.zeros((1, len(theta), len(phi), len(freqs)), dtype=complex) for _ in field_names
]

medium = monitor.medium if monitor.medium else self.medium
k = AbstractFieldProjectionData.wavenumber(medium=medium, frequency=freqs)
phase = np.atleast_1d(
AbstractFieldProjectionData.propagation_phase(dist=monitor.proj_distance, k=k)
)
if self.is_3d_simulation():
# compute projected fields for the dataset associated with each monitor in 3D
phase = np.atleast_1d(
AbstractFieldProjectionData.propagation_phase_3d(dist=monitor.proj_distance, k=k)
)
else:
# compute projected fields for the dataset associated with each monitor in 2D
phase = np.atleast_1d(
AbstractFieldProjectionData.propagation_phase_2d(dist=monitor.proj_distance, k=k)
)

for surface in self.surfaces:
# apply windowing to currents
Expand Down

0 comments on commit d595088

Please sign in to comment.