49 const shared_ptr<MeshAxis>* minor_axis;
50 const shared_ptr<MeshAxis>* major_axis;
52 void onAxisChanged(
Event&
e);
54 void setChangeSignal(
const shared_ptr<MeshAxis>& axis) {
if (axis) axis->changedConnectMethod(
this, &RectangularMesh2D::onAxisChanged); }
55 void unsetChangeSignal(
const shared_ptr<MeshAxis>& axis) {
if (axis) axis->changedDisconnectMethod(
this, &RectangularMesh2D::onAxisChanged); }
64 std::size_t index0, index1;
87 inline std::size_t
getIndex0()
const {
return index0; }
90 inline std::size_t
getIndex1()
const {
return index1; }
99 inline double getLower0()
const {
return mesh.axis[0]->at(index0); }
102 inline double getLower1()
const {
return mesh.axis[1]->at(index1); }
111 inline double getUpper0()
const {
return mesh.axis[0]->at(getUpperIndex0()); }
114 inline double getUpper1()
const {
return mesh.axis[1]->at(getUpperIndex1()); }
117 inline double getSize0()
const {
return getUpper0() - getLower0(); }
120 inline double getSize1()
const {
return getUpper1() - getLower1(); }
129 inline std::size_t
getIndex()
const {
return mesh.getElementIndexFromLowIndexes(getLowerIndex0(), getLowerIndex1()); }
132 inline Box2D toBox()
const {
return mesh.getElementBox(index0, index1); }
142 inline double getVolume()
const {
return getSize0() * getSize1(); }
145 inline double getArea()
const {
return getVolume(); }
148 inline std::size_t
getLoLoIndex()
const {
return mesh.index(getLowerIndex0(), getLowerIndex1()); }
151 inline std::size_t
getLoUpIndex()
const {
return mesh.index(getLowerIndex0(), getUpperIndex1()); }
154 inline std::size_t
getUpLoIndex()
const {
return mesh.index(getUpperIndex0(), getLowerIndex1()); }
157 inline std::size_t
getUpUpIndex()
const {
return mesh.index(getUpperIndex0(), getUpperIndex1()); }
225 const shared_ptr<MeshAxis> axis[2];
263 void setIterationOrder(IterationOrder order);
270 IterationOrder getIterationOrder()
const;
277 return &
"\1\0\0\1"[getIterationOrder() * 2];
289 return &
"\1\0\0\1"[getIterationOrder() * 2];
297 setIterationOrder(axis[0]->size() > axis[1]->size() ? ORDER_01 : ORDER_10);
349 void setAxis(std::size_t
axis_nr, shared_ptr<MeshAxis>
new_val,
bool fireResized =
true);
351 const shared_ptr<MeshAxis>
getAxis0()
const {
return axis[0]; }
355 const shared_ptr<MeshAxis>
getAxis1()
const {
return axis[1]; }
378 const shared_ptr<MeshAxis>&
tran()
const {
return axis[0]; }
386 const shared_ptr<MeshAxis>&
vert()
const {
return axis[1]; }
394 const shared_ptr<MeshAxis>&
ee_x()
const {
return axis[0]; }
400 const shared_ptr<MeshAxis>&
ee_y()
const {
return axis[1]; }
406 const shared_ptr<MeshAxis>&
rad_r()
const {
return axis[0]; }
412 const shared_ptr<MeshAxis>&
rad_z()
const {
return axis[1]; }
419 const shared_ptr<MeshAxis>&
getAxis(
size_t n)
const {
420 if (
n >= 2)
throw Exception(
"bad axis number");
431 return getIterationOrder() == IterationOrder::ORDER_01 ? 0 : 1;
441 return getIterationOrder() == IterationOrder::ORDER_01 ? 1 : 0;
454 return this->getIterationOrder() ==
to_compare.getIterationOrder() || (axis[0]->size() == 1) || (axis[1]->size() == 1);
465 std::size_t
size()
const override {
return axis[0]->size() * axis[1]->size(); }
471 std::size_t
getMaxSize()
const {
return std::max(axis[0]->size(), axis[1]->size()); }
477 std::size_t
getMinSize()
const {
return std::min(axis[0]->size(), axis[1]->size()); }
483 void writeXML(
XMLElement&
object)
const override;
486 bool empty()
const override {
return axis[0]->empty() || axis[1]->empty(); }
504 return index(indexes[0], indexes[1]);
568 return Vec<2, double>(axis[0]->at(index0(index)), axis[1]->at(index1(index)));
578 return Vec<2, double>(axis[0]->at(index0(index)), axis[1]->at(index1(index)));
611 template <
typename RandomAccessContainer>
613 ->
typename std::remove_reference<
decltype(data[0])>::type
615 auto p = flags.wrap(point);
627 typename std::remove_const<
typename std::remove_reference<
decltype(data[0])>::type>::type
637 return flags.postprocess(point,
interpolation::bilinear(left, right, bottom, top,
data_lb,
data_rb,
data_rt,
data_lt, p.c0, p.c1));
646 template <
typename RandomAccessContainer>
648 ->
typename std::remove_reference<
decltype(data[0])>::type {
649 auto p = flags.wrap(point);
652 return flags.postprocess(point, data[this->index(axis[0]->findNearestIndex(p.c0), axis[1]->findNearestIndex(p.c1))]);
660 const std::size_t s = axis[0]->size();
661 return (s != 0)? s-1 : 0;
669 const std::size_t s = axis[1]->size();
670 return (s != 0)? s-1 : 0;
678 return (axis[0]->size() != 0 && axis[1]->size() != 0)?
679 (axis[0]->size()-1) * (axis[1]->size()-1) : 0;
688 return index0(
meshIndex) + 1 < axis[0]->size() && index1(
meshIndex) + 1 < axis[1]->size();
736 return (axis[0]->at(index0+1) - axis[0]->at(index0)) * (axis[1]->at(index1+1) - axis[1]->at(index1));
754 double getElementMidpoint0(std::size_t index0)
const {
return 0.5 * (axis[0]->at(index0) + axis[0]->at(index0+1)); }
761 double getElementMidpoint1(std::size_t index1)
const {
return 0.5 * (axis[1]->at(index1) + axis[1]->at(index1+1)); }
769 return vec(getElementMidpoint0(index0), getElementMidpoint1(index1));
788 return Box2D(axis[0]->at(index0), axis[1]->at(index1), axis[0]->at(index0+1), axis[1]->at(index1+1));
817 BoundaryIteratorImpl(
const RectangularMesh2D& mesh, std::size_t line, std::size_t index): mesh(mesh), line(line), index(index) {}
819 void increment()
override { ++index; }
821 bool equal(
const typename BoundaryNodeSetImpl::IteratorImpl& other)
const override {
822 return index ==
static_cast<const BoundaryIteratorImpl&
>(other).index;
828 struct VerticalIteratorImpl:
public BoundaryIteratorImpl {
830 VerticalIteratorImpl(
const RectangularMesh2D& mesh, std::size_t line, std::size_t index): BoundaryIteratorImpl(mesh, line, index) {}
832 std::size_t dereference()
const override {
return this->mesh.
index(this->line, this->index); }
834 std::unique_ptr<typename BoundaryNodeSetImpl::IteratorImpl> clone()
const override {
835 return std::unique_ptr<typename BoundaryNodeSetImpl::IteratorImpl>(
new VerticalIteratorImpl(*
this));
840 struct HorizontalIteratorImpl:
public BoundaryIteratorImpl {
842 HorizontalIteratorImpl(
const RectangularMesh2D& mesh, std::size_t line, std::size_t index): BoundaryIteratorImpl(mesh, line, index) {}
844 std::size_t dereference()
const override {
return this->mesh.
index(this->index, this->line); }
846 std::unique_ptr<typename BoundaryNodeSetImpl::IteratorImpl> clone()
const override {
847 return std::unique_ptr<typename BoundaryNodeSetImpl::IteratorImpl>(
new HorizontalIteratorImpl(*
this));
851 struct VerticalBoundary:
public BoundaryNodeSetWithMeshImpl<RectangularMesh2D> {
853 typedef typename BoundaryNodeSetImpl::Iterator Iterator;
857 VerticalBoundary(
const RectangularMesh2D& mesh, std::size_t line_axis0): BoundaryNodeSetWithMeshImpl<RectangularMesh2D>(mesh), line(line_axis0) {}
861 bool contains(std::size_t mesh_index)
const override {
862 return this->mesh.
index0(mesh_index) == line;
865 Iterator begin()
const override {
866 return Iterator(
new VerticalIteratorImpl(this->mesh, line, 0));
869 Iterator
end()
const override {
870 return Iterator(
new VerticalIteratorImpl(this->mesh, line, this->mesh.
axis[1]->size()));
873 std::size_t
size()
const override {
874 return this->mesh.
axis[1]->size();
879 struct VerticalBoundaryInRange:
public BoundaryNodeSetWithMeshImpl<RectangularMesh2D> {
881 typedef typename BoundaryNodeSetImpl::Iterator Iterator;
883 std::size_t line, beginInLineIndex, endInLineIndex;
885 VerticalBoundaryInRange(
const RectangularMesh2D& mesh, std::size_t line_axis0, std::size_t beginInLineIndex, std::size_t endInLineIndex)
886 : BoundaryNodeSetWithMeshImpl<RectangularMesh2D>(mesh), line(line_axis0), beginInLineIndex(beginInLineIndex), endInLineIndex(endInLineIndex) {}
890 bool contains(std::size_t mesh_index)
const override {
891 return this->mesh.
index0(mesh_index) == line &&
in_range(this->mesh.
index1(mesh_index), beginInLineIndex, endInLineIndex);
894 Iterator begin()
const override {
895 return Iterator(
new VerticalIteratorImpl(this->mesh, line, beginInLineIndex));
898 Iterator
end()
const override {
899 return Iterator(
new VerticalIteratorImpl(this->mesh, line, endInLineIndex));
902 std::size_t
size()
const override {
903 return endInLineIndex - beginInLineIndex;
907 struct HorizontalBoundary:
public BoundaryNodeSetWithMeshImpl<RectangularMesh2D> {
909 typedef typename BoundaryNodeSetImpl::Iterator Iterator;
913 HorizontalBoundary(
const RectangularMesh2D& mesh, std::size_t line_axis1): BoundaryNodeSetWithMeshImpl<RectangularMesh2D>(mesh), line(line_axis1) {}
917 bool contains(std::size_t mesh_index)
const override {
918 return this->mesh.
index1(mesh_index) == line;
921 Iterator begin()
const override {
922 return Iterator(
new HorizontalIteratorImpl(this->mesh, line, 0));
925 Iterator
end()
const override {
926 return Iterator(
new HorizontalIteratorImpl(this->mesh, line, this->mesh.
axis[0]->size()));
929 std::size_t
size()
const override {
930 return this->mesh.
axis[0]->size();
934 struct HorizontalBoundaryInRange:
public BoundaryNodeSetWithMeshImpl<RectangularMesh2D> {
936 typedef typename BoundaryNodeSetImpl::Iterator Iterator;
938 std::size_t line, beginInLineIndex, endInLineIndex;
940 HorizontalBoundaryInRange(
const RectangularMesh2D& mesh, std::size_t line_axis1, std::size_t beginInLineIndex, std::size_t endInLineIndex)
941 : BoundaryNodeSetWithMeshImpl<RectangularMesh2D>(mesh), line(line_axis1), beginInLineIndex(beginInLineIndex), endInLineIndex(endInLineIndex) {}
944 bool contains(std::size_t mesh_index)
const override {
945 return this->mesh.
index1(mesh_index) == line &&
in_range(this->mesh.
index0(mesh_index), beginInLineIndex, endInLineIndex);
948 Iterator begin()
const override {
949 return Iterator(
new HorizontalIteratorImpl(this->mesh, line, beginInLineIndex));
952 Iterator
end()
const override {
953 return Iterator(
new HorizontalIteratorImpl(this->mesh, line, endInLineIndex));
956 std::size_t
size()
const override {
957 return endInLineIndex - beginInLineIndex;
973 BoundaryNodeSet createVerticalBoundaryAtLine(std::size_t
line_nr_axis0)
const override;
975 BoundaryNodeSet createVerticalBoundaryAtLine(std::size_t
line_nr_axis0, std::size_t
indexBegin, std::size_t indexEnd)
const override;
977 BoundaryNodeSet createVerticalBoundaryNear(
double axis0_coord)
const override;
979 BoundaryNodeSet createVerticalBoundaryNear(
double axis0_coord,
double from,
double to)
const override;
981 BoundaryNodeSet createLeftBoundary()
const override;
983 BoundaryNodeSet createRightBoundary()
const override;
985 BoundaryNodeSet createLeftOfBoundary(
const Box2D&
box)
const override;
987 BoundaryNodeSet createRightOfBoundary(
const Box2D&
box)
const override;
989 BoundaryNodeSet createBottomOfBoundary(
const Box2D&
box)
const override;
991 BoundaryNodeSet createTopOfBoundary(
const Box2D&
box)
const override;
993 BoundaryNodeSet createHorizontalBoundaryAtLine(std::size_t
line_nr_axis1)
const override;
995 BoundaryNodeSet createHorizontalBoundaryAtLine(std::size_t
line_nr_axis1, std::size_t
indexBegin, std::size_t indexEnd)
const override;
997 BoundaryNodeSet createHorizontalBoundaryNear(
double axis1_coord)
const override;
999 BoundaryNodeSet createHorizontalBoundaryNear(
double axis1_coord,
double from,
double to)
const override;
1001 BoundaryNodeSet createTopBoundary()
const override;
1003 BoundaryNodeSet createBottomBoundary()
const override;