https://mooseframework.inl.gov
PointListAdaptor.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "libmesh/nanoflann.hpp"
13 #include "libmesh/utility.h"
14 #include "libmesh/point.h"
15 
16 #include <iterator>
17 
18 template <typename PointObject>
20 {
21 public:
22  using Iterator = typename std::vector<PointObject>::const_iterator;
23 
25  : _begin(begin), _end(end), _size(std::distance(begin, end))
26  {
27  }
28 
29 private:
32 
34  const Iterator _end;
35 
37  std::size_t _size;
38 
39 public:
43  using coord_t = Real;
44 
48  inline size_t kdtree_get_point_count() const { return _size; }
49 
53  const Point & getPoint(const PointObject & item) const;
54 
59  inline coord_t kdtree_distance(const coord_t * p1, const size_t idx_p2, size_t /*size*/) const
60  {
61  mooseAssert(idx_p2 < _size,
62  "The point index should be less than"
63  "total number of points used to build"
64  "the KDTree.");
65 
66  auto it = _begin;
67  std::advance(it, idx_p2);
68  const Point & p2 = getPoint(*it);
69 
70  coord_t dist = 0.0;
71 
72  for (const auto i : make_range(Moose::dim))
73  dist += Utility::pow<2>(p1[i] - p2(i));
74 
75  return dist;
76  }
77 
81  inline coord_t kdtree_get_pt(const size_t idx, int dim) const
82  {
83  mooseAssert(dim < (int)Moose::dim,
84  "The required component number should be less than the LIBMESH_DIM.");
85  mooseAssert(idx < _size,
86  "The index of the point should be less"
87  "than total number of points used to"
88  "construct the KDTree.");
89 
90  auto it = _begin;
91  std::advance(it, idx);
92  const Point & p = getPoint(*it);
93 
94  return p(dim);
95  }
96 
102  template <class BBOX>
103  bool kdtree_get_bbox(BBOX & /* bb */) const
104  {
105  return false;
106  }
107 };
108 
109 // Specialization for PointListAdaptor<Point> (provide your own for custom types)
110 template <>
111 inline const Point &
112 PointListAdaptor<Point>::getPoint(const Point & item) const
113 {
114  return item;
115 }
bool kdtree_get_bbox(BBOX &) const
Optional bounding-box computation.
Real coord_t
libMesh Point coordinate type
const Point & getPoint(const PointObject &item) const
get a Point reference from the PointData object at index idx in the list
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:153
const Iterator _end
end iterator of the underlying point type vector
coord_t kdtree_get_pt(const size_t idx, int dim) const
Returns the dim&#39;th component of the idx&#39;th point in the class.
Real distance(const Point &p)
PointListAdaptor(Iterator begin, Iterator end)
const Iterator _begin
begin iterator of the underlying point type vector
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
std::size_t _size
number of elements pointed to
size_t kdtree_get_point_count() const
Must return the number of data points.
typename std::vector< PointObject >::const_iterator Iterator
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template pow< 2 >(tan(_arg))+1.0) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(sqrt
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
coord_t kdtree_distance(const coord_t *p1, const size_t idx_p2, size_t) const
Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored ...