PLaSK library

Loading...
Searching...
No Matches
translation.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__FILTER__TRANSLATION_H
15#define PLASK__FILTER__TRANSLATION_H
16
17#include "base.hpp"
18#include "../mesh/basic.hpp"
19
20 namespace plask {
21
23 template <typename PropertyT, PropertyType propertyType, typename SpaceType, typename VariadicTemplateTypesHolder>
24 struct TranslatedInnerDataSourceImpl {
25 static_assert(propertyType == FIELD_PROPERTY || propertyType == MULTI_FIELD_PROPERTY,
26 "TranslatedInnerDataSource can't be used with value properties (it can be used only with field properties)");
27};
28
30 template <typename PropertyT, typename SpaceType, typename... ExtraArgs>
31 struct TranslatedInnerDataSourceImpl<PropertyT, FIELD_PROPERTY, SpaceType, VariadicTemplateTypesHolder<ExtraArgs...>>
32: public InnerDataSource<PropertyT, SpaceType, SpaceType, SpaceType /*GeometryObjectD<SpaceType::DIM>*/, GeometryObjectD<SpaceType::DIM>>
33{
34 using typename InnerDataSource<PropertyT, SpaceType, SpaceType, SpaceType /*GeometryObjectD<SpaceType::DIM>*/, GeometryObjectD<SpaceType::DIM>>::Region;
35
37 typedef typename PropertyAt<PropertyT, SpaceType>::ValueType ValueType;
38
39 struct LazySourceImpl {
40
41 std::vector<LazyData<ValueType>> dataForRegion;
42
43 const TranslatedInnerDataSourceImpl<PropertyT, FIELD_PROPERTY, SpaceType, VariadicTemplateTypesHolder<ExtraArgs...>>& source;
44
45 const shared_ptr<const MeshD<SpaceType::DIM>> dst_mesh;
46
47 //std::tuple<ExtraArgs...> extra_args;
48
49 //InterpolationMethod method;
50
51 LazySourceImpl(const TranslatedInnerDataSourceImpl< PropertyT, FIELD_PROPERTY, SpaceType, VariadicTemplateTypesHolder<ExtraArgs...> >& source,
52 const shared_ptr<const MeshD<SpaceType::DIM>>& dst_mesh, ExtraArgs... extra_args, InterpolationMethod method)
53 : dataForRegion(source.regions.size()), source(source), dst_mesh(dst_mesh)/*, extra_args(extra_args...), method(method)*/
54 {
55 for (std::size_t region_index = 0; region_index < source.regions.size(); ++region_index)
56 dataForRegion[region_index].reset(source.in(translate(dst_mesh, - source.regions[region_index].inTranslation), std::forward<ExtraArgs>(extra_args)..., method));
57 }
58
59 plask::optional<ValueType> operator()(std::size_t index) {
60 std::size_t region_index = source.findRegionIndex(dst_mesh->at(index));
61 if (region_index == source.regions.size())
62 return plask::optional<ValueType>();
63
64 /*if (dataForRegion[region_index].isNull())
65 dataForRegion[region_index].reset(source.in(translate(dst_mesh, - source.regions[region_index].inTranslation), extra_args, method));*/
66
67 return dataForRegion[region_index][index];
68 }
69
70 };
71
72 std::function<plask::optional<ValueType>(std::size_t index)> operator()(const shared_ptr<const MeshD<SpaceType::DIM>>& dst_mesh, ExtraArgs... extra_args, InterpolationMethod method) const override {
73 return LazySourceImpl(*this, dst_mesh, std::forward<ExtraArgs>(extra_args)..., method);
74 }
75
76};
77
79 template <typename PropertyT, typename SpaceType, typename... ExtraArgs>
80 struct TranslatedInnerDataSourceImpl<PropertyT, MULTI_FIELD_PROPERTY, SpaceType, VariadicTemplateTypesHolder<ExtraArgs...>>
81: public InnerDataSource<PropertyT, SpaceType, SpaceType, SpaceType /*GeometryObjectD<SpaceType::DIM>*/, GeometryObjectD<SpaceType::DIM>>
82{
83 using typename InnerDataSource<PropertyT, SpaceType, SpaceType, SpaceType /*GeometryObjectD<SpaceType::DIM>*/, GeometryObjectD<SpaceType::DIM>>::Region;
84
86 typedef typename PropertyAt<PropertyT, SpaceType>::ValueType ValueType;
87
88 typedef typename PropertyT::EnumType EnumType;
89
90 struct LazySourceImpl {
91
92 std::vector<LazyData<ValueType>> dataForRegion;
93
94 const TranslatedInnerDataSourceImpl<PropertyT, MULTI_FIELD_PROPERTY, SpaceType, VariadicTemplateTypesHolder<ExtraArgs...>>& source;
95
96 const shared_ptr<const MeshD<SpaceType::DIM>> dst_mesh;
97
98 //std::tuple<ExtraArgs...> extra_args;
99
100 //InterpolationMethod method;
101
102 LazySourceImpl(const TranslatedInnerDataSourceImpl< PropertyT, MULTI_FIELD_PROPERTY, SpaceType, VariadicTemplateTypesHolder<ExtraArgs...> >& source,
103 EnumType n, const shared_ptr<const MeshD<SpaceType::DIM>>& dst_mesh, ExtraArgs... extra_args, InterpolationMethod method)
104 : dataForRegion(source.regions.size()), source(source), dst_mesh(dst_mesh)/*, extra_args(extra_args...), method(method)*/
105 {
106 for (std::size_t region_index = 0; region_index < source.regions.size(); ++region_index)
107 dataForRegion[region_index].reset(source.in(n, translate(dst_mesh, - source.regions[region_index].inTranslation), std::forward<ExtraArgs>(extra_args)..., method));
108 }
109
110 plask::optional<ValueType> operator()(std::size_t index) {
111 std::size_t region_index = source.findRegionIndex(dst_mesh->at(index));
112 if (region_index == source.regions.size())
113 return plask::optional<ValueType>();
114
115 /*if (dataForRegion[region_index].isNull())
116 dataForRegion[region_index].reset(source.in(translate(dst_mesh, - source.regions[region_index].inTranslation), extra_args, method));*/
117
118 return dataForRegion[region_index][index];
119 }
120
121 };
122
123 std::function<plask::optional<ValueType>(std::size_t index)> operator()(EnumType n, const shared_ptr<const MeshD<SpaceType::DIM>>& dst_mesh, ExtraArgs... extra_args, InterpolationMethod method) const override {
124 return LazySourceImpl(*this, n, dst_mesh, std::forward<ExtraArgs>(extra_args)..., method);
125 }
126
127 size_t size() const override { return this->in.size(); }
128};
129
133 template <typename PropertyT, typename SpaceType>
134 using TranslatedInnerDataSource = TranslatedInnerDataSourceImpl<PropertyT, PropertyT::propertyType, SpaceType, typename PropertyT::ExtraParams>;
135
136
138 template <typename PropertyT, PropertyType propertyType, typename SpaceType, typename VariadicTemplateTypesHolder>
139 struct TranslatedOuterDataSourceImpl {
140 static_assert(propertyType == FIELD_PROPERTY || propertyType == MULTI_FIELD_PROPERTY,
141 "TranslatedInnerDataSource can't be used with value properties (it can be used only with field properties)");
142};
143
145 template <typename PropertyT, typename SpaceType, typename... ExtraArgs>
146 struct TranslatedOuterDataSourceImpl<PropertyT, FIELD_PROPERTY, SpaceType, VariadicTemplateTypesHolder<ExtraArgs...>>
147: public OuterDataSource<PropertyT, SpaceType, SpaceType, GeometryObjectD<SpaceType::DIM>, GeometryObjectD<SpaceType::DIM>>
148{
150 typedef typename PropertyAt<PropertyT, SpaceType>::ValueType ValueType;
151
152 std::function<plask::optional<ValueType>(std::size_t index)> operator()(const shared_ptr<const MeshD<SpaceType::DIM>>& dst_mesh, ExtraArgs... extra_args, InterpolationMethod method) const override {
153 LazyData<ValueType> data = this->in(translate(dst_mesh, this->inTranslation), std::forward<ExtraArgs>(extra_args)..., method);
154 return [=] (std::size_t index) { return data[index]; };
155 }
156
157};
158
160 template <typename PropertyT, typename SpaceType, typename... ExtraArgs>
161 struct TranslatedOuterDataSourceImpl<PropertyT, MULTI_FIELD_PROPERTY, SpaceType, VariadicTemplateTypesHolder<ExtraArgs...>>
162: public OuterDataSource<PropertyT, SpaceType, SpaceType, GeometryObjectD<SpaceType::DIM>, GeometryObjectD<SpaceType::DIM>>
163{
165 typedef typename PropertyAt<PropertyT, SpaceType>::ValueType ValueType;
166
167 std::function<plask::optional<ValueType>(std::size_t index)> operator()(typename PropertyT::EnumType n, const shared_ptr<const MeshD<SpaceType::DIM>>& dst_mesh, ExtraArgs... extra_args, InterpolationMethod method) const override {
168 LazyData<ValueType> data = this->in(n, translate(dst_mesh, this->inTranslation), std::forward<ExtraArgs>(extra_args)..., method);
169 return [=] (std::size_t index) { return data[index]; };
170 }
171
172 size_t size() const override { return this->in.size(); }
173};
174
178 template <typename PropertyT, typename SpaceType>
179 using TranslatedOuterDataSource = TranslatedOuterDataSourceImpl<PropertyT, PropertyT::propertyType, SpaceType, typename PropertyT::ExtraParams>;
180
181} // namespace plask
182
183#endif // PLASK__FILTER__TRANSLATION_H