hp-FEM
Adaptive hp-FEM suite for nano-optics
Loading...
Searching...
No Matches
conical_sweep.hpp
Go to the documentation of this file.
1#pragma once
17#include <memory>
18#include <optional>
19#include <vector>
20
22#include "hpfem/core/types.hpp"
26
27namespace hpfem::physics {
28
31 Real setup = 0;
36 Real solve = 0;
37 int points = 0;
38 [[nodiscard]] Real total() const noexcept {
39 return setup + combine + assemble + reduce + factorize + solve;
40 }
41};
42
45 public:
54 ConicalSweep(const fespace::NedelecDofMap<2>& transverse, const fespace::DofMap<2>& longitudinal,
55 const ConicalScatteringSetup& base);
56
60 [[nodiscard]] ConicalSolution solve(const ConicalScatteringSetup& setup);
61
68
75 [[nodiscard]] Matrix solve_loads(const Matrix& loads);
76
79 [[nodiscard]] const ConicalScattering& point() const;
80
81 [[nodiscard]] const SweepTimings& timings() const noexcept { return timings_; }
83 [[nodiscard]] const solvers::LinearSolver& solver() const noexcept { return *solver_; }
84 [[nodiscard]] Index num_groups() const noexcept { return static_cast<Index>(groups_.size()); }
85 [[nodiscard]] Index num_pml_cells() const noexcept {
86 return static_cast<Index>(pml_cells_.size());
87 }
88 [[nodiscard]] Index num_source_cells() const noexcept {
89 return static_cast<Index>(source_cells_.size());
90 }
93 [[nodiscard]] bool cached() const noexcept { return cache_.valid; }
94
95 private:
96 struct Group {
97 Index representative = 0;
98 std::vector<Index> cells;
99 bool tensor = false;
103 std::vector<SparseMatrix> masses;
104 };
106 [[nodiscard]] std::vector<Complex> weights(const Group& group,
107 const ConicalScatteringSetup& setup) const;
111 struct Cache {
112 SparseMatrix pattern;
113 std::vector<Vector> parts;
114 std::vector<Index> pml_outer;
115 std::vector<Index> pml_inner;
116 std::vector<Index> pml_map;
117 std::vector<Index> free_index;
118 SparseMatrix reduced;
119 std::vector<Index> target_offsets;
120 std::vector<Index> targets;
121 bool valid = false;
122 };
125 struct RowTerm {
126 Index master;
127 Complex trial;
128 Complex test;
129 };
132 using Rows = std::vector<std::vector<RowTerm>>;
133 [[nodiscard]] Rows reduction_rows(const ConicalScattering& problem) const;
134 void build_cache(const ConicalScattering& problem, const Rows& rows,
135 const assembly::ConicalSystem& pml);
141 [[nodiscard]] assembly::ConicalSystem pml_system(const ConicalScattering& problem,
142 const ConicalScatteringSetup& setup);
145 [[nodiscard]] Vector factor_point(const ConicalScatteringSetup& setup, bool assemble_load);
147 [[nodiscard]] Vector reduce_load(const Vector& on_free) const;
149 [[nodiscard]] Vector expand(const Vector& reduced) const;
150 [[nodiscard]] ConicalSolution finish(const Vector& reduced, const ConicalScatteringSetup& setup);
151
152 const fespace::NedelecDofMap<2>* transverse_;
153 const fespace::DofMap<2>* longitudinal_;
154 ConicalScatteringSetup base_;
155 Real beta_scale_ = 1;
156 std::vector<Index> bulk_cells_;
157 std::vector<Index> pml_cells_;
158 std::vector<Index> source_cells_;
159 std::size_t base_free_ = 0;
160 SparseMatrix s0_, s1_, s2_;
161 std::vector<Group> groups_;
162 Cache cache_;
163 std::unique_ptr<solvers::LinearSolver> solver_;
164 bool factorised_ = false;
166 struct PmlParts {
167 std::vector<Real> key;
168 SparseMatrix s0, s1, s2, mass;
169 };
170 std::optional<PmlParts> pml_parts_;
171 std::vector<Real> last_pml_key_;
172 std::unique_ptr<ConicalScattering> point_;
173 Rows rows_;
174 SweepTimings timings_;
175};
176
177} // namespace hpfem::physics
Definition dof_map.hpp:51
Definition conical_scattering.hpp:165
The affine operator of a conical scattering problem for sweeps.
Definition conical_sweep.hpp:44
Matrix solve_loads(const Matrix &loads)
Index num_groups() const noexcept
Definition conical_sweep.hpp:84
const SweepTimings & timings() const noexcept
Definition conical_sweep.hpp:81
ConicalSolution solve(const ConicalScatteringSetup &setup)
const ConicalScattering & point() const
const solvers::LinearSolver & solver() const noexcept
The solver after the first point (name, details).
Definition conical_sweep.hpp:83
Index num_pml_cells() const noexcept
Definition conical_sweep.hpp:85
ConicalSweep(const fespace::NedelecDofMap< 2 > &transverse, const fespace::DofMap< 2 > &longitudinal, const ConicalScatteringSetup &base)
void factorize(const ConicalScatteringSetup &setup)
bool cached() const noexcept
Definition conical_sweep.hpp:93
Index num_source_cells() const noexcept
Definition conical_sweep.hpp:88
Factorise once, solve for many right-hand sides.
Definition linear_solver.hpp:17
Definition absorption.hpp:21
double Real
Definition types.hpp:15
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition types.hpp:22
Eigen::SparseMatrix< Complex, Eigen::RowMajor, Index > SparseMatrix
Definition types.hpp:24
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
Description of a conical scattering problem.
Definition conical_scattering.hpp:96
Definition conical_scattering.hpp:152
Accumulated wall-clock seconds of the sweep's phases (all points) and the point count.
Definition conical_sweep.hpp:30
Real setup
the one-time assembly of the affine parts and the pattern cache
Definition conical_sweep.hpp:31
Real factorize
(re)factorisation
Definition conical_sweep.hpp:35
int points
Definition conical_sweep.hpp:37
Real reduce
constraint reduction onto the fixed reduced pattern
Definition conical_sweep.hpp:34
Real solve
triangular solve and expansion
Definition conical_sweep.hpp:36
Real total() const noexcept
Definition conical_sweep.hpp:38
Real assemble
PML and source cells per point.
Definition conical_sweep.hpp:33
Real combine
combination of the cached values
Definition conical_sweep.hpp:32