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
16namespace plask { namespace optical { namespace modal {
17
18template<int dim>
19size_t LevelsAdapterGeneric<dim>::GenericLevel::index(size_t i) const { return matching[i]; }
20
21template<int dim>
22double LevelsAdapterGeneric<dim>::GenericLevel::vpos() const { return vert; }
23
24
29
34
36 return src->axis[0]->size();
37}
38
39template<> std::size_t LevelsAdapterRectangular<2>::Mesh::size() const {
40 return level->src->axis[0]->size();
41}
42
44 return level->src->at(i, level->vert);
45}
46
48 return src->index(i, vert);
49}
50
52 return src->axis[1]->at(vert);
53}
54
56 return src->axis[0]->size() * src->axis[1]->size();
57}
58
59template<> std::size_t LevelsAdapterRectangular<3>::Mesh::size() const {
60 return level->src->axis[0]->size() * level->src->axis[1]->size();
61}
62
64 return level->src->at(i % level->src->axis[0]->size(), i / level->src->axis[0]->size(), level->vert);
65}
66
68 return src->index(i % src->axis[0]->size(), i / src->axis[0]->size(), vert);
69}
70
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
91template struct LevelsAdapterGeneric<2>;
92template struct LevelsAdapterGeneric<3>;
93template struct LevelsAdapterRectangular<2>;
94template struct LevelsAdapterRectangular<3>;
95
96}}} // namespace plask::optical::modal