Coverage for tests/fastercap/fastercap_model_generator_test.py: 100%

60 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-17 17:24 +0000

1# 

2# -------------------------------------------------------------------------------- 

3# SPDX-FileCopyrightText: 2024 Martin Jan Köhler and Harald Pretl 

4# Johannes Kepler University, Institute for Integrated Circuits. 

5# 

6# This file is part of KPEX  

7# (see https://github.com/martinjankoehler/klayout-pex). 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21# SPDX-License-Identifier: GPL-3.0-or-later 

22# -------------------------------------------------------------------------------- 

23# 

24import allure 

25import os 

26import klayout.db as kdb 

27from klayout_pex.fastercap.fastercap_model_generator import FasterCapModelBuilder 

28 

29 

30@allure.parent_suite("Unit Tests") 

31@allure.tag("Capacitance", "FasterCap") 

32def test_fastercap_model_generator(tmp_path): 

33 ly = kdb.Layout() 

34 net1 = ly.create_cell("Net1") 

35 net2 = ly.create_cell("Net2") 

36 net_cells = [net1, net2] 

37 

38 top = ly.create_cell("TOP") 

39 for cell in net_cells: 

40 top.insert(kdb.CellInstArray(cell.cell_index(), kdb.Trans())) 

41 

42 m1 = ly.layer(1, 0) # metal1 

43 v1 = ly.layer(2, 0) # via1 

44 m2 = ly.layer(3, 0) # metal3 

45 

46 net1.shapes(m1).insert(kdb.Box(0, 0, 2000, 500)) 

47 net1.shapes(v1).insert(kdb.Box(1600, 100, 1900, 400)) 

48 net1.shapes(m2).insert(kdb.Box(1500, 0, 3000, 500)) 

49 

50 net2.shapes(m1).insert(kdb.Box(-1000, 0, -600, 400)) 

51 net2.shapes(v1).insert(kdb.Box(-900, 100, -700, 300)) 

52 net2.shapes(m2).insert(kdb.Box(-1000, 0, -600, 400)) 

53 

54 fcm = FasterCapModelBuilder(dbu=ly.dbu, 

55 k_void=3.5, 

56 delaunay_amax=0.5, 

57 delaunay_b=0.5) 

58 

59 fcm.add_material(name='nit', k=4.5) 

60 fcm.add_material(name='nit2', k=7) 

61 

62 z = 0.0 

63 h = 0.5 

64 hnit = 0.1 

65 

66 layer = m1 

67 for cell in net_cells: 

68 nn = cell.name 

69 r = kdb.Region(cell.begin_shapes_rec(layer)) 

70 fcm.add_conductor(net_name=nn, layer=r, z=z, height=h) 

71 rnit = r.sized(100) 

72 fcm.add_dielectric(material_name='nit', layer=rnit, z=z, height=h + hnit) 

73 rnit2 = r.sized(200) 

74 fcm.add_dielectric(material_name='nit2', layer=rnit2, z=z, height=h + hnit) 

75 

76 z += h 

77 

78 layer = v1 

79 for cell in net_cells: 

80 nn = cell.name 

81 r = kdb.Region(cell.begin_shapes_rec(layer)) 

82 fcm.add_conductor(net_name=nn, layer=r, z=z, height=h) 

83 

84 z += h 

85 

86 layer = m2 

87 for cell in net_cells: 

88 nn = cell.name 

89 r = kdb.Region(cell.begin_shapes_rec(layer)) 

90 fcm.add_conductor(net_name=nn, layer=r, z=z, height=h) 

91 rnit = r.sized(100) 

92 fcm.add_dielectric(material_name='nit', layer=rnit, z=z, height=h + hnit) 

93 

94 gen = fcm.generate() 

95 

96 # self-check 

97 gen.check() 

98 

99 output_dir_path_fc = os.path.join(tmp_path, 'FasterCap') 

100 output_dir_path_stl = os.path.join(tmp_path, 'STL') 

101 os.makedirs(output_dir_path_fc) 

102 os.makedirs(output_dir_path_stl) 

103 gen.write_fastcap(prefix='test', output_dir_path=output_dir_path_fc) 

104 gen.dump_stl(prefix='test', output_dir_path=output_dir_path_stl)