Skip to main content

Module mesh

Module mesh 

Source
Expand description

Solver-aware mesh checks and suggestions (design §4, §5.6, §7).

Mesh generation is csx’s business (csx::mesh::MeshBuilder, csx::mesh::detect_edges, csx::grid::smooth_lines). This module looks at a finished mesh with the eyes of the FDTD solver and reports what is likely to go wrong:

  • Resolution. Every cell must be smaller than λ_min/N, where λ_min = c0 / (f_max·n) with n = sqrt(ε_r·μ_r) the largest refractive index of the materials present in that cell slab, and f_max from Fdtd::get_max_frequency. The rule of thumb N ≥ 10…20 follows from the numerical dispersion analysis of the Yee scheme (Taflove & Hagness, Computational Electrodynamics, 3rd ed., ch. 4: the phase velocity error is below about 1 % for 10 cells per wavelength and falls off quadratically).
  • Grading. Neighbouring cells should not differ in size by more than a factor of about 1.5: on a non-uniform mesh the scheme is only first-order accurate at a size jump, and large jumps reflect waves (Taflove & Hagness, non-uniform grids in ch. 3; Monk & Süli 1994 on the supraconvergence of the Yee scheme on non-uniform meshes).
  • Time step. The Courant limit (design §5.4) is set by the smallest cell on every axis; a few tiny cells can make the whole simulation many times slower. The report gives dt, the limiting cells and the ratio to the time step a typical (median) cell would allow. On a cylindrical grid (Grid::cylindrical) the limit comes from the discrete operator and is usually set by the short arcs ρ·Δα next to the axis (design §5.15).
  • Cylindrical grids. Messages name the axes x, y, z for ρ, α, z; α positions are in radians. The resolution check uses the largest arc ρ_max·Δα of each α cell.
  • PML (design §5.6): the layer occupies the outermost n mesh cells of a face; the mesh needs enough cells for it, structure primitives should stay out of it, and the cells in it should be roughly uniform (the conductivity profile assumes slowly varying cells; Berenger 1994, Roden & Gedney 2000).
  • Sheets. Zero-thickness metal or conducting sheets (and axis-aligned lines) must lie on a mesh plane (line) or csx’s discretisation drops them.
  • Cost. Cell count, estimated memory, memory traffic per step and the number of steps implied by the settings.

check works on the model and its csx grid; check_compiled reuses an already compiled model (the actual discretised materials and csx’s discretisation warnings).

All coordinates in messages and Locations are csx drawing units (the unit of the mesh lines); lengths in MeshStats are metres.

use csx::primitives::BoxShape;
use csx::{ContinuousStructure, Primitive, Property};
use ems::prelude::*;

let mut model = ContinuousStructure::new();
model.grid.delta_unit = 1e-3; // mm
for a in 0..3 {
    model.grid.set_lines(a, (0..=40).map(|i| i as f64))?;
}
let fdtd = Fdtd::new()
    .waveform(Waveform::gaussian(5e9, 5e9)) // f_max = 10 GHz, λ = 30 mm
    .boundaries(Boundaries::all(Boundary::pml(8)));
let report = ems::mesh::check(&model, &fdtd)?;
assert!(report.is_ok());

// csx's mesher wants the maximum cell size in drawing units.
let max_res = ems::mesh::suggest_max_cell(&model, &fdtd, 20.0)?;
assert!((max_res - 1.499).abs() < 1e-3); // 29.98 mm / 20

Structs§

CheckOptions
Thresholds of the mesh checks.
MeshIssue
One finding of a mesh check.
MeshReport
Result of a mesh check: issues plus MeshStats.
MeshStats
Mesh statistics and cost estimates gathered by a check.

Enums§

Location
Where a MeshIssue is located. Coordinates are drawing units.
Severity
Severity of a MeshIssue.

Constants§

CSX_DISCRETISATION_PREFIX
Prefix of the MeshIssue::messages with which check_compiled re-reports csx discretisation warnings (the original warnings are in Compiled::warnings; filter on this prefix to avoid duplicates).

Functions§

check
Checks the mesh of model for the solver settings fdtd with the default CheckOptions; see the module docs.
check_compiled
Checks an already compiled model: the refractive index per cell slab comes from the discretised EdgeMaterials (what the solver actually sees, including sub-cell averaging), sheet and line snapping problems are taken from csx’s discretisation warnings in Compiled::warnings, and the grid, time step and PML faces from compiled. model is still needed for the PML intrusion check.
check_with
check with explicit options.
suggest_max_cell
Largest cell size (in drawing units, as expected by csx::mesh::MeshOptions::max_res) that resolves the shortest wavelength in model with n cells: c0 / (f_max·n_max·n) / delta_unit, where n_max is the largest refractive index sqrt(ε_r·μ_r) of the background and all material properties.