hp-FEM
Adaptive hp-FEM suite for nano-optics
Loading...
Searching...
No Matches
pml.hpp
Go to the documentation of this file.
1#pragma once
12
13#include <array>
14#include <cstddef>
15#include <optional>
16
17#include <Eigen/Core>
18
20#include "hpfem/core/types.hpp"
21
22namespace hpfem::pml {
23
33struct PmlProfile {
34 int order = 3;
36
43 [[nodiscard]] static PmlProfile for_angle(Real theta_max, Real target, Real r_amplitude = 1.0,
44 int order = 2);
45};
46
48template <int Dim>
49using ComplexCoordinates = Eigen::Matrix<Complex, Dim, 1>;
50
54template <int Dim>
55class PmlBox {
56 public:
57 static constexpr std::size_t kNumSides = 2 * static_cast<std::size_t>(Dim);
58 using Thickness = std::array<Real, kNumSides>;
59
64 Real background_index = 1.0, PmlProfile profile = {});
69 [[nodiscard]] static Real recommended_thickness(Real k0, Real background_index, Real cell_size,
70 Real wavelengths = 0.5);
77 [[nodiscard]] static Real recommended_thickness(Real k0, Real background_index, Real cell_size,
78 const PmlProfile& profile, int p);
81 [[nodiscard]] static Real resolution_limit(int p) noexcept;
83 [[nodiscard]] static PmlBox uniform(const Point<Dim>& lower, const Point<Dim>& upper,
84 Real thickness, Real k0, Real background_index = 1.0,
85 PmlProfile profile = {});
86
87 [[nodiscard]] const Point<Dim>& lower() const noexcept { return lower_; }
88 [[nodiscard]] const Point<Dim>& upper() const noexcept { return upper_; }
89 [[nodiscard]] const Thickness& thickness() const noexcept { return thickness_; }
90 [[nodiscard]] const PmlProfile& profile() const noexcept { return profile_; }
92 [[nodiscard]] Real sigma_max(std::size_t side) const noexcept { return sigma_max_[side]; }
94 [[nodiscard]] Real k0() const noexcept { return k0_; }
100 [[nodiscard]] Real max_resolution(Real cell_size, Real index) const;
102 [[nodiscard]] Point<Dim> outer_lower() const;
103 [[nodiscard]] Point<Dim> outer_upper() const;
104
106 [[nodiscard]] bool in_layer(const Point<Dim>& x) const;
108 [[nodiscard]] ComplexCoordinates<Dim> stretch(const Point<Dim>& x) const;
113
117 const Point<Dim>& x) const;
123 const assembly::PermittivityTensor<Dim>& eps, const Point<Dim>& x) const;
127 Complex mu_r, const Point<Dim>& x) const;
128
129 private:
132 [[nodiscard]] Real depth(const Point<Dim>& x, int axis) const;
133
134 Point<Dim> lower_;
135 Point<Dim> upper_;
136 Thickness thickness_{};
137 PmlProfile profile_;
138 Real k0_ = 0;
139 std::array<Real, kNumSides> sigma_max_{};
140};
141
143template <int Dim>
151
169template <int Dim>
170[[nodiscard]] std::optional<BackwardWave<Dim>> backward_wave(
171 const assembly::PermittivityTensor<Dim>& eps, int axis, int samples = 2048);
172
173extern template class PmlBox<2>;
174extern template class PmlBox<3>;
175
176} // namespace hpfem::pml
Definition pml.hpp:55
assembly::PermittivityTensor< Dim > permittivity(const assembly::PermittivityTensor< Dim > &eps, const Point< Dim > &x) const
assembly::PermittivityTensor< Dim > permittivity(Complex eps_r, const Point< Dim > &x) const
Real sigma_max(std::size_t side) const noexcept
of side k (0 for a side without layer).
Definition pml.hpp:92
const Point< Dim > & lower() const noexcept
Definition pml.hpp:87
bool in_layer(const Point< Dim > &x) const
True if x lies in at least one layer (some ).
ComplexCoordinates< Dim > stretched_coordinate(const Point< Dim > &x) const
static Real recommended_thickness(Real k0, Real background_index, Real cell_size, Real wavelengths=0.5)
Point< Dim > outer_lower() const
Outer boundary of the layers: the box enlarged by the thicknesses.
const Thickness & thickness() const noexcept
Definition pml.hpp:89
static Real recommended_thickness(Real k0, Real background_index, Real cell_size, const PmlProfile &profile, int p)
static constexpr std::size_t kNumSides
Definition pml.hpp:57
Real k0() const noexcept
Vacuum wavenumber the layers were designed for.
Definition pml.hpp:94
PmlBox(const Point< Dim > &lower, const Point< Dim > &upper, const Thickness &thickness, Real k0, Real background_index=1.0, PmlProfile profile={})
ComplexCoordinates< Dim > stretch(const Point< Dim > &x) const
Stretch factors per axis (1 inside the box).
static Real resolution_limit(int p) noexcept
assembly::InversePermeabilityTensor< Dim > inverse_permeability(Complex mu_r, const Point< Dim > &x) const
std::array< Real, kNumSides > Thickness
x-min, x-max, y-min, y-max[, z-min, z-max]
Definition pml.hpp:58
Point< Dim > outer_upper() const
const Point< Dim > & upper() const noexcept
Definition pml.hpp:88
const PmlProfile & profile() const noexcept
Definition pml.hpp:90
static PmlBox uniform(const Point< Dim > &lower, const Point< Dim > &upper, Real thickness, Real k0, Real background_index=1.0, PmlProfile profile={})
The same thickness on all sides.
Real max_resolution(Real cell_size, Real index) const
Eigen::Matrix< Complex, Dim==2 ? 1 :3, Dim==2 ? 1 :3 > InversePermeabilityTensor
Definition maxwell_forms.hpp:39
Eigen::Matrix< Complex, Dim, Dim > PermittivityTensor
Permittivity tensor ε (Dim × Dim) and inverse permeability tensor acting on curls.
Definition maxwell_forms.hpp:37
Definition pml.hpp:22
Eigen::Matrix< Complex, Dim, 1 > ComplexCoordinates
Per-axis complex stretch factors or stretched coordinates.
Definition pml.hpp:49
std::optional< BackwardWave< Dim > > backward_wave(const assembly::PermittivityTensor< Dim > &eps, int axis, int samples=2048)
double Real
Definition types.hpp:15
Eigen::Matrix< Real, Dim, 1 > Point
Definition types.hpp:27
std::complex< double > Complex
Definition types.hpp:16
A wave that violates the geometric stability condition of the coordinate-stretching PML.
Definition pml.hpp:144
Point< Dim > direction
Unit wave vector (phase direction) of the worst sampled wave.
Definition pml.hpp:146
Real worst
Definition pml.hpp:149
Definition pml.hpp:33
Real reflection
R_0, round-trip field reflection at normal incidence.
Definition pml.hpp:35
int order
m
Definition pml.hpp:34
static PmlProfile for_angle(Real theta_max, Real target, Real r_amplitude=1.0, int order=2)