QPMS
Electromagnetic multiple scattering library and toolkit.
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
scatspec.h File Reference

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>
Include dependency graph for scatspec.h:
This graph shows which files directly or indirectly include this file:

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
 

Enumerations

enum  qpms_scatspec_kindsource_t {
  QPMS_SCATSPEC_KINDSOURCE_SPHERE , QPMS_SCATSPEC_KINDSOURCE_CYLINDER , QPMS_SCATSPEC_KINDSOURCE_SPHEROID , QPMS_SCATSPEC_KINDSOURCE_CONE ,
  QPMS_SCATSPEC_KINDSOURCE_CUT_SPHERE , QPMS_SCATSPEC_KINDSOURCE_CORE_SHELL_SPHERE , QPMS_SCATSPEC_KINDSOURCE_SUPERELLIPSOID , QPMS_SCATSPEC_KINDSOURCE_SCUFFGEN ,
  QPMS_SCATSPEC_KINDSOURCE_SCUFF_FILE , QPMS_SCATSPEC_KINDSOURCE_HDF5_FILE , QPMS_SCATSPEC_KINDSOURCE_DUMMY , QPMS_SCATSPEC_KINDSOURCE_CONSTANT
}
 Origin of a particle kind's T-matrix. More...
 

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.
 

Detailed Description

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.

Note
The qpms_scatspec_t owns the T-matrix generators, material generators and basis specifications referenced by any qpms_scatsys_t created via qpms_scatspec_build_scatsys(); the spec must therefore be kept alive (and unmodified) as long as the built system is used. This mirrors the behaviour of the Python side, where the ScatteringSystem keeps references to the generator objects.

Typedef Documentation

◆ 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.

◆ 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.

Enumeration Type Documentation

◆ qpms_scatspec_kindsource_t

Origin of a particle kind's T-matrix.

Enumerator
QPMS_SCATSPEC_KINDSOURCE_SPHERE 

analytic Lorentz-Mie sphere

QPMS_SCATSPEC_KINDSOURCE_CYLINDER 

analytic axially symmetric cylinder

QPMS_SCATSPEC_KINDSOURCE_SPHEROID 

analytic axially symmetric spheroid

QPMS_SCATSPEC_KINDSOURCE_CONE 

analytic (possibly truncated) cone

QPMS_SCATSPEC_KINDSOURCE_CUT_SPHERE 

analytic axially symmetric cut sphere (spherical cap)

QPMS_SCATSPEC_KINDSOURCE_CORE_SHELL_SPHERE 

(core-shell) sphere, Mie

analytic layered

QPMS_SCATSPEC_KINDSOURCE_SUPERELLIPSOID 

analytic axially symmetric superellipsoid (surface of revolution)

QPMS_SCATSPEC_KINDSOURCE_SCUFFGEN 

external scuff-em generator (gmsh mesh + scuff-tmatrix)

QPMS_SCATSPEC_KINDSOURCE_SCUFF_FILE 

scuff-em .TMatrix text file

QPMS_SCATSPEC_KINDSOURCE_HDF5_FILE 

community-format .tmat.h5 file

QPMS_SCATSPEC_KINDSOURCE_DUMMY 

zero T-matrix

QPMS_SCATSPEC_KINDSOURCE_CONSTANT 

constant user-supplied T-matrix with an explicit VSWF list basis

Function Documentation

◆ qpms_scatspec_build_scatsys()

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.

Note
The returned qpms_scatsys_t references generator data owned by the spec; see the lifetime note in the file documentation.

◆ qpms_scatspec_build_scatsys_with_group()

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).

◆ qpms_scatspec_kind_bspec()

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).

◆ qpms_scatspec_kind_file()

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).

◆ qpms_scatspec_kind_shapeinfo()

_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.

◆ qpms_scatspec_omega()

_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_parse_file()

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.

Parameters
pathPath to the YAML spec file.
overridesOptional array of variable overrides applied on top of the vars section of the file (may also introduce new variables). May be NULL.
noverridesNumber of entries in overrides.
errbufBuffer for a human readable error message (may be NULL).
errlenSize of errbuf.
Returns
A new spec, or NULL on error (with errbuf filled in).

◆ qpms_scatspec_parse_string()

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.

◆ qpms_scatspec_particle_kinds()

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).

◆ qpms_scatspec_particle_transforms()

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).

◆ qpms_scatspec_positions()

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).

◆ qpms_scatspec_symmetry()

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().

◆ qpms_scatspec_system_fingerprint()

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.

Returns
QPMS_SUCCESS, or QPMS_ERROR if the spec is NULL, on an out of memory error, if a T-matrix source file cannot be read, or if the spec uses an optical-property generator not covered by the canonical serialisation (currently only constant, tabulated-interpolator and Lorentz-Drude generators are supported).