Coverage for qpdk / models / capacitor.py: 100%

38 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-14 10:27 +0000

1"""Capacitor Models.""" 

2 

3from functools import partial 

4 

5import jax 

6import jax.numpy as jnp 

7import sax 

8from gdsfactory.typings import CrossSectionSpec 

9 

10from qpdk.models.constants import DEFAULT_FREQUENCY, ε_0 

11from qpdk.models.cpw import cpw_ep_r_from_cross_section, cpw_z0_from_cross_section 

12from qpdk.models.generic import capacitor 

13from qpdk.models.math import ( 

14 capacitance_per_length_conformal, 

15 ellipk_ratio, 

16 epsilon_eff, 

17) 

18 

19 

20@partial(jax.jit, inline=True) 

21def plate_capacitor_capacitance_analytical( 

22 length: float, 

23 width: float, 

24 gap: float, 

25 ep_r: float, 

26) -> float: 

27 r"""Analytical formula for plate capacitor capacitance. 

28 

29 The model assumes two coplanar rectangular pads on a substrate. 

30 The capacitance is calculated using conformal mapping: 

31 

32 .. math:: 

33 

34 k &= \frac{s}{s + 2W} \\ 

35 k' &= \sqrt{1 - k^2} \\ 

36 \epsilon_{\text{eff}} &= \frac{\epsilon_r + 1}{2} \\ 

37 C &= \epsilon_0 \epsilon_{\text{eff}} L \frac{K(k')}{K(k)} 

38 

39 where :math:`s` is the gap, :math:`W` is the pad width, and :math:`L` is the pad length. 

40 

41 See :cite:`chenCompactInductorcapacitorResonators2023`. 

42 """ 

43 # Conformal mapping for coplanar pads 

44 k_sq = (gap / (gap + 2 * width)) ** 2 

45 

46 # C = ε_0 * ε_eff * L * K(k') / K(k) 

47 # Uses K(1-m)/K(m) which is the inverse of ellipk_ratio(m) 

48 c_pul = ε_0 * epsilon_eff(ep_r) / ellipk_ratio(k_sq) 

49 

50 return (length * 1e-6) * c_pul 

51 

52 

53@partial(jax.jit, inline=True) 

54def interdigital_capacitor_capacitance_analytical( 

55 fingers: int, 

56 finger_length: float, 

57 finger_gap: float, 

58 thickness: float, 

59 ep_r: float, 

60) -> jax.Array: 

61 r"""Analytical formula for interdigital capacitor capacitance. 

62 

63 The formula uses conformal mapping for the interior and exterior regions of 

64 the interdigital structure: 

65 

66 .. math:: 

67 

68 \eta &= \frac{w}{w + g} \\ 

69 k_i &= \sin\left(\frac{\pi \eta}{2}\right) \\ 

70 k_e &= \frac{2\sqrt{\eta}}{1 + \eta} \\ 

71 C_i &= \epsilon_0 L (\epsilon_r + 1) \frac{K(k_i)}{K(k_i')} \\ 

72 C_e &= \epsilon_0 L (\epsilon_r + 1) \frac{K(k_e)}{K(k_e')} 

73 

74 The total mutual capacitance for :math:`n` fingers is: 

75 

76 .. math:: 

77 

78 C = \begin{cases} 

79 C_e / 2 & \text{if } n=2 \\ 

80 (n - 3) \frac{C_i}{2} + 2 \frac{C_i C_e}{C_i + C_e} & \text{if } n > 2 

81 \end{cases} 

82 

83 where :math:`w` is the finger thickness (width), :math:`g` is the finger gap, and 

84 :math:`L` is the overlap length. 

85 

86 See :cite:`igrejaAnalyticalEvaluationInterdigital2004,gonzalezDesignFabricationInterdigital2015`. 

87 """ 

88 # Geometric parameters 

89 n = fingers 

90 l_overlap = finger_length * 1e-6 # Overlap length in m 

91 w = thickness # Finger width 

92 g = finger_gap # Finger gap 

93 η = w / (w + g) # Metallization ratio 

94 

95 # Elliptic integral moduli squared 

96 ki_sq = jnp.sin(jnp.pi * η / 2) ** 2 

97 ke_sq = (2 * jnp.sqrt(η) / (1 + η)) ** 2 

98 

99 # Capacitances per unit length (interior and exterior) 

100 # Factor is 2.0 since interdigital formula uses (ep_r + 1) = 2 * ep_eff 

101 c_i = l_overlap * 2.0 * capacitance_per_length_conformal(m=ki_sq, ep_r=ep_r) 

102 c_e = l_overlap * 2.0 * capacitance_per_length_conformal(m=ke_sq, ep_r=ep_r) 

103 

104 # Total mutual capacitance 

105 # Simplifies to c_e/2 for n=2 

106 return jnp.where( # pyrefly: ignore[bad-return] 

107 n == 2, 

108 c_e / 2, 

109 (n - 3) * c_i / 2 + 2 * (c_i * c_e) / (c_i + c_e), 

110 ) 

111 

112 

113def plate_capacitor( 

114 *, 

115 f: sax.FloatArrayLike = DEFAULT_FREQUENCY, 

116 length: float = 26.0, 

117 width: float = 5.0, 

118 gap: float = 7.0, 

119 cross_section: CrossSectionSpec = "cpw", 

120) -> sax.SDict: 

121 r"""Plate capacitor Sax model. 

122 

123 Args: 

124 f: Array of frequency points in Hz 

125 length: Length of the capacitor pad in μm 

126 width: Width of the capacitor pad in μm 

127 gap: Gap between plates in μm 

128 cross_section: Cross-section specification 

129 

130 Returns: 

131 sax.SDict: S-parameters dictionary 

132 """ 

133 f_arr = jnp.asarray(f) 

134 z0 = cpw_z0_from_cross_section(cross_section, f_arr) 

135 ep_r = cpw_ep_r_from_cross_section(cross_section) 

136 capacitance = plate_capacitor_capacitance_analytical( 

137 length=length, width=width, gap=gap, ep_r=ep_r 

138 ) 

139 return capacitor(f=f_arr, capacitance=capacitance, z0=z0) 

140 

141 

142def interdigital_capacitor( 

143 *, 

144 f: sax.FloatArrayLike = DEFAULT_FREQUENCY, 

145 fingers: int = 4, 

146 finger_length: float = 20.0, 

147 finger_gap: float = 2.0, 

148 thickness: float = 5.0, 

149 cross_section: CrossSectionSpec = "cpw", 

150) -> sax.SDict: 

151 r"""Interdigital capacitor Sax model. 

152 

153 Args: 

154 f: Array of frequency points in Hz 

155 fingers: Total number of fingers (must be >= 2) 

156 finger_length: Length of each finger in μm 

157 finger_gap: Gap between adjacent fingers in μm 

158 thickness: Thickness of fingers in μm 

159 cross_section: Cross-section specification 

160 

161 Returns: 

162 sax.SDict: S-parameters dictionary 

163 """ 

164 f_arr = jnp.asarray(f) 

165 z0 = cpw_z0_from_cross_section(cross_section, f_arr) 

166 ep_r = cpw_ep_r_from_cross_section(cross_section) 

167 capacitance = interdigital_capacitor_capacitance_analytical( 

168 fingers=fingers, 

169 finger_length=finger_length, 

170 finger_gap=finger_gap, 

171 thickness=thickness, 

172 ep_r=ep_r, 

173 ) 

174 return capacitor(f=f_arr, capacitance=capacitance, z0=z0) 

175 

176 

177if __name__ == "__main__": 

178 import matplotlib.pyplot as plt 

179 

180 # 1. Plot Plate Capacitor Capacitance vs. Length for different Gaps 

181 lengths = jnp.linspace(10, 500, 100) 

182 gaps_plate = jnp.geomspace(1.0, 20.0, 5) 

183 width_plate = 10.0 

184 ep_r = 11.7 

185 

186 plt.figure(figsize=(10, 6)) 

187 

188 # Broadcast to compute total capacitance for all lengths and gaps (shape: (5, 100)) 

189 # length * 1e-6 happens in the analytical formula, here we replicate it 

190 capacitances_plate = ( 

191 plate_capacitor_capacitance_analytical( 

192 length=lengths[None, :], 

193 width=width_plate, 

194 gap=gaps_plate[:, None], 

195 ep_r=ep_r, 

196 ) 

197 * 1e15 

198 ) # Convert to fF 

199 

200 for i, gap in enumerate(gaps_plate): 

201 plt.plot(lengths, capacitances_plate[i], label=f"gap = {gap:.1f} µm") 

202 

203 plt.xlabel("Pad Length (µm)") 

204 plt.ylabel("Capacitance (fF)") 

205 plt.title( 

206 rf"Plate Capacitor Capacitance ($\mathtt{{width}}=${width_plate} µm, $\epsilon_r={ep_r}$)" 

207 ) 

208 plt.grid(True) 

209 plt.legend() 

210 plt.tight_layout() 

211 plt.show() 

212 

213 # 2. Plot Interdigital Capacitor Capacitance vs. Finger Length for different Finger Counts 

214 finger_lengths = jnp.linspace(10, 100, 100) 

215 finger_counts = jnp.arange(2, 11, 2) # [2, 4, 6, 8, 10] 

216 finger_gap = 2.0 

217 thickness = 5.0 

218 

219 plt.figure(figsize=(10, 6)) 

220 

221 # Broadcast to compute total capacitance for all lengths and counts (shape: (5, 100)) 

222 capacitances_idc = ( 

223 interdigital_capacitor_capacitance_analytical( 

224 fingers=finger_counts[:, None], 

225 finger_length=finger_lengths[None, :], 

226 finger_gap=finger_gap, 

227 thickness=thickness, 

228 ep_r=ep_r, 

229 ) 

230 * 1e15 

231 ) # Convert to fF 

232 

233 for i, n in enumerate(finger_counts): 

234 plt.plot(finger_lengths, capacitances_idc[i], label=f"n = {n} fingers") 

235 

236 plt.xlabel("Overlap Length (µm)") 

237 plt.ylabel("Mutual Capacitance (fF)") 

238 plt.title( 

239 rf"Interdigital Capacitor Capacitance ($\mathtt{{finger\_gap}}=${finger_gap} µm, $\mathtt{{thickness}}=${thickness} µm, $\epsilon_r={ep_r}$)" 

240 ) 

241 plt.grid(True) 

242 plt.legend() 

243 plt.tight_layout() 

244 plt.show()