├── .ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── docs └── images │ ├── S_11_smith.png │ ├── S_x1.png │ ├── Z_1.png │ └── Z_ems+vna.png ├── examples ├── differential │ ├── fab │ │ ├── si-simulation-test-board-B_Cu.gbr │ │ ├── si-simulation-test-board-Edge_Cuts.gbr │ │ ├── si-simulation-test-board-F_Cu.gbr │ │ ├── si-simulation-test-board-In1_Cu.gbr │ │ ├── si-simulation-test-board-In2_Cu.gbr │ │ ├── si-simulation-test-board-PTH.drl │ │ ├── si-simulation-test-board-bottom-pos.csv │ │ ├── si-simulation-test-board-top-pos.csv │ │ └── stackup.json │ └── simulation.json ├── filter │ ├── fab │ │ ├── si-simulation-test-board-B_Cu.gbr │ │ ├── si-simulation-test-board-Edge_Cuts.gbr │ │ ├── si-simulation-test-board-F_Cu.gbr │ │ ├── si-simulation-test-board-In1_Cu.gbr │ │ ├── si-simulation-test-board-In2_Cu.gbr │ │ ├── si-simulation-test-board-PTH.drl │ │ ├── si-simulation-test-board-bottom-pos.csv │ │ ├── si-simulation-test-board-top-pos.csv │ │ └── stackup.json │ ├── simulation.json │ └── vna.csv ├── meander_loose │ ├── fab │ │ ├── si-simulation-test-board-B_Cu.gbr │ │ ├── si-simulation-test-board-Edge_Cuts.gbr │ │ ├── si-simulation-test-board-F_Cu.gbr │ │ ├── si-simulation-test-board-In1_Cu.gbr │ │ ├── si-simulation-test-board-In2_Cu.gbr │ │ ├── si-simulation-test-board-PTH.drl │ │ ├── si-simulation-test-board-bottom-pos.csv │ │ ├── si-simulation-test-board-top-pos.csv │ │ └── stackup.json │ ├── simulation.json │ └── vna.csv ├── meander_tight │ ├── fab │ │ ├── si-simulation-test-board-B_Cu.gbr │ │ ├── si-simulation-test-board-Edge_Cuts.gbr │ │ ├── si-simulation-test-board-F_Cu.gbr │ │ ├── si-simulation-test-board-In1_Cu.gbr │ │ ├── si-simulation-test-board-In2_Cu.gbr │ │ ├── si-simulation-test-board-PTH.drl │ │ ├── si-simulation-test-board-bottom-pos.csv │ │ ├── si-simulation-test-board-top-pos.csv │ │ └── stackup.json │ ├── simulation.json │ └── vna.csv ├── stub_long │ ├── fab │ │ ├── si-simulation-test-board-B_Cu.gbr │ │ ├── si-simulation-test-board-Edge_Cuts.gbr │ │ ├── si-simulation-test-board-F_Cu.gbr │ │ ├── si-simulation-test-board-In1_Cu.gbr │ │ ├── si-simulation-test-board-In2_Cu.gbr │ │ ├── si-simulation-test-board-PTH.drl │ │ ├── si-simulation-test-board-bottom-pos.csv │ │ ├── si-simulation-test-board-top-pos.csv │ │ └── stackup.json │ ├── simulation.json │ └── vna.csv └── stub_short │ ├── fab │ ├── si-simulation-test-board-B_Cu.gbr │ ├── si-simulation-test-board-Edge_Cuts.gbr │ ├── si-simulation-test-board-F_Cu.gbr │ ├── si-simulation-test-board-In1_Cu.gbr │ ├── si-simulation-test-board-In2_Cu.gbr │ ├── si-simulation-test-board-PTH.drl │ ├── si-simulation-test-board-bottom-pos.csv │ ├── si-simulation-test-board-top-pos.csv │ └── stackup.json │ ├── simulation.json │ └── vna.csv ├── pyproject.toml └── src ├── ems2paraview ├── main.py └── paraview_preview.py └── gerber2ems ├── antmicro.mplstyle ├── config.py ├── constants.py ├── gerber_io.py ├── grid_gen.py ├── importer.py ├── main.py ├── postprocess.py └── simulation.py /.ci.yml: -------------------------------------------------------------------------------- 1 | include: 2 | - project: 'repositories/gerber2ems-ci' 3 | file: '/.ci.yml' 4 | - project: 'repositories/gerber2ems-ci' 5 | file: '/.verification.yml' 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | examples/*/ems/* 2 | examples/*/fab/* 3 | !examples/*/fab/*_Cu.gbr 4 | !examples/*/fab/*_Cuts.gbr 5 | !examples/*/fab/stackup.json 6 | !examples/*/fab/*-PTH.drl 7 | !examples/*/fab/*-pos.csv 8 | !examples/*/simulation.json 9 | !examples/*/vna.csv 10 | 11 | .vscode/ 12 | .mypy_cache/ 13 | __pycache__/ 14 | ems-kicad.sh 15 | .venv 16 | *.egg-info/ 17 | build/ 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gerber2ems - openEMS simulation based on Gerber files 2 | 3 | Copyright (c) 2023-2025 [Antmicro](https://www.antmicro.com) 4 | 5 | This project is a Python script that aims to streamline signal integrity simulations using open source tools. 6 | It takes PCB production files as input (Gerber, drill files, stackup information) and simulates trace SI performance using [openEMS](https://github.com/thliebig/openEMS-Project/) - a free and open source electromagnetic field solver that uses the FDTD method. 7 | 8 | ## Installation 9 | 10 | ### [OpenEMS](https://www.openems.de/) 11 | 12 | 13 | Install the following packages (on Debian/Ubuntu): 14 | 15 | ```bash 16 | sudo apt update 17 | sudo apt install build-essential cmake git libhdf5-dev libvtk9-dev libboost-all-dev libcgal-dev libtinyxml-dev qtbase5-dev libvtk9-qt-dev python3-numpy python3-matplotlib cython3 python3-h5py python3-setuptools 18 | ``` 19 | 20 | Clone the repository, compile and install openEMS: 21 | 22 | It is recommended to use the `bb991bb3` commit, as this is the latest one tested with gerber2ems. 23 | ```bash 24 | git clone https://github.com/thliebig/openEMS-Project.git 25 | pushd ./openEMS-Project 26 | git checkout bb991bb3 27 | git submodule update --init --recursive 28 | ./update_openEMS.sh ~/opt/openEMS --python 29 | popd 30 | ``` 31 | 32 | ### Script installation 33 | 34 | 1. Install the dependencies: 35 | ```bash 36 | sudo apt install gerbv paraview python3.11 pipx 37 | pipx ensurepath 38 | ``` 39 | 40 | 2. Clone and install gerber2ems 41 | ```bash 42 | git clone https://github.com/antmicro/gerber2ems.git 43 | pushd ./gerber2ems 44 | pipx install --system-site-packages . 45 | popd 46 | ``` 47 | 48 | You can test `gerber2ems` with built-in examples. 49 | The examples are slices of our open hardware [Signal Integrity Test Board](https://openhardware.antmicro.com/boards/si-simulation-test-board/), which were generated using the [KiCad SI wrapper](https://github.com/antmicro/kicad-si-simulation-wrapper). 50 | Selected examples contain VNA measurements in dedicated vna.csv files, which allows us to compare openEMS simulation results with real life measurements. 51 | ```bash 52 | cd ./gerber2ems/examples/stub_short 53 | gerber2ems -a 54 | ``` 55 | 56 | ## Usage 57 | 58 | For quick lookup, use `gerber2ems --help`. 59 | 60 | To simulate a trace, follow these steps: 61 | 62 | * Prepare input files and put them in the `fab/` folder (described in detail in the [PCB Input File Preparation section](#pcb-input-files-preparation)) 63 | * Prepare the config `simulation.json` file (described in detail in the [Config Preparation section](#config-preparation)) 64 | * Run `gerber2ems -a` (process described in the [Geometry Creation section](#geometry-creation)) 65 | * View the results in `ems/results` (described in detail in the [Results section](#results)) 66 | * Run `gerber2ems -a --export-field` and use Paraview to view an animation of the E-field (described in detail in the [Paraview section](#paraview)) 67 | 68 | ## Results 69 | 70 | The simulation output of the `stub_short` example is shown below. 71 | This software returns the following types of output: 72 | 73 | ### S-parameter and impedance data 74 | 75 | Impedance and S-parameter data gathered during the simulations, stored in CSV format with a header. 76 | 77 | ### S-parameter chart 78 | 79 | Plot of each S-parameter measured during each excitation. 80 | 81 | ![](./docs/images/S_x1.png) 82 | 83 | ### Smith chart 84 | 85 | Plot of parameter S-11 for each excitation. 86 | 87 | ![](./docs/images/S_11_smith.png) 88 | 89 | ### Impedance chart 90 | 91 | Plot of each excited port vs. frequency. 92 | 93 | ![](./docs/images/Z_1.png) 94 | 95 | The `stub_short` example contains a `vna.csv` file, which can be used to verify simulation results. 96 | 97 | ![](./docs/images/Z_ems+vna.png) 98 | 99 | ## How it works 100 | 101 | ### Project preparation 102 | 103 | Simulating an entire PCB is extremely resource-intensive, so it is important to separate a region of interest as small in size as possible - unneeded traces, pours etc., should be removed. 104 | If entire layers are redundant, you can remove them in later steps. 105 | 106 | Ports of interest should be marked by a virtual component in positions files. Their designator should begin with "SP" and be followed by port number. 107 | 108 | Origin point for drill files should be placed in bottom-left corner. 109 | 110 | Every trace or pour that is somehow terminated in reality and will exist in the simulation should also be terminated using a simulation port or connected to ground. 111 | 112 | For now, capacitors are not simulated and, for high frequency simulation, they can be aproximated by shorting them using a trace. 113 | 114 | ### PCB input file preparation 115 | 116 | This script requires multiple input files for geometry creation. 117 | They should all reside in the "fab" folder and are listed below: 118 | 119 | * Gerber files - each simulated copper layer should have a corresponding Gerber file named in the following format: "\-\.gbr" 120 | 121 | * Stackup file - a file describing the PCB stackup, named "stackup.json". 122 | Example format: 123 | 124 | ``` 125 | { 126 | "layers": [ 127 | { 128 | "name": "F.Cu", 129 | "type": "copper", 130 | "color": null, 131 | "thickness": 0.035, 132 | "material": null, 133 | "epsilon": null, 134 | "lossTangent": null 135 | }, 136 | { 137 | "name": "dielectric 1", 138 | "type": "core", 139 | "color": null, 140 | "thickness": 0.2, 141 | "material": "FR4", 142 | "epsilon": 4.5, 143 | "lossTangent": 0.02 144 | } 145 | ], 146 | "format_version": "1.0" 147 | } 148 | ``` 149 | 150 | * Drill file - Drill file in excellon format with plated through-holes. 151 | Filename should end with "-PTH.drl" 152 | 153 | * Position file - File describing positions of ports. 154 | * Filename should end with "-pos.csv" 155 | * Coordinates should be given in relation to bottom left corner 156 | * The area of the port is calculated using the formulas in the table below, based on the `Width` and `Length` values from the `simulation.json` file: 157 | 158 | | Rotation [°] | `X` span | `Y` span | Wave travel direction | 159 | | ------------ | ------------------------------ | ------------------------------ | --------------------- | 160 | | 0 | `(PosX-Width/2, PosX+Width/2)` | `(PosY, PosY+Length)` | Along `Y` | 161 | | 90 | `(PosX-Length, PosX)` | `(PosY-Width/2, PosY+Width/2)` | Opposite to `X` | 162 | | 180 | `(PosX-Width/2, PosX+Width/2)` | `(PosY-Length, PosY)` | Opposite to `Y` | 163 | | 270 | `(PosX, PosX+Length)` | `(PosY-Width/2, PosY+Width/2)` | Along `X` | 164 | 165 | * Example file: 166 | 167 | ``` 168 | # Ref Val Package PosX PosY Rot Side 169 | SP1 Simulation_Port Simulation_Port 3.0000 11.7500 180.0000 top 170 | ``` 171 | 172 | ### Config preparation 173 | 174 | The `simulation.json` file configures the entire simulation. 175 | You can find sample files in the `example_gerbers` folder. 176 | All dimensions in this file are specified in **micrometers**. 177 | This config file consists of three sections: 178 | 179 | #### Miscellaneous 180 | 181 | * `format_version` - specifies the format of the config file 182 | When writing a new config, it should be the newest supported version (visible in the `constants.py` file) 183 | * `frequency` - `start` specifies the lowest frequency of interest and `stop` the highest (in Hz) 184 | * `max_steps` - max number of simulation steps after which the simulation will stop unconditionally 185 | * `pixel_size` - size of pixel in microns. Used during gerber conversion (default: 5) (due to a limitation of libcairo, this needs to be increased for larger boards, but try to keep as low as possible) 186 | * `via/plating_thickness` - via plating thickness (micrometers) 187 | * `via/filling_epsilon` - dielectric constant of the material the vias are filled in with 188 | If they are not filled in, it should be 1 189 | 190 | #### Grid 191 | 192 | * `inter_layers` - number of grid lines in Z axis between neighboring PCB layers (default: 4) 193 | * `optimal` - basic mesh grid pitch (micrometers) (used for cells on metal edge) (default: 50) 194 | * `diagonal` - mesh grid pitch (micrometers) (used for regions with diagonal paths) (default: 50) 195 | * `perpendicular` - mesh grid pitch (micrometers) (used for regions with paths perpendicular to grid) (default: 200) 196 | * `max` - maximum mesh grid pitch (micrometers) (used outside of the board area) (default: 500) 197 | * `cell_ratio/xy` - optimal neighboring cell size ratio (X/Y axis) (default: 1.2) 198 | * `cell_ratio/xy` - optimal neighboring cell size ratio (Z axis) (default: 1.5) 199 | * `margin/xy` - margin size in X/Y axis (micrometers) (how far beyond pcb the grid spreads) (default: 1000) 200 | * `margin/z` - margin size in Z axis (micrometers) (default: 1000). 201 | * `margin/from_trace` - Limit simulation space based on nets-of-interest bounding box (default: True) (if False, board b-box is used). 202 | 203 | Grid pitch options should follow `optimal`<=`diagonal`<=`perpendicular`<=`max`<=`λmin/10` 204 | 205 | #### Ports 206 | 207 | `ports` is a list of ports. Each port has the following parameters: 208 | 209 | * `width` - width of the port (micrometers) 210 | * `length` - length of the port (ports are currently composed of microstripline fragments whose length should be at least 8x mesh cell size) (micrometers) 211 | * `impedance` - terminating impedance of the port (impedance of driver or receiver) (Ohms) 212 | * `layer` - the number of the copper layer where the port is located (counting from the top) 213 | * `plane` - the number of the copper layer where the reference plane of the microstrip is located (counting from the top) 214 | * `excite` - whether the simulator should use this port as an input port (for multiple excited ports, they will be excited in separate simulations). 215 | 216 | #### differential_pairs/traces 217 | 218 | `differential_pairs`/`traces` are lists of simulated signals. Each signal can have following fields: 219 | 220 | * `start_p`, `stop_p`, `start_n`, `stop_n` - port numbers used for signal (differential_pair) 221 | * `start`, `stop` - port numbers used for signal (single ended trace) 222 | * `name` - optional name that allows to identify the signal 223 | * `nets` - list of nets to be included during grid generation (e.g. `["/CSI_A_CLK_N","/CSI_A_CLK_P"]`). If not specified, data from `netinfo.json` file will be used. In case the file is also not present, all nets (except GND) will be considered during grid generation. 224 | 225 | ### Geometry creation 226 | 227 | This is an automatic step commenced with the `-g` flag. 228 | The script locates all the files needed for creating the geometry (Gerbers, drill files, pnp files, stackup file, simulation config file). 229 | Then it converts Gerber files to PNG using gerbv. 230 | The PNG's are then processed into triangles and input into the geometry. 231 | This also adds via geometries as well as port geometries. 232 | Everything is placed on correct Z heights using the stackup file. 233 | 234 | You can view the generated geometry, which is saved to `ems/geometry/geometry.xml`, using AppCSXCAD (installed during openEMS installation). 235 | 236 | ### Simulation 237 | 238 | This is an automatic step commenced with the `-s` flag. 239 | The script loads the geometry and config files. 240 | It inputs all the information into the engine and starts the simulations, iterating over every excited port. 241 | 242 | At this step, the user should verify if the indicated number of timesteps is sufficient. 243 | The engine recommends that it should be at least 3x as long as the pulse: 244 | 245 | ``` 246 | Excitation signal length is: 3211 timesteps (3.18343e-10s) 247 | Max. number of timesteps: 10000 ( --> 3.11429 * Excitation signal length) 248 | ``` 249 | 250 | The simulator converts the geometry into voxels and starts solving Maxwell equations for each edge in the mesh. 251 | It does that for a number of timesteps (maximum number specified in config) and then exits. 252 | For each timestep, electric field data from planes between copper planes is saved to files in the `ems/simulation` folder. Port voltage and current data is also saved. 253 | 254 | During the simulation, one of the ports is excited using a gaussian pulse (wideband frequency content). 255 | This pulse traverses the network and exits using ports (it can also get emitted outside the board). 256 | 257 | You can monitor the simulation by looking at the engine output: 258 | 259 | ``` 260 | [@ 20s] Timestep: 4620 || Speed: 294.4 MC/s (3.372e-03 s/TS) || Energy: ~4.16e-16 (- 7.15dB) 261 | ``` 262 | This way you can see: 263 | * what timestep you are on 264 | * how many mesh voxels per second the simulator processes 265 | * how much energy is left in the system 266 | 267 | The energy should drop during the simulation as it exits through the ports (after the excitation pulse ends), however due to inaccuracies and energy radiated it won't drop to 0. 268 | 269 | After the simulation finishes, the user can verify the data using `Paraview` (described in a [section below](#paraview)). 270 | 271 | ### Postprocessing 272 | 273 | This is an automatic step commenced with the `-p` flag. 274 | The script loads simulation data for each excited port. 275 | It then computes an FFT to get data in the frequency domain. 276 | It then converts the incident and reflected wave data to impedance and S parameters. 277 | These are saved in CSV format in the `ems/results/S-parameters` folder. 278 | This data is also automatically plotted and the plots are saved to `ems/results`. 279 | 280 | ## Paraview 281 | 282 | To view simulation data in Paraview, follow these steps: 283 | 284 | * Run `gerber2ems -a --export-field` 285 | * Run `ems2paraview ` 286 | 287 | `` is a simulated port number, defined in the `simulation.json`, 288 | to list all available ports use: `ems2paraview -l` 289 | 290 | ## Licensing 291 | 292 | This project is published under the [Apache-2.0](LICENSE) license. 293 | -------------------------------------------------------------------------------- /docs/images/S_11_smith.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmicro/gerber2ems/428346f1d1ef7e5c2bc67ee252246b9a1a1f0c30/docs/images/S_11_smith.png -------------------------------------------------------------------------------- /docs/images/S_x1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmicro/gerber2ems/428346f1d1ef7e5c2bc67ee252246b9a1a1f0c30/docs/images/S_x1.png -------------------------------------------------------------------------------- /docs/images/Z_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmicro/gerber2ems/428346f1d1ef7e5c2bc67ee252246b9a1a1f0c30/docs/images/Z_1.png -------------------------------------------------------------------------------- /docs/images/Z_ems+vna.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmicro/gerber2ems/428346f1d1ef7e5c2bc67ee252246b9a1a1f0c30/docs/images/Z_ems+vna.png -------------------------------------------------------------------------------- /examples/differential/fab/si-simulation-test-board-B_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1*% 2 | %TF.CreationDate,2025-02-21T12:43:02+01:00*% 3 | %TF.ProjectId,si-simulation-test-board,44494646-5f50-44e2-9e6b-696361645f70,1.0.1*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L4,Bot*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1) date 2025-02-21 12:43:02* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X140200000Y-114350000D03* 21 | X121960000Y-117215000D03* 22 | X108000000Y-117815000D03* 23 | X126560000Y-117215000D03* 24 | X118500000Y-117215000D03* 25 | X127600000Y-117215000D03* 26 | X140200000Y-108900000D03* 27 | X141725000Y-114375000D03* 28 | X129973654Y-117788654D03* 29 | X115160000Y-117215000D03* 30 | X119660000Y-117215000D03* 31 | X123100000Y-117215000D03* 32 | X114000000Y-117215000D03* 33 | X98100000Y-114368973D03* 34 | X132381000Y-106768000D03* 35 | X116300000Y-117215000D03* 36 | X125400000Y-117215000D03* 37 | X120616000Y-105327000D03* 38 | X124260000Y-117215000D03* 39 | X112860000Y-117215000D03* 40 | X98100000Y-108975000D03* 41 | X120621000Y-106658000D03* 42 | X117460000Y-117215000D03* 43 | X96325000Y-108975000D03* 44 | X110560000Y-117215000D03* 45 | X96325000Y-114368973D03* 46 | X109400000Y-117215000D03* 47 | X128760000Y-117215000D03* 48 | X141725000Y-108925000D03* 49 | X120800000Y-117215000D03* 50 | X111700000Y-117215000D03* 51 | %TD*% 52 | M02* 53 | -------------------------------------------------------------------------------- /examples/differential/fab/si-simulation-test-board-Edge_Cuts.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1*% 2 | %TF.CreationDate,2025-02-21T12:43:02+01:00*% 3 | %TF.ProjectId,si-simulation-test-board,44494646-5f50-44e2-9e6b-696361645f70,1.0.1*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Profile,NP*% 6 | %FSLAX46Y46*% 7 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 8 | G04 Created by KiCad (PCBNEW 8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1) date 2025-02-21 12:43:02* 9 | %MOMM*% 10 | %LPD*% 11 | G01* 12 | G04 APERTURE LIST* 13 | %TA.AperFunction,Profile*% 14 | %ADD10C,0.100000*% 15 | %TD*% 16 | G04 APERTURE END LIST* 17 | D10* 18 | X94300000Y-103992500D02* 19 | X143725000Y-103992500D01* 20 | X143725000Y-119336473D01* 21 | X94300000Y-119336473D01* 22 | X94300000Y-103992500D01* 23 | M02* 24 | -------------------------------------------------------------------------------- /examples/differential/fab/si-simulation-test-board-F_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1*% 2 | %TF.CreationDate,2025-02-21T12:43:02+01:00*% 3 | %TF.ProjectId,si-simulation-test-board,44494646-5f50-44e2-9e6b-696361645f70,1.0.1*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L1,Top*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1) date 2025-02-21 12:43:02* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | %TA.AperFunction,Conductor*% 18 | %ADD11C,0.185000*% 19 | %TD*% 20 | G04 APERTURE END LIST* 21 | D10* 22 | %TO.N,GND*% 23 | X140200000Y-114350000D03* 24 | X121960000Y-117215000D03* 25 | X108000000Y-117815000D03* 26 | X126560000Y-117215000D03* 27 | X118500000Y-117215000D03* 28 | X127600000Y-117215000D03* 29 | X140200000Y-108900000D03* 30 | X141725000Y-114375000D03* 31 | X129973654Y-117788654D03* 32 | X115160000Y-117215000D03* 33 | X119660000Y-117215000D03* 34 | X123100000Y-117215000D03* 35 | X114000000Y-117215000D03* 36 | X98100000Y-114368973D03* 37 | X132381000Y-106768000D03* 38 | X116300000Y-117215000D03* 39 | X125400000Y-117215000D03* 40 | X120616000Y-105327000D03* 41 | X124260000Y-117215000D03* 42 | X112860000Y-117215000D03* 43 | X98100000Y-108975000D03* 44 | X120621000Y-106658000D03* 45 | X117460000Y-117215000D03* 46 | X96325000Y-108975000D03* 47 | X110560000Y-117215000D03* 48 | X96325000Y-114368973D03* 49 | X109400000Y-117215000D03* 50 | X128760000Y-117215000D03* 51 | X141725000Y-108925000D03* 52 | X120800000Y-117215000D03* 53 | X111700000Y-117215000D03* 54 | %TD*% 55 | D11* 56 | %TO.N,/DIFF_P*% 57 | X136669632Y-111111105D02* 58 | X136396105Y-111384632D01* 59 | X136183973Y-111472500D02* 60 | X101881028Y-111472500D01* 61 | X101204632Y-106179632D02* 62 | X101105368Y-106080368D01* 63 | X136757500Y-106406765D02* 64 | X136757500Y-110898973D01* 65 | X101668896Y-111384632D02* 66 | X101380368Y-111096104D01* 67 | X136944633Y-106095368D02* 68 | X136845368Y-106194633D01* 69 | X141850000Y-105992500D02* 70 | X137156765Y-106007500D01* 71 | X101292500Y-110883972D02* 72 | X101292500Y-106391764D01* 73 | X100893236Y-105992500D02* 74 | X96150000Y-105992500D01* 75 | X136757500Y-110898973D02* 76 | G75* 77 | G02* 78 | X136669646Y-111111119I-300000J-27D01* 79 | G01* 80 | X101292500Y-106391764D02* 81 | G75* 82 | G03* 83 | X101204614Y-106179650I-300000J-36D01* 84 | G01* 85 | X101380368Y-111096104D02* 86 | G75* 87 | G02* 88 | X101292520Y-110883972I212132J212104D01* 89 | G01* 90 | X136845368Y-106194633D02* 91 | G75* 92 | G03* 93 | X136757475Y-106406765I212132J-212167D01* 94 | G01* 95 | X137156765Y-106007500D02* 96 | G75* 97 | G03* 98 | X136944650Y-106095385I35J-300000D01* 99 | G01* 100 | X136396105Y-111384632D02* 101 | G75* 102 | G02* 103 | X136183973Y-111472481I-212105J212132D01* 104 | G01* 105 | X101881028Y-111472500D02* 106 | G75* 107 | G02* 108 | X101668882Y-111384646I-28J300000D01* 109 | G01* 110 | X101105368Y-106080368D02* 111 | G75* 112 | G03* 113 | X100893236Y-105992475I-212168J-212132D01* 114 | G01* 115 | %TO.N,/DIFF_N*% 116 | X137131764Y-117299264D02* 117 | X141850000Y-117299264D01* 118 | X101841027Y-111807500D02* 119 | X136143972Y-111807500D01* 120 | X136356104Y-111895368D02* 121 | X136644632Y-112183896D01* 122 | X96150000Y-117299264D02* 123 | X100868235Y-117336473D01* 124 | X101267500Y-116937208D02* 125 | X101267500Y-112381027D01* 126 | X136732500Y-116900000D02* 127 | X136732500Y-112396028D01* 128 | X101080367Y-117248605D02* 129 | X101179632Y-117149340D01* 130 | X136820368Y-117112132D02* 131 | X136919632Y-117211396D01* 132 | X101355368Y-112168895D02* 133 | X101628895Y-111895368D01* 134 | X100868235Y-117336473D02* 135 | G75* 136 | G03* 137 | X101080344Y-117248582I-35J299973D01* 138 | G01* 139 | X136732500Y-116900000D02* 140 | G75* 141 | G03* 142 | X136820368Y-117112132I300000J0D01* 143 | G01* 144 | X136143972Y-111807500D02* 145 | G75* 146 | G02* 147 | X136356118Y-111895354I28J-300000D01* 148 | G01* 149 | X101179632Y-117149340D02* 150 | G75* 151 | G03* 152 | X101267506Y-116937208I-212132J212140D01* 153 | G01* 154 | X136644632Y-112183896D02* 155 | G75* 156 | G02* 157 | X136732480Y-112396028I-212132J-212104D01* 158 | G01* 159 | X101628895Y-111895368D02* 160 | G75* 161 | G02* 162 | X101841027Y-111807519I212105J-212132D01* 163 | G01* 164 | X101267500Y-112381027D02* 165 | G75* 166 | G02* 167 | X101355354Y-112168881I300000J27D01* 168 | G01* 169 | X136919632Y-117211396D02* 170 | G75* 171 | G03* 172 | X137131764Y-117299300I212168J212096D01* 173 | G01* 174 | %TD*% 175 | %TA.AperFunction,Conductor*% 176 | %TO.N,GND*% 177 | G36* 178 | X132768191Y-104211407D02* 179 | G01* 180 | X132804155Y-104260907D01* 181 | X132809000Y-104291500D01* 182 | X132809000Y-107028000D01* 183 | X132790093Y-107086191D01* 184 | X132740593Y-107122155D01* 185 | X132710000Y-107127000D01* 186 | X120338000Y-107127000D01* 187 | X120279809Y-107108093D01* 188 | X120243845Y-107058593D01* 189 | X120239000Y-107028000D01* 190 | X120239000Y-104291500D01* 191 | X120257907Y-104233309D01* 192 | X120307407Y-104197345D01* 193 | X120338000Y-104192500D01* 194 | X132710000Y-104192500D01* 195 | X132768191Y-104211407D01* 196 | G37* 197 | %TD.AperFunction*% 198 | %TD*% 199 | M02* 200 | -------------------------------------------------------------------------------- /examples/differential/fab/si-simulation-test-board-In1_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1*% 2 | %TF.CreationDate,2025-02-21T12:43:02+01:00*% 3 | %TF.ProjectId,si-simulation-test-board,44494646-5f50-44e2-9e6b-696361645f70,1.0.1*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L2,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1) date 2025-02-21 12:43:02* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X140200000Y-114350000D03* 21 | X121960000Y-117215000D03* 22 | X108000000Y-117815000D03* 23 | X126560000Y-117215000D03* 24 | X118500000Y-117215000D03* 25 | X127600000Y-117215000D03* 26 | X140200000Y-108900000D03* 27 | X141725000Y-114375000D03* 28 | X129973654Y-117788654D03* 29 | X115160000Y-117215000D03* 30 | X119660000Y-117215000D03* 31 | X123100000Y-117215000D03* 32 | X114000000Y-117215000D03* 33 | X98100000Y-114368973D03* 34 | X132381000Y-106768000D03* 35 | X116300000Y-117215000D03* 36 | X125400000Y-117215000D03* 37 | X120616000Y-105327000D03* 38 | X124260000Y-117215000D03* 39 | X112860000Y-117215000D03* 40 | X98100000Y-108975000D03* 41 | X120621000Y-106658000D03* 42 | X117460000Y-117215000D03* 43 | X96325000Y-108975000D03* 44 | X110560000Y-117215000D03* 45 | X96325000Y-114368973D03* 46 | X109400000Y-117215000D03* 47 | X128760000Y-117215000D03* 48 | X141725000Y-108925000D03* 49 | X120800000Y-117215000D03* 50 | X111700000Y-117215000D03* 51 | %TD*% 52 | %TA.AperFunction,Conductor*% 53 | %TO.N,GND*% 54 | G36* 55 | X143503326Y-104214174D02* 56 | G01* 57 | X143525000Y-104266500D01* 58 | X143525000Y-104676000D01* 59 | X143503326Y-104728326D01* 60 | X143451000Y-104750000D01* 61 | X139479500Y-104750000D01* 62 | X139479500Y-107240001D01* 63 | X143451000Y-107240000D01* 64 | X143503326Y-107261674D01* 65 | X143525000Y-107314000D01* 66 | X143525000Y-116026000D01* 67 | X143503326Y-116078326D01* 68 | X143451000Y-116100000D01* 69 | X139479500Y-116100000D01* 70 | X139479500Y-118590001D01* 71 | X143451000Y-118590000D01* 72 | X143503326Y-118611674D01* 73 | X143525000Y-118664000D01* 74 | X143525000Y-119062473D01* 75 | X143503326Y-119114799D01* 76 | X143451000Y-119136473D01* 77 | X135307797Y-119136473D01* 78 | X135292371Y-119134847D01* 79 | X129100007Y-117815001D01* 80 | X129100002Y-117815000D01* 81 | X129100000Y-117815000D01* 82 | X108900000Y-117815000D01* 83 | X108899999Y-117815000D01* 84 | X102607513Y-119134897D01* 85 | X102592322Y-119136473D01* 86 | X94574000Y-119136473D01* 87 | X94521674Y-119114799D01* 88 | X94500000Y-119062473D01* 89 | X94500000Y-118657973D01* 90 | X94521674Y-118605647D01* 91 | X94573997Y-118583973D01* 92 | X98500000Y-118583973D01* 93 | X98500000Y-116093973D01* 94 | X94574000Y-116093973D01* 95 | X94521674Y-116072299D01* 96 | X94500000Y-116019973D01* 97 | X94500000Y-107314000D01* 98 | X94521674Y-107261674D01* 99 | X94573997Y-107240000D01* 100 | X98500000Y-107240000D01* 101 | X98500000Y-104750000D01* 102 | X94574000Y-104750000D01* 103 | X94521674Y-104728326D01* 104 | X94500000Y-104676000D01* 105 | X94500000Y-104266500D01* 106 | X94521674Y-104214174D01* 107 | X94574000Y-104192500D01* 108 | X143451000Y-104192500D01* 109 | X143503326Y-104214174D01* 110 | G37* 111 | %TD.AperFunction*% 112 | %TD*% 113 | M02* 114 | -------------------------------------------------------------------------------- /examples/differential/fab/si-simulation-test-board-In2_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1*% 2 | %TF.CreationDate,2025-02-21T12:43:02+01:00*% 3 | %TF.ProjectId,si-simulation-test-board,44494646-5f50-44e2-9e6b-696361645f70,1.0.1*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L3,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1) date 2025-02-21 12:43:02* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X140200000Y-114350000D03* 21 | X121960000Y-117215000D03* 22 | X108000000Y-117815000D03* 23 | X126560000Y-117215000D03* 24 | X118500000Y-117215000D03* 25 | X127600000Y-117215000D03* 26 | X140200000Y-108900000D03* 27 | X141725000Y-114375000D03* 28 | X129973654Y-117788654D03* 29 | X115160000Y-117215000D03* 30 | X119660000Y-117215000D03* 31 | X123100000Y-117215000D03* 32 | X114000000Y-117215000D03* 33 | X98100000Y-114368973D03* 34 | X132381000Y-106768000D03* 35 | X116300000Y-117215000D03* 36 | X125400000Y-117215000D03* 37 | X120616000Y-105327000D03* 38 | X124260000Y-117215000D03* 39 | X112860000Y-117215000D03* 40 | X98100000Y-108975000D03* 41 | X120621000Y-106658000D03* 42 | X117460000Y-117215000D03* 43 | X96325000Y-108975000D03* 44 | X110560000Y-117215000D03* 45 | X96325000Y-114368973D03* 46 | X109400000Y-117215000D03* 47 | X128760000Y-117215000D03* 48 | X141725000Y-108925000D03* 49 | X120800000Y-117215000D03* 50 | X111700000Y-117215000D03* 51 | %TD*% 52 | %TA.AperFunction,Conductor*% 53 | %TO.N,GND*% 54 | G36* 55 | X143503326Y-104214174D02* 56 | G01* 57 | X143525000Y-104266500D01* 58 | X143525000Y-119062473D01* 59 | X143503326Y-119114799D01* 60 | X143451000Y-119136473D01* 61 | X94574000Y-119136473D01* 62 | X94521674Y-119114799D01* 63 | X94500000Y-119062473D01* 64 | X94500000Y-104266500D01* 65 | X94521674Y-104214174D01* 66 | X94574000Y-104192500D01* 67 | X143451000Y-104192500D01* 68 | X143503326Y-104214174D01* 69 | G37* 70 | %TD.AperFunction*% 71 | %TD*% 72 | M02* 73 | -------------------------------------------------------------------------------- /examples/differential/fab/si-simulation-test-board-PTH.drl: -------------------------------------------------------------------------------- 1 | M48 2 | ; DRILL file {KiCad 8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1} date 2025-02-21T12:43:02+0100 3 | ; FORMAT={-:-/ absolute / metric / decimal} 4 | ; #@! TF.CreationDate,2025-02-21T12:43:02+01:00 5 | ; #@! TF.GenerationSoftware,Kicad,Pcbnew,8.0.7-rc1-202412020537~5dd4718db0~ubuntu22.04.1 6 | ; #@! TF.FileFunction,Plated,1,4,PTH 7 | FMAT,2 8 | METRIC 9 | ; #@! TA.AperFunction,Plated,PTH,ViaDrill 10 | T1C0.200 11 | % 12 | G90 13 | G05 14 | T1 15 | X2.025Y10.361 16 | X2.025Y4.967 17 | X3.8Y10.361 18 | X3.8Y4.967 19 | X13.7Y1.521 20 | X15.1Y2.121 21 | X16.26Y2.121 22 | X17.4Y2.121 23 | X18.56Y2.121 24 | X19.7Y2.121 25 | X20.86Y2.121 26 | X22.0Y2.121 27 | X23.16Y2.121 28 | X24.2Y2.121 29 | X25.36Y2.121 30 | X26.316Y14.009 31 | X26.321Y12.678 32 | X26.5Y2.121 33 | X27.66Y2.121 34 | X28.8Y2.121 35 | X29.96Y2.121 36 | X31.1Y2.121 37 | X32.26Y2.121 38 | X33.3Y2.121 39 | X34.46Y2.121 40 | X35.674Y1.548 41 | X38.081Y12.568 42 | X45.9Y10.436 43 | X45.9Y4.986 44 | X47.425Y10.411 45 | X47.425Y4.961 46 | M30 47 | -------------------------------------------------------------------------------- /examples/differential/fab/si-simulation-test-board-bottom-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | -------------------------------------------------------------------------------- /examples/differential/fab/si-simulation-test-board-top-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | "SP1","Simulation_Port","Simulation_Port",47.550000,13.343973,90.000000,top 3 | "SP2","Simulation_Port","Simulation_Port",1.850000,13.343973,-90.000000,top 4 | "SP3","Simulation_Port","Simulation_Port",47.550000,2.037209,90.000000,top 5 | "SP4","Simulation_Port","Simulation_Port",1.850000,2.037209,-90.000000,top 6 | -------------------------------------------------------------------------------- /examples/differential/fab/stackup.json: -------------------------------------------------------------------------------- 1 | {"layers": [{"name": "F.SilkS", "type": "Top Silk Screen", "color": null, "thickness": null, "material": null, "epsilon": null, "lossTangent": null, "user-name": "F_Silkscreen"}, {"name": "F.Paste", "type": "Top Solder Paste", "color": null, "thickness": null, "material": null, "epsilon": null, "lossTangent": null, "user-name": "F_Paste"}, {"name": "F.Mask", "type": "Top Solder Mask", "color": "Black", "thickness": 0.01, "material": null, "epsilon": null, "lossTangent": null, "user-name": "F_Mask"}, {"name": "F.Cu", "type": "copper", "color": null, "thickness": 0.035, "material": null, "epsilon": null, "lossTangent": null, "user-name": "F_Cu"}, {"name": "dielectric 1", "type": "core", "color": null, "thickness": 0.12, "material": "FR4", "epsilon": 4.18, "lossTangent": 0.02, "user-name": "dielectric 1"}, {"name": "In1.Cu", "type": "copper", "color": null, "thickness": 0.035, "material": null, "epsilon": null, "lossTangent": null, "user-name": "In1_Cu"}, {"name": "dielectric 2", "type": "prepreg", "color": null, "thickness": 1.2, "material": "FR4", "epsilon": 4.18, "lossTangent": 0.02, "user-name": "dielectric 2"}, {"name": "In2.Cu", "type": "copper", "color": null, "thickness": 0.035, "material": null, "epsilon": null, "lossTangent": null, "user-name": "In2_Cu"}, {"name": "dielectric 3", "type": "core", "color": null, "thickness": 0.12, "material": "FR4", "epsilon": 4.18, "lossTangent": 0.02, "user-name": "dielectric 3"}, {"name": "B.Cu", "type": "copper", "color": null, "thickness": 0.035, "material": null, "epsilon": null, "lossTangent": null, "user-name": "B_Cu"}, {"name": "B.Mask", "type": "Bottom Solder Mask", "color": "Black", "thickness": 0.01, "material": null, "epsilon": null, "lossTangent": null, "user-name": "B_Mask"}, {"name": "B.Paste", "type": "Bottom Solder Paste", "color": null, "thickness": null, "material": null, "epsilon": null, "lossTangent": null, "user-name": "B_Paste"}, {"name": "B.SilkS", "type": "Bottom Silk Screen", "color": null, "thickness": null, "material": null, "epsilon": null, "lossTangent": null, "user-name": "B_Silkscreen"}], "format_version": "1.0"} -------------------------------------------------------------------------------- /examples/differential/simulation.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.2", 3 | "frequency": { 4 | "start": 200000000.0, 5 | "stop": 6000000000.0 6 | }, 7 | "max_steps": 57395, 8 | "ports": [ 9 | { 10 | "number": 1, 11 | "width": 300, 12 | "length": 500, 13 | "impedance": 50, 14 | "layer": 0, 15 | "plane": 2, 16 | "excite": true 17 | }, 18 | { 19 | "number": 2, 20 | "width": 300, 21 | "length": 500, 22 | "impedance": 50, 23 | "layer": 0, 24 | "plane": 2, 25 | "excite": false 26 | }, 27 | { 28 | "number": 3, 29 | "width": 300, 30 | "length": 500, 31 | "impedance": 50, 32 | "layer": 0, 33 | "plane": 2, 34 | "excite": true 35 | }, 36 | { 37 | "number": 4, 38 | "width": 300, 39 | "length": 500, 40 | "impedance": 50, 41 | "layer": 0, 42 | "plane": 2, 43 | "excite": false 44 | } 45 | ], 46 | "differential_pairs": [ 47 | { 48 | "start_p": 0, 49 | "stop_p": 1, 50 | "start_n": 2, 51 | "stop_n": 3, 52 | "name": "DIFF" 53 | } 54 | ] 55 | } 56 | -------------------------------------------------------------------------------- /examples/filter/fab/si-simulation-test-board-B_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T13:05:29+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L4,Bot*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 13:05:29* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X125245000Y-130915000D03* 21 | X110540000Y-130915000D03* 22 | X117840000Y-130915000D03* 23 | X113740000Y-120115000D03* 24 | X122840000Y-120115000D03* 25 | X125945000Y-130915000D03* 26 | X109840000Y-130915000D03* 27 | X122140000Y-120115000D03* 28 | X118540000Y-130915000D03* 29 | X111240000Y-130915000D03* 30 | X126645000Y-130915000D03* 31 | X114440000Y-120115000D03* 32 | %TD*% 33 | M02* 34 | -------------------------------------------------------------------------------- /examples/filter/fab/si-simulation-test-board-Edge_Cuts.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T13:05:29+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Profile,NP*% 6 | %FSLAX46Y46*% 7 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 8 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 13:05:29* 9 | %MOMM*% 10 | %LPD*% 11 | G01* 12 | G04 APERTURE LIST* 13 | %TA.AperFunction,Profile*% 14 | %ADD10C,0.100000*% 15 | %TD*% 16 | G04 APERTURE END LIST* 17 | D10* 18 | X94000000Y-118000000D02* 19 | X144000000Y-118000000D01* 20 | X144000000Y-133000000D01* 21 | X94000000Y-133000000D01* 22 | X94000000Y-118000000D01* 23 | M02* 24 | -------------------------------------------------------------------------------- /examples/filter/fab/si-simulation-test-board-F_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T13:05:29+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L1,Top*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 13:05:29* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,NonConductor*% 15 | %ADD10C,2.200000*% 16 | %TD*% 17 | %TA.AperFunction,ViaPad*% 18 | %ADD11C,0.550000*% 19 | %TD*% 20 | G04 APERTURE END LIST* 21 | %TA.AperFunction,NonConductor*% 22 | G36* 23 | X124850000Y-119365000D02* 24 | G01* 25 | X127040000Y-119365000D01* 26 | X127040000Y-130915000D01* 27 | X124850000Y-130915000D01* 28 | X124850000Y-119365000D01* 29 | G37* 30 | %TD.AperFunction*% 31 | %TA.AperFunction,NonConductor*% 32 | G36* 33 | X117455000Y-120085000D02* 34 | G01* 35 | X119045000Y-120085000D01* 36 | X119045000Y-130915000D01* 37 | X117455000Y-130915000D01* 38 | X117455000Y-120085000D01* 39 | G37* 40 | %TD.AperFunction*% 41 | %TA.AperFunction,NonConductor*% 42 | G36* 43 | X113250000Y-120085000D02* 44 | G01* 45 | X114840000Y-120085000D01* 46 | X114840000Y-130915000D01* 47 | X113250000Y-130915000D01* 48 | X113250000Y-120085000D01* 49 | G37* 50 | %TD.AperFunction*% 51 | %TA.AperFunction,NonConductor*% 52 | G36* 53 | X109450000Y-119365000D02* 54 | G01* 55 | X111640000Y-119365000D01* 56 | X111640000Y-130915000D01* 57 | X109450000Y-130915000D01* 58 | X109450000Y-119365000D01* 59 | G37* 60 | %TD.AperFunction*% 61 | D10* 62 | X141825000Y-127622500D02* 63 | X125945000Y-127615000D01* 64 | %TA.AperFunction,NonConductor*% 65 | G36* 66 | X121655000Y-120085000D02* 67 | G01* 68 | X123245000Y-120085000D01* 69 | X123245000Y-130915000D01* 70 | X121655000Y-130915000D01* 71 | X121655000Y-120085000D01* 72 | G37* 73 | %TD.AperFunction*% 74 | X110495000Y-127615000D02* 75 | X96700000Y-127615000D01* 76 | D11* 77 | %TO.N,GND*% 78 | X125245000Y-130915000D03* 79 | X110540000Y-130915000D03* 80 | X117840000Y-130915000D03* 81 | X113740000Y-120115000D03* 82 | X122840000Y-120115000D03* 83 | X125945000Y-130915000D03* 84 | X109840000Y-130915000D03* 85 | X122140000Y-120115000D03* 86 | X118540000Y-130915000D03* 87 | X111240000Y-130915000D03* 88 | X126645000Y-130915000D03* 89 | X114440000Y-120115000D03* 90 | %TD*% 91 | M02* 92 | -------------------------------------------------------------------------------- /examples/filter/fab/si-simulation-test-board-In1_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T13:05:29+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L2,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 13:05:29* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X125245000Y-130915000D03* 21 | X110540000Y-130915000D03* 22 | X117840000Y-130915000D03* 23 | X113740000Y-120115000D03* 24 | X122840000Y-120115000D03* 25 | X125945000Y-130915000D03* 26 | X109840000Y-130915000D03* 27 | X122140000Y-120115000D03* 28 | X118540000Y-130915000D03* 29 | X111240000Y-130915000D03* 30 | X126645000Y-130915000D03* 31 | X114440000Y-120115000D03* 32 | %TD*% 33 | %TA.AperFunction,Conductor*% 34 | %TO.N,GND*% 35 | G36* 36 | X98516914Y-129732313D02* 37 | G01* 38 | X98521674Y-129736674D01* 39 | X98778326Y-129993326D01* 40 | X98799718Y-130039202D01* 41 | X98800000Y-130045652D01* 42 | X98800000Y-132925500D01* 43 | X98782687Y-132973066D01* 44 | X98738850Y-132998376D01* 45 | X98726000Y-132999500D01* 46 | X94074500Y-132999500D01* 47 | X94026934Y-132982187D01* 48 | X94001624Y-132938350D01* 49 | X94000500Y-132925500D01* 50 | X94000500Y-129789000D01* 51 | X94017813Y-129741434D01* 52 | X94061650Y-129716124D01* 53 | X94074500Y-129715000D01* 54 | X94100000Y-129715000D01* 55 | X98469348Y-129715000D01* 56 | X98516914Y-129732313D01* 57 | G37* 58 | %TD.AperFunction*% 59 | %TA.AperFunction,Conductor*% 60 | G36* 61 | X143973066Y-129732313D02* 62 | G01* 63 | X143998376Y-129776150D01* 64 | X143999500Y-129789000D01* 65 | X143999500Y-132925500D01* 66 | X143982187Y-132973066D01* 67 | X143938350Y-132998376D01* 68 | X143925500Y-132999500D01* 69 | X139374000Y-132999500D01* 70 | X139326434Y-132982187D01* 71 | X139301124Y-132938350D01* 72 | X139300000Y-132925500D01* 73 | X139300000Y-130245652D01* 74 | X139317313Y-130198086D01* 75 | X139321674Y-130193326D01* 76 | X139778326Y-129736674D01* 77 | X139824202Y-129715282D01* 78 | X139830652Y-129715000D01* 79 | X143925500Y-129715000D01* 80 | X143973066Y-129732313D01* 81 | G37* 82 | %TD.AperFunction*% 83 | %TA.AperFunction,Conductor*% 84 | G36* 85 | X143973066Y-118017813D02* 86 | G01* 87 | X143998376Y-118061650D01* 88 | X143999500Y-118074500D01* 89 | X143999500Y-125541000D01* 90 | X143982187Y-125588566D01* 91 | X143938350Y-125613876D01* 92 | X143925500Y-125615000D01* 93 | X139630652Y-125615000D01* 94 | X139583086Y-125597687D01* 95 | X139578326Y-125593326D01* 96 | X139321674Y-125336674D01* 97 | X139300282Y-125290798D01* 98 | X139300000Y-125284348D01* 99 | X139300000Y-125015000D01* 100 | X138300000Y-124015000D01* 101 | X135330652Y-124015000D01* 102 | X135283086Y-123997687D01* 103 | X135278326Y-123993326D01* 104 | X129411826Y-118126826D01* 105 | X129390434Y-118080950D01* 106 | X129403535Y-118032055D01* 107 | X129444999Y-118003021D01* 108 | X129464152Y-118000500D01* 109 | X143925500Y-118000500D01* 110 | X143973066Y-118017813D01* 111 | G37* 112 | %TD.AperFunction*% 113 | %TA.AperFunction,Conductor*% 114 | G36* 115 | X108583414Y-118017813D02* 116 | G01* 117 | X108608724Y-118061650D01* 118 | X108599934Y-118111500D01* 119 | X108588174Y-118126826D01* 120 | X102621674Y-124093326D01* 121 | X102575798Y-124114718D01* 122 | X102569348Y-124115000D01* 123 | X98900000Y-124115000D01* 124 | X98900000Y-125084348D01* 125 | X98882687Y-125131914D01* 126 | X98878326Y-125136674D01* 127 | X98521674Y-125493326D01* 128 | X98475798Y-125514718D01* 129 | X98469348Y-125515000D01* 130 | X94074500Y-125515000D01* 131 | X94026934Y-125497687D01* 132 | X94001624Y-125453850D01* 133 | X94000500Y-125441000D01* 134 | X94000500Y-118074500D01* 135 | X94017813Y-118026934D01* 136 | X94061650Y-118001624D01* 137 | X94074500Y-118000500D01* 138 | X108535848Y-118000500D01* 139 | X108583414Y-118017813D01* 140 | G37* 141 | %TD.AperFunction*% 142 | %TD*% 143 | M02* 144 | -------------------------------------------------------------------------------- /examples/filter/fab/si-simulation-test-board-In2_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T13:05:29+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L3,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 13:05:29* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X125245000Y-130915000D03* 21 | X110540000Y-130915000D03* 22 | X117840000Y-130915000D03* 23 | X113740000Y-120115000D03* 24 | X122840000Y-120115000D03* 25 | X125945000Y-130915000D03* 26 | X109840000Y-130915000D03* 27 | X122140000Y-120115000D03* 28 | X118540000Y-130915000D03* 29 | X111240000Y-130915000D03* 30 | X126645000Y-130915000D03* 31 | X114440000Y-120115000D03* 32 | %TD*% 33 | %TA.AperFunction,Conductor*% 34 | %TO.N,GND*% 35 | G36* 36 | X143973066Y-118017813D02* 37 | G01* 38 | X143998376Y-118061650D01* 39 | X143999500Y-118074500D01* 40 | X143999500Y-132925500D01* 41 | X143982187Y-132973066D01* 42 | X143938350Y-132998376D01* 43 | X143925500Y-132999500D01* 44 | X94074500Y-132999500D01* 45 | X94026934Y-132982187D01* 46 | X94001624Y-132938350D01* 47 | X94000500Y-132925500D01* 48 | X94000500Y-118074500D01* 49 | X94017813Y-118026934D01* 50 | X94061650Y-118001624D01* 51 | X94074500Y-118000500D01* 52 | X143925500Y-118000500D01* 53 | X143973066Y-118017813D01* 54 | G37* 55 | %TD.AperFunction*% 56 | %TD*% 57 | M02* 58 | -------------------------------------------------------------------------------- /examples/filter/fab/si-simulation-test-board-PTH.drl: -------------------------------------------------------------------------------- 1 | M48 2 | ; DRILL file {KiCad 7.0.6-7.0.6~ubuntu22.04.1} date Fri 01 Sep 2023 13:05:29 CEST 3 | ; FORMAT={-:-/ absolute / metric / decimal} 4 | ; #@! TF.CreationDate,2023-09-01T13:05:29+02:00 5 | ; #@! TF.GenerationSoftware,Kicad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1 6 | ; #@! TF.FileFunction,Plated,1,4,PTH 7 | FMAT,2 8 | METRIC 9 | ; #@! TA.AperFunction,Plated,PTH,ViaDrill 10 | T1C0.200 11 | % 12 | G90 13 | G05 14 | T1 15 | X15.84Y2.085 16 | X16.54Y2.085 17 | X17.24Y2.085 18 | X19.74Y12.885 19 | X20.44Y12.885 20 | X23.84Y2.085 21 | X24.54Y2.085 22 | X28.14Y12.885 23 | X28.84Y12.885 24 | X31.245Y2.085 25 | X31.945Y2.085 26 | X32.645Y2.085 27 | T0 28 | M30 29 | -------------------------------------------------------------------------------- /examples/filter/fab/si-simulation-test-board-bottom-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | -------------------------------------------------------------------------------- /examples/filter/fab/si-simulation-test-board-top-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | SP1,Simulation_Port,Simulation_Port,1.6,5.4,-90,top 3 | SP2,Simulation_Port,Simulation_Port,49,5.4,90,top 4 | -------------------------------------------------------------------------------- /examples/filter/fab/stackup.json: -------------------------------------------------------------------------------- 1 | { 2 | "layers": [ 3 | { 4 | "name": "F.SilkS", 5 | "type": "Top Silk Screen", 6 | "color": null, 7 | "thickness": null, 8 | "material": null, 9 | "epsilon": null, 10 | "lossTangent": null 11 | }, 12 | { 13 | "name": "F.Paste", 14 | "type": "Top Solder Paste", 15 | "color": null, 16 | "thickness": null, 17 | "material": null, 18 | "epsilon": null, 19 | "lossTangent": null 20 | }, 21 | { 22 | "name": "F.Mask", 23 | "type": "Top Solder Mask", 24 | "color": "Black", 25 | "thickness": 0.01, 26 | "material": null, 27 | "epsilon": null, 28 | "lossTangent": null 29 | }, 30 | { 31 | "name": "F.Cu", 32 | "type": "copper", 33 | "color": null, 34 | "thickness": 0.035, 35 | "material": null, 36 | "epsilon": null, 37 | "lossTangent": null 38 | }, 39 | { 40 | "name": "dielectric 1", 41 | "type": "core", 42 | "color": null, 43 | "thickness": 1.32, 44 | "material": "FR4", 45 | "epsilon": 4.18, 46 | "lossTangent": 0.02 47 | }, 48 | { 49 | "name": "In2.Cu", 50 | "type": "copper", 51 | "color": null, 52 | "thickness": 0.035, 53 | "material": null, 54 | "epsilon": null, 55 | "lossTangent": null 56 | }, 57 | { 58 | "name": "B.Mask", 59 | "type": "Bottom Solder Mask", 60 | "color": "Black", 61 | "thickness": 0.01, 62 | "material": null, 63 | "epsilon": null, 64 | "lossTangent": null 65 | }, 66 | { 67 | "name": "B.Paste", 68 | "type": "Bottom Solder Paste", 69 | "color": null, 70 | "thickness": null, 71 | "material": null, 72 | "epsilon": null, 73 | "lossTangent": null 74 | }, 75 | { 76 | "name": "B.SilkS", 77 | "type": "Bottom Silk Screen", 78 | "color": null, 79 | "thickness": null, 80 | "material": null, 81 | "epsilon": null, 82 | "lossTangent": null 83 | } 84 | ], 85 | "format_version": "1.0" 86 | } -------------------------------------------------------------------------------- /examples/filter/simulation.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.2", 3 | "frequency": { 4 | "start": 200000000.0, 5 | "stop": 6000000000.0 6 | }, 7 | "max_steps": 39845, 8 | "pixel_size": 2.5, 9 | "ports": [ 10 | { 11 | "width": 2200, 12 | "length": 3000, 13 | "impedance": 50, 14 | "layer": 0, 15 | "plane": 1, 16 | "excite": true 17 | }, 18 | { 19 | "width": 2200, 20 | "length": 3000, 21 | "impedance": 50, 22 | "layer": 0, 23 | "plane": 1, 24 | "excite": true 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /examples/meander_loose/fab/si-simulation-test-board-B_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T09:52:36+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L4,Bot*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 09:52:36* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X111015000Y-54075000D03* 21 | X111040000Y-52550000D03* 22 | X117015000Y-55850001D03* 23 | X117015000Y-54075000D03* 24 | X117040000Y-52550000D03* 25 | X111015000Y-55850000D03* 26 | %TD*% 27 | M02* 28 | -------------------------------------------------------------------------------- /examples/meander_loose/fab/si-simulation-test-board-Edge_Cuts.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T09:52:36+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Profile,NP*% 6 | %FSLAX46Y46*% 7 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 8 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 09:52:36* 9 | %MOMM*% 10 | %LPD*% 11 | G01* 12 | G04 APERTURE LIST* 13 | %TA.AperFunction,Profile*% 14 | %ADD10C,0.100000*% 15 | %TD*% 16 | G04 APERTURE END LIST* 17 | D10* 18 | X110000000Y-52000000D02* 19 | X117500000Y-52000000D01* 20 | X117500000Y-72500000D01* 21 | X110000000Y-72500000D01* 22 | X110000000Y-52000000D01* 23 | M02* 24 | -------------------------------------------------------------------------------- /examples/meander_loose/fab/si-simulation-test-board-F_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T09:52:36+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L1,Top*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 09:52:36* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | %TA.AperFunction,Conductor*% 18 | %ADD11C,0.185000*% 19 | %TD*% 20 | G04 APERTURE END LIST* 21 | D10* 22 | %TO.N,GND*% 23 | X111015000Y-54075000D03* 24 | X111040000Y-52550000D03* 25 | X117015000Y-55850001D03* 26 | X117015000Y-54075000D03* 27 | X117040000Y-52550000D03* 28 | X111015000Y-55850000D03* 29 | %TD*% 30 | D11* 31 | %TO.N,unconnected-(J21-Pad1)*% 32 | X113997500Y-68832500D02* 33 | X114562862Y-68832500D01* 34 | X113432138Y-68832500D02* 35 | X113997500Y-68832500D01* 36 | X113997500Y-60832500D02* 37 | X114562862Y-60832500D01* 38 | X114562862Y-63232500D02* 39 | X113997500Y-63232500D01* 40 | X114562862Y-61632500D02* 41 | X113997500Y-61632500D01* 42 | X114562862Y-69632500D02* 43 | X114397500Y-69632500D01* 44 | X113997500Y-64832500D02* 45 | X113432138Y-64832500D01* 46 | X113997500Y-66432500D02* 47 | X113432138Y-66432500D01* 48 | X113997500Y-54175000D02* 49 | X113997500Y-57232500D01* 50 | X113997500Y-62432500D02* 51 | X114562862Y-62432500D01* 52 | X113997500Y-60032500D02* 53 | X113432138Y-60032500D01* 54 | X114562862Y-66432500D02* 55 | X113997500Y-66432500D01* 56 | X113997500Y-67232500D02* 57 | X114562862Y-67232500D01* 58 | X113997500Y-64032500D02* 59 | X114562862Y-64032500D01* 60 | X114562862Y-64832500D02* 61 | X113997500Y-64832500D01* 62 | X113432138Y-67232500D02* 63 | X113997500Y-67232500D01* 64 | X113432138Y-62432500D02* 65 | X113997500Y-62432500D01* 66 | X113432138Y-59232500D02* 67 | X113997500Y-59232500D01* 68 | X114562862Y-58432500D02* 69 | X114397500Y-58432500D01* 70 | X114397500Y-58432500D02* 71 | X113432138Y-58432500D01* 72 | X113432138Y-65632500D02* 73 | X113997500Y-65632500D01* 74 | X113997500Y-63232500D02* 75 | X113432138Y-63232500D01* 76 | X114562862Y-60032500D02* 77 | X113997500Y-60032500D01* 78 | X114397500Y-57632500D02* 79 | X114562862Y-57632500D01* 80 | X113997500Y-65632500D02* 81 | X114562862Y-65632500D01* 82 | X113997500Y-61632500D02* 83 | X113432138Y-61632500D01* 84 | X113432138Y-64032500D02* 85 | X113997500Y-64032500D01* 86 | X113997500Y-70032500D02* 87 | X113997500Y-70707989D01* 88 | X113432138Y-60832500D02* 89 | X113997500Y-60832500D01* 90 | X113997500Y-59232500D02* 91 | X114562862Y-59232500D01* 92 | X113997500Y-68032500D02* 93 | X113432138Y-68032500D01* 94 | X114562862Y-68032500D02* 95 | X113997500Y-68032500D01* 96 | X114962900Y-69232500D02* 97 | G75* 98 | G03* 99 | X114562862Y-68832500I-400000J0D01* 100 | G01* 101 | X114562862Y-60032462D02* 102 | G75* 103 | G03* 104 | X114962862Y-59632500I38J399962D01* 105 | G01* 106 | X114562862Y-68032462D02* 107 | G75* 108 | G03* 109 | X114962862Y-67632500I38J399962D01* 110 | G01* 111 | X114962900Y-59632500D02* 112 | G75* 113 | G03* 114 | X114562862Y-59232500I-400000J0D01* 115 | G01* 116 | X113997500Y-57232500D02* 117 | G75* 118 | G03* 119 | X114397500Y-57632500I400000J0D01* 120 | G01* 121 | X114962900Y-64432500D02* 122 | G75* 123 | G03* 124 | X114562862Y-64032500I-400000J0D01* 125 | G01* 126 | X113032100Y-68432500D02* 127 | G75* 128 | G03* 129 | X113432138Y-68832500I400000J0D01* 130 | G01* 131 | X114562862Y-66432462D02* 132 | G75* 133 | G03* 134 | X114962862Y-66032500I38J399962D01* 135 | G01* 136 | X114562862Y-58432462D02* 137 | G75* 138 | G03* 139 | X114962862Y-58032500I38J399962D01* 140 | G01* 141 | X114962900Y-62832500D02* 142 | G75* 143 | G03* 144 | X114562862Y-62432500I-400000J0D01* 145 | G01* 146 | X114962900Y-61232500D02* 147 | G75* 148 | G03* 149 | X114562862Y-60832500I-400000J0D01* 150 | G01* 151 | X113032100Y-58832500D02* 152 | G75* 153 | G03* 154 | X113432138Y-59232500I400000J0D01* 155 | G01* 156 | X113432138Y-68032538D02* 157 | G75* 158 | G03* 159 | X113032138Y-68432500I-38J-399962D01* 160 | G01* 161 | X113432138Y-58432538D02* 162 | G75* 163 | G03* 164 | X113032138Y-58832500I-38J-399962D01* 165 | G01* 166 | X114562862Y-69632462D02* 167 | G75* 168 | G03* 169 | X114962862Y-69232500I38J399962D01* 170 | G01* 171 | X114397500Y-69632500D02* 172 | G75* 173 | G03* 174 | X113997500Y-70032500I0J-400000D01* 175 | G01* 176 | X113032100Y-65232500D02* 177 | G75* 178 | G03* 179 | X113432138Y-65632500I400000J0D01* 180 | G01* 181 | X113032100Y-63632500D02* 182 | G75* 183 | G03* 184 | X113432138Y-64032500I400000J0D01* 185 | G01* 186 | X114562862Y-63232462D02* 187 | G75* 188 | G03* 189 | X114962862Y-62832500I38J399962D01* 190 | G01* 191 | X113432138Y-63232538D02* 192 | G75* 193 | G03* 194 | X113032138Y-63632500I-38J-399962D01* 195 | G01* 196 | X114962900Y-58032500D02* 197 | G75* 198 | G03* 199 | X114562862Y-57632500I-400000J0D01* 200 | G01* 201 | X113432138Y-60032538D02* 202 | G75* 203 | G03* 204 | X113032138Y-60432500I-38J-399962D01* 205 | G01* 206 | X113432138Y-64832538D02* 207 | G75* 208 | G03* 209 | X113032138Y-65232500I-38J-399962D01* 210 | G01* 211 | X113432138Y-66432538D02* 212 | G75* 213 | G03* 214 | X113032138Y-66832500I-38J-399962D01* 215 | G01* 216 | X114562862Y-61632462D02* 217 | G75* 218 | G03* 219 | X114962862Y-61232500I38J399962D01* 220 | G01* 221 | X114562862Y-64832462D02* 222 | G75* 223 | G03* 224 | X114962862Y-64432500I38J399962D01* 225 | G01* 226 | X113032100Y-60432500D02* 227 | G75* 228 | G03* 229 | X113432138Y-60832500I400000J0D01* 230 | G01* 231 | X113032100Y-66832500D02* 232 | G75* 233 | G03* 234 | X113432138Y-67232500I400000J0D01* 235 | G01* 236 | X114962900Y-67632500D02* 237 | G75* 238 | G03* 239 | X114562862Y-67232500I-400000J0D01* 240 | G01* 241 | X113432138Y-61632538D02* 242 | G75* 243 | G03* 244 | X113032138Y-62032500I-38J-399962D01* 245 | G01* 246 | X113032100Y-62032500D02* 247 | G75* 248 | G03* 249 | X113432138Y-62432500I400000J0D01* 250 | G01* 251 | X114962900Y-66032500D02* 252 | G75* 253 | G03* 254 | X114562862Y-65632500I-400000J0D01* 255 | G01* 256 | %TD*% 257 | M02* 258 | -------------------------------------------------------------------------------- /examples/meander_loose/fab/si-simulation-test-board-In1_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T09:52:36+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L2,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 09:52:36* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X111015000Y-54075000D03* 21 | X111040000Y-52550000D03* 22 | X117015000Y-55850001D03* 23 | X117015000Y-54075000D03* 24 | X117040000Y-52550000D03* 25 | X111015000Y-55850000D03* 26 | %TD*% 27 | %TA.AperFunction,Conductor*% 28 | %TO.N,GND*% 29 | G36* 30 | X117473066Y-52017813D02* 31 | G01* 32 | X117498376Y-52061650D01* 33 | X117499500Y-52074500D01* 34 | X117499500Y-72425500D01* 35 | X117482187Y-72473066D01* 36 | X117438350Y-72498376D01* 37 | X117425500Y-72499500D01* 38 | X110074500Y-72499500D01* 39 | X110026934Y-72482187D01* 40 | X110001624Y-72438350D01* 41 | X110000500Y-72425500D01* 42 | X110000500Y-52074500D01* 43 | X110017813Y-52026934D01* 44 | X110061650Y-52001624D01* 45 | X110074500Y-52000500D01* 46 | X117425500Y-52000500D01* 47 | X117473066Y-52017813D01* 48 | G37* 49 | %TD.AperFunction*% 50 | %TD*% 51 | M02* 52 | -------------------------------------------------------------------------------- /examples/meander_loose/fab/si-simulation-test-board-In2_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T09:52:36+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L3,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 09:52:36* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X111015000Y-54075000D03* 21 | X111040000Y-52550000D03* 22 | X117015000Y-55850001D03* 23 | X117015000Y-54075000D03* 24 | X117040000Y-52550000D03* 25 | X111015000Y-55850000D03* 26 | %TD*% 27 | %TA.AperFunction,Conductor*% 28 | %TO.N,GND*% 29 | G36* 30 | X117473066Y-52017813D02* 31 | G01* 32 | X117498376Y-52061650D01* 33 | X117499500Y-52074500D01* 34 | X117499500Y-72425500D01* 35 | X117482187Y-72473066D01* 36 | X117438350Y-72498376D01* 37 | X117425500Y-72499500D01* 38 | X110074500Y-72499500D01* 39 | X110026934Y-72482187D01* 40 | X110001624Y-72438350D01* 41 | X110000500Y-72425500D01* 42 | X110000500Y-52074500D01* 43 | X110017813Y-52026934D01* 44 | X110061650Y-52001624D01* 45 | X110074500Y-52000500D01* 46 | X117425500Y-52000500D01* 47 | X117473066Y-52017813D01* 48 | G37* 49 | %TD.AperFunction*% 50 | %TD*% 51 | M02* 52 | -------------------------------------------------------------------------------- /examples/meander_loose/fab/si-simulation-test-board-PTH.drl: -------------------------------------------------------------------------------- 1 | M48 2 | ; DRILL file {KiCad 7.0.6-7.0.6~ubuntu22.04.1} date Fri 01 Sep 2023 09:52:36 CEST 3 | ; FORMAT={-:-/ absolute / metric / decimal} 4 | ; #@! TF.CreationDate,2023-09-01T09:52:36+02:00 5 | ; #@! TF.GenerationSoftware,Kicad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1 6 | ; #@! TF.FileFunction,Plated,1,4,PTH 7 | FMAT,2 8 | METRIC 9 | ; #@! TA.AperFunction,Plated,PTH,ViaDrill 10 | T1C0.200 11 | % 12 | G90 13 | G05 14 | T1 15 | X1.015Y18.425 16 | X1.015Y16.65 17 | X1.04Y19.95 18 | X7.015Y18.425 19 | X7.015Y16.65 20 | X7.04Y19.95 21 | T0 22 | M30 23 | -------------------------------------------------------------------------------- /examples/meander_loose/fab/si-simulation-test-board-bottom-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | -------------------------------------------------------------------------------- /examples/meander_loose/fab/si-simulation-test-board-top-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | SP1,Simulation_Port,Simulation_Port,4,18.3,180,top 3 | -------------------------------------------------------------------------------- /examples/meander_loose/fab/stackup.json: -------------------------------------------------------------------------------- 1 | { 2 | "layers": [ 3 | { 4 | "name": "F.SilkS", 5 | "type": "Top Silk Screen", 6 | "color": null, 7 | "thickness": null, 8 | "material": null, 9 | "epsilon": null, 10 | "lossTangent": null 11 | }, 12 | { 13 | "name": "F.Paste", 14 | "type": "Top Solder Paste", 15 | "color": null, 16 | "thickness": null, 17 | "material": null, 18 | "epsilon": null, 19 | "lossTangent": null 20 | }, 21 | { 22 | "name": "F.Mask", 23 | "type": "Top Solder Mask", 24 | "color": "Black", 25 | "thickness": 0.01, 26 | "material": null, 27 | "epsilon": null, 28 | "lossTangent": null 29 | }, 30 | { 31 | "name": "F.Cu", 32 | "type": "copper", 33 | "color": null, 34 | "thickness": 0.035, 35 | "material": null, 36 | "epsilon": null, 37 | "lossTangent": null 38 | }, 39 | { 40 | "name": "dielectric 1", 41 | "type": "core", 42 | "color": null, 43 | "thickness": 0.12, 44 | "material": "FR4", 45 | "epsilon": 4.18, 46 | "lossTangent": 0.02 47 | }, 48 | { 49 | "name": "In1.Cu", 50 | "type": "copper", 51 | "color": null, 52 | "thickness": 0.035, 53 | "material": null, 54 | "epsilon": null, 55 | "lossTangent": null 56 | }, 57 | { 58 | "name": "B.Mask", 59 | "type": "Bottom Solder Mask", 60 | "color": "Black", 61 | "thickness": 0.01, 62 | "material": null, 63 | "epsilon": null, 64 | "lossTangent": null 65 | }, 66 | { 67 | "name": "B.Paste", 68 | "type": "Bottom Solder Paste", 69 | "color": null, 70 | "thickness": null, 71 | "material": null, 72 | "epsilon": null, 73 | "lossTangent": null 74 | }, 75 | { 76 | "name": "B.SilkS", 77 | "type": "Bottom Silk Screen", 78 | "color": null, 79 | "thickness": null, 80 | "material": null, 81 | "epsilon": null, 82 | "lossTangent": null 83 | } 84 | ], 85 | "format_version": "1.0" 86 | } -------------------------------------------------------------------------------- /examples/meander_loose/simulation.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.2", 3 | "frequency": { 4 | "start": 200000000.0, 5 | "stop": 6000000000.0 6 | }, 7 | "max_steps": 54200, 8 | "pixel_size": 2.5, 9 | "ports": [ 10 | { 11 | "width": 200, 12 | "length": 1000, 13 | "impedance": 50, 14 | "layer": 0, 15 | "plane": 1, 16 | "excite": true 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /examples/meander_tight/fab/si-simulation-test-board-B_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T12:16:00+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L4,Bot*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 12:16:00* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X120990000Y-53925000D03* 21 | X127015000Y-52400000D03* 22 | X121015000Y-52400000D03* 23 | X126990000Y-53925000D03* 24 | X126990000Y-55700001D03* 25 | X120990000Y-55700000D03* 26 | %TD*% 27 | M02* 28 | -------------------------------------------------------------------------------- /examples/meander_tight/fab/si-simulation-test-board-Edge_Cuts.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T12:16:00+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Profile,NP*% 6 | %FSLAX46Y46*% 7 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 8 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 12:16:00* 9 | %MOMM*% 10 | %LPD*% 11 | G01* 12 | G04 APERTURE LIST* 13 | %TA.AperFunction,Profile*% 14 | %ADD10C,0.100000*% 15 | %TD*% 16 | G04 APERTURE END LIST* 17 | D10* 18 | X120500000Y-51750000D02* 19 | X127500000Y-51750000D01* 20 | X127500000Y-72000000D01* 21 | X120500000Y-72000000D01* 22 | X120500000Y-51750000D01* 23 | M02* 24 | -------------------------------------------------------------------------------- /examples/meander_tight/fab/si-simulation-test-board-F_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T12:16:00+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L1,Top*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 12:16:00* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | %TA.AperFunction,Conductor*% 18 | %ADD11C,0.185000*% 19 | %TD*% 20 | G04 APERTURE END LIST* 21 | D10* 22 | %TO.N,GND*% 23 | X120990000Y-53925000D03* 24 | X127015000Y-52400000D03* 25 | X121015000Y-52400000D03* 26 | X126990000Y-53925000D03* 27 | X126990000Y-55700001D03* 28 | X120990000Y-55700000D03* 29 | %TD*% 30 | D11* 31 | %TO.N,unconnected-(J22-Pad1)*% 32 | X124810020Y-62175000D02* 33 | X123997500Y-62175000D01* 34 | X124810020Y-59495000D02* 35 | X124165000Y-59495000D01* 36 | X123997500Y-61505000D02* 37 | X123184980Y-61505000D01* 38 | X124810020Y-63515000D02* 39 | X124165000Y-63515000D01* 40 | X124810020Y-62845000D02* 41 | X123997500Y-62845000D01* 42 | X123997500Y-61840000D02* 43 | X124810020Y-61840000D01* 44 | X124165000Y-59495000D02* 45 | X123184980Y-59495000D01* 46 | X123184980Y-59830000D02* 47 | X123997500Y-59830000D01* 48 | X123184980Y-63180000D02* 49 | X123997500Y-63180000D01* 50 | X123997500Y-59830000D02* 51 | X124810020Y-59830000D01* 52 | X124165000Y-59160000D02* 53 | X124810020Y-59160000D01* 54 | X123997500Y-60165000D02* 55 | X123184980Y-60165000D01* 56 | X123997500Y-63682500D02* 57 | X123997500Y-68881680D01* 58 | X123997500Y-60835000D02* 59 | X123184980Y-60835000D01* 60 | X123997500Y-53975000D02* 61 | X123997500Y-58992500D01* 62 | X123997500Y-60500000D02* 63 | X124810020Y-60500000D01* 64 | X124810020Y-61505000D02* 65 | X123997500Y-61505000D01* 66 | X123997500Y-62175000D02* 67 | X123184980Y-62175000D01* 68 | X123184980Y-62510000D02* 69 | X123997500Y-62510000D01* 70 | X123997500Y-63180000D02* 71 | X124810020Y-63180000D01* 72 | X123184980Y-61840000D02* 73 | X123997500Y-61840000D01* 74 | X123997500Y-61170000D02* 75 | X124810020Y-61170000D01* 76 | X123184980Y-60500000D02* 77 | X123997500Y-60500000D01* 78 | X123997500Y-68881680D02* 79 | X123997500Y-70507500D01* 80 | X124810020Y-60165000D02* 81 | X123997500Y-60165000D01* 82 | X123997500Y-62845000D02* 83 | X123184980Y-62845000D01* 84 | X123997500Y-62510000D02* 85 | X124810020Y-62510000D01* 86 | X123184980Y-61170000D02* 87 | X123997500Y-61170000D01* 88 | X124810020Y-60835000D02* 89 | X123997500Y-60835000D01* 90 | X123017500Y-59662500D02* 91 | G75* 92 | G03* 93 | X123184980Y-59830000I167500J0D01* 94 | G01* 95 | X124977500Y-60667500D02* 96 | G75* 97 | G03* 98 | X124810020Y-60500000I-167500J0D01* 99 | G01* 100 | X123017500Y-63012500D02* 101 | G75* 102 | G03* 103 | X123184980Y-63180000I167500J0D01* 104 | G01* 105 | X124810020Y-62845020D02* 106 | G75* 107 | G03* 108 | X124977520Y-62677500I-20J167520D01* 109 | G01* 110 | X123184980Y-61504980D02* 111 | G75* 112 | G03* 113 | X123017480Y-61672500I20J-167520D01* 114 | G01* 115 | X124810020Y-61505020D02* 116 | G75* 117 | G03* 118 | X124977520Y-61337500I-20J167520D01* 119 | G01* 120 | X124977500Y-61337500D02* 121 | G75* 122 | G03* 123 | X124810020Y-61170000I-167500J0D01* 124 | G01* 125 | X123017500Y-61672500D02* 126 | G75* 127 | G03* 128 | X123184980Y-61840000I167500J0D01* 129 | G01* 130 | X123017500Y-62342500D02* 131 | G75* 132 | G03* 133 | X123184980Y-62510000I167500J0D01* 134 | G01* 135 | X123184980Y-60834980D02* 136 | G75* 137 | G03* 138 | X123017480Y-61002500I20J-167520D01* 139 | G01* 140 | X124977500Y-59997500D02* 141 | G75* 142 | G03* 143 | X124810020Y-59830000I-167500J0D01* 144 | G01* 145 | X123184980Y-60164980D02* 146 | G75* 147 | G03* 148 | X123017480Y-60332500I20J-167520D01* 149 | G01* 150 | X123017500Y-61002500D02* 151 | G75* 152 | G03* 153 | X123184980Y-61170000I167500J0D01* 154 | G01* 155 | X123017500Y-60332500D02* 156 | G75* 157 | G03* 158 | X123184980Y-60500000I167500J0D01* 159 | G01* 160 | X124165000Y-63515000D02* 161 | G75* 162 | G03* 163 | X123997500Y-63682500I0J-167500D01* 164 | G01* 165 | X123184980Y-62174980D02* 166 | G75* 167 | G03* 168 | X123017480Y-62342500I20J-167520D01* 169 | G01* 170 | X124977500Y-62677500D02* 171 | G75* 172 | G03* 173 | X124810020Y-62510000I-167500J0D01* 174 | G01* 175 | X124810020Y-63515020D02* 176 | G75* 177 | G03* 178 | X124977520Y-63347500I-20J167520D01* 179 | G01* 180 | X123184980Y-59494980D02* 181 | G75* 182 | G03* 183 | X123017480Y-59662500I20J-167520D01* 184 | G01* 185 | X124810020Y-60835020D02* 186 | G75* 187 | G03* 188 | X124977520Y-60667500I-20J167520D01* 189 | G01* 190 | X123997500Y-58992500D02* 191 | G75* 192 | G03* 193 | X124165000Y-59160000I167500J0D01* 194 | G01* 195 | X124810020Y-62175020D02* 196 | G75* 197 | G03* 198 | X124977520Y-62007500I-20J167520D01* 199 | G01* 200 | X124977500Y-62007500D02* 201 | G75* 202 | G03* 203 | X124810020Y-61840000I-167500J0D01* 204 | G01* 205 | X124810020Y-59495020D02* 206 | G75* 207 | G03* 208 | X124977520Y-59327500I-20J167520D01* 209 | G01* 210 | X123184980Y-62844980D02* 211 | G75* 212 | G03* 213 | X123017480Y-63012500I20J-167520D01* 214 | G01* 215 | X124977500Y-59327500D02* 216 | G75* 217 | G03* 218 | X124810020Y-59160000I-167500J0D01* 219 | G01* 220 | X124810020Y-60165020D02* 221 | G75* 222 | G03* 223 | X124977520Y-59997500I-20J167520D01* 224 | G01* 225 | X124977500Y-63347500D02* 226 | G75* 227 | G03* 228 | X124810020Y-63180000I-167500J0D01* 229 | G01* 230 | %TD*% 231 | M02* 232 | -------------------------------------------------------------------------------- /examples/meander_tight/fab/si-simulation-test-board-In1_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T12:16:00+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L2,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 12:16:00* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X120990000Y-53925000D03* 21 | X127015000Y-52400000D03* 22 | X121015000Y-52400000D03* 23 | X126990000Y-53925000D03* 24 | X126990000Y-55700001D03* 25 | X120990000Y-55700000D03* 26 | %TD*% 27 | %TA.AperFunction,Conductor*% 28 | %TO.N,GND*% 29 | G36* 30 | X127473066Y-51767813D02* 31 | G01* 32 | X127498376Y-51811650D01* 33 | X127499500Y-51824500D01* 34 | X127499500Y-71925500D01* 35 | X127482187Y-71973066D01* 36 | X127438350Y-71998376D01* 37 | X127425500Y-71999500D01* 38 | X120574500Y-71999500D01* 39 | X120526934Y-71982187D01* 40 | X120501624Y-71938350D01* 41 | X120500500Y-71925500D01* 42 | X120500500Y-51824500D01* 43 | X120517813Y-51776934D01* 44 | X120561650Y-51751624D01* 45 | X120574500Y-51750500D01* 46 | X127425500Y-51750500D01* 47 | X127473066Y-51767813D01* 48 | G37* 49 | %TD.AperFunction*% 50 | %TD*% 51 | M02* 52 | -------------------------------------------------------------------------------- /examples/meander_tight/fab/si-simulation-test-board-In2_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-01T12:16:00+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L3,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-01 12:16:00* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X120990000Y-53925000D03* 21 | X127015000Y-52400000D03* 22 | X121015000Y-52400000D03* 23 | X126990000Y-53925000D03* 24 | X126990000Y-55700001D03* 25 | X120990000Y-55700000D03* 26 | %TD*% 27 | %TA.AperFunction,Conductor*% 28 | %TO.N,GND*% 29 | G36* 30 | X127473066Y-51767813D02* 31 | G01* 32 | X127498376Y-51811650D01* 33 | X127499500Y-51824500D01* 34 | X127499500Y-71925500D01* 35 | X127482187Y-71973066D01* 36 | X127438350Y-71998376D01* 37 | X127425500Y-71999500D01* 38 | X120574500Y-71999500D01* 39 | X120526934Y-71982187D01* 40 | X120501624Y-71938350D01* 41 | X120500500Y-71925500D01* 42 | X120500500Y-51824500D01* 43 | X120517813Y-51776934D01* 44 | X120561650Y-51751624D01* 45 | X120574500Y-51750500D01* 46 | X127425500Y-51750500D01* 47 | X127473066Y-51767813D01* 48 | G37* 49 | %TD.AperFunction*% 50 | %TD*% 51 | M02* 52 | -------------------------------------------------------------------------------- /examples/meander_tight/fab/si-simulation-test-board-PTH.drl: -------------------------------------------------------------------------------- 1 | M48 2 | ; DRILL file {KiCad 7.0.6-7.0.6~ubuntu22.04.1} date Fri 01 Sep 2023 12:16:00 CEST 3 | ; FORMAT={-:-/ absolute / metric / decimal} 4 | ; #@! TF.CreationDate,2023-09-01T12:16:00+02:00 5 | ; #@! TF.GenerationSoftware,Kicad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1 6 | ; #@! TF.FileFunction,Plated,1,4,PTH 7 | FMAT,2 8 | METRIC 9 | ; #@! TA.AperFunction,Plated,PTH,ViaDrill 10 | T1C0.200 11 | % 12 | G90 13 | G05 14 | T1 15 | X0.49Y18.075 16 | X0.49Y16.3 17 | X0.515Y19.6 18 | X6.49Y18.075 19 | X6.49Y16.3 20 | X6.515Y19.6 21 | T0 22 | M30 23 | -------------------------------------------------------------------------------- /examples/meander_tight/fab/si-simulation-test-board-bottom-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | -------------------------------------------------------------------------------- /examples/meander_tight/fab/si-simulation-test-board-top-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | SP1,Simulation_Port,Simulation_Port,3.5,18,180,top 3 | -------------------------------------------------------------------------------- /examples/meander_tight/fab/stackup.json: -------------------------------------------------------------------------------- 1 | { 2 | "layers": [ 3 | { 4 | "name": "F.SilkS", 5 | "type": "Top Silk Screen", 6 | "color": null, 7 | "thickness": null, 8 | "material": null, 9 | "epsilon": null, 10 | "lossTangent": null 11 | }, 12 | { 13 | "name": "F.Paste", 14 | "type": "Top Solder Paste", 15 | "color": null, 16 | "thickness": null, 17 | "material": null, 18 | "epsilon": null, 19 | "lossTangent": null 20 | }, 21 | { 22 | "name": "F.Mask", 23 | "type": "Top Solder Mask", 24 | "color": "Black", 25 | "thickness": 0.01, 26 | "material": null, 27 | "epsilon": null, 28 | "lossTangent": null 29 | }, 30 | { 31 | "name": "F.Cu", 32 | "type": "copper", 33 | "color": null, 34 | "thickness": 0.035, 35 | "material": null, 36 | "epsilon": null, 37 | "lossTangent": null 38 | }, 39 | { 40 | "name": "dielectric 1", 41 | "type": "core", 42 | "color": null, 43 | "thickness": 0.12, 44 | "material": "FR4", 45 | "epsilon": 4.18, 46 | "lossTangent": 0.02 47 | }, 48 | { 49 | "name": "In1.Cu", 50 | "type": "copper", 51 | "color": null, 52 | "thickness": 0.035, 53 | "material": null, 54 | "epsilon": null, 55 | "lossTangent": null 56 | }, 57 | { 58 | "name": "B.Mask", 59 | "type": "Bottom Solder Mask", 60 | "color": "Black", 61 | "thickness": 0.01, 62 | "material": null, 63 | "epsilon": null, 64 | "lossTangent": null 65 | }, 66 | { 67 | "name": "B.Paste", 68 | "type": "Bottom Solder Paste", 69 | "color": null, 70 | "thickness": null, 71 | "material": null, 72 | "epsilon": null, 73 | "lossTangent": null 74 | }, 75 | { 76 | "name": "B.SilkS", 77 | "type": "Bottom Silk Screen", 78 | "color": null, 79 | "thickness": null, 80 | "material": null, 81 | "epsilon": null, 82 | "lossTangent": null 83 | } 84 | ], 85 | "format_version": "1.0" 86 | } -------------------------------------------------------------------------------- /examples/meander_tight/simulation.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.2", 3 | "frequency": { 4 | "start": 200000000.0, 5 | "stop": 6000000000.0 6 | }, 7 | "max_steps": 57865, 8 | "pixel_size": 2.5, 9 | "ports": [ 10 | { 11 | "width": 200, 12 | "length": 1000, 13 | "impedance": 50, 14 | "layer": 0, 15 | "plane": 1, 16 | "excite": true 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /examples/stub_long/fab/si-simulation-test-board-B_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-04T14:35:40+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L4,Bot*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-04 14:35:40* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X129194001Y-88992501D03* 21 | %TD*% 22 | M02* 23 | -------------------------------------------------------------------------------- /examples/stub_long/fab/si-simulation-test-board-Edge_Cuts.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-04T14:35:40+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Profile,NP*% 6 | %FSLAX46Y46*% 7 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 8 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-04 14:35:40* 9 | %MOMM*% 10 | %LPD*% 11 | G01* 12 | G04 APERTURE LIST* 13 | %TA.AperFunction,Profile*% 14 | %ADD10C,0.100000*% 15 | %TD*% 16 | G04 APERTURE END LIST* 17 | D10* 18 | X94000000Y-84600000D02* 19 | X144000000Y-84600000D01* 20 | X144000000Y-90400000D01* 21 | X94000000Y-90400000D01* 22 | X94000000Y-84600000D01* 23 | M02* 24 | -------------------------------------------------------------------------------- /examples/stub_long/fab/si-simulation-test-board-F_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-04T14:35:40+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L1,Top*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-04 14:35:40* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | G04 Aperture macros list* 15 | %AMRoundRect* 16 | 0 Rectangle with rounded corners* 17 | 0 $1 Rounding radius* 18 | 0 $2 $3 $4 $5 $6 $7 $8 $9 X,Y pos of 4 corners* 19 | 0 Add a 4 corners polygon primitive as box body* 20 | 4,1,4,$2,$3,$4,$5,$6,$7,$8,$9,$2,$3,0* 21 | 0 Add four circle primitives for the rounded corners* 22 | 1,1,$1+$1,$2,$3* 23 | 1,1,$1+$1,$4,$5* 24 | 1,1,$1+$1,$6,$7* 25 | 1,1,$1+$1,$8,$9* 26 | 0 Add four rect primitives between the rounded corners* 27 | 20,1,$1+$1,$2,$3,$4,$5,0* 28 | 20,1,$1+$1,$4,$5,$6,$7,0* 29 | 20,1,$1+$1,$6,$7,$8,$9,0* 30 | 20,1,$1+$1,$8,$9,$2,$3,0*% 31 | G04 Aperture macros list end* 32 | %TA.AperFunction,SMDPad,CuDef*% 33 | %ADD10RoundRect,0.100000X0.130000X0.100000X-0.130000X0.100000X-0.130000X-0.100000X0.130000X-0.100000X0*% 34 | %TD*% 35 | %TA.AperFunction,ViaPad*% 36 | %ADD11C,0.550000*% 37 | %TD*% 38 | %TA.AperFunction,Conductor*% 39 | %ADD12C,0.185000*% 40 | %TD*% 41 | G04 APERTURE END LIST* 42 | D10* 43 | %TO.P,R3,1*% 44 | %TO.N,GND*% 45 | X129064001Y-88992501D03* 46 | %TO.P,R3,2*% 47 | %TO.N,Net-(J7-Pad1)*% 48 | X128424001Y-88992501D03* 49 | %TD*% 50 | D11* 51 | %TO.N,GND*% 52 | X129194001Y-88992501D03* 53 | %TD*% 54 | D12* 55 | %TO.N,Net-(J7-Pad1)*% 56 | X128300000Y-88992500D02* 57 | X128400000Y-88992500D01* 58 | X109792501Y-86007499D02* 59 | X109792501Y-87992499D01* 60 | X109800000Y-86000000D02* 61 | X109792501Y-86007499D01* 62 | X110792500Y-88992500D02* 63 | X128300000Y-88992500D01* 64 | X109792501Y-87992499D02* 65 | X110792500Y-88992500D01* 66 | X100600000Y-86000000D02* 67 | X137200000Y-86000000D01* 68 | %TD*% 69 | M02* 70 | -------------------------------------------------------------------------------- /examples/stub_long/fab/si-simulation-test-board-In1_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-04T14:35:40+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L2,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-04 14:35:40* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X129194001Y-88992501D03* 21 | %TD*% 22 | %TA.AperFunction,Conductor*% 23 | %TO.N,GND*% 24 | G36* 25 | X143973066Y-84617813D02* 26 | G01* 27 | X143998376Y-84661650D01* 28 | X143999500Y-84674500D01* 29 | X143999500Y-90325500D01* 30 | X143982187Y-90373066D01* 31 | X143938350Y-90398376D01* 32 | X143925500Y-90399500D01* 33 | X94074500Y-90399500D01* 34 | X94026934Y-90382187D01* 35 | X94001624Y-90338350D01* 36 | X94000500Y-90325500D01* 37 | X94000500Y-84674500D01* 38 | X94017813Y-84626934D01* 39 | X94061650Y-84601624D01* 40 | X94074500Y-84600500D01* 41 | X143925500Y-84600500D01* 42 | X143973066Y-84617813D01* 43 | G37* 44 | %TD.AperFunction*% 45 | %TD*% 46 | M02* 47 | -------------------------------------------------------------------------------- /examples/stub_long/fab/si-simulation-test-board-In2_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-04T14:35:40+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L3,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-04 14:35:40* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X129194001Y-88992501D03* 21 | %TD*% 22 | %TA.AperFunction,Conductor*% 23 | %TO.N,GND*% 24 | G36* 25 | X143973066Y-84617813D02* 26 | G01* 27 | X143998376Y-84661650D01* 28 | X143999500Y-84674500D01* 29 | X143999500Y-90325500D01* 30 | X143982187Y-90373066D01* 31 | X143938350Y-90398376D01* 32 | X143925500Y-90399500D01* 33 | X94074500Y-90399500D01* 34 | X94026934Y-90382187D01* 35 | X94001624Y-90338350D01* 36 | X94000500Y-90325500D01* 37 | X94000500Y-84674500D01* 38 | X94017813Y-84626934D01* 39 | X94061650Y-84601624D01* 40 | X94074500Y-84600500D01* 41 | X143925500Y-84600500D01* 42 | X143973066Y-84617813D01* 43 | G37* 44 | %TD.AperFunction*% 45 | %TD*% 46 | M02* 47 | -------------------------------------------------------------------------------- /examples/stub_long/fab/si-simulation-test-board-PTH.drl: -------------------------------------------------------------------------------- 1 | M48 2 | ; DRILL file {KiCad 7.0.6-7.0.6~ubuntu22.04.1} date Mon 04 Sep 2023 14:35:40 CEST 3 | ; FORMAT={-:-/ absolute / metric / decimal} 4 | ; #@! TF.CreationDate,2023-09-04T14:35:40+02:00 5 | ; #@! TF.GenerationSoftware,Kicad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1 6 | ; #@! TF.FileFunction,Plated,1,4,PTH 7 | FMAT,2 8 | METRIC 9 | ; #@! TA.AperFunction,Plated,PTH,ViaDrill 10 | T1C0.200 11 | % 12 | G90 13 | G05 14 | T1 15 | X35.194Y1.407 16 | T0 17 | M30 18 | -------------------------------------------------------------------------------- /examples/stub_long/fab/si-simulation-test-board-bottom-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | -------------------------------------------------------------------------------- /examples/stub_long/fab/si-simulation-test-board-top-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | R3,R_0R_0201,R_0201,34.744001,1.407499,180,top 3 | SP1,Simulation_Port,Simulation_Port,6.8,4.4,-90,top 4 | SP2,Simulation_Port,Simulation_Port,43,4.4,90,top 5 | -------------------------------------------------------------------------------- /examples/stub_long/fab/stackup.json: -------------------------------------------------------------------------------- 1 | { 2 | "layers": [ 3 | { 4 | "name": "F.SilkS", 5 | "type": "Top Silk Screen", 6 | "color": null, 7 | "thickness": null, 8 | "material": null, 9 | "epsilon": null, 10 | "lossTangent": null 11 | }, 12 | { 13 | "name": "F.Paste", 14 | "type": "Top Solder Paste", 15 | "color": null, 16 | "thickness": null, 17 | "material": null, 18 | "epsilon": null, 19 | "lossTangent": null 20 | }, 21 | { 22 | "name": "F.Mask", 23 | "type": "Top Solder Mask", 24 | "color": "Black", 25 | "thickness": 0.01, 26 | "material": null, 27 | "epsilon": null, 28 | "lossTangent": null 29 | }, 30 | { 31 | "name": "F.Cu", 32 | "type": "copper", 33 | "color": null, 34 | "thickness": 0.035, 35 | "material": null, 36 | "epsilon": null, 37 | "lossTangent": null 38 | }, 39 | { 40 | "name": "dielectric 1", 41 | "type": "core", 42 | "color": null, 43 | "thickness": 0.12, 44 | "material": "FR4", 45 | "epsilon": 4.18, 46 | "lossTangent": 0.02 47 | }, 48 | { 49 | "name": "In1.Cu", 50 | "type": "copper", 51 | "color": null, 52 | "thickness": 0.035, 53 | "material": null, 54 | "epsilon": null, 55 | "lossTangent": null 56 | }, 57 | { 58 | "name": "B.Mask", 59 | "type": "Bottom Solder Mask", 60 | "color": "Black", 61 | "thickness": 0.01, 62 | "material": null, 63 | "epsilon": null, 64 | "lossTangent": null 65 | }, 66 | { 67 | "name": "B.Paste", 68 | "type": "Bottom Solder Paste", 69 | "color": null, 70 | "thickness": null, 71 | "material": null, 72 | "epsilon": null, 73 | "lossTangent": null 74 | }, 75 | { 76 | "name": "B.SilkS", 77 | "type": "Bottom Silk Screen", 78 | "color": null, 79 | "thickness": null, 80 | "material": null, 81 | "epsilon": null, 82 | "lossTangent": null 83 | } 84 | ], 85 | "format_version": "1.0" 86 | } -------------------------------------------------------------------------------- /examples/stub_long/simulation.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.2", 3 | "frequency": { 4 | "start": 200000000.0, 5 | "stop": 6000000000.0 6 | }, 7 | "max_steps": 58840, 8 | "pixel_size": 2.5, 9 | "ports": [ 10 | { 11 | "width": 200, 12 | "length": 600, 13 | "impedance": 50, 14 | "layer": 0, 15 | "plane": 1, 16 | "excite": true 17 | }, 18 | { 19 | "width": 200, 20 | "length": 600, 21 | "impedance": 50, 22 | "layer": 0, 23 | "plane": 1, 24 | "excite": false 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /examples/stub_short/fab/si-simulation-test-board-B_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-04T14:34:43+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L4,Bot*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-04 14:34:43* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X116576043Y-99109757D03* 21 | %TD*% 22 | M02* 23 | -------------------------------------------------------------------------------- /examples/stub_short/fab/si-simulation-test-board-Edge_Cuts.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-04T14:34:43+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Profile,NP*% 6 | %FSLAX46Y46*% 7 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 8 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-04 14:34:43* 9 | %MOMM*% 10 | %LPD*% 11 | G01* 12 | G04 APERTURE LIST* 13 | %TA.AperFunction,Profile*% 14 | %ADD10C,0.100000*% 15 | %TD*% 16 | G04 APERTURE END LIST* 17 | D10* 18 | X99200000Y-94600000D02* 19 | X139200000Y-94600000D01* 20 | X139200000Y-100200000D01* 21 | X99200000Y-100200000D01* 22 | X99200000Y-94600000D01* 23 | M02* 24 | -------------------------------------------------------------------------------- /examples/stub_short/fab/si-simulation-test-board-F_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-04T14:34:43+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L1,Top*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-04 14:34:43* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | G04 Aperture macros list* 15 | %AMRoundRect* 16 | 0 Rectangle with rounded corners* 17 | 0 $1 Rounding radius* 18 | 0 $2 $3 $4 $5 $6 $7 $8 $9 X,Y pos of 4 corners* 19 | 0 Add a 4 corners polygon primitive as box body* 20 | 4,1,4,$2,$3,$4,$5,$6,$7,$8,$9,$2,$3,0* 21 | 0 Add four circle primitives for the rounded corners* 22 | 1,1,$1+$1,$2,$3* 23 | 1,1,$1+$1,$4,$5* 24 | 1,1,$1+$1,$6,$7* 25 | 1,1,$1+$1,$8,$9* 26 | 0 Add four rect primitives between the rounded corners* 27 | 20,1,$1+$1,$2,$3,$4,$5,0* 28 | 20,1,$1+$1,$4,$5,$6,$7,0* 29 | 20,1,$1+$1,$6,$7,$8,$9,0* 30 | 20,1,$1+$1,$8,$9,$2,$3,0*% 31 | G04 Aperture macros list end* 32 | %TA.AperFunction,SMDPad,CuDef*% 33 | %ADD10RoundRect,0.100000X0.130000X0.100000X-0.130000X0.100000X-0.130000X-0.100000X0.130000X-0.100000X0*% 34 | %TD*% 35 | %TA.AperFunction,ViaPad*% 36 | %ADD11C,0.550000*% 37 | %TD*% 38 | %TA.AperFunction,Conductor*% 39 | %ADD12C,0.185000*% 40 | %TD*% 41 | G04 APERTURE END LIST* 42 | D10* 43 | %TO.P,R4,1*% 44 | %TO.N,GND*% 45 | X116464000Y-99100001D03* 46 | %TO.P,R4,2*% 47 | %TO.N,Net-(J10-Pad1)*% 48 | X115824000Y-99100001D03* 49 | %TD*% 50 | D11* 51 | %TO.N,GND*% 52 | X116576043Y-99109757D03* 53 | %TD*% 54 | D12* 55 | %TO.N,Net-(J10-Pad1)*% 56 | X111015001Y-99100002D02* 57 | X115800000Y-99100000D01* 58 | X109900000Y-97985000D02* 59 | X111015001Y-99100002D01* 60 | X109900000Y-96000000D02* 61 | X109900000Y-97985000D01* 62 | X100400000Y-96000000D02* 63 | X138000000Y-96000000D01* 64 | %TD*% 65 | M02* 66 | -------------------------------------------------------------------------------- /examples/stub_short/fab/si-simulation-test-board-In1_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-04T14:34:43+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L2,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-04 14:34:43* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X116576043Y-99109757D03* 21 | %TD*% 22 | %TA.AperFunction,Conductor*% 23 | %TO.N,GND*% 24 | G36* 25 | X139173066Y-94617813D02* 26 | G01* 27 | X139198376Y-94661650D01* 28 | X139199500Y-94674500D01* 29 | X139199500Y-100125500D01* 30 | X139182187Y-100173066D01* 31 | X139138350Y-100198376D01* 32 | X139125500Y-100199500D01* 33 | X99274500Y-100199500D01* 34 | X99226934Y-100182187D01* 35 | X99201624Y-100138350D01* 36 | X99200500Y-100125500D01* 37 | X99200500Y-94674500D01* 38 | X99217813Y-94626934D01* 39 | X99261650Y-94601624D01* 40 | X99274500Y-94600500D01* 41 | X139125500Y-94600500D01* 42 | X139173066Y-94617813D01* 43 | G37* 44 | %TD.AperFunction*% 45 | %TD*% 46 | M02* 47 | -------------------------------------------------------------------------------- /examples/stub_short/fab/si-simulation-test-board-In2_Cu.gbr: -------------------------------------------------------------------------------- 1 | %TF.GenerationSoftware,KiCad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1*% 2 | %TF.CreationDate,2023-09-04T14:34:43+02:00*% 3 | %TF.ProjectId,si-simulation-test-board,73692d73-696d-4756-9c61-74696f6e2d74,rev?*% 4 | %TF.SameCoordinates,Original*% 5 | %TF.FileFunction,Copper,L3,Inr*% 6 | %TF.FilePolarity,Positive*% 7 | %FSLAX46Y46*% 8 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 9 | G04 Created by KiCad (PCBNEW 7.0.6-7.0.6~ubuntu22.04.1) date 2023-09-04 14:34:43* 10 | %MOMM*% 11 | %LPD*% 12 | G01* 13 | G04 APERTURE LIST* 14 | %TA.AperFunction,ViaPad*% 15 | %ADD10C,0.550000*% 16 | %TD*% 17 | G04 APERTURE END LIST* 18 | D10* 19 | %TO.N,GND*% 20 | X116576043Y-99109757D03* 21 | %TD*% 22 | %TA.AperFunction,Conductor*% 23 | %TO.N,GND*% 24 | G36* 25 | X139173066Y-94617813D02* 26 | G01* 27 | X139198376Y-94661650D01* 28 | X139199500Y-94674500D01* 29 | X139199500Y-100125500D01* 30 | X139182187Y-100173066D01* 31 | X139138350Y-100198376D01* 32 | X139125500Y-100199500D01* 33 | X99274500Y-100199500D01* 34 | X99226934Y-100182187D01* 35 | X99201624Y-100138350D01* 36 | X99200500Y-100125500D01* 37 | X99200500Y-94674500D01* 38 | X99217813Y-94626934D01* 39 | X99261650Y-94601624D01* 40 | X99274500Y-94600500D01* 41 | X139125500Y-94600500D01* 42 | X139173066Y-94617813D01* 43 | G37* 44 | %TD.AperFunction*% 45 | %TD*% 46 | M02* 47 | -------------------------------------------------------------------------------- /examples/stub_short/fab/si-simulation-test-board-PTH.drl: -------------------------------------------------------------------------------- 1 | M48 2 | ; DRILL file {KiCad 7.0.6-7.0.6~ubuntu22.04.1} date Mon 04 Sep 2023 14:34:43 CEST 3 | ; FORMAT={-:-/ absolute / metric / decimal} 4 | ; #@! TF.CreationDate,2023-09-04T14:34:43+02:00 5 | ; #@! TF.GenerationSoftware,Kicad,Pcbnew,7.0.6-7.0.6~ubuntu22.04.1 6 | ; #@! TF.FileFunction,Plated,1,4,PTH 7 | FMAT,2 8 | METRIC 9 | ; #@! TA.AperFunction,Plated,PTH,ViaDrill 10 | T1C0.200 11 | % 12 | G90 13 | G05 14 | T1 15 | X17.376Y1.09 16 | T0 17 | M30 18 | -------------------------------------------------------------------------------- /examples/stub_short/fab/si-simulation-test-board-bottom-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | -------------------------------------------------------------------------------- /examples/stub_short/fab/si-simulation-test-board-top-pos.csv: -------------------------------------------------------------------------------- 1 | Ref,Val,Package,PosX,PosY,Rot,Side 2 | R4,R_0R_0201,R_0201,16.944,1.099999,180,top 3 | SP1,Simulation_Port,Simulation_Port,1.6,4.2,-90,top 4 | SP2,Simulation_Port,Simulation_Port,37.8,4.2,90,top 5 | -------------------------------------------------------------------------------- /examples/stub_short/fab/stackup.json: -------------------------------------------------------------------------------- 1 | { 2 | "layers": [ 3 | { 4 | "name": "F.SilkS", 5 | "type": "Top Silk Screen", 6 | "color": null, 7 | "thickness": null, 8 | "material": null, 9 | "epsilon": null, 10 | "lossTangent": null 11 | }, 12 | { 13 | "name": "F.Paste", 14 | "type": "Top Solder Paste", 15 | "color": null, 16 | "thickness": null, 17 | "material": null, 18 | "epsilon": null, 19 | "lossTangent": null 20 | }, 21 | { 22 | "name": "F.Mask", 23 | "type": "Top Solder Mask", 24 | "color": "Black", 25 | "thickness": 0.01, 26 | "material": null, 27 | "epsilon": null, 28 | "lossTangent": null 29 | }, 30 | { 31 | "name": "F.Cu", 32 | "type": "copper", 33 | "color": null, 34 | "thickness": 0.035, 35 | "material": null, 36 | "epsilon": null, 37 | "lossTangent": null 38 | }, 39 | { 40 | "name": "dielectric 1", 41 | "type": "core", 42 | "color": null, 43 | "thickness": 0.12, 44 | "material": "FR4", 45 | "epsilon": 4.18, 46 | "lossTangent": 0.02 47 | }, 48 | { 49 | "name": "In1.Cu", 50 | "type": "copper", 51 | "color": null, 52 | "thickness": 0.035, 53 | "material": null, 54 | "epsilon": null, 55 | "lossTangent": null 56 | }, 57 | { 58 | "name": "B.Mask", 59 | "type": "Bottom Solder Mask", 60 | "color": "Black", 61 | "thickness": 0.01, 62 | "material": null, 63 | "epsilon": null, 64 | "lossTangent": null 65 | }, 66 | { 67 | "name": "B.Paste", 68 | "type": "Bottom Solder Paste", 69 | "color": null, 70 | "thickness": null, 71 | "material": null, 72 | "epsilon": null, 73 | "lossTangent": null 74 | }, 75 | { 76 | "name": "B.SilkS", 77 | "type": "Bottom Silk Screen", 78 | "color": null, 79 | "thickness": null, 80 | "material": null, 81 | "epsilon": null, 82 | "lossTangent": null 83 | } 84 | ], 85 | "format_version": "1.0" 86 | } -------------------------------------------------------------------------------- /examples/stub_short/simulation.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.2", 3 | "frequency": { 4 | "start": 200000000.0, 5 | "stop": 6000000000.0 6 | }, 7 | "max_steps": 69600, 8 | "pixel_size": 2.5, 9 | "ports": [ 10 | { 11 | "width": 200, 12 | "length": 600, 13 | "impedance": 50, 14 | "layer": 0, 15 | "plane": 1, 16 | "excite": true 17 | }, 18 | { 19 | "width": 200, 20 | "length": 600, 21 | "impedance": 50, 22 | "layer": 0, 23 | "plane": 1, 24 | "excite": false 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools >= 65", "wheel >= 0.38", "setuptools_scm>=8"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "gerber2ems" 7 | authors = [ 8 | { name = "Antmicro" } 9 | ] 10 | description = "Perform EM simulations based on standard PCB production files (gerbers)" 11 | 12 | # The version is automatically generated by setuptools-scm 13 | # to include the commit hash. To change the version of the package, 14 | # create a git tag for a commit available on the main branch instead! 15 | # For example: 16 | # git tag vX.Y.Z 17 | # The tag must then be pushed to the corresponding remote: 18 | # git push origin tag vX.Y.Z 19 | # The resulting version will then be: X.Y.Z+HASH 20 | # Do not tag commits inside branches! Tags do not follow commits, 21 | # and modifying any commits in a development branch will not update 22 | # the tag. Only create tags for commits that won't be modified 23 | # anymore (i.e, main branch). 24 | dynamic = ["version"] 25 | 26 | requires-python = ">=3.8" 27 | license = {file = "LICENSE"} 28 | dependencies = ["numpy", "matplotlib", "coloredlogs", "nanomesh", "scikit-rf", "Pillow", "scipy", "pyserde"] 29 | scripts = {gerber2ems = "gerber2ems.main:main", ems2paraview = "ems2paraview.main:main"} 30 | 31 | [tool.setuptools.package-data] 32 | gerber2ems = ["*.mplstyle"] 33 | 34 | [project.optional-dependencies] 35 | dev = ["mypy", "ruff", "black"] 36 | 37 | [tool.ruff] 38 | lint.select = ["E", "F", "N", "B", "D", "A", "RET"] 39 | line-length = 120 40 | target-version = "py38" 41 | 42 | [tool.black] 43 | line-length = 120 44 | 45 | [tool.mypy] 46 | ignore_missing_imports = true 47 | disallow_untyped_defs = true 48 | 49 | -------------------------------------------------------------------------------- /src/ems2paraview/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """Main script.""" 3 | 4 | import os 5 | import argparse 6 | import subprocess 7 | from pathlib import Path 8 | 9 | parser = argparse.ArgumentParser(prog="gerber2ems-preview") 10 | parser.add_argument("port", nargs="?", help="Select port number") 11 | parser.add_argument("-l", "--list-layers", help="list all simulated layers", action="store_true") 12 | 13 | 14 | def get_ports() -> list[str]: 15 | """Get all the simulated ports.""" 16 | path = os.getcwd() + "/ems/simulation/" 17 | return os.listdir(path) 18 | 19 | 20 | def run_paraview(port: str) -> None: 21 | """Run paraview.""" 22 | path = Path(__file__) 23 | path = path.parent / "paraview_preview.py" 24 | subprocess.run(["paraview", "--script", path], env=dict(os.environ, GERBER2EMS_PORT=port)) 25 | 26 | 27 | def main() -> None: 28 | """Run the script.""" 29 | args = parser.parse_args() 30 | ports = get_ports() 31 | if args.list_layers: 32 | print("Simulated ports:") 33 | for port in ports: 34 | print(port) 35 | exit() 36 | 37 | if args.port in ports: 38 | run_paraview(str(args.port)) 39 | elif args.port is None: 40 | print("Port not specified") 41 | exit() 42 | else: 43 | print(f"Port {args.port} not found") 44 | exit() 45 | -------------------------------------------------------------------------------- /src/ems2paraview/paraview_preview.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """Script running within Paraview.""" 3 | 4 | import os 5 | from pathlib import Path 6 | from paraview.simple import * # type: ignore #noqa: F403 7 | 8 | 9 | def get_sim_results(port: str) -> list[str]: 10 | """Get path to simulation result files, from specified port.""" 11 | path = Path.cwd() / "ems" / "simulation" / port 12 | return [str(p) for p in path.glob("*.vtr")] 13 | 14 | 15 | def run_preview(files: list[str]) -> None: 16 | """Set up and run preview.""" 17 | paraview.simple._DisableFirstRenderCameraReset() # type: ignore #noqa: F405 18 | 19 | e_field = XMLRectilinearGridReader(registrationName="e_field", FileName=files) # type: ignore #noqa: F405 20 | e_field.PointArrayStatus = ["E-Field"] 21 | 22 | animation_scene = GetAnimationScene() # type: ignore #noqa: F405 23 | 24 | animation_scene.UpdateAnimationUsingDataTimeSteps() 25 | 26 | render_view = GetActiveViewOrCreate("RenderView") # type: ignore #noqa: F405 27 | 28 | e_field_vtr_display = Show(e_field, render_view, "UniformGridRepresentation") # type: ignore #noqa: F405 29 | 30 | ColorBy(e_field_vtr_display, ("POINTS", "E-Field", "Magnitude")) # type: ignore #noqa: F405 31 | 32 | e_field_vtr_display.RescaleTransferFunctionToDataRange(True, False) 33 | 34 | e_field_vtr_display.SetScalarBarVisibility(render_view, True) 35 | 36 | render_view.Update() 37 | 38 | render_view.ResetCamera(False) 39 | 40 | animation_scene.Play() 41 | 42 | 43 | if __name__ == "__main__": 44 | port = os.environ["GERBER2EMS_PORT"] 45 | 46 | files = get_sim_results(port) 47 | run_preview(files) 48 | -------------------------------------------------------------------------------- /src/gerber2ems/antmicro.mplstyle: -------------------------------------------------------------------------------- 1 | font.family : lato 2 | axes.titlesize : 16 3 | axes.facecolor : 2E303E 4 | axes.edgecolor : c4c2c5 5 | axes.labelcolor : dfdfdf 6 | axes.labelsize : 12 7 | figure.facecolor : 2E303E 8 | text.color : FFFFFF 9 | grid.color : c4c2c5 10 | xtick.labelcolor: c4c2c5 11 | ytick.labelcolor: c4c2c5 12 | xtick.color: c4c2c5 13 | ytick.color: c4c2c5 14 | axes.prop_cycle: cycler('color', ['c4c2c5', 'f15f32', '00af91', 'c0e4eb', 'e74a3c']) 15 | patch.edgecolor : dfdfdf 16 | -------------------------------------------------------------------------------- /src/gerber2ems/config.py: -------------------------------------------------------------------------------- 1 | """Contains classes that describe the configuration.""" 2 | 3 | from __future__ import annotations 4 | 5 | import sys 6 | import logging 7 | from typing import Any, List, Optional, Tuple, Dict 8 | from enum import Enum 9 | from math import sqrt 10 | from serde import serde, field, coerce, from_dict 11 | from serde.json import to_json 12 | from pathlib import Path 13 | import json 14 | from argparse import Namespace 15 | 16 | from gerber2ems.constants import CONFIG_FORMAT_VERSION, UNIT, DEFAULT_CONFIG_PATH 17 | 18 | logger = logging.getLogger(__name__) 19 | port_count: int = 0 20 | 21 | 22 | @serde(type_check=coerce) 23 | class PortConfig: 24 | """Class representing and parsing port config.""" 25 | 26 | name: str = field(default="Unnamed") 27 | position: Optional[Tuple[float, float]] = field(default=None, skip=True) 28 | direction: Optional[float] = field(default=None, skip=True) 29 | width: float = field(default=200) 30 | length: float = field(default=1000) 31 | impedance: float = field(default=50) 32 | layer: int = field(default=0) 33 | plane: int = field(default=1) 34 | dB_margin: float = field(default=-15) # noqa: N815 35 | excite: bool = field(default=False) 36 | 37 | 38 | @serde(type_check=coerce) 39 | class DifferentialPairConfig: 40 | """Class representing and parsing differential pair config.""" 41 | 42 | start_p: int = field(default=0) 43 | stop_p: int = field(default=1) 44 | start_n: int = field(default=2) 45 | stop_n: int = field(default=3) 46 | name: Optional[str] = field(default=None) 47 | nets: List[str] = field(default_factory=list) 48 | correct: bool = field(default=True, skip=True) 49 | 50 | def __post_init__(self) -> None: 51 | """Validate trace config.""" 52 | global port_count 53 | if self.name is None: 54 | self.name = f"{self.start_p}_{self.stop_p}_{self.start_n}_{self.stop_n}" 55 | for f in ["start_p", "stop_p", "start_n", "stop_n"]: 56 | pn = getattr(self, f) 57 | if pn >= port_count: 58 | logger.warning(f"Differential pair {self.name} is defined to use not existing port number {pn} as {f}") 59 | self.correct = False 60 | 61 | 62 | @serde(type_check=coerce) 63 | class SingleEndedConfig: 64 | """Class representing and parsing single-ended config.""" 65 | 66 | start: int = field(default=0) 67 | stop: int = field(default=1) 68 | name: Optional[str] = field(default=None) 69 | nets: List[str] = field(default_factory=list) 70 | correct: bool = field(default=True, skip=True) 71 | 72 | def __post_init__(self) -> None: 73 | """Validate trace config.""" 74 | global port_count 75 | if self.name is None: 76 | self.name = f"{self.start}_{self.stop}" 77 | for f in ["start", "stop"]: 78 | pn = getattr(self, f) 79 | if pn >= port_count: 80 | logger.warning(f"Trace {self.name} is defined to use not existing port number {pn} as {f}") 81 | self.correct = False 82 | 83 | 84 | class LayerConfig: 85 | """Class representing and parsing layer config.""" 86 | 87 | def __init__(self, config: Any) -> None: 88 | """Initialize LayerConfig based on passed json object.""" 89 | self.kind = self.parse_kind(config["type"]) 90 | self.thickness = 0 91 | if config["thickness"] is not None: 92 | self.thickness = config["thickness"] / 1000 / UNIT 93 | if self.kind == LayerKind.METAL: 94 | self.file = config["name"].replace(".", "_") 95 | elif self.kind == LayerKind.SUBSTRATE: 96 | self.epsilon = config["epsilon"] 97 | 98 | def __repr__(self) -> str: 99 | """Get human-readable string describing layer.""" 100 | return f"Layer kind:{self.kind} thickness: {self.thickness}" 101 | 102 | @staticmethod 103 | def parse_kind(kind: str) -> LayerKind: 104 | """Parse type name to enum.""" 105 | if kind in ["core", "prepreg"]: 106 | return LayerKind.SUBSTRATE 107 | if kind == "copper": 108 | return LayerKind.METAL 109 | return LayerKind.OTHER 110 | 111 | 112 | class LayerKind(Enum): 113 | """Enum describing layer type.""" 114 | 115 | SUBSTRATE = 1 116 | METAL = 2 117 | OTHER = 3 118 | 119 | 120 | @serde(type_check=coerce) 121 | class Frequency: 122 | """Frequency config.""" 123 | 124 | start: float = field(default=1e6) 125 | stop: float = field(default=6e9) 126 | 127 | 128 | @serde(type_check=coerce) 129 | class Via: 130 | """Via config.""" 131 | 132 | plating_thickness: float = field(default=50) 133 | filling_epsilon: float = field(default=1) 134 | 135 | 136 | @serde(type_check=coerce) 137 | class Margin: 138 | """Margin config (how far outside area of interest should grid span).""" 139 | 140 | xy: float = field(default=1000) 141 | z: float = field(default=1000) 142 | from_trace: bool = field(default=True) 143 | 144 | 145 | @serde(type_check=coerce) 146 | class CellRatio: 147 | """Cell Ratio config (Optimal scaling between neighboring grid cell sizes).""" 148 | 149 | xy: float = field(default=1.2) 150 | z: float = field(default=1.5) 151 | 152 | 153 | @serde(type_check=coerce) 154 | class Grid: 155 | """Grid generation config (configures simulation grid density).""" 156 | 157 | inter_layers: int = field(default=4) 158 | optimal: float = field(default=50) 159 | diagonal: float = field(default=50) 160 | perpendicular: float = field(default=200) 161 | max: float = field(default=500) 162 | margin: Margin = field(default_factory=Margin) 163 | cell_ratio: CellRatio = field(default_factory=CellRatio) 164 | 165 | 166 | @serde(type_check=coerce) 167 | class _Config: 168 | """Main config class.""" 169 | 170 | format_version: str = field(default=CONFIG_FORMAT_VERSION) 171 | ports: List[PortConfig] = field(default_factory=list) 172 | frequency: Frequency = field(default_factory=Frequency) 173 | max_steps: int = field(default=100e3) 174 | pixel_size: int = field(default=5.0) 175 | via: Via = field(default_factory=Via) 176 | grid: Grid = field(default_factory=Grid) 177 | traces: List[SingleEndedConfig] = field(default_factory=list) 178 | diff_pairs: List[DifferentialPairConfig] = field(default_factory=list, rename="differential_pairs") 179 | 180 | pcb_width: int = field(default=0, skip=True) 181 | pcb_height: int = field(default=0, skip=True) 182 | layers: List[LayerConfig] = field(default_factory=list, skip=True) 183 | arguments: Namespace = field( 184 | default_factory=Namespace, skip=True, deserializer=lambda _: None, serializer=lambda _: None 185 | ) 186 | 187 | def __post_init__(self) -> None: 188 | """Validate grid setting.""" 189 | min_wavelength = 3e8 * 1e6 / sqrt(4.13) / self.frequency.stop # min wavelength (in microns) 190 | self.grid.max = min(int(min_wavelength / 10), self.grid.max) 191 | self.grid.perpendicular = min(self.grid.perpendicular, self.grid.max) 192 | self.grid.diagonal = min(self.grid.diagonal, self.grid.perpendicular) 193 | self.grid.optimal = min(self.grid.diagonal, self.grid.optimal) 194 | self.format_version = CONFIG_FORMAT_VERSION 195 | 196 | 197 | class Config: 198 | """Config validation and parsing singleton class.""" 199 | 200 | _instance = None 201 | _config: _Config 202 | 203 | def __new__(cls, *args: Any) -> Config: 204 | """Get already existing instance of Config or create new if it does not exist.""" 205 | if cls._instance is None: 206 | cls._instance = super(Config, cls).__new__(cls) 207 | return cls._instance 208 | 209 | @classmethod 210 | def set_config(cls, cfg: _Config) -> None: 211 | """Initialize inner config.""" 212 | Config()._config = cfg 213 | 214 | @classmethod 215 | def load(cls, args: Namespace) -> None: 216 | """Load config file (default: simulation.json).""" 217 | global port_count 218 | if cls._instance is None: 219 | cls._instance = Config() 220 | 221 | logger.info("Parsing config") 222 | cfg_path_s = args.config 223 | if cfg_path_s is None: 224 | cfg_path_s = DEFAULT_CONFIG_PATH 225 | cfg_path = Path(cfg_path_s).absolute() 226 | json_cfg = get_cfg_json(cfg_path, args.update_config) 227 | 228 | version = json_cfg.get("format_version", None) 229 | if is_cfg_version_invalid(version): 230 | logger.error("Config format (%s) is not supported (supported: %s)", version, CONFIG_FORMAT_VERSION) 231 | sys.exit(1) 232 | 233 | port_count = len(json_cfg["ports"]) 234 | cls._instance._config = from_dict(_Config, json_cfg) 235 | cls._instance._config.arguments = args 236 | 237 | if args.update_config: 238 | with cfg_path.open(mode="w", encoding="utf-8") as file: 239 | file.write(to_json(cls._instance._config, indent=4)) 240 | 241 | def __getattr__(self, name: str) -> Any: 242 | """Get value of field from internal config structure.""" 243 | return getattr(self._config, name) 244 | 245 | @classmethod 246 | def load_stackup(cls, stackup: Dict[str, Any]) -> None: 247 | """Load stackup from json object.""" 248 | if not cls._instance: 249 | return 250 | layers = [] 251 | for layer in stackup["layers"]: 252 | layers.append(LayerConfig(layer)) 253 | cls._instance._config.layers = list( 254 | filter( 255 | lambda layer: layer.kind in [LayerKind.METAL, LayerKind.SUBSTRATE], 256 | layers, 257 | ) 258 | ) 259 | 260 | def get_substrates(self) -> List[LayerConfig]: 261 | """Return substrate layers configs.""" 262 | return list(filter(lambda layer: layer.kind == LayerKind.SUBSTRATE, self.layers)) 263 | 264 | def get_metals(self) -> List[LayerConfig]: 265 | """Return metals layers configs.""" 266 | return list(filter(lambda layer: layer.kind == LayerKind.METAL, self.layers)) 267 | 268 | 269 | def is_cfg_version_invalid(version: str | None) -> bool: 270 | """Check if config format version is supported.""" 271 | return ( 272 | version is None 273 | or not version.split(".")[0] == CONFIG_FORMAT_VERSION.split(".")[0] 274 | or version.split(".")[1] > CONFIG_FORMAT_VERSION.split(".")[1] 275 | ) 276 | 277 | 278 | def get_cfg_json(cfg_path: Path, update_config: bool) -> Dict[str, Any]: 279 | """Read config file and load it to dictionary. 280 | 281 | If update_config switch is enabled and there is no config file at provided path, returns config stub dictionary. 282 | """ 283 | logger.info(f"Loading config from {cfg_path}") 284 | if not cfg_path.is_file() and update_config: 285 | cfg_path.touch() 286 | return {"format_version": CONFIG_FORMAT_VERSION, "ports": []} 287 | if not cfg_path.is_file(): 288 | logger.error("Config file doesn't exist: %s", cfg_path) 289 | sys.exit(1) 290 | 291 | with cfg_path.open(mode="r", encoding="utf-8") as file: 292 | try: 293 | json_cfg = json.load(file) 294 | except json.JSONDecodeError as error: 295 | logger.error("JSON decoding failed at %d:%d: %s", error.lineno, error.colno, error.msg) 296 | sys.exit(1) 297 | return json_cfg 298 | -------------------------------------------------------------------------------- /src/gerber2ems/constants.py: -------------------------------------------------------------------------------- 1 | """Module containing constans used in the app.""" 2 | 3 | import os 4 | 5 | UNIT = 1e-6 # Length units used in the whole script are microns 6 | BASE_DIR = "ems" # Name of the directory that outputs will be stored in 7 | SIMULATION_DIR = os.path.join(BASE_DIR, "simulation") 8 | GEOMETRY_DIR = os.path.join(BASE_DIR, "geometry") 9 | RESULTS_DIR = os.path.join(BASE_DIR, "results") 10 | PLOT_STYLE = os.path.join(os.path.abspath(os.path.dirname(__file__)), "antmicro.mplstyle") 11 | DEFAULT_CONFIG_PATH = "./simulation.json" 12 | 13 | # Via geometry is approximated using n-sided right prism 14 | VIA_POLYGON = 12 15 | 16 | STACKUP_FORMAT_VERSION = "1.0" 17 | CONFIG_FORMAT_VERSION = "1.2" 18 | -------------------------------------------------------------------------------- /src/gerber2ems/gerber_io.py: -------------------------------------------------------------------------------- 1 | """Module provides classes related to gerber file parsing and representation.""" 2 | 3 | from dataclasses import dataclass, field 4 | from pathlib import Path 5 | from typing import List, Dict, Optional, Callable 6 | from enum import Enum 7 | import re 8 | import logging 9 | from functools import partial 10 | from math import cos, sin, radians 11 | from copy import deepcopy 12 | 13 | logger = logging.getLogger(__name__) 14 | 15 | 16 | class PlotMode(Enum): 17 | """Enum represents Plotting mode, matching gerber file specification (G01,G02,G03).""" 18 | 19 | LINEAR = 1 20 | CIRCULAR_CLOCK = 2 21 | CIRCULAR_NCLOCK = 3 22 | 23 | 24 | @dataclass 25 | class NumberFormat: 26 | """Class contains format which is used to encode floats in gerber file.""" 27 | 28 | int_digits: int = 4 29 | """Maximum number of digits used to encode integer part""" 30 | frac_digits: int = 6 31 | """Number of digits used to encode fractional part""" 32 | 33 | def parse(self, i: str) -> float: 34 | """Decode number from gerber format and convert it to float.""" 35 | return float(i) / (10**self.frac_digits) 36 | 37 | 38 | @dataclass 39 | class Position: 40 | """Coordinates of 2D point.""" 41 | 42 | x: float 43 | y: float 44 | 45 | def mirror(self, axis: str) -> None: 46 | """Mirror point using `axis` axis.""" 47 | setattr(self, axis, -getattr(self, axis)) 48 | 49 | def rotate(self, angle: float) -> None: 50 | """Rotate point around (0,0).""" 51 | (self.x, self.y) = (self.x * cos(angle) + self.y * sin(angle), self.x * sin(angle) + self.y * cos(angle)) 52 | 53 | def scale(self, scale: float) -> None: 54 | """Scale position by `scale`.""" 55 | (self.x, self.y) = (self.x * scale, self.y * scale) 56 | 57 | def move(self, offset: "Position") -> None: 58 | """Move point by `offset`.""" 59 | (self.x, self.y) = (self.x + offset.x, self.y + offset.y) 60 | 61 | 62 | @dataclass 63 | class PadMeta: 64 | """Class stores metadata about pad.""" 65 | 66 | comp_ref: str 67 | """Reference designator of component this pad belongs to""" 68 | pin_num: str 69 | """Pad numeration inside associated component (eg. 1, A1, ..)""" 70 | pin_name: str 71 | """Pad name/function (eg. GPIO_1)""" 72 | 73 | 74 | @dataclass 75 | class Pad: 76 | """Class describes component pad (flashed aperture in gerber file).""" 77 | 78 | aperture: str 79 | """Name/key of aperture used to create ths pad""" 80 | net: str 81 | """Net this pad is connected to""" 82 | pos: Position 83 | """Pad coordinates""" 84 | pin_ref: Optional[PadMeta] = None 85 | """Pad metadata""" 86 | additive: bool = True 87 | """If false pad draw will work like eraser""" 88 | mirror: str = "N" 89 | """Aperture is mirrored in specified axis""" 90 | rotation: float = 0 91 | """Rotation of aperture""" 92 | scale: float = 1 93 | """Scale of aperture""" 94 | 95 | 96 | @dataclass 97 | class TraceSegment: 98 | """Class represents single trace segment (one line).""" 99 | 100 | start: Position 101 | """Coordinates of point on line start""" 102 | stop: Position 103 | """Coordinates of point on line end""" 104 | 105 | aperture: str 106 | """Name/key of aperture used to create ths trace (determines width)""" 107 | width: float 108 | """Trace width (should follow aperture size)""" 109 | mode: PlotMode = PlotMode.LINEAR 110 | """Mode in which trace was drawn""" 111 | normal: bool = True 112 | """Matters only for traces near parallel to axis and when width==0; 113 | If true normal(pointing inward shape) aligns with positive direction of dominant axis""" 114 | 115 | def __post_init__(self) -> None: 116 | """Ensure that position is not shared with anything.""" 117 | self.start = deepcopy(self.start) 118 | self.stop = deepcopy(self.stop) 119 | 120 | def dominant_x(self) -> bool: 121 | """Return True when difference between start and stop is larger on X axis than on Y axis.""" 122 | return abs(self.start.x - self.stop.x) > abs(self.start.y - self.stop.y) 123 | 124 | def rotate(self, ang: float) -> None: 125 | """Rotate segment by `ang` angle (in degrees).""" 126 | if self.dominant_x(): 127 | flipped_norm = (self.start.y < 0) != self.normal 128 | else: 129 | flipped_norm = (self.start.x < 0) != self.normal 130 | self.start.rotate(ang) 131 | self.stop.rotate(ang) 132 | if self.dominant_x(): 133 | self.normal = (self.start.y < 0) ^ flipped_norm 134 | else: 135 | self.normal = (self.start.x < 0) ^ flipped_norm 136 | self.normal = self.normal if ang % 360 < 180 else not self.normal 137 | 138 | 139 | @dataclass 140 | class Trace: 141 | """Collection of traces of single net.""" 142 | 143 | segments: List[TraceSegment] 144 | 145 | 146 | class ApertureType: 147 | """Abstract class for describing Aperture shape.""" 148 | 149 | hole_diameter: float 150 | """Diameter of a round hole. A decimal >0. If omitted the aperture is solid.""" 151 | 152 | def _contours(self) -> List[TraceSegment]: 153 | """Return contours of an aperture.""" 154 | return [] 155 | 156 | def contours( 157 | self, pos: Optional[Position] = None, rot: float = 0, scale: float = 1, mirror: str = "N", post_rot: float = 0 158 | ) -> List[TraceSegment]: 159 | """Return contours of an aperture with transform applied. 160 | 161 | Rotation can be of two kinds `rot` that is applied before scale/move, and `post_rot` that is applied after them 162 | """ 163 | cont = self._contours() 164 | for c in cont: 165 | if "X" in mirror: 166 | c.start.mirror("x") 167 | c.stop.mirror("x") 168 | c.normal = c.normal if c.dominant_x() else not c.normal 169 | if "Y" in mirror: 170 | c.start.mirror("y") 171 | c.stop.mirror("y") 172 | c.normal = c.normal if not c.dominant_x() else not c.normal 173 | c.rotate(rot) 174 | c.start.scale(scale) 175 | c.stop.scale(scale) 176 | c.normal = c.normal if scale > 0 else not c.normal 177 | pos = Position(0, 0) if pos is None else pos 178 | c.start.move(pos) 179 | c.stop.move(pos) 180 | c.rotate(post_rot) 181 | return cont 182 | 183 | 184 | @dataclass 185 | class ApertureCircle(ApertureType): 186 | """Aperture shape that is circle.""" 187 | 188 | diameter: float 189 | 190 | def _contours(self) -> List[TraceSegment]: 191 | """Return contours of an aperture.""" 192 | d2 = self.diameter / 2 193 | points = [ 194 | Position(0, d2), 195 | Position(d2, 0), 196 | Position(-d2, 0), 197 | Position(0, -d2), 198 | ] 199 | seg = partial(TraceSegment, aperture="", width=0, mode=PlotMode.CIRCULAR_CLOCK) 200 | return [ 201 | seg(points[0], points[1]), 202 | seg(points[1], points[2]), 203 | seg(points[2], points[3]), 204 | seg(points[3], points[0]), 205 | ] 206 | 207 | 208 | @dataclass 209 | class ApertureRect(ApertureType): 210 | """Aperture shape that is rectangle.""" 211 | 212 | x: float 213 | """Width""" 214 | y: float 215 | """Height""" 216 | 217 | def _contours(self) -> List[TraceSegment]: 218 | """Return contours of an aperture.""" 219 | x2 = self.x / 2 220 | y2 = self.y / 2 221 | points = [ 222 | Position(x2, y2), 223 | Position(-x2, y2), 224 | Position(-x2, -y2), 225 | Position(x2, -y2), 226 | ] 227 | seg = partial(TraceSegment, aperture="", width=0, mode=PlotMode.LINEAR) 228 | return [ 229 | seg(points[0], points[1], normal=False), 230 | seg(points[1], points[2], normal=True), 231 | seg(points[2], points[3], normal=True), 232 | seg(points[3], points[0], normal=False), 233 | ] 234 | 235 | 236 | @dataclass 237 | class ApertureObround(ApertureRect): 238 | """Aperture shape that is obround (two half circles with rect in between).""" 239 | 240 | def _contours(self) -> List[TraceSegment]: 241 | """Return contours of an aperture.""" 242 | x2 = self.x / 2 243 | y2 = self.y / 2 244 | d = y2 - x2 245 | rect = [ 246 | Position(d, y2), 247 | Position(-d, y2), 248 | Position(-d, -y2), 249 | Position(d, -y2), 250 | ] 251 | circ = [Position(x2, 0), Position(-x2, 0)] 252 | seg_c = partial(TraceSegment, aperture="", width=0, mode=PlotMode.CIRCULAR_CLOCK) 253 | seg_l = partial(TraceSegment, aperture="", width=0, mode=PlotMode.LINEAR) 254 | return [ 255 | seg_l(rect[0], rect[1], normal=False), 256 | seg_l(rect[2], rect[3], normal=True), 257 | seg_c(rect[0], circ[0]), 258 | seg_c(rect[3], circ[0]), 259 | seg_c(rect[1], circ[1]), 260 | seg_c(rect[2], circ[1]), 261 | ] 262 | 263 | 264 | def _points2outline(points: List[Position]) -> List[TraceSegment]: 265 | """Connect `points` with trace segments.""" 266 | seg = partial(TraceSegment, aperture="", width=0, mode=PlotMode.LINEAR) 267 | segments = [] 268 | for idx in range(len(points)): 269 | s = seg(points[idx], points[idx % len(points)]) 270 | if s.dominant_x(): 271 | s.normal = s.start.y < 0 272 | else: 273 | s.normal = s.start.x < 0 274 | segments.append(s) 275 | return segments 276 | 277 | 278 | def _parse_expr(s: str) -> Callable: 279 | """Transform expression from aperture macro definition into python callable.""" 280 | s = s.replace(r"x", r"*") 281 | s = re.sub(r"\$([0-9]*)", r"args[\1]", s) 282 | return lambda args: eval(s, {"__builtins__": None}, {"args": args}) 283 | 284 | 285 | @dataclass 286 | class AperturePolygon(ApertureType): 287 | """Aperture shape that is regular polygon.""" 288 | 289 | diameter: float 290 | """Diameter of the circle circumscribing the regular polygon, i.e. the circle through the polygon vertices""" 291 | vertices: int 292 | """Number of vertices""" 293 | rotation: float 294 | """The rotation angle, in degrees counterclockwise. A decimal. 295 | With rotation angle zero there is a vertex on the positive X-axis 296 | through the aperture center""" 297 | 298 | def _contours(self) -> List[TraceSegment]: 299 | """Return contours of an aperture.""" 300 | points = [] 301 | d2 = self.diameter 302 | for i in range(self.vertices): 303 | ang = radians(self.rotation + 360 * i / self.vertices) 304 | points.append(Position(d2 * cos(ang), d2 * sin(ang))) 305 | return _points2outline(points) 306 | 307 | 308 | class ApertureMacro(ApertureType): 309 | """Aperture macro definition. 310 | 311 | After setting `args` it represents also specific aperture 312 | """ 313 | 314 | args: List[float] 315 | """Values during aperture instantiation (macro call)""" 316 | name: str 317 | """Macro ID""" 318 | variables: List[Callable] 319 | """Expressions that calculate additional macro variables""" 320 | commands: List[Callable] 321 | """Commands that create shape of aperture""" 322 | 323 | def __init__(self, lines: List[str]) -> None: 324 | """Parse aperture macro definition.""" 325 | lines_i = iter(lines) 326 | self.name = next(lines_i).removeprefix("AM") 327 | self.variables = [] 328 | self.commands = [] 329 | for line in lines_i: 330 | if line.startswith("0"): 331 | # comment line 332 | continue 333 | if line.startswith("$"): 334 | # variable 335 | self.variables.append(_parse_expr(line.partition("=")[2])) 336 | continue 337 | 338 | line_i = iter(line.split(",")) 339 | op = next(line_i) 340 | sline = [_parse_expr(li) for li in line_i] 341 | if op == "1": 342 | # circle 343 | def f(args: List[float], sline: List[Callable] = sline) -> List[TraceSegment]: 344 | param = [p(args) for p in sline] 345 | ap = ApertureCircle(diameter=param[1] * 1000) 346 | rot = param[4] if len(param) > 4 else 0 347 | return ap.contours(pos=Position(param[2] * 1000, param[3] * 1000), post_rot=rot) 348 | 349 | elif op == "20": 350 | # line start/stop/width 351 | def f(args: List[float], sline: List[Callable] = sline) -> List[TraceSegment]: 352 | param = [p(args) for p in sline] 353 | trace = TraceSegment( 354 | start=Position(param[2] * 1000, param[3] * 1000), 355 | stop=Position(param[4] * 1000, param[5] * 1000), 356 | aperture="", 357 | width=param[1] * 1000, 358 | ) 359 | trace.rotate(param[6]) 360 | return [trace] 361 | 362 | elif op == "21": 363 | # line center/width/length 364 | def f(args: List[float], sline: List[Callable] = sline) -> List[TraceSegment]: 365 | param = [p(args) for p in sline] 366 | len2 = 1000 * param[1] / 2 367 | trace = TraceSegment( 368 | start=Position(param[3] * 1000 - len2, param[4] * 1000), 369 | stop=Position(param[3] * 1000 + len2, param[4] * 1000), 370 | aperture="", 371 | width=param[2] * 1000, 372 | ) 373 | trace.rotate(param[5]) 374 | return [trace] 375 | 376 | elif op == "4": 377 | # outline 378 | def f(args: List[float], sline: List[Callable] = sline) -> List[TraceSegment]: 379 | param = [p(args) for p in sline] 380 | points = [] 381 | for i in range(param[1] + 1): 382 | points.append(Position(param[2 + i * 2] * 1000, param[3 + i * 2] * 1000)) 383 | contours = _points2outline(points) 384 | for seg in contours: 385 | seg.rotate(param[-1]) 386 | return contours 387 | 388 | elif op == "5": 389 | # polygon 390 | def f(args: List[float], sline: List[Callable] = sline) -> List[TraceSegment]: 391 | param = [p(args) for p in sline] 392 | ap = AperturePolygon(vertices=param[1], diameter=param[4] * 1000, rotation=0) 393 | return ap.contours(pos=Position(param[2] * 1000, param[3] * 1000), post_rot=param[5]) 394 | 395 | elif op == "7": 396 | # Thermal relief 397 | # TODO 398 | pass 399 | else: 400 | raise Exception(f"Unknown aperture macro op: {line}") 401 | self.commands.append(f) 402 | 403 | def _contours(self) -> List[TraceSegment]: 404 | """Return contours of an aperture.""" 405 | for v in self.variables: 406 | self.args.append(v([0.0] + self.args)) 407 | contours = [] 408 | for cmd in self.commands: 409 | contours.extend(cmd([0.0] + self.args)) 410 | return contours 411 | 412 | 413 | @dataclass 414 | class Aperture: 415 | """Represents Aperture as specified in gerber file. 416 | 417 | Aperture is basic shape used to draw anything in gerber file 418 | """ 419 | 420 | function: str 421 | """Intended use of this aperture (eg. Via, SMD-pad)""" 422 | data: ApertureType 423 | """Type/Shape of this aperture""" 424 | 425 | 426 | @dataclass 427 | class FileFormat: 428 | """Format data about file.""" 429 | 430 | unit: str = "MM" 431 | """Unit in which all dimensions/coordinates are given""" 432 | omit_zeros: bool = True 433 | """Leading zeros in numbers can be omitted if True""" 434 | absolute: bool = True 435 | """Coordinates used in this file are absolute if True""" 436 | x_format: NumberFormat = field(default_factory=lambda: NumberFormat()) 437 | """Format used to encode position in X-axis""" 438 | y_format: NumberFormat = field(default_factory=lambda: NumberFormat()) 439 | """Format used to encode position in Y-axis""" 440 | 441 | def parse_position(self, x: str, y: str) -> Position: 442 | """Convert position from format used in gerber file to `Position` class.""" 443 | pos = Position(self.x_format.parse(x), self.y_format.parse(y)) 444 | if self.unit == "MM": 445 | pos.x *= 1000 446 | pos.y *= 1000 447 | return pos 448 | 449 | 450 | @dataclass 451 | class ParserState: 452 | """Temporary state of gerber file parser.""" 453 | 454 | aperture: str = "" 455 | """Recently set aperture (will be used for upcoming trace creation/pad flashing)""" 456 | aperture_func: str = "" 457 | """Recently set aperture function (will be set for upcoming aperture declarations)""" 458 | net: str = "no-net" 459 | """Recently set net (will be used for upcoming trace creation/pad flashing)""" 460 | refpin: Optional[PadMeta] = None 461 | """Recently set pad metadata (will be used for upcoming pad flashing)""" 462 | unparsed_region: bool = False 463 | """Region of code that is currently ignored by parser""" 464 | pos: Position = field(default_factory=lambda: Position(x=0, y=0)) 465 | """Current position (will be used for upcoming trace creation)""" 466 | plot_mode: PlotMode = PlotMode.LINEAR 467 | """Current plot mode (will be used for upcoming trace creation)""" 468 | additive: bool = True 469 | """If false future draws will work like eraser""" 470 | mirror: str = "N" 471 | """Aperture should be mirrored for upcoming operations""" 472 | rotation: float = 0 473 | """Rotation of aperture for upcoming operations""" 474 | scale: float = 1 475 | """Scale of aperture for upcoming operations""" 476 | fformat: FileFormat = field(default_factory=lambda: FileFormat()) 477 | """Position/dimension format used currently""" 478 | zone: bool = False 479 | """Plotting zone (started by G37, ends with G36)""" 480 | zone_contours: List[TraceSegment] = field(default_factory=list) 481 | """Contours of zone that is currently being parsed""" 482 | ap_macro: List[str] = field(default_factory=list) 483 | """Body of currently parsed aperture macro""" 484 | 485 | 486 | @dataclass(init=False) 487 | class GerberFile: 488 | """Gerber file parsed representation.""" 489 | 490 | unparsed: str 491 | """Parts of code that are currently not supported by parser""" 492 | apertures: Dict[str, Aperture] 493 | """All apertures used in this file""" 494 | traces: Dict[str, Trace] 495 | """Traces defined in this file, grouped by nets""" 496 | pads: List[Pad] 497 | """List of all pads defined in this file""" 498 | parser: ParserState 499 | """Temporary parser state""" 500 | ap_macros: Dict[str, ApertureMacro] 501 | """List of aperture macro definitions""" 502 | 503 | def __init__(self, path: Path) -> None: 504 | """Load and parse gerber file from specified path.""" 505 | logger.info(f"Parsing gerber file: {path}") 506 | self.unparsed = "" 507 | self.apertures = {} 508 | self.traces = {} 509 | self.pads = [] 510 | self.ap_macros = {} 511 | self.parser = ParserState() 512 | with open(path) as file_h: 513 | file = file_h.read() 514 | lines = re.findall(r".*[*][%]?\n", file) 515 | for line in lines: 516 | if line.startswith("%"): 517 | self.process_percent_line(line) 518 | else: 519 | self.process_normal_line(line) 520 | 521 | def process_percent_line(self, line: str) -> None: 522 | """Parse & process line starting with `%` sign. 523 | 524 | % lines carry following information: 525 | - pin information (component, pin number, pin name) for next pads 526 | - Function of following apertures 527 | - Net of following metal patterns 528 | - Scaling, polarization, rotation, mirror of aperture 529 | - Aperture definition 530 | 531 | Function updates parser state and aperture dictionary 532 | """ 533 | self.unparsed = self.unparsed + line 534 | sline = line.strip("%*\n") 535 | split = sline.split(",") 536 | if split[0][0:2] == "AM": 537 | self.parser.ap_macro.append(sline) 538 | elif split[0] == "TO.P": 539 | self.parser.refpin = PadMeta( 540 | comp_ref=split[1], pin_num=split[2], pin_name=split[3] if len(split) > 3 else "" 541 | ) 542 | elif split[0] == "TO.N": 543 | self.parser.net = split[1] 544 | elif split[0] == "TA" and split[1] == "AperFunction": 545 | self.parser.aperture_func = split[2] 546 | elif split[0] == "TD": 547 | self.parser.net = "no-net" 548 | self.parser.refpin = None 549 | elif split[0][0:2] == "LP": 550 | self.parser.additive = split[0][2] == "D" 551 | elif split[0][0:2] == "LR": 552 | self.parser.rotation = float(split[0][2:]) 553 | elif split[0][0:2] == "LM": 554 | self.parser.mirror = split[0][2:].upper() 555 | elif split[0][0:2] == "LS": 556 | self.parser.scale = float(split[0][2:]) 557 | 558 | elif split[0].startswith("AD"): 559 | full_id = split[0].split(",")[0].removeprefix("AD") 560 | aper_data_type = full_id.removeprefix("D").lstrip("0123456789") 561 | name = full_id.removesuffix(aper_data_type) 562 | aper_data = ApertureType() 563 | p = split[1].split("X") 564 | p_used = len(p) 565 | if aper_data_type == "C": 566 | aper_data = ApertureCircle(float(p[0]) * 1000) 567 | p_used = 1 568 | elif aper_data_type == "R": 569 | aper_data = ApertureRect(float(p[0]) * 1000, float(p[1]) * 1000) 570 | p_used = 2 571 | elif aper_data_type == "O": 572 | aper_data = ApertureObround(float(p[0]) * 1000, float(p[1]) * 1000) 573 | p_used = 2 574 | elif aper_data_type == "P": 575 | aper_data = AperturePolygon(float(p[0]) * 1000, int(p[1]), float(p[2])) 576 | p_used = 3 577 | elif aper_data_type in self.ap_macros: 578 | p_used = len(p) 579 | aper_data = deepcopy(self.ap_macros[aper_data_type]) 580 | aper_data.args = [float(i) for i in p] 581 | 582 | if p_used < len(p): 583 | aper_data.hole_diameter = float(p[p_used]) * 1000 584 | self.apertures[name] = Aperture(self.parser.aperture_func, aper_data) 585 | 586 | def process_normal_line(self, line: str) -> None: 587 | """Parse & process normal line (not starting with `%` sign). 588 | 589 | Normal line can have following functions: 590 | - Start/Stop Region/zone(G36-G37), block macro(AB), step&repeat(SR) definition 591 | - Comments (GO4) 592 | - Plot mode (G01-G03), Linear/Circular 593 | - Plotting operation (X*) 594 | - Set aperture (D*) 595 | - Body of aperture macro 596 | 597 | Function updates parser state and Trace/Pad collections 598 | """ 599 | sline = line.strip("%*\n") 600 | split = sline.split(",") 601 | if split[0] in ["AB", "SR"]: 602 | self.parser.unparsed_region = not self.parser.unparsed_region 603 | 604 | if self.parser.unparsed_region: 605 | self.unparsed = self.unparsed + line 606 | return 607 | 608 | if len(self.parser.ap_macro) != 0: 609 | self.parser.ap_macro.append(sline) 610 | if line.rstrip().endswith("%"): 611 | apm = ApertureMacro(self.parser.ap_macro) 612 | self.ap_macros[apm.name] = apm 613 | self.parser.ap_macro = [] 614 | elif split[0] == "G36": 615 | self.parser.zone_contours = [] 616 | self.parser.zone = True 617 | elif split[0] == "G37": 618 | s_start = self.parser.zone_contours[0] 619 | s_end = self.parser.zone_contours[-1] 620 | self.parser.zone_contours.append(TraceSegment(s_start.start, s_end.stop, "", 0, PlotMode.LINEAR)) 621 | trace = self.traces.get(self.parser.net, Trace([])) 622 | trace.segments.extend(self.parser.zone_contours) 623 | self.traces[self.parser.net] = trace 624 | self.parser.zone_contours = [] 625 | self.parser.zone = False 626 | elif split[0][0:3] in ["G04", "G75"]: 627 | self.unparsed = self.unparsed + line 628 | elif split[0].startswith("G"): 629 | self.parser.plot_mode = PlotMode(int(split[0][2])) 630 | elif split[0].startswith("D"): 631 | self.parser.aperture = split[0] 632 | elif split[0].startswith("X"): 633 | self.process_drawing_line(sline) 634 | 635 | def process_drawing_line(self, line: str) -> None: 636 | """Parse & process line that describes plotting operation (starting with X). 637 | 638 | Updates trace/pad collections, moves cursor position 639 | """ 640 | sline = line.removeprefix("X") 641 | [x, _, y] = sline.partition("Y") 642 | [y, _, op] = y.partition("D") 643 | [y, _, y_offset] = y.partition("J") 644 | [y, _, x_offset] = y.partition("I") 645 | pos = self.parser.fformat.parse_position(x, y) 646 | opi = int(op) 647 | if opi == 1: 648 | if self.parser.zone: 649 | self.parser.zone_contours.append(TraceSegment(self.parser.pos, pos, "", 0, self.parser.plot_mode)) 650 | else: 651 | trace = self.traces.get(self.parser.net, Trace([])) 652 | ap_name = self.parser.aperture 653 | ap = self.apertures.get(ap_name, None) 654 | if not ap: 655 | logger.error(f"Aperture `{ap_name}` used for line: `{line}` not defined!") 656 | return 657 | if not isinstance(ap.data, ApertureCircle): 658 | logger.error(f"Aperture `{ap_name}` used for line: `{line}` is not circular aperture!") 659 | return 660 | 661 | trace.segments.append( 662 | TraceSegment(self.parser.pos, pos, ap_name, ap.data.diameter, self.parser.plot_mode) 663 | ) 664 | self.traces[self.parser.net] = trace 665 | elif opi == 2: 666 | self.parser.pos = pos 667 | elif opi == 3: 668 | aperture = self.apertures.get(self.parser.aperture, None) 669 | pin_ref = None if aperture is None or aperture.function != "ComponentPad" else self.parser.refpin 670 | self.pads.append( 671 | Pad( 672 | aperture=self.parser.aperture, 673 | net=self.parser.net, 674 | pos=pos, 675 | pin_ref=pin_ref, 676 | additive=self.parser.additive, 677 | mirror=self.parser.mirror, 678 | rotation=self.parser.rotation, 679 | scale=self.parser.scale, 680 | ) 681 | ) 682 | -------------------------------------------------------------------------------- /src/gerber2ems/importer.py: -------------------------------------------------------------------------------- 1 | """Module containing functions for importing gerbers.""" 2 | 3 | import csv 4 | import json 5 | import subprocess 6 | import os 7 | import logging 8 | from typing import List, Tuple 9 | import sys 10 | import re 11 | from functools import partial 12 | from multiprocessing import Pool 13 | from pathlib import Path 14 | import PIL.Image 15 | import numpy as np 16 | from nanomesh import Image, Mesher2D 17 | import matplotlib as mpl 18 | 19 | from gerber2ems.config import Config 20 | from gerber2ems.constants import ( 21 | GEOMETRY_DIR, 22 | UNIT, 23 | STACKUP_FORMAT_VERSION, 24 | ) 25 | 26 | logger = logging.getLogger(__name__) 27 | 28 | PIL.Image.MAX_IMAGE_PIXELS = None 29 | cfg = Config() 30 | 31 | 32 | def process_gbrs_to_pngs() -> None: 33 | """Process all gerber files to PNG's. 34 | 35 | Finds edge cuts gerber as well as copper gerbers in `fab` directory. 36 | Processes copper gerbers into PNG's using edge_cuts for framing. 37 | Output is saved to `ems/geometry` folder 38 | """ 39 | logger.info("Processing gerber files (may take a while for larger boards)") 40 | 41 | fab = Path.cwd() / "fab" 42 | edge = next(fab.glob("*Edge_Cuts.gbr"), None) 43 | if edge is None: 44 | logger.error("No edge_cuts gerber found") 45 | sys.exit(1) 46 | 47 | layers = list(fab.glob("*_Cu.gbr")) 48 | if len(layers) == 0: 49 | logger.warning("No copper gerbers found") 50 | 51 | with Pool(initargs=(cfg._config,), initializer=Config.set_config) as p: 52 | p.map(partial(gbr_to_png, edge), layers) 53 | 54 | 55 | def gbr_to_png(edge_filename: Path, gerber_filename: Path) -> None: 56 | """Generate PNG from gerber file. 57 | 58 | Generates PNG of a gerber using gerbv. 59 | Edge cuts gerber is used to crop the image correctly. 60 | Output DPI is based on config.pixel_size constant. 61 | """ 62 | output_filename = Path.cwd() / GEOMETRY_DIR / gerber_filename.with_suffix(".png").name.rpartition("-")[2] 63 | 64 | dpi = 1 / (cfg.pixel_size * UNIT / 0.0254) 65 | logger.debug("Generating PNG (DPI: %d) for %s", dpi, gerber_filename) 66 | 67 | not_cropped_name = output_filename.with_stem(output_filename.stem + "_not_cropped") 68 | if not dpi.is_integer(): 69 | logger.warning("DPI is not an integer number: %f", dpi) 70 | gerbv_command = [ 71 | "gerbv", 72 | gerber_filename, 73 | edge_filename, 74 | "--background=#000000", 75 | "--foreground=#ffffffff", 76 | "--foreground=#00007f", 77 | "-o", 78 | not_cropped_name, 79 | "--dpi", 80 | f"{dpi}", 81 | "--border=0", 82 | "--export=png", 83 | "-a", 84 | ] 85 | 86 | subprocess.run(gerbv_command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) 87 | 88 | not_cropped_image = PIL.Image.open(not_cropped_name) 89 | 90 | edge_width = 0 91 | v_probe = not_cropped_image.height / 2 92 | px_access = not_cropped_image.load() 93 | for i in range(not_cropped_image.width): 94 | px = px_access[i, v_probe] 95 | if 0xBF > px[2] > 0x3F: 96 | # px belongs to edge 97 | edge_width += 1 98 | continue 99 | if edge_width != 0: 100 | break 101 | ew2 = int(edge_width / 2) 102 | cropped_image = not_cropped_image.crop((ew2, ew2, not_cropped_image.width - ew2, not_cropped_image.height - ew2)) 103 | cropped_image.save(output_filename) 104 | 105 | if not cfg.arguments.debug: 106 | os.remove(not_cropped_name) 107 | 108 | 109 | def get_dimensions(input_filename: str) -> Tuple[int, int]: 110 | """Return board dimensions based on png. 111 | 112 | Opens PNG found in `ems/geometry` directory, 113 | gets it's size and subtracts border thickness to get board dimensions 114 | """ 115 | pixel_size = cfg.pixel_size 116 | path = os.path.join(GEOMETRY_DIR, input_filename) 117 | image = PIL.Image.open(path) 118 | image_width, image_height = image.size 119 | height = image_height * pixel_size 120 | width = image_width * pixel_size 121 | logger.debug("Board dimensions read from file are: height:%f width:%f", height, width) 122 | return (width, height) 123 | 124 | 125 | def get_triangles(input_filename: str) -> np.ndarray: 126 | """Triangulate image. 127 | 128 | Processes file from `ems/geometry`. 129 | Converts to grayscale, thresholds it to remove border 130 | and then uses Nanomesh to create a triangular mesh of the copper. 131 | Returns a list of triangles, where each triangle consists of coordinates for each vertex. 132 | """ 133 | img_path = Path(GEOMETRY_DIR) / input_filename 134 | image = PIL.Image.open(img_path) 135 | gray = image.convert("L") 136 | thresh = gray.point(lambda p: 255 if p < 230 else 0) 137 | cooper_np = np.array(thresh) 138 | copper = Image(cooper_np) 139 | 140 | mesher = Mesher2D(copper) 141 | # These constans are set so there won't be to many triangles. 142 | # If in some case triangles are too coarse they should be adjusted 143 | max_edge_dist = int(60000 / (cfg.pixel_size**2 / 25)) 144 | mesher.generate_contour(max_edge_dist=max_edge_dist, precision=1, group_regions=False) 145 | mesher.plot_contour() 146 | mesh = mesher.triangulate(opts=f"epAq15a{max_edge_dist}") 147 | 148 | points = mesh.get("triangle").points 149 | cells = mesh.get("triangle").cells 150 | 151 | # Selecting only triangles that represent copper 152 | cu_triangles = [] 153 | for cell in cells: 154 | t = (points[cell[0]], points[cell[1]], points[cell[2]]) 155 | center = np.average(t, axis=0) 156 | is_copper = int(cooper_np[int(center[0]), int(center[1])] < 127) 157 | if not is_copper: 158 | continue 159 | cu_triangles.append( 160 | [ 161 | image_to_board_coordinates(t[0]), 162 | image_to_board_coordinates(t[1]), 163 | image_to_board_coordinates(t[2]), 164 | ] 165 | ) 166 | cu_triangles_np = np.stack(cu_triangles, axis=0) 167 | 168 | logger.debug("Found %d triangles for %s", len(cu_triangles), input_filename) 169 | 170 | if cfg.arguments.debug: 171 | plot_mesh(img_path, image.size, cu_triangles_np) 172 | 173 | return cu_triangles_np 174 | 175 | 176 | def plot_mesh(img_path: Path, img_size: Tuple[int, int], cu_triangles_np: np.ndarray) -> None: 177 | """Plot cooper mesh to file.""" 178 | filename = img_path.with_stem(img_path.stem + "_mesh") 179 | logger.debug("Saving mesh to file: %s", filename) 180 | fig, ax = mpl.pyplot.subplots() 181 | 182 | ax.set_xlim(0, image_to_board_coordinates(img_size[0]) / 1000) 183 | ylim = image_to_board_coordinates(img_size[1]) / 1000 184 | ax.set_ylim(0, ylim) 185 | x, y = cu_triangles_np[:, :, 1].flatten() / 1000, -cu_triangles_np[:, :, 0].flatten() / 1000 + ylim 186 | cu_count = cu_triangles_np.shape[0] 187 | ax.set_aspect("equal") 188 | ax.set_xlabel("Slice X position [mm]") 189 | ax.set_ylabel("Slice Y position [mm]") 190 | ax.set_title(f"{img_path.stem} triangle mesh") 191 | c = np.ones(cu_count) 192 | cmap = mpl.colors.ListedColormap("#B87333") 193 | ax.tripcolor(x, y, c, triangles=np.arange(cu_count * 3).reshape((cu_count, 3)), edgecolor="k", lw=0.05, cmap=cmap) 194 | fig.savefig( 195 | filename, 196 | dpi=2400, 197 | bbox_inches="tight", 198 | ) 199 | mpl.pyplot.close() 200 | 201 | 202 | def image_to_board_coordinates(point: np.ndarray | int) -> np.ndarray: 203 | """Transform point coordinates from image to board coordinates.""" 204 | return point * cfg.pixel_size 205 | 206 | 207 | def get_vias() -> List[List[float]]: 208 | """Get via information from excellon file. 209 | 210 | Looks for excellon file in `fab` directory. Its filename should end with `-PTH.drl` 211 | It then processes it to find all vias. 212 | """ 213 | files = os.listdir(os.path.join(os.getcwd(), "fab")) 214 | drill_filename = next(filter(lambda name: "-PTH.drl" in name, files), None) 215 | if drill_filename is None: 216 | logger.error("Couldn't find drill file") 217 | sys.exit(1) 218 | 219 | drills = {0: 0.0} # Drills are numbered from 1. 0 is added as a "no drill" option 220 | current_drill = 0 221 | vias: List[List[float]] = [] 222 | with open(os.path.join(os.getcwd(), "fab", drill_filename), "r", encoding="utf-8") as drill_file: 223 | for line in drill_file.readlines(): 224 | # Regex for finding drill sizes (in mm) 225 | match = re.fullmatch("T([0-9]+)C([0-9]+.[0-9]+)\\n", line) 226 | if match is not None: 227 | drills[int(match.group(1))] = float(match.group(2)) / 1000 / UNIT 228 | 229 | # Regex for finding drill switches (in mm) 230 | match = re.fullmatch("T([0-9]+)\\n", line) 231 | if match is not None: 232 | current_drill = int(match.group(1)) 233 | 234 | # Regex for finding hole positions (in mm) 235 | match = re.fullmatch("X([0-9]+.[0-9]+)Y([0-9]+.[0-9]+)\\n", line) 236 | if match is not None: 237 | if current_drill in drills: 238 | logger.debug( 239 | f"Adding via at: X{float(match.group(1)) / 1000 / UNIT}Y{float(match.group(2)) / 1000 / UNIT}" 240 | ) 241 | vias.append( 242 | [ 243 | float(match.group(1)) / 1000 / UNIT, 244 | float(match.group(2)) / 1000 / UNIT, 245 | drills[current_drill], 246 | ] 247 | ) 248 | else: 249 | logger.warning("Drill file parsing failed. Drill with specifed number wasn't found") 250 | logger.debug("Found %d vias", len(vias)) 251 | return vias 252 | 253 | 254 | def import_stackup() -> None: 255 | """Import stackup information from `fab/stackup.json` file and load it into config object.""" 256 | filename = "fab/stackup.json" 257 | with open(filename, "r", encoding="utf-8") as file: 258 | try: 259 | stackup = json.load(file) 260 | except json.JSONDecodeError as error: 261 | logger.error( 262 | "JSON decoding failed at %d:%d: %s", 263 | error.lineno, 264 | error.colno, 265 | error.msg, 266 | ) 267 | sys.exit(1) 268 | ver = stackup["format_version"] 269 | if ( 270 | ver is not None 271 | and ver.split(".")[0] == STACKUP_FORMAT_VERSION.split(".", maxsplit=1)[0] 272 | and ver.split(".")[1] >= STACKUP_FORMAT_VERSION.split(".", maxsplit=1)[1] 273 | ): 274 | cfg.load_stackup(stackup) 275 | else: 276 | logger.error( 277 | "Stackup format (%s) is not supported (supported: %s)", 278 | ver, 279 | STACKUP_FORMAT_VERSION, 280 | ) 281 | sys.exit() 282 | 283 | 284 | def import_port_positions() -> None: 285 | """Import port positions from PnP .csv files. 286 | 287 | Looks for all PnP files in `fab` folder (files ending with `-pos.csv`) 288 | Parses them to find port footprints and inserts their position information to config object. 289 | """ 290 | ports: List[Tuple[int, Tuple[float, float], float]] = [] 291 | for filename in os.listdir(os.path.join(os.getcwd(), "fab")): 292 | if filename.endswith("-pos.csv"): 293 | ports += get_ports_from_file(os.path.join(os.getcwd(), "fab", filename)) 294 | 295 | for number, position, direction in ports: 296 | if len(cfg.ports) > number: 297 | port = cfg.ports[number] 298 | if port.position is None: 299 | cfg.ports[number].position = position 300 | cfg.ports[number].direction = direction 301 | else: 302 | logger.warning( 303 | "Port #%i is defined twice on the board. Ignoring the second instance", 304 | number, 305 | ) 306 | for index, port in enumerate(cfg.ports): 307 | if port.position is None: 308 | logger.error("Port #%i is not defined on board. It will be skipped", index) 309 | 310 | 311 | def get_ports_from_file(filename: str) -> List[Tuple[int, Tuple[float, float], float]]: 312 | """Parse pnp CSV file and return all ports in format (number, (x, y), direction).""" 313 | ports: List[Tuple[int, Tuple[float, float], float]] = [] 314 | with open(filename, "r", encoding="utf-8") as csvfile: 315 | reader = csv.reader(csvfile, delimiter=",", quotechar='"') 316 | next(reader, None) # skip the headers 317 | for row in reader: 318 | if "Simulation_Port" in row[2] or "Simulation-Port" in row[2]: 319 | number = int(row[0][2:]) 320 | ports.append( 321 | ( 322 | number - 1, 323 | (float(row[3]) / 1000 / UNIT, float(row[4]) / 1000 / UNIT), 324 | float(row[5]), 325 | ) 326 | ) 327 | logging.debug("Found port #%i position in pos file", number) 328 | 329 | return ports 330 | -------------------------------------------------------------------------------- /src/gerber2ems/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """Main module of EM-Simulator.""" 4 | import os 5 | import sys 6 | import argparse 7 | import logging 8 | from typing import Any 9 | import shutil 10 | 11 | import coloredlogs 12 | import numpy as np 13 | 14 | from gerber2ems.constants import BASE_DIR, SIMULATION_DIR, GEOMETRY_DIR, RESULTS_DIR 15 | from gerber2ems.simulation import Simulation 16 | from gerber2ems.postprocess import Postprocesor 17 | from gerber2ems.config import Config 18 | import gerber2ems.importer as importer 19 | 20 | logger = logging.getLogger(__name__) 21 | cfg = Config() 22 | 23 | 24 | def main() -> None: 25 | """Run the script.""" 26 | args = parse_arguments() 27 | Config.load(args) 28 | setup_logging(args) 29 | if args.update_config: 30 | exit(0) 31 | 32 | if not any( 33 | [ 34 | args.geometry, 35 | args.simulate, 36 | args.postprocess, 37 | args.all, 38 | ] 39 | ): 40 | logger.info('No steps selected. Exiting. To select steps use "-g", "-s", "-p", "-a" flags') 41 | sys.exit(0) 42 | 43 | create_dir(BASE_DIR) 44 | 45 | if args.geometry or args.all: 46 | logger.info("Creating geometry") 47 | create_dir(GEOMETRY_DIR, cleanup=True) 48 | sim = Simulation() 49 | geometry(sim) 50 | if args.simulate or args.all: 51 | logger.info("Running simulation") 52 | create_dir(SIMULATION_DIR, cleanup=True) 53 | simulate() 54 | if args.postprocess or args.all: 55 | logger.info("Postprocessing") 56 | create_dir(RESULTS_DIR, cleanup=True) 57 | sim = Simulation() 58 | postprocess(sim) 59 | 60 | 61 | def geometry(sim: Simulation) -> None: 62 | """Create a geometry for the simulation.""" 63 | importer.import_stackup() 64 | importer.import_port_positions() 65 | importer.process_gbrs_to_pngs() 66 | 67 | top_layer_name = cfg.get_metals()[0].file 68 | (width, height) = importer.get_dimensions(top_layer_name + ".png") 69 | cfg.pcb_height = height 70 | cfg.pcb_width = width 71 | 72 | sim.create_materials() 73 | sim.add_gerbers() 74 | sim.add_grid() 75 | sim.add_substrates() 76 | if cfg.arguments.export_field: 77 | sim.add_dump_boxes() 78 | sim.set_boundary_conditions(pml=False) 79 | sim.add_vias() 80 | sim.add_ports() 81 | sim.save_geometry() 82 | 83 | 84 | def simulate() -> None: 85 | """Run the simulation.""" 86 | for index, port in enumerate(cfg.ports): 87 | if port.excite: 88 | sim = Simulation() 89 | logging.info("Simulating with excitation on port #%i", index) 90 | sim.load_geometry() 91 | sim.set_excitation() 92 | sim.setup_ports(index) 93 | sim.run(index) 94 | 95 | 96 | def postprocess(sim: Simulation) -> None: 97 | """Postprocess data from the simulation.""" 98 | if len(sim.ports) == 0: 99 | sim.add_virtual_ports() 100 | 101 | frequencies = np.linspace(cfg.frequency.start, cfg.frequency.stop, 1001) 102 | post = Postprocesor(frequencies, len(cfg.ports)) 103 | impedances = np.array([p.impedance for p in cfg.ports]) 104 | post.add_impedances(impedances) 105 | 106 | for index, port in enumerate(cfg.ports): 107 | if port.excite: 108 | reflected, incident = sim.get_port_parameters(index, frequencies) 109 | for i, _ in enumerate(cfg.ports): 110 | post.add_port_data(i, index, incident[i], reflected[i]) 111 | 112 | post.process_data() 113 | post.save_to_file() 114 | post.render_s_params() 115 | post.render_impedance() 116 | post.render_smith() 117 | post.render_diff_pair_s_params() 118 | post.render_diff_impedance() 119 | post.render_trace_delays() 120 | 121 | 122 | def parse_arguments() -> argparse.Namespace: 123 | """Parse commandline arguments.""" 124 | parser = argparse.ArgumentParser( 125 | prog="EM-Simulator", 126 | description="This application allows to perform EM simulations based on standard PCB production files (gerber)", 127 | ) 128 | parser.add_argument( 129 | "-c", "--config", metavar="CONFIG_FILE", help="Path to config file [default: `./simulation.json`]" 130 | ) 131 | parser.add_argument("--update-config", action="store_true", help="Add missing fields to config file") 132 | parser.add_argument("-g", "--geometry", action="store_true", help="Create geometry") 133 | parser.add_argument("-s", "--simulate", action="store_true", help="Run simulation") 134 | parser.add_argument("-p", "--postprocess", action="store_true", help="Postprocess the data") 135 | parser.add_argument( 136 | "-a", "--all", action="store_true", help="Execute all steps (geometry, simulation, postprocessing)" 137 | ) 138 | parser.add_argument( 139 | "--export-field", "--ef", action="store_true", help="Export electric field data from the simulation" 140 | ) 141 | parser.add_argument("-t", "--transparent", action="store_true", help="Export graphs with transparent background") 142 | group = parser.add_mutually_exclusive_group() 143 | group.add_argument("-d", "--debug", action="store_true", dest="debug") 144 | group.add_argument("-l", "--log", choices=["DEBUG", "INFO", "WARNING", "ERROR"], dest="log_level") 145 | 146 | return parser.parse_args() 147 | 148 | 149 | def setup_logging(args: Any) -> None: 150 | """Set up logging based on command line arguments.""" 151 | level = logging.INFO 152 | if args.debug: 153 | level = logging.DEBUG 154 | if args.log_level is not None: 155 | level = logging.getLevelName(args.log_level) 156 | 157 | if level == logging.DEBUG: 158 | coloredlogs.install( 159 | fmt="[%(asctime)s][%(name)s:%(lineno)d][%(levelname).4s] %(message)s", 160 | datefmt="%H:%M:%S", 161 | level=level, 162 | logger=logger, 163 | ) 164 | else: 165 | coloredlogs.install( 166 | fmt="[%(asctime)s][%(levelname).4s] %(message)s", 167 | datefmt="%H:%M:%S", 168 | level=level, 169 | logger=logger, 170 | ) 171 | 172 | to_disable = ["PIL", "matplotlib"] 173 | for name in to_disable: 174 | disabled_logger = logging.getLogger(name) 175 | disabled_logger.setLevel(logging.ERROR) 176 | 177 | 178 | def create_dir(path: str, cleanup: bool = False) -> None: 179 | """Create a directory if doesn't exist.""" 180 | directory_path = os.path.join(os.getcwd(), path) 181 | if cleanup and os.path.exists(directory_path): 182 | shutil.rmtree(directory_path) 183 | if not os.path.exists(directory_path): 184 | os.mkdir(directory_path) 185 | 186 | 187 | if __name__ == "__main__": 188 | main() 189 | -------------------------------------------------------------------------------- /src/gerber2ems/postprocess.py: -------------------------------------------------------------------------------- 1 | """Module contains functions useful for postprocessing data.""" 2 | 3 | from typing import Union, Tuple, Optional 4 | import logging 5 | import os 6 | 7 | import numpy as np 8 | import matplotlib.pyplot as plt 9 | import skrf 10 | 11 | from gerber2ems.config import Config 12 | from gerber2ems.constants import RESULTS_DIR, PLOT_STYLE 13 | 14 | logger = logging.getLogger(__name__) 15 | cfg = Config() 16 | 17 | 18 | class Postprocesor: 19 | """Class used to postprocess and display simulation data.""" 20 | 21 | def __init__(self, frequencies: np.ndarray, port_count: int) -> None: 22 | """Initialize postprocessor.""" 23 | self.frequencies = frequencies # Frequency list for whitch parameters are calculated 24 | self.count = port_count # Number of ports 25 | 26 | self.incident = np.empty( 27 | [self.count, self.count, len(self.frequencies)], np.complex128 28 | ) # Incident wave phasor table ([measured_port][excited_port][frequency]) 29 | self.incident[:] = np.nan 30 | self.reflected = np.empty( 31 | [self.count, self.count, len(self.frequencies)], np.complex128 32 | ) # Reflected wave phasors table ([measured_port][excited_port][frequency]) 33 | self.reflected[:] = np.nan 34 | self.reference_zs = np.empty([self.count], np.complex128) 35 | self.reference_zs[:] = np.nan # Reference impedances of ports 36 | 37 | self.s_params = np.empty( 38 | [self.count, self.count, len(self.frequencies)], np.complex128 39 | ) # S-parameter table ([output_port][input_port][frequency]) 40 | self.s_params[:] = np.nan 41 | self.impedances = np.empty([self.count, len(self.frequencies)], np.complex128) 42 | self.impedances[:] = np.nan 43 | self.delays = np.empty( 44 | [self.count, self.count, len(self.frequencies)], np.float64 45 | ) # Group delay table ([output_port][input_port][frequency]) 46 | 47 | def add_port_data( 48 | self, 49 | port: int, 50 | excited_port: int, 51 | incident: np.ndarray, 52 | reflected: np.ndarray, 53 | ) -> None: 54 | """Add port data to postprocessor. 55 | 56 | Data consists of incident and reflected phasor data in relation to frequency 57 | """ 58 | if self.is_valid(self.incident[port][excited_port]): 59 | logger.warning("This port data has already been supplied, overwriting") 60 | self.incident[port][excited_port] = incident 61 | self.reflected[port][excited_port] = reflected 62 | 63 | def add_impedances(self, impedances: np.ndarray) -> None: 64 | """Add port reference impedances.""" 65 | self.reference_zs = impedances 66 | 67 | def process_data(self) -> None: 68 | """Calculate all needed parameters for further processing. Should be called after all ports are added.""" 69 | logger.info("Processing all data from simulation. Calculating S-parameters and impedance") 70 | for i, _ in enumerate(self.incident): 71 | if self.is_valid(self.incident[i][i]): 72 | for j, _ in enumerate(self.incident): 73 | if self.is_valid(self.reflected[j][i]): 74 | self.s_params[j][i] = self.reflected[j][i] / self.incident[i][i] 75 | 76 | for i, reference_z in enumerate(self.reference_zs): 77 | s_param = self.s_params[i][i] 78 | if self.is_valid(reference_z) and self.is_valid(s_param): 79 | self.impedances[i] = reference_z * (1 + s_param) / (1 - s_param) 80 | 81 | for i in range(self.count): 82 | if self.is_valid(self.incident[i][i]): 83 | for j in range(self.count): 84 | if self.is_valid(self.s_params[j][i]): 85 | phase = np.unwrap(np.angle(self.s_params[j][i])) 86 | group_delay = -( 87 | np.convolve(phase, [1, -1], mode="valid") 88 | / np.convolve(self.frequencies, [1, -1], mode="valid") 89 | / 2 90 | / np.pi 91 | ) 92 | group_delay = np.append(group_delay, group_delay[-1]) 93 | self.delays[j][i] = group_delay 94 | 95 | def get_impedance(self, port: int) -> Union[np.ndarray, None]: 96 | """Return specified port impedance.""" 97 | if port >= self.count: 98 | logger.error("Port no. %d doesn't exist", port) 99 | return None 100 | if self.is_valid(self.impedances[port]): 101 | logger.error("Impedance for port %d wasn't calculated", port) 102 | return None 103 | return self.impedances[port] 104 | 105 | def get_s_param(self, output_port: int, input_port: int) -> Optional[np.ndarray]: 106 | """Return specified S parameter.""" 107 | if output_port >= self.count: 108 | logger.error("Port no. %d doesn't exist", output_port) 109 | return None 110 | if input_port >= self.count: 111 | logger.error("Port no. %d doesn't exist", output_port) 112 | return None 113 | s_param = self.s_params[output_port][input_port] 114 | if self.is_valid(s_param): 115 | return s_param 116 | logger.error("S%d%d wasn't calculated", output_port, input_port) 117 | return None 118 | 119 | def render_s_params(self) -> None: 120 | """Render all S parameter plots to files.""" 121 | logger.info("Rendering S-parameter plots") 122 | plt.style.use(PLOT_STYLE) 123 | for i in range(self.count): 124 | if self.is_valid(self.s_params[i][i]): 125 | fig, axes = plt.subplots() 126 | for j in range(self.count): 127 | s_param = self.s_params[j][i] 128 | if self.is_valid(s_param): 129 | axes.plot( 130 | self.frequencies / 1e9, 131 | 20 * np.log10(np.abs(s_param)), 132 | label="$S_{" + f"{j+1}{i+1}" + "}$", 133 | ) 134 | axes.legend(loc="center left", bbox_to_anchor=(1.0, 0.5)) 135 | axes.set_xlabel("Frequency, f [GHz]") 136 | axes.set_ylabel("Magnitude, [dB]") 137 | axes.grid(True) 138 | bottom, top = axes.get_ylim() 139 | axes.set_ylim([min(bottom, -60), max(top, 5)]) 140 | fig.savefig( 141 | os.path.join(os.getcwd(), RESULTS_DIR, f"S_x{i+1}.png"), 142 | bbox_inches="tight", 143 | transparent=cfg.arguments.transparent, 144 | ) 145 | 146 | def render_diff_pair_s_params(self) -> None: 147 | """Render differential pair S parameter plots to files.""" 148 | logger.info("Rendering differential pair S-parameter plots") 149 | plt.style.use(PLOT_STYLE) 150 | for pair in cfg.diff_pairs: 151 | if ( 152 | pair.correct 153 | and self.is_valid(self.s_params[pair.start_p][pair.start_p]) 154 | and self.is_valid(self.s_params[pair.start_n][pair.start_n]) 155 | ): 156 | fig, axes = plt.subplots() 157 | s_param = 0.5 * ( 158 | self.s_params[pair.start_p][pair.start_p] 159 | - self.s_params[pair.start_n][pair.start_p] 160 | - self.s_params[pair.start_p][pair.start_n] 161 | + self.s_params[pair.start_n][pair.start_n] 162 | ) 163 | if self.is_valid(s_param): 164 | axes.plot( 165 | self.frequencies / 1e9, 166 | 20 * np.log10(np.abs(s_param)), 167 | label="$SDD_{11}$", 168 | ) 169 | s_param = 0.5 * ( 170 | self.s_params[pair.stop_p][pair.start_p] 171 | - self.s_params[pair.stop_p][pair.start_n] 172 | - self.s_params[pair.stop_n][pair.start_p] 173 | + self.s_params[pair.stop_n][pair.start_n] 174 | ) 175 | if self.is_valid(s_param): 176 | axes.plot( 177 | self.frequencies / 1e9, 178 | 20 * np.log10(np.abs(s_param)), 179 | label="$SDD_{21}$", 180 | ) 181 | axes.legend(loc="center left", bbox_to_anchor=(1, 0.5)) 182 | axes.set_xlabel("Frequency, f [GHz]") 183 | axes.set_ylabel("Magnitude, [dB]") 184 | axes.grid(True) 185 | bottom, top = axes.get_ylim() 186 | axes.set_ylim([min(bottom, -60), max(top, 5)]) 187 | fig.savefig( 188 | os.path.join(os.getcwd(), RESULTS_DIR, "SDD_Diff"), 189 | bbox_inches="tight", 190 | transparent=cfg.arguments.transparent, 191 | ) 192 | 193 | def render_diff_impedance(self) -> None: 194 | """Render differential pair impedance plots to files.""" 195 | logger.info("Rendering differential pair impedance plots") 196 | plt.style.use(PLOT_STYLE) 197 | for pair in cfg.diff_pairs: 198 | if ( 199 | pair.correct 200 | and self.is_valid(self.s_params[pair.start_p][pair.start_p]) 201 | and self.is_valid(self.s_params[pair.start_n][pair.start_n]) 202 | ): 203 | fig, axes = plt.subplots() 204 | s11 = self.s_params[pair.start_p][pair.start_p] 205 | s21 = self.s_params[pair.start_n][pair.start_p] 206 | s12 = self.s_params[pair.start_p][pair.start_n] 207 | s22 = self.s_params[pair.start_n][pair.start_n] 208 | gamma = ((2 * s11 - s21) * (1 - s22 - s12) + (1 - s11 - s21) * (1 + s22 - 2 * s12)) / ( 209 | (2 - s21) * (1 - s22 - s12) + (1 - s11 - s21) * (1 + s22) 210 | ) 211 | if ( 212 | self.reference_zs[pair.start_p] 213 | == self.reference_zs[pair.start_n] 214 | == self.reference_zs[pair.stop_p] 215 | == self.reference_zs[pair.stop_n] 216 | ): 217 | z0 = self.reference_zs[pair.start_p] 218 | impedance = z0 * (1 + gamma) / (1 - gamma) 219 | 220 | fig, axs = plt.subplots(2) 221 | axs[0].plot(self.frequencies / 1e9, np.abs(impedance)) 222 | axs[1].plot( 223 | self.frequencies / 1e9, 224 | np.angle(impedance, deg=True), 225 | linestyle="dashed", 226 | color="orange", 227 | ) 228 | 229 | axs[0].set_ylabel("Magnitude, $|Z_{diff}| [\Omega]$") 230 | axs[1].set_ylabel("Angle, $arg(Z_{diff}) [^\circ]$") 231 | axs[1].set_xlabel("Frequency, f [GHz]") 232 | axs[0].grid(True) 233 | axs[1].grid(True) 234 | 235 | bottom, top = axs[0].get_ylim() 236 | axs[0].set_ylim([min(bottom, 0), max(top, 200)]) 237 | bottom, top = axs[1].get_ylim() 238 | axs[1].set_ylim([min(bottom, -90), max(top, 90)]) 239 | 240 | fig.savefig( 241 | os.path.join(os.getcwd(), RESULTS_DIR, "Z_diff.png"), 242 | bbox_inches="tight", 243 | transparent=cfg.arguments.transparent, 244 | ) 245 | else: 246 | logger.error( 247 | f"Reference impedances for ports in differential pair {pair.name} are not all equal. Cannot calculate impedance" # noqa: E501 248 | ) 249 | 250 | def calculate_min_max_impedance(self, s11_margin: np.ndarray, z0: float) -> Tuple[float, float]: 251 | """Calculate aproximated min-max values for impedance (it assumes phase is 0).""" 252 | angles = [0, np.pi] 253 | reflection_coeffs = 10 ** (-s11_margin / 20) * (np.cos(angles) + 1j * np.sin(angles)) 254 | impedances = z0 * (1 + reflection_coeffs) / (1 - reflection_coeffs) 255 | return (abs(impedances[0]), abs(impedances[1])) 256 | 257 | def render_impedance(self, include_margins: bool = False) -> None: 258 | """Render all ports impedance plots to files.""" 259 | logger.info("Rendering impedance plots") 260 | plt.style.use(PLOT_STYLE) 261 | for port, impedance in enumerate(self.impedances): 262 | if self.is_valid(impedance): 263 | fig, axs = plt.subplots(2) 264 | axs[0].plot(self.frequencies / 1e9, np.abs(impedance)) 265 | axs[1].plot( 266 | self.frequencies / 1e9, 267 | np.angle(impedance, deg=True), 268 | linestyle="dashed", 269 | color="orange", 270 | ) 271 | 272 | axs[0].set_ylabel("Magnitude, $|Z_{" + str(port) + r"}| [\Omega]$") 273 | axs[1].set_ylabel("Angle, $arg(Z_{" + str(port) + r"}) [^\circ]$") 274 | axs[1].set_xlabel("Frequency, f [GHz]") 275 | axs[0].grid(True) 276 | axs[1].grid(True) 277 | 278 | if include_margins: 279 | s11_margin = cfg.ports[port].dB_margin 280 | z0 = cfg.ports[port].impedance 281 | min_z, max_z = self.calculate_min_max_impedance(s11_margin, z0) 282 | 283 | axs[0].axhline(np.real(min_z), color="red") 284 | axs[0].axhline(np.real(max_z), color="red") 285 | 286 | bottom, top = axs[0].get_ylim() 287 | axs[0].set_ylim([min(bottom, 0), max(top, 100)]) 288 | bottom, top = axs[1].get_ylim() 289 | axs[1].set_ylim([min(bottom, -90), max(top, 90)]) 290 | 291 | fig.savefig( 292 | os.path.join(os.getcwd(), RESULTS_DIR, f"Z_{port+1}.png"), 293 | bbox_inches="tight", 294 | transparent=cfg.arguments.transparent, 295 | ) 296 | 297 | def render_smith(self) -> None: 298 | """Render port reflection smithcharts to files.""" 299 | logger.info("Rendering smith charts") 300 | plt.style.use(PLOT_STYLE) 301 | net = skrf.Network(frequency=self.frequencies / 1e9, s=self.s_params.transpose(2, 0, 1)) 302 | for port in range(self.count): 303 | if self.is_valid(self.s_params[port][port]): 304 | fig, axes = plt.subplots() 305 | s11_margin = cfg.ports[port].dB_margin 306 | vswr_margin = (10 ** (s11_margin / 20) + 1) / (10 ** (s11_margin / 20) - 1) 307 | net.plot_s_smith( 308 | m=port, 309 | n=port, 310 | ax=axes, 311 | draw_labels=False, 312 | show_legend=True, 313 | draw_vswr=[vswr_margin], 314 | ) 315 | axes.legend(bbox_to_anchor=(1.0, 0.5), loc="center left") 316 | fig.savefig( 317 | os.path.join(os.getcwd(), RESULTS_DIR, f"S_{port+1}{port+1}_smith.png"), 318 | bbox_inches="tight", 319 | transparent=cfg.arguments.transparent, 320 | ) 321 | 322 | def render_trace_delays(self) -> None: 323 | """Render all trace delay plots to files.""" 324 | logger.info("Rendering trace delay plots") 325 | plt.style.use(PLOT_STYLE) 326 | for trace in cfg.traces: 327 | if trace.correct and self.is_valid(self.delays[trace.stop][trace.start]): 328 | fig, axes = plt.subplots() 329 | axes.plot( 330 | self.frequencies / 1e9, 331 | self.delays[trace.stop][trace.start] * 1e9, 332 | label=f"{trace.name} delay", 333 | ) 334 | axes.legend(loc="center left", bbox_to_anchor=(0.5, 1)) 335 | axes.set_xlabel("Frequency, f [GHz]") 336 | axes.set_ylabel("Trace delay, [ns]") 337 | axes.grid(True) 338 | fig.savefig( 339 | os.path.join(os.getcwd(), RESULTS_DIR, f"{trace.name}_delay.png"), 340 | bbox_inches="tight", 341 | transparent=cfg.arguments.transparent, 342 | ) 343 | 344 | for pair in cfg.diff_pairs: 345 | if ( 346 | pair.correct 347 | and self.is_valid(self.delays[pair.stop_p][pair.start_n]) 348 | and self.is_valid(self.delays[pair.stop_n][pair.start_p]) 349 | ): 350 | fig, axes = plt.subplots() 351 | axes.plot( 352 | self.frequencies / 1e9, 353 | self.delays[pair.stop_p][pair.start_n] * 1e9, 354 | label="N trace delay", 355 | ) 356 | axes.plot( 357 | self.frequencies / 1e9, 358 | self.delays[pair.stop_n][pair.start_p] * 1e9, 359 | label="P trace delay", 360 | ) 361 | axes.legend(loc="center left", bbox_to_anchor=(1, 0.5)) 362 | axes.set_xlabel("Frequency, f [GHz]") 363 | axes.set_ylabel("Trace delay, [ns]") 364 | axes.grid(True) 365 | fig.savefig( 366 | os.path.join(os.getcwd(), RESULTS_DIR, "diff_delay.png"), 367 | bbox_inches="tight", 368 | transparent=cfg.arguments.transparent, 369 | ) 370 | 371 | def save_to_file(self) -> None: 372 | """Save all parameters to files.""" 373 | for i, _ in enumerate(self.s_params): 374 | if self.is_valid(self.s_params[i][i]): 375 | self.save_port_to_file(i, RESULTS_DIR) 376 | 377 | def save_port_to_file(self, port_number: int, path: str) -> None: 378 | """Save all parameters from single excitation.""" 379 | frequencies = np.transpose([self.frequencies]) 380 | s_params = np.transpose(self.s_params[:, port_number, :], (1, 0)) 381 | delays = np.transpose(self.delays[:, port_number, :], (1, 0)) 382 | impedances = np.transpose([self.impedances[port_number]]) 383 | 384 | header: str = "Frequency [Hz], " 385 | header += "".join([f"|S{i}{port_number}| [-], " for i, _ in enumerate(self.s_params[port_number])]) 386 | header += "".join([f"Arg(S{i}{port_number}) [-], " for i, _ in enumerate(self.s_params[port_number])]) 387 | header += "".join([f"Delay {port_number}>{i} [s], " for i, _ in enumerate(self.delays[port_number])]) 388 | header += f"|Z{port_number}| [Ohm] , " 389 | header += f"Arg(Z{port_number}) [-]" 390 | 391 | output = np.hstack( 392 | [ 393 | frequencies, 394 | np.abs(s_params), 395 | np.angle(s_params), 396 | delays, 397 | np.abs(impedances), 398 | np.angle(impedances), 399 | ] 400 | ) 401 | file_path = f"Port_{port_number}_data.csv" 402 | logger.debug("Saving port no. %d parameters to file: %s", port_number, file_path) 403 | np.savetxt(os.path.join(path, file_path), output, fmt="%e", delimiter=", ", header=header, comments="") 404 | 405 | @staticmethod 406 | def is_valid(array: np.ndarray) -> bool: 407 | """Check if array doesn't have any NaN's.""" 408 | return not np.any(np.isnan(array)) 409 | -------------------------------------------------------------------------------- /src/gerber2ems/simulation.py: -------------------------------------------------------------------------------- 1 | """Module containing Simulation class used for interacting with openEMS.""" 2 | 3 | import logging 4 | import os 5 | import re 6 | import sys 7 | import math 8 | from typing import Tuple, List, Any 9 | from multiprocessing import Pool 10 | 11 | import CSXCAD 12 | import openEMS 13 | import numpy as np 14 | 15 | from gerber2ems.config import Config, PortConfig, LayerKind 16 | from gerber2ems.constants import ( 17 | UNIT, 18 | SIMULATION_DIR, 19 | GEOMETRY_DIR, 20 | VIA_POLYGON, 21 | ) 22 | import gerber2ems.importer as importer 23 | from gerber2ems.grid_gen import GridGenerator 24 | from gerber2ems.gerber_io import Pad, ApertureRect, Aperture, Position 25 | 26 | logger = logging.getLogger(__name__) 27 | cfg = Config() 28 | 29 | 30 | class Simulation: 31 | """Class used for interacting with openEMS.""" 32 | 33 | def __init__(self) -> None: 34 | """Initialize simulation object.""" 35 | self.csx = CSXCAD.ContinuousStructure() 36 | self.fdtd = openEMS.openEMS(NrTS=cfg.max_steps) 37 | self.fdtd.SetCSX(self.csx) 38 | self.grid = self.csx.GetGrid() 39 | self.grid.SetDeltaUnit(UNIT) 40 | 41 | self.ports: List[openEMS.ports.MSLPort] = [] 42 | 43 | # Separate metal materials for easier switching of layers 44 | self.gerber_materials: List[Any] = [] 45 | self.substrate_materials: List[Any] = [] 46 | self.plane_material = self.csx.AddMetal("Plane") 47 | self.via_material = self.csx.AddMetal("Via") 48 | self.via_filling_material = self.csx.AddMaterial("ViaFilling", epsilon=cfg.via.filling_epsilon) 49 | 50 | def create_materials(self) -> None: 51 | """Create materials required for simulation.""" 52 | for i, _ in enumerate(cfg.get_metals()): 53 | self.gerber_materials.append(self.csx.AddMetal(f"Gerber_{i}")) 54 | for i, layer in enumerate(cfg.get_substrates()): 55 | self.substrate_materials.append(self.csx.AddMaterial(f"Substrate_{i}", epsilon=layer.epsilon)) 56 | 57 | def print_grid_stats(self) -> None: 58 | """Print stats about grid: line count, minimal spacing, positions.""" 59 | logger.debug("Grid x lines: %s", self.grid.GetLines("x")) 60 | logger.debug("Grid y lines: %s", self.grid.GetLines("y")) 61 | logger.debug("Grid z lines: %s", self.grid.GetLines("z")) 62 | 63 | def get_stat(lines: List[float]) -> List[float]: 64 | msize = math.inf 65 | mscale = -math.inf 66 | prev = lines[1] 67 | prev_size = abs((lines[0] - lines[1])) 68 | for line in lines: 69 | size = abs(prev - line) 70 | msize = min(size, msize) 71 | scale = prev_size / size 72 | scale = scale if scale > 1 else 1 / scale 73 | mscale = max(scale, mscale) 74 | prev = line 75 | prev_size = size 76 | return [msize, mscale] 77 | 78 | sx = get_stat(self.grid.GetLines("x")) 79 | sy = get_stat(self.grid.GetLines("y")) 80 | sz = get_stat(self.grid.GetLines("z")) 81 | xyz = [ 82 | self.grid.GetQtyLines("x"), 83 | self.grid.GetQtyLines("y"), 84 | self.grid.GetQtyLines("z"), 85 | ] 86 | logger.info( 87 | "Grid line count, x: %d, y: %d z: %d. Total number of cells: ~%.2fM", 88 | xyz[0], 89 | xyz[1], 90 | xyz[2], 91 | xyz[0] * xyz[1] * xyz[2] / 1.0e6, 92 | ) 93 | logger.info("Minimal cell size, x: %f, y: %f z: %f [um]", sx[0], sy[0], sz[0]) 94 | logger.info("Max cell size ratio, x: %f, y: %f z: %f ", sx[1], sy[1], sz[1]) 95 | 96 | def add_grid(self) -> None: 97 | """Add grid to simulation.""" 98 | self.grid_gen = GridGenerator() 99 | self.add_port_grid() 100 | logger.info("Compiling grid") 101 | self.grid = self.grid_gen.generate(self.grid) 102 | 103 | self.print_grid_stats() 104 | 105 | def add_gerbers(self) -> None: 106 | """Add metal from all gerber files.""" 107 | logger.info("Adding copper from gerber files") 108 | 109 | offset = 0 110 | index = 0 111 | contours = [] 112 | with Pool(initargs=(cfg._config,), initializer=Config.set_config) as p: 113 | contours = p.map( 114 | importer.get_triangles, 115 | [lc.file + ".png" for lc in cfg.layers if lc.kind == LayerKind.METAL], 116 | ) 117 | 118 | icontours = iter(contours) 119 | for layer in cfg.layers: 120 | if layer.kind == LayerKind.SUBSTRATE: 121 | offset -= layer.thickness 122 | elif layer.kind == LayerKind.METAL: 123 | logger.info("Adding metal mesh for %s", layer.file) 124 | self.add_contours(next(icontours), offset, index) 125 | index += 1 126 | 127 | def add_contours(self, contours: np.ndarray, z_height: float, layer_index: int) -> None: 128 | """Add contours as flat polygons on specified z-height.""" 129 | logger.debug("Adding contours on z=%f", z_height) 130 | for contour in contours: 131 | points: List[List[float]] = [[], []] 132 | for point in contour: 133 | # Half of the border thickness is subtracted as image is shifted by it 134 | points[0].append((point[1])) 135 | points[1].append(cfg.pcb_height - point[0]) 136 | 137 | self.gerber_materials[layer_index].AddPolygon(points, "z", z_height, priority=1) 138 | 139 | def get_metal_layer_offset(self, index: int) -> float: 140 | """Get z offset of nth metal layer.""" 141 | current_metal_index = -1 142 | offset = 0 143 | for layer in cfg.layers: 144 | if layer.kind == LayerKind.METAL: 145 | current_metal_index += 1 146 | if current_metal_index == index: 147 | return offset 148 | elif layer.kind == LayerKind.SUBSTRATE: 149 | offset -= layer.thickness 150 | logger.error("Hadn't found %dth metal layer", index) 151 | sys.exit(1) 152 | 153 | def add_port_grid(self) -> None: 154 | """Add grid around ports for simulation.""" 155 | logger.info("Adding ports grid") 156 | 157 | for port_config in cfg.ports: 158 | if port_config.position is None or port_config.direction is None: 159 | logger.error("Port has no defined position or rotation, skipping") 160 | return 161 | angle = port_config.direction / 360 * 2 * math.pi 162 | ap = f"PORT{len(self.grid_gen.add_apertures) + 1}" 163 | (w, h) = ((port_config.width), (port_config.length)) 164 | (width, height) = ( 165 | w * round(math.cos(angle)) - h * round(math.sin(angle)), 166 | w * round(math.sin(angle)) + h * round(math.cos(angle)), 167 | ) 168 | self.grid_gen.add_pads.append( 169 | Pad( 170 | ap, 171 | "PORT", 172 | Position( 173 | port_config.position[0] + self.grid_gen.xmin + width / 2, 174 | port_config.position[1] + self.grid_gen.ymin, 175 | ), 176 | ) 177 | ) 178 | self.grid_gen.add_apertures[ap] = Aperture( 179 | "", 180 | ApertureRect(width, height), 181 | ) 182 | 183 | def add_msl_port(self, port_config: PortConfig, port_number: int, excite: bool = False) -> None: 184 | """Add microstripline port based on config.""" 185 | logger.debug("Adding port number %d", len(self.ports)) 186 | 187 | if port_config.position is None or port_config.direction is None: 188 | logger.error("Port has no defined position or rotation, skipping") 189 | return 190 | 191 | while port_config.direction < 0: 192 | port_config.direction += 360 193 | 194 | dir_map = {0: "y", 90: "x", 180: "y", 270: "x"} 195 | if int(port_config.direction) not in dir_map: 196 | logger.error("Ports rotation is not a multiple of 90 degrees which is not supported, skipping") 197 | return 198 | 199 | start_z = self.get_metal_layer_offset(port_config.layer) 200 | stop_z = self.get_metal_layer_offset(port_config.plane) 201 | 202 | angle = port_config.direction / 360 * 2 * math.pi 203 | 204 | start = [ 205 | round(port_config.position[0] - (port_config.width / 2) * round(math.cos(angle))), 206 | round(port_config.position[1] - (port_config.width / 2) * round(math.sin(angle))), 207 | round(start_z), 208 | ] 209 | stop = [ 210 | round( 211 | port_config.position[0] 212 | + (port_config.width / 2) * round(math.cos(angle)) 213 | - port_config.length * round(math.sin(angle)) 214 | ), 215 | round( 216 | port_config.position[1] 217 | + (port_config.width / 2) * round(math.sin(angle)) 218 | + port_config.length * round(math.cos(angle)) 219 | ), 220 | round(stop_z), 221 | ] 222 | logger.debug("Adding port at start: %s end: %s", start, stop) 223 | 224 | port = self.fdtd.AddMSLPort( 225 | port_number, 226 | self.csx.AddMetal(f"Port_{port_number}"), 227 | start, 228 | stop, 229 | dir_map[int(port_config.direction)], 230 | "z", 231 | Feed_R=port_config.impedance, 232 | priority=100, 233 | excite=1 if excite else 0, 234 | ) 235 | self.ports.append(port) 236 | 237 | def add_resistive_port(self, port_config: PortConfig, excite: bool = False) -> None: 238 | """Add resistive port based on config.""" 239 | logger.debug("Adding port number %d", len(self.ports)) 240 | 241 | if port_config.position is None or port_config.direction is None: 242 | logger.error("Port has no defined position or rotation, skipping") 243 | return 244 | 245 | dir_map = {0: "y", 90: "x", 180: "y", 270: "x"} 246 | if int(port_config.direction) not in dir_map: 247 | logger.error("Ports rotation is not a multiple of 90 degrees which is not supported, skipping") 248 | return 249 | 250 | start_z = self.get_metal_layer_offset(port_config.layer) 251 | stop_z = self.get_metal_layer_offset(port_config.plane) 252 | 253 | angle = port_config.direction / 360 * 2 * math.pi 254 | 255 | start = [ 256 | round(port_config.position[0] - (port_config.width / 2) * round(math.cos(angle))), 257 | round(port_config.position[1] - (port_config.width / 2) * round(math.sin(angle))), 258 | round(start_z), 259 | ] 260 | stop = [ 261 | round(port_config.position[0] + (port_config.width / 2) * round(math.cos(angle))), 262 | round(port_config.position[1] - (port_config.width / 2) * round(math.sin(angle))), 263 | round(stop_z), 264 | ] 265 | logger.debug("Adding resistive port at start: %s end: %s", start, stop) 266 | 267 | port = self.fdtd.AddLumpedPort( 268 | len(self.ports), 269 | port_config.impedance, 270 | start, 271 | stop, 272 | "z", 273 | excite=1 if excite else 0, 274 | priority=100, 275 | ) 276 | self.ports.append(port) 277 | 278 | def add_virtual_port(self, port_config: PortConfig) -> None: 279 | """Add virtual port for extracting sim data from files. Needed due to OpenEMS api desing.""" 280 | logger.debug("Adding virtual port number %d", len(self.ports)) 281 | for i in range(11): 282 | self.grid.AddLine("x", i) 283 | self.grid.AddLine("y", i) 284 | self.grid.AddLine("z", 0) 285 | self.grid.AddLine("z", 10) 286 | port = self.fdtd.AddMSLPort( 287 | len(self.ports), 288 | self.csx.AddMetal(f"VirtualPort_{len(self.ports)}"), 289 | [0, 0, 0], 290 | [10, 10, 10], 291 | "x", 292 | "z", 293 | Feed_R=port_config.impedance, 294 | priority=100, 295 | excite=0, 296 | ) 297 | self.ports.append(port) 298 | 299 | def add_plane(self, z_height: float) -> None: 300 | """Add metal plane in whole bounding box of the PCB.""" 301 | self.plane_material.AddBox( 302 | [0, 0, z_height], 303 | [cfg.pcb_width, cfg.pcb_height, z_height], 304 | priority=1, 305 | ) 306 | 307 | def add_substrates(self) -> None: 308 | """Add substrate in whole bounding box of the PCB.""" 309 | logger.info("Adding substrates") 310 | 311 | offset = 0 312 | for i, layer in enumerate(cfg.get_substrates()): 313 | self.substrate_materials[i].AddBox( 314 | [0, 0, offset], 315 | [ 316 | cfg.pcb_width, 317 | cfg.pcb_height, 318 | offset - layer.thickness, 319 | ], 320 | priority=-i - 1, 321 | ) 322 | logger.debug("Added substrate from %f to %f", offset, offset - layer.thickness) 323 | offset -= layer.thickness 324 | 325 | def add_vias(self) -> None: 326 | """Add all vias from excellon file.""" 327 | logger.info("Adding vias from excellon file") 328 | vias = importer.get_vias() 329 | for via in vias: 330 | self.add_via(via[0], via[1], via[2]) 331 | 332 | def add_via(self, x_pos: float, y_pos: float, diameter: float) -> None: 333 | """Add via at specified position with specified diameter.""" 334 | thickness = sum(layer.thickness for layer in cfg.get_substrates()) 335 | 336 | x_coords = [] 337 | y_coords = [] 338 | for i in range(VIA_POLYGON): 339 | x_coords.append(x_pos + np.sin(i / VIA_POLYGON * 2 * np.pi) * diameter / 2) 340 | y_coords.append(y_pos + np.cos(i / VIA_POLYGON * 2 * np.pi) * diameter / 2) 341 | self.via_filling_material.AddLinPoly([x_coords, y_coords], "z", -thickness, thickness, priority=51) 342 | 343 | x_coords = [] 344 | y_coords = [] 345 | for i in range(VIA_POLYGON)[::-1]: 346 | x_coords.append(x_pos + np.sin(i / VIA_POLYGON * 2 * np.pi) * (diameter / 2 + cfg.via.plating_thickness)) 347 | y_coords.append(y_pos + np.cos(i / VIA_POLYGON * 2 * np.pi) * (diameter / 2 + cfg.via.plating_thickness)) 348 | self.via_material.AddLinPoly([x_coords, y_coords], "z", -thickness, thickness, priority=50) 349 | 350 | def add_dump_boxes(self) -> None: 351 | """Add electric field dump box in whole bounding box of the PCB at half the thickness of each substrate.""" 352 | logger.info("Adding dump box for each dielectic") 353 | offset = 0 354 | for i, layer in enumerate(cfg.get_substrates()): 355 | height = offset - layer.thickness / 2 356 | logger.debug("Adding dump box at %f", height) 357 | dump = self.csx.AddDump(f"e_field_{i}", sub_sampling=[1, 1, 1]) 358 | start = [ 359 | -cfg.grid.margin.xy, 360 | -cfg.grid.margin.xy, 361 | height, 362 | ] 363 | stop = [ 364 | cfg.pcb_width + cfg.grid.margin.xy, 365 | cfg.pcb_height + cfg.grid.margin.xy, 366 | height, 367 | ] 368 | dump.AddBox(start, stop) 369 | offset -= layer.thickness 370 | 371 | def set_boundary_conditions(self, pml: bool = False) -> None: 372 | """Add boundary conditions. MUR for fast simulation, PML for more accurate.""" 373 | if pml: 374 | logger.info("Adding perfectly matched layer boundary condition") 375 | self.fdtd.SetBoundaryCond(["PML_8", "PML_8", "PML_8", "PML_8", "PML_8", "PML_8"]) 376 | else: 377 | logger.info("Adding MUR boundary condition") 378 | self.fdtd.SetBoundaryCond(["MUR", "MUR", "MUR", "MUR", "MUR", "MUR"]) 379 | 380 | def set_excitation(self) -> None: 381 | """Set gauss excitation according to config.""" 382 | logger.debug( 383 | "Setting excitation to gaussian pulse from %f to %f", 384 | cfg.frequency.start, 385 | cfg.frequency.stop, 386 | ) 387 | self.fdtd.SetGaussExcite( 388 | (cfg.frequency.start + cfg.frequency.stop) / 2, 389 | (cfg.frequency.stop - cfg.frequency.start) / 2, 390 | ) 391 | 392 | def set_sinus_excitation(self, freq: float) -> None: 393 | """Set sinus excitation at specified frequency.""" 394 | logger.debug("Setting excitation to sine at %f", freq) 395 | self.fdtd.SetSinusExcite(freq) 396 | 397 | def run(self, excited_port_number: int) -> None: 398 | """Execute simulation.""" 399 | logger.info("Starting simulation") 400 | cwd = os.getcwd() 401 | self.fdtd.Run(os.path.join(os.getcwd(), SIMULATION_DIR, str(excited_port_number))) 402 | 403 | os.chdir(cwd) 404 | 405 | def save_geometry(self) -> None: 406 | """Save geometry to file.""" 407 | filename = os.path.join(os.getcwd(), GEOMETRY_DIR, "geometry.xml") 408 | logger.info("Saving geometry to %s", filename) 409 | self.csx.Write2XML(filename) 410 | 411 | # Replacing , with . for numerals in the file 412 | # (openEMS bug mitigation for locale that uses , as decimal separator) 413 | with open(filename, "r") as f: 414 | content = f.read() 415 | new_content = re.sub(r"([0-9]+),([0-9]+e)", r"\g<1>.\g<2>", content) 416 | with open(filename, "w") as f: 417 | f.write(new_content) 418 | 419 | def load_geometry(self) -> None: 420 | """Load geometry from file.""" 421 | filename = os.path.join(os.getcwd(), GEOMETRY_DIR, "geometry.xml") 422 | logger.info("Loading geometry from %s", filename) 423 | if not os.path.exists(filename): 424 | logger.error("Geometry file does not exist. Did you run geometry step?") 425 | sys.exit(1) 426 | self.csx.ReadFromXML(filename) 427 | self.grid = self.csx.GetGrid() 428 | 429 | def get_port_parameters(self, index: int, frequencies: np.ndarray) -> Tuple[List, List]: 430 | """Return reflected and incident power vs frequency for each port.""" 431 | result_path = os.path.join(os.getcwd(), SIMULATION_DIR, str(index)) 432 | 433 | incident: List[np.ndarray] = [] 434 | reflected: List[np.ndarray] = [] 435 | for index, port in enumerate(self.ports): 436 | try: 437 | port.CalcPort(result_path, frequencies) 438 | logger.debug("Found data for port %d", index) 439 | except IOError: 440 | logger.error("Port data files do not exist. Did you run simulation step?") 441 | sys.exit(1) 442 | incident.append(port.uf_inc) 443 | reflected.append(port.uf_ref) 444 | 445 | return (reflected, incident) 446 | 447 | def setup_ports(self, enabled_idx: int) -> None: 448 | """Set up ports excitation.""" 449 | logger.info("Setting up ports") 450 | 451 | for prop in self.csx.GetAllProperties(): 452 | if not isinstance(prop, CSXCAD.CSProperties.CSPropExcitation): 453 | continue 454 | pname = prop.GetName() 455 | idx = int(pname.removeprefix(pname.rstrip("0123456789"))) 456 | if idx != enabled_idx: 457 | prop.SetExcitation([0, 0, 0]) 458 | else: 459 | prop.SetExcitation([0, 0, 1]) 460 | 461 | def add_ports(self) -> None: 462 | """Add ports for simulation.""" 463 | logger.info("Adding ports") 464 | 465 | self.ports = [] 466 | 467 | for index, port_config in enumerate(cfg.ports): 468 | self.add_msl_port(port_config, index, True) 469 | 470 | def add_virtual_ports(self) -> None: 471 | """Add virtual ports needed for data postprocessing due to openEMS api design.""" 472 | logger.info("Adding virtual ports") 473 | for port_config in cfg.ports: 474 | self.add_virtual_port(port_config) 475 | --------------------------------------------------------------------------------