PLaSK library

Loading...
Searching...
No Matches
transformed.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__MESH_TRANSFORMED_H
15#define PLASK__MESH_TRANSFORMED_H
16
17#include "mesh.hpp"
18#include "../geometry/space.hpp"
19
20 namespace plask {
21
25//TODO better version for rectangular source (with size reduction by the size of removed axis)
26 struct ReductionTo2DMesh: public MeshD<2> {
27
29 typedef Geometry3D SourceGeometry;
30
32 typedef Geometry2DCartesian TargetGeometry;
33
35 enum { SRC_DIM = 3 };
36
37 Vec<2,double> translation;
38
39 const shared_ptr<const MeshD<3>> sourceMesh;
40
41 ReductionTo2DMesh(const shared_ptr<const MeshD<3>> sourceMesh, const Vec<2,double>& translation=Primitive<2>::ZERO_VEC)
42 : translation(translation), sourceMesh(sourceMesh) {}
43
44 ReductionTo2DMesh(const shared_ptr<const MeshD<3>> sourceMesh, const Vec<3,double>& translation)
45 : translation(vec<2>(translation)), sourceMesh(sourceMesh) {}
46
47 Vec<2, double> at(std::size_t index) const override {
48 return vec<2>(sourceMesh->at(index)) - translation;
49 }
50
51 std::size_t size() const override {
52 return sourceMesh->size();
53 }
54};
55
56
60 struct PLASK_API CylReductionTo2DMesh: public MeshD<2> {
61
63 typedef Geometry3D SourceGeometry;
64
66 typedef Geometry2DCylindrical TargetGeometry;
67
69 enum { SRC_DIM = 3 };
70
71 Vec<3,double> translation;
72
73 const shared_ptr<const MeshD<3>> sourceMesh;
74
75 CylReductionTo2DMesh(const shared_ptr<const MeshD<3>> sourceMesh, const Vec<3,double>& translation=Primitive<3>::ZERO_VEC)
76 : translation(translation), sourceMesh(sourceMesh) {}
77
78 Vec<2, double> at(std::size_t index) const override {
79 return rotateToLonTranAbs(sourceMesh->at(index) - translation);
80 }
81
82 std::size_t size() const override {
83 return sourceMesh->size();
84 }
85
86 Vec<3,double> rVector(std::size_t index) const {
87 return sourceMesh->at(index) - translation;
88 }
89};
90
91
96 class PLASK_API CartesianMesh2DTo3D: public MeshD<3> {
97
98 Vec<3,double> translation;
99
100 const shared_ptr<const MeshD<2>> sourceMesh;
101
102 public:
103
105 typedef Geometry2DCartesian SourceGeometry;
106
108 typedef Geometry3D TargetGeometry;
109
111 enum { SRC_DIM = 2 };
112
113 CartesianMesh2DTo3D(const shared_ptr<const MeshD<2>>& sourceMesh, Vec<3,double> translation=Primitive<3>::ZERO_VEC, double lon=0)
114 : translation(translation), sourceMesh(sourceMesh) {
115 this->translation.lon() += lon;
116 }
117
118 Vec<3, double> at(std::size_t index) const override {
119 return vec3Dplus2D(translation, sourceMesh->at(index));
120 }
121
122 std::size_t size() const override {
123 return sourceMesh->size();
124 }
125};
126
127
133 class PLASK_API CartesianMesh2DTo3DExtend: public MeshD<3> {
134
135 const shared_ptr<const MeshD<2>> sourceMesh;
136
137 Vec<3,double> translation;
138
139 double stepSize;
140
142 std::size_t pointsCount;
143
144 public:
145
147 typedef Geometry2DCartesian SourceGeometry;
148
150 typedef Geometry3D TargetGeometry;
151
153 enum { SRC_DIM = 2 };
154
155 CartesianMesh2DTo3DExtend(const shared_ptr<const MeshD<2>>& sourceMesh, const Vec<3,double>& translation, double longBegin, double lonSize, std::size_t pointsCount=10)
156 : sourceMesh(sourceMesh), translation(translation), stepSize(lonSize / double(pointsCount-1)), pointsCount(pointsCount) {
157 this->translation.lon() += longBegin;
158 }
159
160 Vec<3, double> at(std::size_t index) const override {
161 return translation + vec(sourceMesh->at(index / pointsCount), stepSize * double(index));
162 }
163
164 std::size_t size() const override {
165 return sourceMesh->size() * pointsCount;
166 }
167};
168
169
175 struct PLASK_API PointsOnCircleMeshExtend: public MeshD<3> {
176
177 const shared_ptr<const MeshD<2>> sourceMesh;
178
179 Vec<3,double> translation;
180
181 double slice;
182
183 std::size_t pointsCount;
184
185 Vec<3, double> getCenterForPoint(const Vec<2, double>& p) const {
186 return Vec<3, double>(this->translation.lon(), this->translation.tran(), this->translation.vert() + p.rad_z());
187 }
188
189 public:
190
192 typedef Geometry2DCylindrical SourceGeometry;
193
195 typedef Geometry3D TargetGeometry;
196
198 enum { SRC_DIM = 2 };
199
200 PointsOnCircleMeshExtend(const shared_ptr<const MeshD<2>>& sourceMesh, const Vec<3, double>& translation=Primitive<3>::ZERO_VEC, std::size_t pointsCount=18)
201 : sourceMesh(sourceMesh), translation(translation), slice(PI_DOUBLED / double(pointsCount)), pointsCount(pointsCount) {
202 }
203
204 Vec<3, double> at(std::size_t index) const override {
205 Vec<2, double> p = sourceMesh->at(index / pointsCount);
206 const double angle = slice * double(index % pointsCount);
207 return Vec<3, double>(
208 this->translation.lon() + p.rad_r() * cos(angle),
209 this->translation.tran() + p.rad_r() * sin(angle),
210 this->translation.vert() + p.rad_z()
211 );
212 }
213
214 std::size_t size() const override {
215 return sourceMesh->size() * pointsCount;
216 }
217
218 Vec<3,double> rVector(std::size_t index) const {
219 return at(index) - translation;
220 }
221};
222
223} // namespace plask
224
225#endif // PLASK__MESH_TRANSFORMED_H