21using Tensor3 = Eigen::Matrix<Complex, 3, 3>;
54 [[nodiscard]]
bool is_isotropic() const noexcept {
return eps_tensor_ ==
nullptr; }
58 if (eps_tensor_) throw_anisotropic(
"eps_scalar");
65 return eps_tensor_ ? *eps_tensor_ :
Tensor3(eps_r_ * Tensor3::Identity());
69 return Tensor3((1.0 / mu_r_) * Tensor3::Identity());
74 if (eps_tensor_) throw_anisotropic(
"refractive_index");
75 return std::sqrt(eps_r_ * mu_r_);
93 [[noreturn]]
static void throw_anisotropic(
const char* accessor);
97 std::shared_ptr<const Tensor3> eps_tensor_;
116 static_assert(Dim == 2 || Dim == 3);
118 if constexpr (Dim == 3) {
121 if (eps(0, 2) !=
Complex{0.0, 0.0} || eps(1, 2) !=
Complex{0.0, 0.0}) {
124 return eps.template topLeftCorner<2, 2>();
142 const Eigen::Matrix<Real, N, N> loss = permittivity_tensor<N>(material).imag();
143 return (e.adjoint() * loss.template cast<Complex>() * e)(0, 0).real();
156 [[nodiscard]]
bool has(
mesh::Tag tag)
const {
return materials_.contains(tag); }
165 return static_cast<Index>(cells_.size());
170 if (!cells_.empty()) {
171 const auto it = cells_.find(c);
172 if (it != cells_.end())
return it->second;
181 std::map<mesh::Tag, Material> materials_;
182 std::map<Index, Material> cells_;
Definition material.hpp:149
const Material & background() const noexcept
Definition material.hpp:155
void clear_cells()
Removes all per-cell overrides.
Definition material.hpp:163
const Material & of_cell(const mesh::Mesh< Dim > &mesh, Index c) const
Material of cell c of a mesh: the cell's override if set, otherwise its tag's.
Definition material.hpp:169
bool has(mesh::Tag tag) const
Definition material.hpp:156
MaterialMap(Material background=Material::vacuum())
Definition material.hpp:151
bool is_isotropic() const
True if every material of the map (background, tags, cell overrides) is isotropic.
const Material & at(mesh::Tag tag) const
Material of a tag, the background if unlisted.
Index num_cell_overrides() const noexcept
Definition material.hpp:164
MaterialMap & set_cell(Index cell, Material material)
MaterialMap & set(mesh::Tag tag, Material material)
Definition material.hpp:31
bool operator==(const Material &other) const
Same kind and the same parameters (tensors compared entry by entry).
Material & set_eps_scalar(Complex eps_r) noexcept
Makes the medium isotropic with permittivity εr (drops a tensor).
Definition material.hpp:79
Complex mu_scalar() const noexcept
Permeability μr (always scalar).
Definition material.hpp:62
static Material isotropic(Complex eps_r, Complex mu_r=Complex{1.0, 0.0}) noexcept
Definition material.hpp:38
static Material anisotropic(const Tensor3 &eps_r, Complex mu_r=Complex{1.0, 0.0})
Tensor3 eps_tensor() const
Permittivity tensor: εr·I for an isotropic medium.
Definition material.hpp:64
Complex refractive_index() const
Definition material.hpp:73
Material(Complex eps_r, Complex mu_r) noexcept
Isotropic medium with permittivity εr and permeability μr.
Definition material.hpp:36
Material()=default
Vacuum.
static Material vacuum() noexcept
Definition material.hpp:48
Tensor3 mu_inv_tensor() const
Inverse permeability tensor .
Definition material.hpp:68
static Material dielectric(Real n) noexcept
Lossless non-magnetic dielectric of refractive index n.
Definition material.hpp:50
Complex eps_scalar() const
Definition material.hpp:57
Material & set_mu(Complex mu_r) noexcept
Definition material.hpp:84
bool is_isotropic() const noexcept
Definition material.hpp:54
Tag cell_tag(Index c) const
Definition mesh.hpp:296
Definition material.hpp:18
Real loss_density(const Material &material, const Eigen::Matrix< Complex, N, 1 > &e)
Definition material.hpp:140
void throw_in_plane_coupling()
bool is_lossless(const Material &material)
True if the permittivity is real (no loss and no gain), isotropic or tensor.
Definition material.hpp:129
Eigen::Matrix< Complex, 3, 3 > Tensor3
Complex 3×3 tensor in the laboratory frame (x, y, z).
Definition material.hpp:21
Real max_real_index(const Material &material)
Eigen::Matrix< Complex, Dim, Dim > permittivity_tensor(const Material &material)
Definition material.hpp:115
std::int32_t Tag
Integer tag of a physical group (Gmsh convention: positive; 0 means untagged).
Definition mesh.hpp:23
double Real
Definition types.hpp:15
std::int64_t Index
global indices (DoFs, entities)
Definition types.hpp:17
std::complex< double > Complex
Definition types.hpp:16