hp-FEM
Adaptive hp-FEM suite for nano-optics
Loading...
Searching...
No Matches
waveguide_port.hpp
Go to the documentation of this file.
1#pragma once
42
43#include <memory>
44#include <vector>
45
46#include "hpfem/core/types.hpp"
49#include "hpfem/mesh/mesh.hpp"
51
52namespace hpfem::physics {
53
60 std::vector<Complex> incident;
67 std::vector<mesh::Tag> pmc_tags;
68};
69
85
88 std::vector<Complex> incoming;
89 std::vector<Complex> outgoing;
90};
91
93template <int Dim>
94class PortModes {
95 public:
105 const materials::MaterialMap& materials, Real omega, Index num_modes,
106 int extra_order = 2, const std::vector<mesh::Tag>& pmc_tags = {});
107
108 [[nodiscard]] const std::vector<PortMode>& modes() const noexcept { return modes_; }
109 [[nodiscard]] Index num_modes() const noexcept { return static_cast<Index>(modes_.size()); }
112 [[nodiscard]] const Vector& functional(Index m) const { return functionals_[as_size(m)]; }
114 [[nodiscard]] Complex normalisation(Index m) const { return normalisations_[as_size(m)]; }
116 [[nodiscard]] std::vector<Complex> coefficients(const Vector& e) const;
118 [[nodiscard]] const std::vector<Index>& dofs() const noexcept { return port_dofs_; }
121 [[nodiscard]] Complex trace(Index m, Real s) const;
123 [[nodiscard]] Real profile(Index m, Real s) const;
127 [[nodiscard]] Eigen::Matrix<Complex, Dim, 1> transverse_field(Index m, const Point<Dim>& x) const;
130 [[nodiscard]] Real length() const noexcept { return length_; }
132 [[nodiscard]] const Point<Dim>& origin() const noexcept { return origin_; }
134 [[nodiscard]] const Point<Dim>& tangent() const noexcept { return tangent_; }
136 [[nodiscard]] const Point<Dim>& tangent2() const noexcept { return tangent2_; }
137 [[nodiscard]] const Point<Dim>& normal() const noexcept { return normal_; }
139 [[nodiscard]] const mesh::Mesh<2>* section() const noexcept { return section_.get(); }
140
141 private:
142 struct Segment {
143 Index facet;
144 Index cell;
145 Real s0, s1;
146 Index v0, v1;
147 Index bubbles;
148 int order;
149 Real eps_r, mu_r;
150 };
151 void build_2d(const fespace::NedelecDofMap<Dim>& dofs, mesh::Tag facet_tag,
152 const materials::MaterialMap& materials, Index num_modes, int extra_order);
153 void build_3d(const fespace::NedelecDofMap<Dim>& dofs, mesh::Tag facet_tag,
154 const materials::MaterialMap& materials, Index num_modes, int extra_order,
155 const std::vector<mesh::Tag>& pmc_tags);
157 void basis(const Segment& seg, Real s, std::vector<Real>& values,
158 std::vector<Real>& derivatives) const;
159 [[nodiscard]] const Segment& segment_at(Real s) const;
162 [[nodiscard]] Index section_cell(const Point<2>& uv, Point<2>& xi) const;
164 void section_field(Index m, Index cell, const Point<2>& xi, Eigen::Matrix<Complex, 2, 1>& e_t,
165 Complex& e_z, Eigen::Matrix<Complex, 2, 1>& grad_e_z) const;
166
167 std::vector<Segment> segments_;
168 Index num_1d_ = 0;
169 Real omega_ = 0;
170 Real length_ = 0;
171 Point<Dim> origin_;
172 Point<Dim> tangent_;
173 Point<Dim> tangent2_;
174 Point<Dim> normal_;
175 std::vector<PortMode> modes_;
176 std::vector<Vector> profiles_;
177 std::vector<Vector> functionals_;
178 std::vector<Complex> normalisations_;
179 std::vector<Index> port_dofs_;
180 // 3D: the cross-section (shared between copies of the port; immutable after the build)
181 std::shared_ptr<const mesh::Mesh<2>> section_;
182 std::shared_ptr<const fespace::NedelecDofMap<2>> section_nedelec_;
183 std::shared_ptr<const fespace::DofMap<2>> section_h1_;
184 std::vector<WaveguideMode> section_modes_;
185};
186
187extern template class PortModes<2>;
188extern template class PortModes<3>;
189
190} // namespace hpfem::physics
Definition dof_map.hpp:51
Definition material.hpp:149
Definition mesh.hpp:61
Modes, functionals and normalisations of one port; built by Scattering from the setup.
Definition waveguide_port.hpp:94
Eigen::Matrix< Complex, Dim, 1 > transverse_field(Index m, const Point< Dim > &x) const
Index num_modes() const noexcept
Definition waveguide_port.hpp:109
PortModes(const fespace::NedelecDofMap< Dim > &dofs, mesh::Tag facet_tag, const materials::MaterialMap &materials, Real omega, Index num_modes, int extra_order=2, const std::vector< mesh::Tag > &pmc_tags={})
Complex trace(Index m, Real s) const
const Point< Dim > & origin() const noexcept
Origin of the port frame; 2D: the start of the port coordinate (s increases along t').
Definition waveguide_port.hpp:132
const Point< Dim > & normal() const noexcept
Definition waveguide_port.hpp:137
std::vector< Complex > coefficients(const Vector &e) const
Coefficients of a discrete field.
const Point< Dim > & tangent2() const noexcept
3D: the second frame vector t₂ (t₁ × t₂ = n); 2D: unused.
Definition waveguide_port.hpp:136
const mesh::Mesh< 2 > * section() const noexcept
3D: the extracted cross-section mesh in frame coordinates (u, v); nothing in 2D.
Definition waveguide_port.hpp:139
const Vector & functional(Index m) const
Definition waveguide_port.hpp:112
const std::vector< Index > & dofs() const noexcept
DoFs touched by the port (sorted).
Definition waveguide_port.hpp:118
Complex normalisation(Index m) const
.
Definition waveguide_port.hpp:114
Real profile(Index m, Real s) const
2D: (the H_z profile) at the port coordinate s.
Real length() const noexcept
Definition waveguide_port.hpp:130
const std::vector< PortMode > & modes() const noexcept
Definition waveguide_port.hpp:108
const Point< Dim > & tangent() const noexcept
2D: the unit tangent t' of the port coordinate; 3D: the first frame vector t₁.
Definition waveguide_port.hpp:134
std::int32_t Tag
Integer tag of a physical group (Gmsh convention: positive; 0 means untagged).
Definition mesh.hpp:23
constexpr Tag kNoTag
Definition mesh.hpp:24
Definition absorption.hpp:21
double Real
Definition types.hpp:15
Eigen::Matrix< Real, Dim, 1 > Point
Definition types.hpp:27
constexpr std::size_t as_size(Index i) noexcept
Converts a non-negative global or local index to a container index.
Definition types.hpp:34
std::int64_t Index
global indices (DoFs, entities)
Definition types.hpp:17
Eigen::Matrix< Complex, Eigen::Dynamic, 1 > Vector
Definition types.hpp:20
std::complex< double > Complex
Definition types.hpp:16
Modal coefficients of a solution on one port.
Definition waveguide_port.hpp:87
std::vector< Complex > incoming
a_m (the setup's amplitudes)
Definition waveguide_port.hpp:88
std::vector< Complex > outgoing
b_m = c_m − a_m
Definition waveguide_port.hpp:89
Definition waveguide_port.hpp:79
Complex beta
propagation constant [1/m], Im β ≥ 0 (evanescent: iβ'')
Definition waveguide_port.hpp:80
Real power
power [W] of the outgoing mode of unit amplitude (0 if evanescent)
Definition waveguide_port.hpp:82
bool propagating
Definition waveguide_port.hpp:83
Complex effective_index
β / k0
Definition waveguide_port.hpp:81
A port of a scattering problem: the boundary facets of a waveguide cross-section.
Definition waveguide_port.hpp:55
mesh::Tag facet_tag
Definition waveguide_port.hpp:56
std::vector< mesh::Tag > pmc_tags
Definition waveguide_port.hpp:67
Index num_modes
Definition waveguide_port.hpp:59
std::vector< Complex > incident
Definition waveguide_port.hpp:60