PLaSK library

Loading...
Searching...
No Matches
meshadapter.cpp
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#include "meshadapter.hpp"
15
16 namespace plask { namespace optical { namespace modal {
17
18 template<int dim>
19 size_t LevelsAdapterGeneric<dim>::GenericLevel::index(size_t i) const { return matching[i]; }
20
21 template<int dim>
22 double LevelsAdapterGeneric<dim>::GenericLevel::vpos() const { return vert; }
23
24
25 template<> shared_ptr<LevelsAdapter::Level> LevelsAdapterRectangular<2>::yield() {
26 if (idx == src->axis[1]->size()) return shared_ptr<typename LevelsAdapter::Level>();
27 return plask::make_shared<LevelsAdapterRectangular<2>::RectangularLevel>(src, idx++);
28}
29
30 template<> shared_ptr<LevelsAdapter::Level> LevelsAdapterRectangular<3>::yield() {
31 if (idx == src->axis[2]->size()) return shared_ptr<typename LevelsAdapter::Level>();
32 return plask::make_shared<LevelsAdapterRectangular<3>::RectangularLevel>(src, idx++);
33}
34
35 template<> std::size_t LevelsAdapterRectangular<2>::RectangularLevel::size() const {
36 return src->axis[0]->size();
37}
38
39 template<> std::size_t LevelsAdapterRectangular<2>::Mesh::size() const {
40 return level->src->axis[0]->size();
41}
42
43 template<> plask::Vec<2> LevelsAdapterRectangular<2>::Mesh::at(std::size_t i) const {
44 return level->src->at(i, level->vert);
45}
46
47 template<> size_t LevelsAdapterRectangular<2>::RectangularLevel::index(size_t i) const {
48 return src->index(i, vert);
49}
50
51 template<> double LevelsAdapterRectangular<2>::RectangularLevel::vpos() const {
52 return src->axis[1]->at(vert);
53}
54
55 template<> std::size_t LevelsAdapterRectangular<3>::RectangularLevel::size() const {
56 return src->axis[0]->size() * src->axis[1]->size();
57}
58
59 template<> std::size_t LevelsAdapterRectangular<3>::Mesh::size() const {
60 return level->src->axis[0]->size() * level->src->axis[1]->size();
61}
62
63 template<> plask::Vec<3> LevelsAdapterRectangular<3>::Mesh::at(std::size_t i) const {
64 return level->src->at(i % level->src->axis[0]->size(), i / level->src->axis[0]->size(), level->vert);
65}
66
67 template<> size_t LevelsAdapterRectangular<3>::RectangularLevel::index(size_t i) const {
68 return src->index(i % src->axis[0]->size(), i / src->axis[0]->size(), vert);
69}
70
71 template<> double LevelsAdapterRectangular<3>::RectangularLevel::vpos() const {
72 return src->axis[2]->at(vert);
73}
74
75
76std::unique_ptr<LevelsAdapter> makeLevelsAdapter(const shared_ptr<const Mesh>& src)
77{
78 typedef std::unique_ptr<LevelsAdapter> ReturnT;
79
80 if (auto mesh = dynamic_pointer_cast<const RectangularMesh<2>>(src))
81 return ReturnT(new LevelsAdapterRectangular<2>(mesh));
82 else if (auto mesh = dynamic_pointer_cast<const RectangularMesh<3>>(src))
83 return ReturnT(new LevelsAdapterRectangular<3>(mesh));
84 else if (auto mesh = dynamic_pointer_cast<const MeshD<2>>(src))
85 return ReturnT(new LevelsAdapterGeneric<2>(mesh));
86 else if (auto mesh = dynamic_pointer_cast<const MeshD<3>>(src))
87 return ReturnT(new LevelsAdapterGeneric<3>(mesh));
88 return ReturnT();
89}
90
91 template struct LevelsAdapterGeneric<2>;
92 template struct LevelsAdapterGeneric<3>;
93 template struct LevelsAdapterRectangular<2>;
94 template struct LevelsAdapterRectangular<3>;
95
96}}} // namespace plask::optical::modal