PLaSK library
Loading...
Searching...
No Matches
rectangular_masked2d.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 */
15
16namespace plask {
17
20 initNodesAndElements(predicate);
21}
22
28
30 this->fullMesh.reset(rectangularMesh, clone_axes);
31 reset(predicate);
32}
33
36{
37}
38
39void RectangularMaskedMesh2D::initNodesAndElements(const RectangularMaskedMesh2D::Predicate &predicate)
40{
41 for (auto el_it = this->fullMesh.elements().begin(); el_it != this->fullMesh.elements().end(); ++el_it)
42 if (predicate(*el_it)) {
44 nodeSet.insert(el_it->getLoLoIndex());
45 nodeSet.insert(el_it->getLoUpIndex());
46 nodeSet.insert(el_it->getUpLoIndex());
47 nodeSet.push_back(el_it->getUpUpIndex()); //this is safe also for 10 axis order
48 /*boundaryIndex[0].improveLo(el_it->getLowerIndex0());
49 boundaryIndex[0].improveUp(el_it->getUpperIndex0());
50 boundaryIndex[1].improveLo(el_it->getLowerIndex1());
51 boundaryIndex[1].improveUp(el_it->getUpperIndex1());*/ // this is initialized lazy
52 }
56}
57
58bool RectangularMaskedMesh2D::prepareInterpolation(const Vec<2> &point, Vec<2> &wrapped_point, std::size_t &index0_lo, std::size_t &index0_hi, std::size_t &index1_lo, std::size_t &index1_hi, const InterpolationFlags &flags) const {
59 wrapped_point = flags.wrap(point);
60
61 if (!canBeIncluded(wrapped_point)) return false;
62
67
68 double lo0 = fullMesh.axis[0]->at(index0_lo), hi0 = fullMesh.axis[0]->at(index0_hi),
69 lo1 = fullMesh.axis[1]->at(index1_lo), hi1 = fullMesh.axis[1]->at(index1_hi);
70
72 for (char i1 = 0; i1 < 2; ++i1) {
73 for (char i0 = 0; i0 < 2; ++i0) {
74 if (elementSet.includes(fullMesh.getElementIndexFromLowIndexes(index0_lo, index1_lo))) {
76 return true;
77 }
79 else if (index0_lo < fullMesh.axis[0]->size()-2 && hi0-MIN_DISTANCE < wrapped_point.c0 && wrapped_point.c0 <= hi0) index0_lo = index0_hi;
80 else break;
81 }
82 index0_lo = index0_hi - 1;
84 else if (index1_lo < fullMesh.axis[1]->size()-2 && hi1-MIN_DISTANCE < wrapped_point.c1 && wrapped_point.c1 <= hi1) index1_lo = index1_hi;
85 else break;
86 }
87
88 return false;
89}
90
91
92
93
98
100 return new BoundaryNodeSetImpl<1>(*this, line_nr_axis0, indexBegin, indexEnd);
101}
102
106
108 std::size_t begInd, endInd;
109 if (!details::getIndexesInBoundsExt(begInd, endInd, *fullMesh.axis[1], from, to))
110 return new EmptyBoundaryImpl();
111 return createVerticalBoundaryAtLine(fullMesh.axis[0]->findNearestIndex(axis0_coord), begInd, endInd);
112}
113
117
121
123 std::size_t line, begInd, endInd;
124 if (details::getLineLo(line, *fullMesh.axis[0], box.lower.c0, box.upper.c0) &&
125 details::getIndexesInBounds(begInd, endInd, *fullMesh.axis[1], box.lower.c1, box.upper.c1))
127 else
128 return new EmptyBoundaryImpl();
129}
130
132 std::size_t line, begInd, endInd;
133 if (details::getLineHi(line, *fullMesh.axis[0], box.lower.c0, box.upper.c0) &&
134 details::getIndexesInBounds(begInd, endInd, *fullMesh.axis[1], box.lower.c1, box.upper.c1))
136 else
137 return new EmptyBoundaryImpl();
138}
139
141 std::size_t line, begInd, endInd;
142 if (details::getLineLo(line, *fullMesh.axis[1], box.lower.c1, box.upper.c1) &&
143 details::getIndexesInBounds(begInd, endInd, *fullMesh.axis[0], box.lower.c0, box.upper.c0))
145 else
146 return new EmptyBoundaryImpl();
147}
148
150 std::size_t line, begInd, endInd;
151 if (details::getLineHi(line, *fullMesh.axis[1], box.lower.c1, box.upper.c1) &&
152 details::getIndexesInBounds(begInd, endInd, *fullMesh.axis[0], box.lower.c0, box.upper.c0))
154 else
155 return new EmptyBoundaryImpl();
156}
157
162
164 return new BoundaryNodeSetImpl<0>(*this, indexBegin, line_nr_axis1, indexEnd);
165}
166
170
172 std::size_t begInd, endInd;
173 if (!details::getIndexesInBoundsExt(begInd, endInd, *fullMesh.axis[0], from, to))
174 return new EmptyBoundaryImpl();
175 return createHorizontalBoundaryAtLine(fullMesh.axis[1]->findNearestIndex(axis1_coord), begInd, endInd);
176}
177
181
185
186} // namespace plask