Skip to content
Merged
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
1 change: 0 additions & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ jobs:
run: |
uv run pytest -rxXs --basetemp=tmp
- name: Store reports
if: failure()
uses: actions/upload-artifact@v6
with:
name: reports-${{ matrix.os }}
Expand Down
37 changes: 29 additions & 8 deletions src/pyxems/csx.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ def to_xml(self, short=True) -> str:
return f' Number="{self.number}" Type="{self.type}" Weight="{self.weight}" NormDir="{self.normdir}" StartTime="{self.starttime:g}" StopTime="{self.stoptime:g}"'


@dataclass(frozen=True)
class DumpBoxProperty:
number: int = 0
type: int = 0
weight: int = 1
normdir: int = -1
starttime: float = 0
stoptime: float = 0
dumptype: int = 0
dumpmode: int = 1
filetype: int = 1
multigridlevel: int = 0

def to_xml(self, short=True) -> str:
return f' Number="{self.number}" Type="{self.type}" Weight="{self.weight}" NormDir="{self.normdir}" StartTime="{self.starttime:g}" StopTime="{self.stoptime:g}" DumpType="{self.dumptype}" DumpMode="{self.dumpmode}" FileType="{self.filetype}" MultiGridLevel="{self.multigridlevel}"'


@dataclass(frozen=True)
class Color:
r: int
Expand Down Expand Up @@ -137,7 +154,11 @@ class Property:
fillcolor: Color = field(default_factory=lambda: Color(255, 255, 255, 255))
edgecolor: Color = field(default_factory=lambda: Color(0, 0, 0, 255))
material: (
MaterialProperty | LumpedProperty | ExcitationProperty | ProbeBoxProperty
MaterialProperty
| LumpedProperty
| ExcitationProperty
| ProbeBoxProperty
| DumpBoxProperty
) = field(
default_factory=lambda: MaterialProperty(
"Property", Physical(1.0), Physical(1.0)
Expand All @@ -157,15 +178,9 @@ class Property:

def to_xml(self) -> str:
match self.kind:
case "Metal":
iso = ""
case "Material":
iso = ' Isotropy="1"'
case "LumpedElement":
iso = self.material.to_xml()
case "Excitation":
iso = self.material.to_xml()
case "ProbeBox":
case "LumpedElement" | "ProbeBox" | "Excitation" | "DumpBox":
iso = self.material.to_xml()
case _:
iso = ""
Expand Down Expand Up @@ -241,6 +256,12 @@ def add_property(
starttime=prop_conf["starttime"] if "starttime" in prop_conf else 0,
stoptime=prop_conf["stoptime"] if "stoptime" in prop_conf else 0,
)
case "DumpBox":
property = DumpBoxProperty(
dumptype=int(
prop_conf["dumptype"] if "dumptype" in prop_conf else 0
),
)
case _:
raise ValueError(f"Unknown property kind: {kind}")
prop = Property(
Expand Down
21 changes: 16 additions & 5 deletions src/pyxems/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from shutil import which
import os
from typing import Optional
import logging

try:
import cyclopts
Expand All @@ -19,13 +20,23 @@

def find_openems_executable() -> Optional[Path]:
if which("openEMS") is not None:
logging.info(f"Found OpenEMS executable in PATH: {which('openEMS')}")
return Path(which("openEMS")) # type: ignore
load_dotenv()
if "OPENEMS_PATH" in os.environ:
openems_path = Path(os.environ["OPENEMS_PATH"]) / "openEMS"
if openems_path.is_file():
return openems_path
return None
if "OPENEMS_PATH" not in os.environ:
logging.info(
"OPENEMS_PATH environment variable not set. Please set it to the directory containing the OpenEMS executable."
)
return None
openems_path = Path(os.environ["OPENEMS_PATH"]) / (
"openEMS" if os.name != "nt" else "openEMS.exe"
)
if not openems_path.is_file():
logging.info(
f"OpenEMS executable not found at {openems_path}. Please ensure OPENEMS_PATH is set correctly."
)
return None
return openems_path


def check_config() -> bool:
Expand Down
58 changes: 58 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,63 @@ def test_generate_simp_patch(tmp_path: Path):
priority=0,
property_id=6,
)
oems_config.csx.add_property("DumpBox", "nf2ff_E", Color(12, 62, 153))
start = (-90.50519, -90.66667, -40.34557)
stop = (-90.50519, 90.66667, 90.32554)
oems_config.csx.add_box(start, stop, priority=0, property_id=7)
oems_config.csx.add_box(
(-start[0], *start[1:]), (-stop[0], *stop[1:]), priority=0, property_id=7
)
oems_config.csx.add_box(
start, (-stop[0], -stop[1], stop[2]), priority=0, property_id=7
)
oems_config.csx.add_box(
(start[0], -start[1], start[2]),
(-stop[0], stop[1], stop[2]),
priority=0,
property_id=7,
)
oems_config.csx.add_box(
(start[0], start[1], start[2]),
(-stop[0], stop[1], start[2]),
priority=0,
property_id=7,
)
oems_config.csx.add_box(
(start[0], start[1], stop[2]),
(-stop[0], stop[1], stop[2]),
priority=0,
property_id=7,
)
oems_config.csx.add_property(
"DumpBox", "nf2ff_H", Color(36, 94, 13), prop_conf={"dumptype": 1}
)
start = (-90.50519, -90.66667, -40.34557)
stop = (-90.50519, 90.66667, 90.32554)
oems_config.csx.add_box(start, stop, priority=0, property_id=8)
oems_config.csx.add_box(
(-start[0], *start[1:]), (-stop[0], *stop[1:]), priority=0, property_id=8
)
oems_config.csx.add_box(
start, (-stop[0], -stop[1], stop[2]), priority=0, property_id=8
)
oems_config.csx.add_box(
(start[0], -start[1], start[2]),
(-stop[0], stop[1], stop[2]),
priority=0,
property_id=8,
)
oems_config.csx.add_box(
(start[0], start[1], start[2]),
(-stop[0], stop[1], start[2]),
priority=0,
property_id=8,
)
oems_config.csx.add_box(
(start[0], start[1], stop[2]),
(-stop[0], stop[1], stop[2]),
priority=0,
property_id=8,
)
write_openEMS_xml(tmp_path / "openEMS_config.xml", oems_config)
assert (tmp_path / "openEMS_config.xml").read_text() == ref.read_text()
6 changes: 4 additions & 2 deletions tests/test_run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pathlib import Path
from pyxems.run import simulate, check_config
from pyxems.run import simulate, check_config, find_openems_executable
import pytest


@pytest.mark.skipif(not check_config(), reason="OpenEMS exe not found.")
@pytest.mark.skipif(
not check_config(), reason=f"OpenEMS exe not found. {find_openems_executable()}"
)
def test_simulate(tmp_path: Path):
config_path = Path(__file__).parent / "data" / "simp_patch.xml"
result = simulate(config_path, tmp_path)
Expand Down