PLaSK library

Loading...
Searching...
No Matches
rectangular3d.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__RECTANGULAR3D_H
15#define PLASK__RECTANGULAR3D_H
16
21#include "rectangular_common.hpp"
22#include "rectilinear3d.hpp"
23#include "../optional.hpp"
24
25 namespace plask {
26
36 class PLASK_API RectangularMesh3D: public RectilinearMesh3D {
37
38 public:
39
40 typedef RectilinearMesh3D::ElementMesh<RectangularMesh3D> ElementMesh;
41
46 explicit RectangularMesh3D(IterationOrder iterationOrder = ORDER_012);
47
56 RectangularMesh3D(shared_ptr<MeshAxis> mesh0, shared_ptr<MeshAxis> mesh1, shared_ptr<MeshAxis> mesh2, IterationOrder iterationOrder = ORDER_012);
57
63 RectangularMesh3D(const RectangularMesh3D& src, bool clone_axes = false);
64
69 const shared_ptr<MeshAxis>& lon() const { return axis[0]; }
70
75 const shared_ptr<MeshAxis>& tran() const { return axis[1]; }
76
81 const shared_ptr<MeshAxis>& vert() const { return axis[2]; }
82
87 const shared_ptr<MeshAxis>& ee_z() const { return axis[0]; }
88
93 const shared_ptr<MeshAxis>& ee_x() const { return axis[1]; }
94
99 const shared_ptr<MeshAxis>& ee_y() const { return axis[2]; }
100
105 const shared_ptr<MeshAxis>& rad_r() const { return axis[0]; }
106
111 const shared_ptr<MeshAxis>& rad_phi() const { return axis[1]; }
112
117 const shared_ptr<MeshAxis>& rad_z() const { return axis[2]; }
118
123 void writeXML(XMLElement& object) const override;
124
125 using RectilinearMesh3D::at; // MSVC needs this
126
134 Vec<3, double> at(std::size_t index0, std::size_t index1, std::size_t index2) const override {
135 return Vec<3, double>(axis[0]->at(index0), axis[1]->at(index1), axis[2]->at(index2));
136 }
137
142 shared_ptr<RectangularMesh3D::ElementMesh> getElementMesh() const;
143
149 double getElementArea(std::size_t index0, std::size_t index1, std::size_t index2) const {
150 return (axis[0]->at(index0+1) - axis[0]->at(index0)) * (axis[1]->at(index1+1) - axis[1]->at(index1)) * (axis[2]->at(index2+1) - axis[2]->at(index2));
151 }
152
158 double getElementArea(std::size_t element_index) const {
159 std::size_t bl_index = getElementMeshLowIndex(element_index);
160 return getElementArea(index0(bl_index), index1(bl_index), index2(bl_index));
161 }
162
168 Vec<3, double> getElementMidpoint(std::size_t index0, std::size_t index1, std::size_t index2) const override {
169 return vec(getElementMidpoint0(index0), getElementMidpoint1(index1), getElementMidpoint2(index2));
170 }
171
177 Vec<3, double> getElementMidpoint(std::size_t element_index) const {
178 std::size_t bl_index = getElementMeshLowIndex(element_index);
179 return getElementMidpoint(index0(bl_index), index1(bl_index), index2(bl_index));
180 }
181
187 Box3D getElementBox(std::size_t index0, std::size_t index1, std::size_t index2) const {
188 return Box3D(axis[0]->at(index0), axis[1]->at(index1), axis[2]->at(index2), axis[0]->at(index0+1), axis[1]->at(index1+1), axis[2]->at(index2+1));
189 }
190
196 Box3D getElementBox(std::size_t element_index) const {
197 std::size_t bl_index = getElementMeshLowIndex(element_index);
198 return getElementBox(index0(bl_index), index1(bl_index), index2(bl_index));
199 }
200
201};
202
203 template <typename SrcT, typename DstT>
204 struct InterpolationAlgorithm<RectangularMesh3D, SrcT, DstT, INTERPOLATION_LINEAR> {
205 static LazyData<DstT> interpolate(const shared_ptr<const RectangularMesh3D>& src_mesh, const DataVector<const SrcT>& src_vec,
206 const shared_ptr<const MeshD<3>>& dst_mesh, const InterpolationFlags& flags) {
207 if (src_mesh->axis[0]->size() == 0 || src_mesh->axis[1]->size() == 0 || src_mesh->axis[2]->size() == 0)
208 throw BadMesh("interpolate", "source mesh empty");
209 return new LinearInterpolatedLazyDataImpl<DstT, RectilinearMesh3D, SrcT>(src_mesh, src_vec, dst_mesh, flags);
210 }
211};
212
213 template <typename SrcT, typename DstT>
214 struct InterpolationAlgorithm<RectangularMesh3D, SrcT, DstT, INTERPOLATION_NEAREST> {
215 static LazyData<DstT> interpolate(const shared_ptr<const RectangularMesh3D>& src_mesh, const DataVector<const SrcT>& src_vec,
216 const shared_ptr<const MeshD<3>>& dst_mesh, const InterpolationFlags& flags) {
217 if (src_mesh->axis[0]->size() == 0 || src_mesh->axis[1]->size() == 0 || src_mesh->axis[2]->size() == 0)
218 throw BadMesh("interpolate", "source mesh empty");
219 return new NearestNeighborInterpolatedLazyDataImpl<DstT, RectilinearMesh3D, SrcT>(src_mesh, src_vec, dst_mesh, flags);
220 }
221};
222
223
224
225 template <typename SrcT, typename DstT, InterpolationMethod method>
226 struct InterpolationAlgorithm<typename std::enable_if<method != INTERPOLATION_DEFAULT, RectangularMesh3D::ElementMesh>::type, SrcT, DstT, method> {
227 static LazyData<DstT> interpolate(const shared_ptr<const RectangularMesh3D::ElementMesh>& src_mesh, const DataVector<const SrcT>& src_vec,
228 const shared_ptr<const MeshD<3>>& dst_mesh, const InterpolationFlags& flags) {
229 return InterpolationAlgorithm<RectangularMesh3D, SrcT, DstT, method>::interpolate(src_mesh, src_vec, dst_mesh, flags);
230 }
231};
232
233 template <typename SrcT, typename DstT>
234 struct InterpolationAlgorithm<RectangularMesh3D::ElementMesh, SrcT, DstT, INTERPOLATION_NEAREST> {
235 static LazyData<DstT> interpolate(const shared_ptr<const RectangularMesh3D::ElementMesh>& src_mesh, const DataVector<const SrcT>& src_vec,
236 const shared_ptr<const MeshD<3>>& dst_mesh, const InterpolationFlags& flags) {
237 if (src_mesh->axis[0]->size() == 0 || src_mesh->axis[1]->size() == 0)
238 throw BadMesh("interpolate", "source mesh empty");
239 return new NearestNeighborInterpolatedLazyDataImpl<DstT, RectangularMesh3D::ElementMesh, SrcT>(src_mesh, src_vec, dst_mesh, flags);
240 }
241};
242
243
249 PLASK_API shared_ptr<RectangularMesh3D > make_rectangular_mesh(const RectangularMesh3D &to_copy);
250 inline shared_ptr<RectangularMesh3D> make_rectangular_mesh(shared_ptr<const RectangularMesh3D> to_copy) { return make_rectangular_mesh(*to_copy); }
251
252} // namespace plask
253
254#endif // PLASK__RECTANGULAR3D_H