The original update equations in the FDTD engine have extremely
long lines and are difficult to read and work with. This patch
inserts line breaks, it aligns all array indexes by x/y/z
coordinates to make it easy to visually compare.
Signed-off-by: Yifeng Li <tomli@tomli.me>
Currently, openEMS doesn't have any special code to handle SIGINT (which
is raised by pressing Control-C). By default, the program is terminated
without saving data. This worked okay in the past, but now its
limitations are becoming obvious.
1. When openEMS is used as a Python module, Control-C stops working
because SIGINT is now managed by Python in order to generate
KeyboardInterrupt exceptions, normally this isn't a problem, but if
we are running an external C++ (Cython) function such as openEMS, the
Python interpreter mainloop has no control until we return. As a
result, SIGINT is received but never handled. In Cython, programs are
expected to call PyErr_CheckSignals() in its blocking loop periodically
to temporally transfer control back to Python to handle signals. But
this introduces a dependency of Cython in the FDTD mainloop.
2. During a simulation, it's not possible to abort it gracefully by
pressing Control-C, this is a limitation of openEMS itself, it's
always a force exit. Currently the only supported method for graceful
exit is creating a file called "ABORT" in the simulation directory.
If we already need to implement a signal handler, adding a graceful
exit at the same time would be a good idea.
This commit installs SIGINT handlers during SetupFDTD() and RunFDTD().
1. In RunFDTD(), if SIGINT is received once, a status flag is set, which
is then checked in CheckAbortCond(), allowing a graceful exit with the
same effect of an "ABORT" file. If SIGINT is received twice, openEMS
force exit without saving data (just like the old default behavior).
2. In SetupFDTD(), if SIGINT is received, openEMS immediately force
exit without saving data, identical to the old behavior. In a huge
simulation, initializing and compressing operators may have a long
time. so we want an early exit before RunFDTD().
3. Before RunFDTD() and SetupFDTD() return, the original signal handler
for SIGINT is restored. This is important since when we're acting as
a shared library. When a program (such as the Python interpreter) calls
us, changing the SIGINT handler unilaterally may overwrite the original
handler and affect the functionality of the original program. For
example, Python would never be able to raise KeyboardInterrupt again.
Thus, we save the original handler and restore it later.
Signed-off-by: Yifeng Li <tomli@tomli.me>
Currently, on ARM and PPC, CMakeLists.txt uses:
set(CMAKE_CXX_FLAGS "-DNO_WARN_X86_INTRINSICS -DSSE_CORRECT_DENORMALS")
but this overwrites the default value of CMAKE_CXX_FLAGS from CMake,
including user-specified CXXFLAGS via environmental variable, making
it impossible to change CXXFLAGS.
This patch appends instead of overwrite CMAKE_CXX_FLAGS via:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNO_WARN_X86_INTRINSICS -DSSE_CORRECT_DENORMALS")
Signed-off-by: Yifeng Li <tomli@tomli.me>
Currently, running openEMS's example Python scripts on macOS always fails
with the following error:
$ python3 MSL_NotchFilter.py
Traceback (most recent call last):
File "/Users/gentoo/code/openEMS-Project/openEMS/python/Tutorials/MSL_NotchFilter.py", line 103, in <module>
FDTD.Run(Sim_Path, cleanup=True)
File "openEMS/openEMS.pyx", line 489, in openEMS.openEMS.openEMS.Run
AssertionError
This is caused by an oversight of an assertion in openEMS.pyx:
os.chdir(sim_path)
# ...
assert os.getcwd() == sim_path
The problem here is that "sim_path" is not a canonical path name,
so the assertion would fail if the path we're switching into contains
a symbolic link. This problem affects all operating systems, it's not
limited to macOS. But on macOS, the problem is especially serious,
since macOS's "/tmp" is a link to "/private/tmp" by default. Thus, it
causes an AssertionError in all the included Python examples.
Instead of doing "assert os.getcwd() == sim_path", we should write
"assert os.getcwd() == os.path.realpath(sim_path)" to ensure that
we're checking a canonical path.
Signed-off-by: Yifeng Li <tomli@tomli.me>
Accroding to NumPy's development team, "for a long time, np.int has
been an alias of the builtin int. This is repeatedly a cause of
confusion for newcomers, and existed mainly for historic reasons."
This and many other aliases have been deprecated since NumPy v1.20.0,
and at this point they've been completely removed. Replace "np.int"
with "int" allows ports.py to run again.
Signed-off-by: Yifeng Li <tomli@tomli.me>