Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openems #226

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,24 @@ jobs:
winget settings --enable LocalManifestFiles
winget install -m .\manifests\n\NGSpice\NGSpice\42
Add-Content $env:GITHUB_PATH "$env:LOCALAPPDATA\Microsoft\WinGet\Packages\NGSpice.NGSpice__DefaultSource\Spice64\bin"
winget install -m .\manifests\o\OpenEMS\OpenEMS\0.0.36
Add-Content $env:GITHUB_PATH "$env:LOCALAPPDATA\Microsoft\WinGet\Packages\OpenEMS.OpenEMS__DefaultSource\OpenEMS"
- name: Config Ubuntu - Setup External Tools
if: ${{runner.os != 'Windows' }}
run: |
sudo apt-get update
sudo apt-get install -y klayout ngspice
sudo apt-get install -y klayout ngspice python3-openems
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"
cache: 'poetry'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
poetry config virtualenvs.options.system-site-packages true
poetry install --with dev,doc
poetry run pwd
- name: check and format
Expand Down
13 changes: 13 additions & 0 deletions hades/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typer import Typer
from pathlib import Path
from hades.devices.mos import Mos
Expand Down Expand Up @@ -51,3 +52,15 @@ def template(project_name: Path = "./working_dir"):
makedirs(project_name)
with open(join(project_name, "design.yml"), "w") as f:
yaml.dump(yaml.load(template_file, yaml.Loader), f)


@app.command("init")
def post_install():
"""
Post-installation script.
:return:
"""
from hades.wrappers.openems import init

logging.basicConfig(filename="hades.log", level=logging.INFO, filemode="w")
init()
116 changes: 116 additions & 0 deletions hades/wrappers/openems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import logging
import shutil
from pylab import *

Check failure on line 3 in hades/wrappers/openems.py

View workflow job for this annotation

GitHub Actions / testing (ubuntu-latest)

Ruff (F403)

hades/wrappers/openems.py:3:1: F403 `from pylab import *` used; unable to detect undefined names
from openEMS.physical_constants import *

Check failure on line 4 in hades/wrappers/openems.py

View workflow job for this annotation

GitHub Actions / testing (ubuntu-latest)

Ruff (F403)

hades/wrappers/openems.py:4:1: F403 `from openEMS.physical_constants import *` used; unable to detect undefined names


def init():
open_ems_path = shutil.which("OpenEMS")
logging.info(f"OpenEMS_Path: {open_ems_path}")
import os, tempfile

Check failure on line 10 in hades/wrappers/openems.py

View workflow job for this annotation

GitHub Actions / testing (ubuntu-latest)

Ruff (E401)

hades/wrappers/openems.py:10:5: E401 Multiple imports on one line

from CSXCAD import ContinuousStructure
from openEMS import openEMS

### Setup the simulation
Sim_Path = os.path.join(tempfile.gettempdir(), "Rect_WG")

post_proc_only = False
unit = 1e-6 # drawing unit in um

# waveguide dimensions
# WR42
a = 10700 # waveguide width
b = 4300 # waveguide height
length = 50000
# frequency range of interest
f_start = 20e9
f_0 = 24e9
f_stop = 26e9
lambda0 = C0 / f_0 / unit

Check failure on line 30 in hades/wrappers/openems.py

View workflow job for this annotation

GitHub Actions / testing (ubuntu-latest)

Ruff (F405)

hades/wrappers/openems.py:30:15: F405 `C0` may be undefined, or defined from star imports
# waveguide TE-mode definition
TE_mode = "TE10"
# targeted mesh resolution
mesh_res = lambda0 / 30

### Setup FDTD parameter & excitation function
FDTD = openEMS(NrTS=1e4)
FDTD.SetGaussExcite(0.5 * (f_start + f_stop), 0.5 * (f_stop - f_start))
# boundary conditions
FDTD.SetBoundaryCond([0, 0, 0, 0, 3, 3])
### Setup geometry & mesh
CSX = ContinuousStructure()
FDTD.SetCSX(CSX)
mesh = CSX.GetGrid()
mesh.SetDeltaUnit(unit)

mesh.AddLine("x", [0, a])
mesh.AddLine("y", [0, b])
mesh.AddLine("z", [0, length])

## Apply the waveguide port
ports = []
start = [0, 0, 10 * mesh_res]
stop = [a, b, 15 * mesh_res]
mesh.AddLine("z", [start[2], stop[2]])
ports.append(
FDTD.AddRectWaveGuidePort(0, start, stop, "z", a * unit, b * unit, TE_mode, 1)
)

start = [0, 0, length - 10 * mesh_res]
stop = [a, b, length - 15 * mesh_res]
mesh.AddLine("z", [start[2], stop[2]])
ports.append(
FDTD.AddRectWaveGuidePort(1, start, stop, "z", a * unit, b * unit, TE_mode)
)

mesh.SmoothMeshLines("all", mesh_res, ratio=1.4)

### Define dump box...
Et = CSX.AddDump("Et", file_type=0, sub_sampling=[2, 2, 2])
start = [0, 0, 0]
stop = [a, b, length]
Et.AddBox(start, stop)
### Run the simulation
if True: # debugging only
CSX_file = os.path.join(Sim_Path, "rect_wg.xml")
if not os.path.exists(Sim_Path):
os.mkdir(Sim_Path)
CSX.Write2XML(CSX_file)
from CSXCAD import AppCSXCAD_BIN

os.system(AppCSXCAD_BIN + ' "{}"'.format(CSX_file))

if not post_proc_only:
FDTD.Run(Sim_Path, cleanup=True)

### Postprocessing & plotting
freq = linspace(f_start, f_stop, 201)

Check failure on line 88 in hades/wrappers/openems.py

View workflow job for this annotation

GitHub Actions / testing (ubuntu-latest)

Ruff (F405)

hades/wrappers/openems.py:88:12: F405 `linspace` may be undefined, or defined from star imports
for port in ports:
port.CalcPort(Sim_Path, freq)

s11 = ports[0].uf_ref / ports[0].uf_inc
s21 = ports[1].uf_ref / ports[0].uf_inc
ZL = ports[0].uf_tot / ports[0].if_tot
ZL_a = ports[0].ZL # analytic waveguide impedance

## Plot s-parameter
figure()

Check failure on line 98 in hades/wrappers/openems.py

View workflow job for this annotation

GitHub Actions / testing (ubuntu-latest)

Ruff (F405)

hades/wrappers/openems.py:98:5: F405 `figure` may be undefined, or defined from star imports
plot(freq * 1e-6, 20 * log10(abs(s11)), "k-", linewidth=2, label="$S_{11}$")

Check failure on line 99 in hades/wrappers/openems.py

View workflow job for this annotation

GitHub Actions / testing (ubuntu-latest)

Ruff (F405)

hades/wrappers/openems.py:99:5: F405 `plot` may be undefined, or defined from star imports

Check failure on line 99 in hades/wrappers/openems.py

View workflow job for this annotation

GitHub Actions / testing (ubuntu-latest)

Ruff (F405)

hades/wrappers/openems.py:99:28: F405 `log10` may be undefined, or defined from star imports
grid()

Check failure on line 100 in hades/wrappers/openems.py

View workflow job for this annotation

GitHub Actions / testing (ubuntu-latest)

Ruff (F405)

hades/wrappers/openems.py:100:5: F405 `grid` may be undefined, or defined from star imports
plot(freq * 1e-6, 20 * log10(abs(s21)), "r--", linewidth=2, label="$S_{21}$")

Check failure on line 101 in hades/wrappers/openems.py

View workflow job for this annotation

GitHub Actions / testing (ubuntu-latest)

Ruff (F405)

hades/wrappers/openems.py:101:5: F405 `plot` may be undefined, or defined from star imports
legend()
ylabel("S-Parameter (dB)")
xlabel(r"frequency (MHz) $\rightarrow$")

## Compare analytic and numerical wave-impedance
figure()
plot(freq * 1e-6, real(ZL), linewidth=2, label="$\Re\{Z_L\}$")
grid()
plot(freq * 1e-6, imag(ZL), "r--", linewidth=2, label="$\Im\{Z_L\}$")
plot(freq * 1e-6, ZL_a, "g-.", linewidth=2, label="$Z_{L, analytic}$")
ylabel("ZL $(\Omega)$")
xlabel(r"frequency (MHz) $\rightarrow$")
legend()

show()
20 changes: 20 additions & 0 deletions manifests/o/OpenEMS/OpenEMS/0.0.36/OpenEMS.OpenEMS.installer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Created using wingetcreate 1.6.1.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.installer.1.6.0.schema.json

PackageIdentifier: OpenEMS.OpenEMS
PackageVersion: 0.0.36
InstallerType: zip
NestedInstallerType: portable
NestedInstallerFiles:
- RelativeFilePath: openEMS\AppCSXCAD.exe
PortableCommandAlias: AppCSXCAD
- RelativeFilePath: openEMS\nf2ff.exe
PortableCommandAlias: nf2ff
- RelativeFilePath: openEMS\openEMS.exe
PortableCommandAlias: OpenEMS
Installers:
- InstallerUrl: https://github.com/thliebig/openEMS-Project/releases/download/v0.0.36/openEMS_v0.0.36.zip
Architecture: x64
InstallerSha256: E0D62B1176C0897AD18876B45667DE877D7D3B58B37C0BE95545F9B988896059
ManifestType: installer
ManifestVersion: 1.6.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Created using wingetcreate 1.6.1.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.defaultLocale.1.6.0.schema.json

PackageIdentifier: OpenEMS.OpenEMS
PackageVersion: 0.0.36
PackageLocale: en-US
Publisher: OpenEMS
PackageName: OpenEMS
License: GPL v3.0
ShortDescription: a free and open electromagnetic field solver
ManifestType: defaultLocale
ManifestVersion: 1.6.0
8 changes: 8 additions & 0 deletions manifests/o/OpenEMS/OpenEMS/0.0.36/OpenEMS.OpenEMS.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Created using wingetcreate 1.6.1.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.version.1.6.0.schema.json

PackageIdentifier: OpenEMS.OpenEMS
PackageVersion: 0.0.36
DefaultLocale: en-US
ManifestType: version
ManifestVersion: 1.6.0
Loading
Loading