![]() |
QPMS
Electromagnetic multiple scattering library and toolkit.
|
Declarative YAML specification of scattering systems. More...
#include "qpms_types.h"#include "scatsystem.h"#include "groups.h"#include <stddef.h>#include <sys/types.h>#include <complex.h>

Go to the source code of this file.
Data Structures | |
| struct | qpms_scatspec_var_t |
| A named variable override for the spec parser. More... | |
| struct | qpms_scatspec_shapeinfo_t |
Typedefs | |
| typedef struct qpms_scatspec_var_t | qpms_scatspec_var_t |
| A named variable override for the spec parser. | |
| typedef struct qpms_scatspec_t | qpms_scatspec_t |
| An opaque, resolved scattering system specification. | |
| typedef struct qpms_scatspec_shapeinfo_t | qpms_scatspec_shapeinfo_t |
| typedef struct qpms_spg_detection_t | qpms_spg_detection_t |
Functions | |
| qpms_scatspec_t * | qpms_scatspec_parse_file (const char *path, const qpms_scatspec_var_t *overrides, size_t noverrides, char *errbuf, size_t errlen) |
| Parses and validates a spec file. | |
| qpms_scatspec_t * | qpms_scatspec_parse_string (const char *yaml, ssize_t len, const qpms_scatspec_var_t *overrides, size_t noverrides, char *errbuf, size_t errlen) |
| As qpms_scatspec_parse_file(), but parses from a NUL-terminated string. | |
| void | qpms_scatspec_free (qpms_scatspec_t *spec) |
| Frees a spec. Any qpms_scatsys_t built from it becomes invalid afterwards. | |
| size_t | qpms_scatspec_particle_count (const qpms_scatspec_t *spec) |
| Number of particles after the placement expansion. | |
| void | qpms_scatspec_positions (const qpms_scatspec_t *spec, cart3_t *out) |
| size_t | qpms_scatspec_kind_count (const qpms_scatspec_t *spec) |
| Number of particle kinds defined in the spec. | |
| int | qpms_scatspec_kind_source (const qpms_scatspec_t *spec, size_t ki) |
| T-matrix source kind of a particle kind, or -1 if ki is out of range. | |
| const char * | qpms_scatspec_kind_file (const qpms_scatspec_t *spec, size_t ki) |
| _Bool | qpms_scatspec_kind_shapeinfo (const qpms_scatspec_t *spec, size_t ki, qpms_scatspec_shapeinfo_t *out) |
| const char * | qpms_scatspec_kind_name (const qpms_scatspec_t *spec, size_t ki) |
| Name of a particle kind, or NULL if ki is out of range (borrowed pointer). | |
| const qpms_vswf_set_spec_t * | qpms_scatspec_kind_bspec (const qpms_scatspec_t *spec, size_t ki) |
| void | qpms_scatspec_particle_kinds (const qpms_scatspec_t *spec, size_t *out) |
| void | qpms_scatspec_particle_transforms (const qpms_scatspec_t *spec, qpms_irot3_t *out) |
| qpms_epsmu_t | qpms_scatspec_medium_eval (const qpms_scatspec_t *spec, _Complex double omega) |
| Evaluates the background medium (system.medium) at an angular frequency. | |
| int | qpms_scatspec_lattice_dimension (const qpms_scatspec_t *spec) |
| Lattice dimension (0 = finite system, 1-3 = periodic). | |
| void | qpms_scatspec_lattice_basis (const qpms_scatspec_t *spec, cart3_t *out) |
| Copies the lattice basis vectors to out (which must have room for 3). | |
| const qpms_finite_group_t * | qpms_scatspec_symmetry (const qpms_scatspec_t *spec) |
| const qpms_spg_detection_t * | qpms_scatspec_detection (const qpms_scatspec_t *spec) |
| int | qpms_scatspec_has_omega (const qpms_scatspec_t *spec) |
| Returns whether the spec defines the initial frequency (system.omega). | |
| _Complex double | qpms_scatspec_omega (const qpms_scatspec_t *spec) |
| qpms_scatsys_t * | qpms_scatspec_build_scatsys (const qpms_scatspec_t *spec, _Complex double omega) |
| Builds a scattering system from the spec. | |
| qpms_scatsys_t * | qpms_scatspec_build_scatsys_with_group (const qpms_scatspec_t *spec, const qpms_finite_group_t *group, _Complex double omega) |
| int | qpms_scatspec_system_fingerprint (const qpms_scatspec_t *spec, char hex[65]) |
| Computes a SHA-256 fingerprint of the resolved physical system. | |
Declarative YAML specification of scattering systems.
This module defines a compact, human friendly format for describing scattering systems (particle shapes, materials, geometry, lattice periodicity, point group symmetries) in a YAML file, and loads them into a qpms_scatsys_t without any dependency on the Python part of QPMS.
The full format description with examples lives in scatspec.md in the repository root. A quick sketch:
version: 1
vars: # named variables, overridable at load time
pitch: 375*nm
radius: 0.4 * pitch
particles:
disk:
shape: cylinder
material: Ag
r: radius
h: 30*nm
lMax: 3
places:
- particle: disk
array: {shape: [30, 40], step: [pitch, pitch], centered: true}
- particle: disk
position: [pitch/2, 0, 0]
rotate: {z: pi/4}
mirror: xz
system:
medium: 1.52
symmetry: D2h # finite systems; mutually exclusive with lattice
# symmetry: auto # detect the point group from the placements
# lattice: {type: hexagonal, a: pitch} # -> periodic system
Most numeric fields accept either a plain (SI) number or an expression string evaluated with specexpr (specexpr.h); see there for the built-in constants and functions.
| typedef struct qpms_scatspec_shapeinfo_t qpms_scatspec_shapeinfo_t |
"As given" parameters of an analytic (sphere, cylinder, spheroid, cone, cut sphere, core-shell sphere, superellipsoid) particle kind. The material and outside descriptions mirror the way the material was specified in the YAML document (scalars verbatim, mappings rendered as comma-separated key=value pairs). The strings are borrowed from the spec. Unused numeric fields are set to zero.
| typedef struct qpms_spg_detection_t qpms_spg_detection_t |
The result of the automatic point-group detection, or NULL when the spec did not request it (system.symmetry: auto) or the detection failed. The returned pointer is owned by the spec.
Origin of a particle kind's T-matrix.
| qpms_scatsys_t * qpms_scatspec_build_scatsys | ( | const qpms_scatspec_t * | spec, |
| _Complex double | omega | ||
| ) |
Builds a scattering system from the spec.
The T-matrix generators are evaluated at omega, which must lie within the validity ranges of all materials and T-matrix interpolators used by the spec. Returns NULL on failure.
| qpms_scatsys_t * qpms_scatspec_build_scatsys_with_group | ( | const qpms_scatspec_t * | spec, |
| const qpms_finite_group_t * | group, | ||
| _Complex double | omega | ||
| ) |
As qpms_scatspec_build_scatsys(), but applies an explicit group instead of the spec's own system.symmetry (NULL falls back to the spec's group, cf. qpms_scatspec_build_scatsys()). Used e.g. to build the scattering system with the little group of a given Bloch vector. The group operations must map the placed particles exactly onto placed particles of matching T-matrices (the group is verified, not used to generate the arrangement).
| const qpms_vswf_set_spec_t * qpms_scatspec_kind_bspec | ( | const qpms_scatspec_t * | spec, |
| size_t | ki | ||
| ) |
Basis spec of a particle kind, or NULL if ki is out of range (borrowed pointer; owned by the spec).
| const char * qpms_scatspec_kind_file | ( | const qpms_scatspec_t * | spec, |
| size_t | ki | ||
| ) |
T-matrix source file of a particle kind, or NULL if the kind is not file-based or ki is out of range (borrowed pointer, owned by the spec).
| _Bool qpms_scatspec_kind_shapeinfo | ( | const qpms_scatspec_t * | spec, |
| size_t | ki, | ||
| qpms_scatspec_shapeinfo_t * | out | ||
| ) |
Collects the parameters of an analytic (sphere, cylinder, spheroid, cone, cut sphere, core-shell sphere or superellipsoid) particle kind. Returns false (leaving out untouched) if the kind is not analytic or ki is out of range.
| _Complex double qpms_scatspec_omega | ( | const qpms_scatspec_t * | spec | ) |
Returns the system.omega value of the spec (only meaningful if qpms_scatspec_has_omega() is true).
| qpms_scatspec_t * qpms_scatspec_parse_file | ( | const char * | path, |
| const qpms_scatspec_var_t * | overrides, | ||
| size_t | noverrides, | ||
| char * | errbuf, | ||
| size_t | errlen | ||
| ) |
Parses and validates a spec file.
| path | Path to the YAML spec file. |
| overrides | Optional array of variable overrides applied on top of the vars section of the file (may also introduce new variables). May be NULL. |
| noverrides | Number of entries in overrides. |
| errbuf | Buffer for a human readable error message (may be NULL). |
| errlen | Size of errbuf. |
| qpms_scatspec_t * qpms_scatspec_parse_string | ( | const char * | yaml, |
| ssize_t | len, | ||
| const qpms_scatspec_var_t * | overrides, | ||
| size_t | noverrides, | ||
| char * | errbuf, | ||
| size_t | errlen | ||
| ) |
As qpms_scatspec_parse_file(), but parses from a NUL-terminated string.
If len is negative, strlen(yaml) is used.
| void qpms_scatspec_particle_kinds | ( | const qpms_scatspec_t * | spec, |
| size_t * | out | ||
| ) |
Copies the particle kind index of each expanded particle to out (which must have room for qpms_scatspec_particle_count() entries).
| void qpms_scatspec_particle_transforms | ( | const qpms_scatspec_t * | spec, |
| qpms_irot3_t * | out | ||
| ) |
Copies the placement transform (mirror, then rotation) of each expanded particle to out (which must have room for qpms_scatspec_particle_count() entries).
| void qpms_scatspec_positions | ( | const qpms_scatspec_t * | spec, |
| cart3_t * | out | ||
| ) |
Copies the expanded particle positions to out (which must have room for qpms_scatspec_particle_count() entries).
| const qpms_finite_group_t * qpms_scatspec_symmetry | ( | const qpms_scatspec_t * | spec | ) |
The point group symmetry (NULL if none set; use with qpms_scatspec_lattice_dimension() to distinguish "no symmetry requested" from periodic systems, which always require a trivial symmetry). With system.symmetry: auto this is the runtime-constructed oriented group detected from the placements; the detection result itself is available through qpms_scatspec_detection().
| int qpms_scatspec_system_fingerprint | ( | const qpms_scatspec_t * | spec, |
| char | hex[65] | ||
| ) |
Computes a SHA-256 fingerprint of the resolved physical system.
Serialises the physics-defining state of the spec (background medium, named materials, particle kinds including file-based T-matrix sources hashed by content, particle placements, lattice, symmetry setting) in a canonical form and hashes it. Two specs yield the same fingerprint iff they describe the same physical system, independently of cosmetic differences of the source YAML files (whitespace, variable names). Intended for provenance records and append-reuse checks in the results container.