PLaSK library
Loading...
Searching...
No Matches
meshadapter.hpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef PLASK__SOLVER_OPTICAL_MODAL_MESHADAPTER_H
15#define PLASK__SOLVER_OPTICAL_MODAL_MESHADAPTER_H
16
17#include <boost/iterator/filter_iterator.hpp>
18
19#include "plask/mesh/mesh.hpp"
20
21#include "matrices.hpp"
22
23namespace plask { namespace optical { namespace modal {
24
25
28{
29 struct Level {
35 virtual size_t index(size_t i) const = 0;
36
40 virtual double vpos() const = 0;
41
45 virtual size_t size() const = 0;
46
50 virtual shared_ptr<const Mesh> mesh() const = 0;
51 };
52
53 virtual ~LevelsAdapter() {}
54
55 virtual shared_ptr<Level> yield() = 0;
56};
57
58
60template <int dim>
62{
63 struct GenericLevel;
64
65 struct Mesh: public MeshD<dim> {
66 protected:
68 public:
69 Mesh(const GenericLevel* level): level(level) {}
70 // Overrides
71 std::size_t size() const override { return level->matching.size(); }
72 plask::Vec<dim> at(std::size_t i) const override { return (*level->src)[level->matching[i]]; }
73 };
74
76 protected:
77 std::vector<size_t> matching;
78 shared_ptr<const MeshD<dim>> src;
79 double vert;
80 friend struct LevelsAdapterGeneric<dim>::Mesh;
81 public:
82 GenericLevel(shared_ptr<const MeshD<dim>> src, double level): src(src), vert(level) {
83 for (auto it = src->begin(); it != src->end(); ++it) {
84 if ((*it)[dim-1] == level) matching.push_back(it.index);
85 }
86 }
87 // Overrides
88 size_t index(size_t i) const override;
89 double vpos() const override;
90 std::size_t size() const override { return matching.size(); }
91 shared_ptr<const plask::Mesh> mesh() const override { return plask::make_shared<const Mesh>(this); }
92 };
93
95 shared_ptr<const MeshD<dim>> src;
96
98 std::set<double> levels;
99
101 std::set<double>::iterator iter;
102
103 LevelsAdapterGeneric(shared_ptr<const MeshD<dim>> src): src(src) {
104 for (auto point: *src) {
105 levels.insert(point[dim-1]);
106 }
107 iter = levels.begin();
108 }
109
110 shared_ptr<typename LevelsAdapter::Level> yield() override {
111 if (iter == levels.end()) return shared_ptr<typename LevelsAdapter::Level>();
112 return plask::make_shared<GenericLevel>(src, *(iter++));
113 }
114};
115
117template <int dim>
119{
120 struct RectangularLevel;
121
122 struct Mesh: public MeshD<dim> {
123 protected:
125 public:
127 Mesh(const RectangularLevel* level): level(level) {}
128 // Overrides
129 std::size_t size() const override;
130 plask::Vec<dim> at(std::size_t i) const override;
131 };
132
134 protected:
135 shared_ptr<const RectangularMesh<dim>> src;
136 size_t vert;
137 friend struct LevelsAdapterRectangular<dim>::Mesh;
138 public:
140 RectangularLevel(shared_ptr<const RectangularMesh<dim>> src, size_t vert): src(src), vert(vert) {}
141 // Overrides
142 size_t index(size_t i) const override;
143 double vpos() const override;
144 std::size_t size() const override;
145 shared_ptr<const plask::Mesh> mesh() const override { return plask::make_shared<const Mesh>(this); }
146 };
147
149 shared_ptr<const RectangularMesh<dim>> src;
150
152 size_t idx;
153
154 LevelsAdapterRectangular(shared_ptr<const RectangularMesh<dim>> src): src(src), idx(0) {}
155
156 shared_ptr<typename LevelsAdapter::Level> yield() override;
157};
158
159
164std::unique_ptr<LevelsAdapter> PLASK_SOLVER_API makeLevelsAdapter(const shared_ptr<const Mesh>& src);
165
166
167}}} // namespace plask::optical::modal
168
169#endif // PLASK__SOLVER_OPTICAL_MODAL_MESHADAPTER_H