Wildmeshing Toolkit
AttributeTransferStrategy.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <wmtk/Mesh.hpp>
4 
5 
6 namespace wmtk::operations {
7 
8 
9 template <typename MyType>
11 {
12 public:
14  PrimitiveType primitive_type() const override;
15  Mesh& mesh() override;
17 
18 
19  // bool matches_attribute(
20  // const wmtk::attribute::MeshAttributeHandle& attr,
21  // const simplex::Simplex& s) const final override;
22 };
23 
28 template <typename MyType, typename ParentType>
30 {
31 public:
36 
37  template <typename T>
39  template <typename T>
43 
44 
45  // you can pass as many COLUMN vectors as you want to the function depending on the relative
46  // locations of simplices
47  // if the simplex for update() is uniquely represented after a lub_map then the order of
48  // simplices received is guaranteed to follow that of faces_single_dimension or
49  // cofaces_single_dimension. Otherwise data is recieved in an arbitrary order.
50  using FunctorWithoutSimplicesType = std::function<MyVecType(const ParentMatType&)>;
51  using FunctorType = std::function<MyVecType(const ParentMatType&, const std::vector<Tuple>&)>;
52 
54  const attribute::MeshAttributeHandle& my_handle,
55  const attribute::MeshAttributeHandle& parent_handle,
56  FunctorType&& = nullptr);
58  const attribute::MeshAttributeHandle& my_handle,
59  const attribute::MeshAttributeHandle& parent_handle,
60  FunctorWithoutSimplicesType&& = nullptr);
61 
62  void run(const simplex::Simplex& s) const final override;
63 
64 
66 
68  {
69  return
70  [fp](const ParentMatType& a, const std::vector<Tuple>&) -> MyVecType { return fp(a); };
71  }
72  std::vector<wmtk::attribute::MeshAttributeHandle> sources() const final override
73  {
74  return {m_parent_handle};
75  }
76 
77 
78 protected:
79  std::pair<ParentMatType, std::vector<Tuple>> read_parent_values(
80  const simplex::Simplex& my_simplex) const;
81 
82 private:
85 };
86 
87 // template <typename MyType, typename ParentType>
88 
89 // SingleAttributeTransferStrategy(
90 // const attribute::MeshAttributeHandle&,
91 // const attribute::MeshAttributeHandle&) -> SingleAttributeTransferStrategy<MyType,
92 // ParentType>;
93 
94 // template <typename MyType, typename ParentType, typename FunctorType>
95 
96 // SingleAttributeTransferStrategy(
97 // const attribute::MeshAttributeHandle&,
98 // const attribute::MeshAttributeHandle&,
99 // FunctorType&& f) -> SingleAttributeTransferStrategy<MyType, ParentType>;
100 
101 template <typename MyType, typename ParentType>
104  const attribute::MeshAttributeHandle& parent,
105  FunctorType&& f)
106  : AttributeTransferStrategy<MyType>(me)
107  , m_functor(f)
108  , m_parent_handle(parent)
109 {
110  assert(me.template holds<MyType>());
111  assert(parent.template holds<ParentType>());
112 }
113 template <typename MyType, typename ParentType>
116  const attribute::MeshAttributeHandle& parent,
118  : SingleAttributeTransferStrategy(me, parent, make_nosimplices_func(std::move(f)))
119 {}
120 
121 template <typename MyType, typename ParentType>
123  const simplex::Simplex& my_simplex) const -> std::pair<ParentMatType, std::vector<Tuple>>
124 {
125  auto acc =
126  m_parent_handle.mesh().create_const_accessor(m_parent_handle.template as<ParentType>());
127  auto simps =
128  AttributeTransferStrategyBase::get_parent_simplices(handle(), m_parent_handle, my_simplex);
129 
131  m_parent_handle.mesh().get_attribute_dimension(m_parent_handle.template as<ParentType>()),
132  simps.size());
133 
134  using Index = Eigen::Index;
135  for (Index j = 0; j < Index(simps.size()); ++j) {
136  A.col(j) = acc.const_vector_attribute(simps[j]);
137  }
138  return std::make_pair(std::move(A), std::move(simps));
139 }
140 template <typename MyType, typename ParentType>
142 {
143  assert(mesh().is_valid(s.tuple()));
144  if (s.primitive_type() != primitive_type()) {
145  // TODO: is this an error out or silent fail
146  return;
147  }
148 
149  if (m_functor) {
150  auto [parent_data, simps] = read_parent_values(s);
151  if (simps.empty()) return;
152  auto acc = const_cast<Mesh&>(mesh()).create_accessor(handle().template as<MyType>());
153 
154  acc.vector_attribute(s.tuple()) = m_functor(parent_data, simps);
155  }
156 }
157 template <typename MyType, typename ParentType>
159 {
160  return m_parent_handle.primitive_type();
161 }
162 
163 } // namespace wmtk::operations
static std::vector< Tuple > get_parent_simplices(const Mesh &m, const Mesh &parent, const simplex::Simplex &s, PrimitiveType parent_primitive_type)
AttributeTransferStrategy(const attribute::MeshAttributeHandle &my_handle)
static FunctorType make_nosimplices_func(FunctorWithoutSimplicesType &&fp)
std::function< MyVecType(const ParentMatType &, const std::vector< Tuple > &)> FunctorType
void run(const simplex::Simplex &s) const final override
std::vector< wmtk::attribute::MeshAttributeHandle > sources() const final override
SingleAttributeTransferStrategy(const attribute::MeshAttributeHandle &my_handle, const attribute::MeshAttributeHandle &parent_handle, FunctorType &&=nullptr)
std::pair< ParentMatType, std::vector< Tuple > > read_parent_values(const simplex::Simplex &my_simplex) const
std::function< MyVecType(const ParentMatType &)> FunctorWithoutSimplicesType
const Tuple & tuple() const
Definition: Simplex.hpp:53
PrimitiveType primitive_type() const
Definition: Simplex.hpp:51
Definition: autodiff.h:995
Vector< T, Eigen::Dynamic > VectorX
Definition: Types.hpp:19
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Definition: Types.hpp:14