Skip to content
Open
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
39 changes: 39 additions & 0 deletions api/python/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{ lib
, buildPythonPackage
, hatchling
, openemsh
, openems
, appcsxcad
}:

buildPythonPackage {
pname = "python-${openemsh.pname}";
inherit (openemsh) version;

src = lib.nix-filter {
root = ../..;
include = [
"api/python"
"CHANGELOG"
"README.md"
];
};

sourceRoot = "source/api/python";

pyproject = true;

build-system = [
hatchling
];

dependencies = [
openemsh
openems
appcsxcad
];

meta = openemsh.meta // {
description = "Python API for OpenEMSH, OpenEMS mesher";
};
}
51 changes: 51 additions & 0 deletions api/python/openemsh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import shutil
import subprocess
from openEMS import openEMS

def run_openemsh(fdtd: openEMS, csx_file: str, args: list[str] = ["-Gv"]):
"""
Invokes OpenEMSH mesher

:param csx_file: CSX XML file path.
"""
fdtd.Write2XML(csx_file)
subprocess.run(["openemsh", "-i", csx_file] + args, capture_output=False, text=True, check=True, stderr=subprocess.STDOUT)
fdtd.ReadFromXML(csx_file)

def run_appcsxcad(fdtd: openEMS, csx_file: str, edit: bool = False, render_disc_material: bool = False):
"""
Invokes AppCSXCAD

:param csx_file: CSX XML file path.
:param edit: Edit mode, `--disableEdit`.
:param render_disc_material: Render discrete material, `--RenderDiscMaterial`.
"""
fdtd.Write2XML(csx_file)
command = ["AppCSXCAD"]
if render_disc_material:
command += ["--RenderDiscMaterial"]
if not edit:
command += ["--disableEdit"]
command += [csx_file]
subprocess.run(
command,
capture_output=False,
text=True,
check=False)
if edit:
fdtd.ReadFromXML(csx_file)

def ensure_sim_path(sim_path: str, cleanup: bool = False):
"""
Ensure simulation path exists, optionaly cleanup old simulation files, if any.
Use this instead of regular openEMS.Run cleanup param, before writing CSX file.

:param sim_path: Simulation path.
:param cleanup: Remove old result in simulation path.
"""
if cleanup and os.path.exists(sim_path):
shutil.rmtree(sim_path, ignore_errors=True)
os.mkdir(sim_path)
if not os.path.exists(sim_path):
os.mkdir(sim_path)
38 changes: 38 additions & 0 deletions api/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
dynamic = ["version"]
name = "openemsh"
description = "API for OpenEMSH, openEMS mesher"
dependencies = []
license = "GPL-3.0-or-later"
readme = "../../README.md"
keywords = ["openems", "fdtd", "mesh"]
authors = [
{name = "Thomas Lepoix", email = "thomas.lepoix@protonmail.ch"}
]
maintainers = [
{name = "Thomas Lepoix", email = "thomas.lepoix@protonmail.ch"}
]

[project.urls]
homepage = "https://github.com/Open-RFlab/openemsh"
source = "https://github.com/Open-RFlab/openemsh"
changelog = "https://github.com/Open-RFlab/openemsh/blob/main/CHANGELOG"
releasenotes = "https://github.com/Open-RFlab/openemsh/releases"
#documentation = "https://github.com/Open-RFlab/openemsh"
issues = "https://github.com/Open-RFlab/openemsh/issues"
funding = "https://liberapay.com/thomaslepoix"

[project.scripts]
spam-cli = "spam:main_cli"

[project.gui-scripts]
spam-gui = "spam:main_gui"

[tool.hatch.version]
path = "../../CHANGELOG"
# TODO + in version are not fine
pattern = "^[^ ]+ \\((?P<version>.*)\\)$"
63 changes: 56 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,20 @@
packages = [
nixGL.packages.${system}.nixGLDefault
pkgs.openems
pkgs.openemsh
pkgs.appcsxcad
(pkgs.octaveFull.withPackages (p: [
pkgs.octave-openems
pkgs.octave-csxcad
pkgs.octave-openems
pkgs.octave-openems-hll
]))
(pkgs.python3.withPackages (p: [
p.numpy
p.matplotlib
pkgs.python-csxcad
pkgs.python-openems
pkgs.python-openemsh
]))
];
};

Expand Down Expand Up @@ -219,12 +227,12 @@
}) {};

csxcad = (prev.csxcad.overrideAttrs (new: old: {
version = "0.6.3";
version = "0116fc1";
src = prev.fetchFromGitHub {
owner = "thliebig";
repo = "CSXCAD";
rev = "v${new.version}";
hash = "sha256-SSV5ulx3rCJg99I/oOQbqe+gOSs+BfcCo6UkWHVhnSs=";
rev = new.version;
hash = "sha256-/xd4GyHEzX9ZstrAPgHeo7xrp/srycfdMAuDq82D4z8=";
};
prePatch = ''
substituteInPlace CMakeLists.txt --replace-fail 'INSTALL(DIRECTORY matlab DESTINATION share/CSXCAD)' ""
Expand All @@ -235,6 +243,13 @@
};

qcsxcad = (prev.qcsxcad.overrideAttrs (new: old: {
version = "63ac6f8";
src = prev.fetchFromGitHub {
owner = "thliebig";
repo = "QCSXCAD";
rev = new.version;
hash = "sha256-kJZcuY2CSaaFAQiBemIqLrABUBpym047ISnmwg3kKXQ=";
};
nativeBuildInputs = old.nativeBuildInputs ++ [
prev.libsForQt5.wrapQtAppsHook
];
Expand All @@ -244,6 +259,14 @@
};

appcsxcad = (prev.appcsxcad.overrideAttrs (new: old: {
version = "731d2dc";
src = prev.fetchFromGitHub {
owner = "thliebig";
repo = "AppCSXCAD";
rev = new.version;
hash = "sha256-RcXLgh+Czs3TdvsX+OtDMrqqcBN/QCCJu644Fwz3RLE=";
};

nativeBuildInputs = old.nativeBuildInputs ++ [
prev.libsForQt5.wrapQtAppsHook
];
Expand All @@ -253,12 +276,12 @@
};

openems = (prev.openems.overrideAttrs (new: old: {
version = "0.0.36";
version = "fc15273";
src = prev.fetchFromGitHub {
owner = "thliebig";
repo = "openEMS";
rev = "v${new.version}";
hash = "sha256-wdH+Zw7G2ZigzBMX8p3GKdFVx/AhbTNL+P3w+YjI/dc=";
rev = new.version;
hash = "sha256-JNJU8KS/6qgifn41+ivosofb/IWKPsCGBj9tdehpZBQ=";
};
postFixup = ""; # Avoid oct file building / setup.m patching.
prePatch = ''
Expand All @@ -268,6 +291,32 @@
})).override {
stdenv = prev.fastStdenv;
inherit (final) csxcad qcsxcad;
withQcsxcad = false;
};

python-csxcad = (prev.python3Packages.python-csxcad.overrideAttrs (new: old: {
CSXCAD_INSTALL_PATH_IGNORE = true;
})).override {
inherit (final) csxcad openems;
};

python-openems = (prev.python3Packages.python-openems.overrideAttrs (new: old: {
OPENEMS_INSTALL_PATH_IGNORE = true;
nativeBuildInputs = old.nativeBuildInputs ++ [
prev.boost.dev
];
setupPyBuildFlags = old.setupPyBuildFlags ++ [
"-I${prev.boost.dev}/include"
"-L${prev.boost}/lib"
"-R${prev.boost}/lib"
];
})).override {
inherit (final) csxcad openems python-csxcad;
};

python-openemsh = prev.python3Packages.callPackage ./api/python/default.nix {
inherit lib;
inherit (final) appcsxcad openemsh;
};

octave-csxcad = prev.octavePackages.buildOctavePackage rec {
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target_sources( openemsh
"${CMAKE_CURRENT_SOURCE_DIR}/utils/entity.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/tree_node.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/state_management.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/logger.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/utils/progress.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/domain/geometrics/space.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/domain/geometrics/relation.cpp"
Expand Down Expand Up @@ -84,6 +85,7 @@ add_executable( openemsh_bin WIN32 )
target_sources( openemsh_bin
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/ui/cli/cli.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/cli/logger.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/cli/progress.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/utils/nodegraph/highlightable.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/utils/nodegraph/port.cpp"
Expand Down Expand Up @@ -132,6 +134,7 @@ target_sources( openemsh_bin
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/about_dialog.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/icons.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/main_window.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/logger.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/progress.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/style.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/qt/resources.qrc"
Expand Down
12 changes: 10 additions & 2 deletions src/domain/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
///*****************************************************************************

#include <algorithm>
#include <limits>
#include <set>
#include <utility>

Expand Down Expand Up @@ -65,10 +66,16 @@ shared_ptr<Board> Board::Builder::build(Params&& params) {
return make_shared<Board>(
std::move(polygons),
std::move(fixed_meshline_policy_creators),
std::move(material),
std::move(params),
Caretaker::singleton().get_history_root());
}

//******************************************************************************
void Board::Builder::set_background_material(shared_ptr<Material> background) {
material = background;
}

// TODO should be in meshline manager?
//******************************************************************************
void Board::Builder::add_fixed_meshline_policy(Axis const axis, Coord const coord) {
Expand Down Expand Up @@ -146,12 +153,14 @@ Board::Board(PlaneSpace<vector<shared_ptr<Polygon>>>&& polygons, Params&& params
Board::Board(
PlaneSpace<std::vector<std::shared_ptr<Polygon>>>&& polygons,
AxisSpace<std::vector<std::function<void (Board*, Timepoint*)>>>&& fixed_meshline_policy_creators,
shared_ptr<Material>&& background,
Params&& params,
Timepoint* t)
: Originator(t, BoardState(std::move(polygons)))
, global_params(make_shared<GlobalParams>(std::move(params), t))
, conflict_manager(make_shared<ConflictManager>(t))
, line_policy_manager(make_shared<MeshlinePolicyManager>(global_params.get(), t))
, material(background)
, fixed_meshline_policy_creators(std::move(fixed_meshline_policy_creators)) {

conflict_manager->init(line_policy_manager.get());
Expand Down Expand Up @@ -196,8 +205,7 @@ pair<shared_ptr<Material>, remove_const_t<decltype(Polygon::priority)>> Board::f
if(!materials.empty())
return materials.back();
else
// TODO if no material return Board::background_material
return {};
return { material, std::numeric_limits<remove_const_t<decltype(Polygon::priority)>>::min() };
}

//******************************************************************************
Expand Down
5 changes: 5 additions & 0 deletions src/domain/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "utils/state_management.hpp"
#include "conflict_manager.hpp"
#include "global.hpp"
#include "material.hpp"
#include "meshline_policy_manager.hpp"
//#include "meshline_policy.hpp"
//#include "range.hpp"
Expand Down Expand Up @@ -59,6 +60,7 @@ class Board
class Builder {
public:

void set_background_material(std::shared_ptr<Material> background);
void add_fixed_meshline_policy(Axis axis, Coord coord);
void add_polygon(Plane plane, std::shared_ptr<Material> const& material, std::string const& name, std::size_t priority, Polygon::RangeZ const& z_placement, std::initializer_list<Point> points);
void add_polygon(Plane plane, std::shared_ptr<Material> const& material, std::string const& name, std::size_t priority, Polygon::RangeZ const& z_placement, std::vector<std::unique_ptr<Point const>>&& points);
Expand All @@ -67,16 +69,19 @@ class Board
[[nodiscard]] std::shared_ptr<Board> build(Params&& params = Params());

private:
std::shared_ptr<Material> material;
PlaneSpace<std::vector<std::shared_ptr<Polygon>>> polygons;
AxisSpace<std::vector<std::function<void (Board*, Timepoint*)>>> fixed_meshline_policy_creators;
};

std::shared_ptr<Material> material;
AxisSpace<std::vector<std::function<void (Board*, Timepoint*)>>> const fixed_meshline_policy_creators; // Meant to delay MeshlinePolicies creation at Step time instead of Parse time.

Board(PlaneSpace<std::vector<std::shared_ptr<Polygon>>>&& polygons, Params&& params, Timepoint* t);
Board(
PlaneSpace<std::vector<std::shared_ptr<Polygon>>>&& polygons,
AxisSpace<std::vector<std::function<void (Board*, Timepoint*)>>>&& fixed_meshline_policy_creators,
std::shared_ptr<Material>&& background,
Params&& params,
Timepoint* t);

Expand Down
5 changes: 5 additions & 0 deletions src/domain/global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
#pragma once

#include <cstddef>
#include <utility>
#include <vector>

#include "geometrics/space.hpp"
#include "utils/state_management.hpp"

namespace domain {
Expand All @@ -23,6 +26,8 @@ struct Params {
std::size_t diagonal_lmin = 2;
double diagonal_dmax = 0.2;
double consecutive_diagonal_minimal_angle = 20; // Limite between acute / obtuse angles.

std::vector<std::pair<Axis, double>> input_fixed_meshlines;
};

//******************************************************************************
Expand Down
Loading
Loading