Tatooine
vertex_property_sampler.h
Go to the documentation of this file.
1#ifndef TATOOINE_DETAIL_UNSTRUCTURED_SIMPLICIAL_GRID_VERTEX_PROPERTY_SAMPLER_H
2#define TATOOINE_DETAIL_UNSTRUCTURED_SIMPLICIAL_GRID_VERTEX_PROPERTY_SAMPLER_H
3//==============================================================================
5//==============================================================================
7//==============================================================================
8template <floating_point Real, std::size_t NumDimensions,
9 std::size_t SimplexDim, typename T>
11 : field<vertex_property_sampler<Real, NumDimensions, SimplexDim, T>, Real,
12 NumDimensions, T> {
13 using grid_type =
18 NumDimensions, T>;
19 using real_type = Real;
20 using pos_type = typename grid_type::pos_type;
22 typename grid_type::template typed_vertex_property_type<T>;
23
24 static auto constexpr num_dimensions() { return NumDimensions; }
25
26 private:
29 //--------------------------------------------------------------------------
30 public:
33 : m_grid{grid}, m_prop{prop} {}
34 //--------------------------------------------------------------------------
35 auto grid() const -> auto const& { return m_grid; }
36 auto property() const -> auto const& { return m_prop; }
37 //--------------------------------------------------------------------------
38 [[nodiscard]] auto evaluate(pos_type const& x, real_type const /*t*/) const
39 -> T {
40 return evaluate(
41 x, std::make_index_sequence<grid_type::num_vertices_per_simplex()>{});
42 }
43 //--------------------------------------------------------------------------
44 template <std::size_t... VertexSeq>
45 [[nodiscard]] auto evaluate(pos_type const& x,
46 std::index_sequence<VertexSeq...> /*seq*/) const
47 -> T {
48 auto simplex_handles = m_grid.hierarchy().nearby_simplices(x);
49 if (simplex_handles.empty()) {
51 }
52 for (auto t : simplex_handles) {
53 auto const vs = m_grid.simplex_at(t);
54 static constexpr auto NV = grid_type::num_vertices_per_simplex();
55 auto A = mat<Real, NV, NV>::ones();
56 auto b = vec<Real, NV>::ones();
57 for (std::size_t r = 0; r < num_dimensions(); ++r) {
58 (
59 [&]() {
60 if (VertexSeq > 0) {
61 A(r, VertexSeq) = m_grid[std::get<VertexSeq>(vs)](r) -
62 m_grid[std::get<0>(vs)](r);
63 } else {
64 ((A(r, VertexSeq) = 0), ...);
65 }
66 }(),
67 ...);
68
69 b(r) = x(r) - m_grid[std::get<0>(vs)](r);
70 }
71 auto const barycentric_coord = *solve(A, b);
72 Real const eps = 1e-8;
73 if (((barycentric_coord(VertexSeq) >= -eps) && ...) &&
74 ((barycentric_coord(VertexSeq) <= 1 + eps) && ...)) {
75 return (
76 (m_prop[std::get<VertexSeq>(vs)] * barycentric_coord(VertexSeq)) +
77 ...);
78 }
79 }
81 }
82};
83//==============================================================================
84} // namespace tatooine::detail::unstructured_simplicial_grid
85//==============================================================================
86#endif
Definition: grid_edge.h:16
Definition: edge_vtp_writer.h:12
auto solve(polynomial< Real, 1 > const &p) -> std::vector< Real >
solve a + b*x
Definition: polynomial.h:187
vec_type pos_type
Definition: axis_aligned_bounding_box.h:109
auto grid() const -> auto const &
Definition: vertex_property_sampler.h:35
auto property() const -> auto const &
Definition: vertex_property_sampler.h:36
vertex_property_sampler(grid_type const &grid, typed_vertex_property_type const &prop)
Definition: vertex_property_sampler.h:31
auto evaluate(pos_type const &x, real_type const) const -> T
Definition: vertex_property_sampler.h:38
auto evaluate(pos_type const &x, std::index_sequence< VertexSeq... >) const -> T
Definition: vertex_property_sampler.h:45
grid_type const & m_grid
Definition: vertex_property_sampler.h:27
static auto constexpr num_dimensions()
Definition: vertex_property_sampler.h:24
typename grid_type::pos_type pos_type
Definition: vertex_property_sampler.h:20
typed_vertex_property_type const & m_prop
Definition: vertex_property_sampler.h:28
typename grid_type::template typed_vertex_property_type< T > typed_vertex_property_type
Definition: vertex_property_sampler.h:22
Definition: field.h:134
static auto constexpr ones()
Definition: mat.h:38
static auto constexpr ood_tensor()
Definition: field.h:21
Definition: unstructured_simplicial_grid.h:52
auto simplex_at(simplex_handle t) const -> auto
Definition: unstructured_simplicial_grid.h:303
auto hierarchy() const -> auto &
Definition: unstructured_simplicial_grid.h:1201
static constexpr auto num_vertices_per_simplex()
Definition: unstructured_simplicial_grid.h:84
static auto constexpr ones()
Definition: vec.h:28