Skip to content

Commit 0a9cffe

Browse files
authored
Fix a bug in capacitance when symmetry is present (#2469)
* Fix a bug in capacitance when symmetry is present * Add test
1 parent 03d893f commit 0a9cffe

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

tests/test_components/test_heat_charge.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,3 +1559,43 @@ def test_fossum():
15591559
"""Check that fossum model can be defined."""
15601560

15611561
_ = td.FossumCarrierLifetime(tau_300=3.3e-6, alpha_T=-0.5, N0=7.1e15, A=1, B=0, C=1, alpha=1)
1562+
1563+
1564+
@pytest.mark.parametrize("symmetry", [(0, 0, 0), (0, 1, 0), (1, 0, 0), (1, 1, 0)])
1565+
def test_symmetry_capacitance(symmetry):
1566+
"""Check that symmetry_expanded_copy works as expected"""
1567+
1568+
data = [1, 2, 3]
1569+
voltages = [0, 1, 2]
1570+
1571+
hole_capacitance = td.SteadyVoltageDataArray(
1572+
data=data,
1573+
coords={"v": voltages},
1574+
)
1575+
1576+
electron_capacitance = td.SteadyVoltageDataArray(
1577+
data=data,
1578+
coords={"v": voltages},
1579+
)
1580+
1581+
monitor = td.SteadyCapacitanceMonitor(
1582+
center=(0, 0, 0),
1583+
size=(1, 1, 1),
1584+
name="test_monitor",
1585+
)
1586+
1587+
mnt_data = td.SteadyCapacitanceData(
1588+
monitor=monitor,
1589+
hole_capacitance=hole_capacitance,
1590+
electron_capacitance=electron_capacitance,
1591+
symmetry=symmetry,
1592+
)
1593+
1594+
num_symmetries = np.sum(np.array([1 if d > 0 else 0 for d in symmetry]))
1595+
scaling_factor = np.power(2, num_symmetries)
1596+
1597+
for n in range(len(data)):
1598+
assert mnt_data.symmetry_expanded_copy.hole_capacitance.data[n] == data[n] * scaling_factor
1599+
assert (
1600+
mnt_data.symmetry_expanded_copy.electron_capacitance.data[n] == data[n] * scaling_factor
1601+
)

tidy3d/components/tcad/data/monitor_data/charge.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from typing import Dict, Union
66

7+
import numpy as np
78
import pydantic.v1 as pd
89

910
from tidy3d.components.base import skip_if_fields_missing
@@ -435,4 +436,27 @@ def field_name(self, val: str) -> str:
435436
@property
436437
def symmetry_expanded_copy(self) -> SteadyCapacitanceData:
437438
"""Return copy of self with symmetry applied."""
438-
return self
439+
num_symmetries = np.sum(np.array([1 if d > 0 else 0 for d in self.symmetry]))
440+
scaling_factor = np.power(2, num_symmetries)
441+
442+
if self.hole_capacitance is None:
443+
new_hole_capacitance = None
444+
else:
445+
new_values = self.hole_capacitance.values * scaling_factor
446+
new_hole_capacitance = SteadyVoltageDataArray(
447+
data=new_values, coords=self.hole_capacitance.coords
448+
)
449+
450+
if self.electron_capacitance is None:
451+
new_electron_capacitance = None
452+
else:
453+
new_values = self.electron_capacitance.values * scaling_factor
454+
new_electron_capacitance = SteadyVoltageDataArray(
455+
data=new_values, coords=self.electron_capacitance.coords
456+
)
457+
458+
return self.updated_copy(
459+
hole_capacitance=new_hole_capacitance,
460+
electron_capacitance=new_electron_capacitance,
461+
symmetry=(0, 0, 0),
462+
)

0 commit comments

Comments
 (0)