PLaSK library

Loading...
Searching...
No Matches
lateral.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) 2023 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_MESH_LATERAL_HPP
15#define PLASK_MESH_LATERAL_HPP
16
17#include "axis1d.hpp"
18#include "interpolation.hpp"
19#include "mesh.hpp"
20
21 namespace plask {
22
23 namespace detail {
24 struct FlatMesh : MeshD<2> {
25 shared_ptr<const MeshD<3>> originalMesh;
26
27 FlatMesh(const shared_ptr<const MeshD<3>>& originalMesh) : originalMesh(originalMesh) {}
28
29 std::size_t size() const override { return originalMesh->size(); }
30
31 plask::Vec<2> at(std::size_t index) const override {
32 auto point = originalMesh->at(index);
33 return Vec<2>(point.c0, point.c1);
34 }
35};
36} // namespace detail
37
41 template <typename MeshT> struct LateralMesh3D : MeshD<3> {
42 shared_ptr<MeshT> lateralMesh;
43 double vert;
44
45 LateralMesh3D(const shared_ptr<MeshT>& lateralMesh, double vert = 0.) : lateralMesh(lateralMesh), vert(vert) {}
46
47 std::size_t size() const override { return lateralMesh->size(); }
48
49 plask::Vec<3> at(std::size_t index) const override {
50 Vec<2> p = lateralMesh->at(index);
51 return Vec<3>(p.c0, p.c1, vert);
52 }
53
54 template <typename T = MeshT> shared_ptr<LateralMesh3D<typename T::ElementMesh>> getElementMesh() const {
55 return make_shared<LateralMesh3D<typename T::ElementMesh>>(lateralMesh->getElementMesh(), vert);
56 }
57};
58
59 template <typename SrcMeshT, typename SrcT, typename DstT, InterpolationMethod method>
60 struct InterpolationAlgorithm<LateralMesh3D<SrcMeshT>, SrcT, DstT, method> {
61 static LazyData<DstT> interpolate(const shared_ptr<const LateralMesh3D<SrcMeshT>>& src_mesh,
62 const DataVector<const SrcT>& src_vec,
63 const shared_ptr<const MeshD<3>>& dst_mesh,
64 const InterpolationFlags& flags) {
65 return InterpolationAlgorithm<SrcMeshT, SrcT, DstT, method>::interpolate(
66 src_mesh->lateralMesh, src_vec, make_shared<const detail::FlatMesh>(dst_mesh), flags);
67 }
68};
69
70 template <typename SrcMeshT, typename SrcT, typename DstT>
71 struct InterpolationAlgorithm<LateralMesh3D<SrcMeshT>, SrcT, DstT, INTERPOLATION_DEFAULT> {
72 static LazyData<DstT> interpolate(const shared_ptr<const LateralMesh3D<SrcMeshT>>&,
73 const DataVector<const SrcT>&,
74 const shared_ptr<const MeshD<3>>&,
75 const InterpolationFlags& PLASK_UNUSED(flags)) {
76 throw CriticalException(
77 "interpolate(...) called for INTERPOLATION_DEFAULT method. Contact solver author to fix this issue."
78#ifndef NDEBUG
79 "\n\nINFO FOR SOLVER AUTHOR: To avoid this error use "
80 "'getInterpolationMethod<YOUR_DEFAULT_METHOD>(interpolation_method) in C++ code of the provider in your solver.\n"
81#endif
82 );
83 }
84};
85
89 template <typename MeshT> struct MultiLateralMesh3D : MeshD<3> {
90 shared_ptr<MeshT> lateralMesh;
91 shared_ptr<MeshAxis> vertAxis;
92
93 MultiLateralMesh3D(const shared_ptr<MeshT>& lateralMesh, const shared_ptr<MeshAxis>& vert)
94 : lateralMesh(lateralMesh), vertAxis(vert) {}
95
96 std::size_t size() const override { return lateralMesh->size() * vertAxis->size(); }
97
98 plask::Vec<3> at(std::size_t index) const override {
99 size_t i = index / vertAxis->size(), j = index % vertAxis->size();
100 Vec<2> p = lateralMesh->at(i);
101 return Vec<3>(p.c0, p.c1, vertAxis->at(j));
102 }
103
104 template <typename T = MeshT> shared_ptr<MultiLateralMesh3D<typename T::ElementMesh>> getElementMesh() const {
105 return shared_ptr<MultiLateralMesh3D<typename T::ElementMesh>>(
106 new MultiLateralMesh3D<typename T::ElementMesh>(lateralMesh->getElementMesh(), vertAxis->getMidpointAxis()));
107 }
108};
109
110} // namespace plask
111
112#endif