Data and files#
Draft Written from harmolab/utils/file_path.py, harmolab/rwg/rwg1.py to rwg4.py, harmolab/utils/mesh/gmsh_function.py, harmolab/utils/mesh/mesh_io.py and harmolab/utils/frequency_sweep.py at commit 72fb8c6; the file listing and the reloading example are outputs of documentation/figure_notebooks/guide_first_simulation.ipynb. Awaiting review.
The solver is a pipeline of stages, and each stage saves its result to a .mat file (MATLAB format,
read and written with scipy.io) before the next one reads it. This page says where those files are,
what they contain, and how to use them.
Where: data/, under the working directory#
Every path is relative to the working directory: a notebook run from its own folder reads and
writes the data/ folder next to it, a script reads and writes the data/ folder of the directory it
is started from. setup_save_file_paths(name) creates the folders below if they are missing and
returns a path object with the name of every file of the antenna name:
Folder |
File, |
Written by |
|---|---|---|
|
|
|
|
|
|
|
|
stage |
|
|
stage |
|
|
stage |
|
|
stage |
|
|
|
|
|
|
|
|
|
|
PDF and GIF figures |
the plotting functions, with |
The first use of efield2 also writes the observation sphere, data/gmsh_files/hollow_sphere.msh and
data/antennas_mesh/hollow_sphere.mat, and reuses them afterwards.
What: the content of each file#
For the dipole of First simulation (\(N\) = 144 RWG edges, 116 triangles, 89 points):
File |
Variables (shape) |
|---|---|
|
|
|
|
|
the same, plus |
|
|
|
the same constants; |
|
|
|
|
gap_currents is the physical current across the port, \(b_p^\mathsf T I\) (Ports).
Files written before the port refactoring (branch refactor/ports, merged into main) stored it multiplied by
\(e^{-j\varphi}\), \(\varphi\) being the phase of the port voltage; with a zero phase the two agree.
Units are SI throughout; amplitudes are peak values.
Reloading results#
Each stage has a DataManager that reads its file back, so a result can be used again without
recomputing it. Continuing First simulation (where path and np are defined):
from harmolab.rwg.rwg2 import DataManager_rwg2
from harmolab.rwg.rwg3 import DataManager_rwg3
from harmolab.rwg.rwg4 import DataManager_rwg4
points, triangles, edges, vecteurs_rho = DataManager_rwg2.load_data(path.mat_mesh2)
frequency, omega, mu, epsilon, light_speed_c, eta, Z = DataManager_rwg3.load_data(path.mat_impedance)
(frequency, omega, mu, epsilon, light_speed_c, eta,
V, I, gap_currents, gap_voltages, impedances, feed_powers) = DataManager_rwg4.load_data(path.mat_current, radiation=True)
print(edges.total_number_of_edges, "edges;", Z.shape, "matrix;", "Z_in =", np.round(impedances, 2), "Ohm")
144 edges; (144, 144) matrix; Z_in = (72.74+4.09j) Ohm
DataManager_rwg1.load_data(path.mat_mesh1) returns points, triangles, edges. For a scattering
result, call DataManager_rwg4.load_data(path.mat_current, scattering=True), which returns the
incident direction and polarisation instead of the port results.
Note
The arrays read back are squeezed: with one port, impedances comes back as a 0-dimensional
array (printed (72.74+4.09j) above), whereas radiation_algorithm returned an array of length 1.
np.atleast_1d(impedances)[0] works in both cases.
Missing or unreadable files raise MeshDataError with the name of the file, instead of failing later
on an unrelated error.
Mixing files from two meshes#
The mesh and impedance files carry a mesh_fingerprint, a short hash of the mesh arrays. Before
solving, rwg4 checks that the _mesh2 and _impedance files it is given have the same one, and
raises MeshConsistencyError otherwise: an impedance matrix left over from an earlier mesh cannot be
combined with a new one by mistake. Files written before this check existed carry no fingerprint and
pass silently. The current file has no fingerprint.
Meshes from MATLAB#
The p, t format is the one of Makarov’s MATLAB code [1]: p (3, N)
coordinates, t (4, M) 1-based vertex indices with a domain label in the 4th row. Such a file can be
used directly by scattering_algorithm (give the file name; see Scattering: illuminating a structure).
The CMA solver falls back on path.mat when there is no path.msh (cma_mesh.prepare_cma_mesh;
see Characteristic mode analysis).
radiation_algorithm cannot take one: it always starts by regenerating path.mat from the gmsh file
path.msh, which must therefore exist.