9#include <kernel/geometry/atlas/surface_mesh.hpp>
10#include <kernel/geometry/cgal.hpp>
11#include <kernel/geometry/index_set.hpp>
12#include <kernel/geometry/mesh_part.hpp>
13#include <kernel/geometry/vertex_set.hpp>
15#include <kernel/lafem/dense_vector_blocked.hpp>
16#include <kernel/lafem/unit_filter_blocked.hpp>
17#include <kernel/shape.hpp>
18#include <kernel/space/dof_mapping_renderer.hpp>
19#include <kernel/util/dist.hpp>
20#include <kernel/util/memory_arbiter.hpp>
21#include <kernel/util/tiny_algebra.hpp>
28 template<
typename DataType_>
41 return a + alpha * ab;
51 const DataType_ d1 = dot(ab, ap);
52 const DataType_ d2 = dot(ac, ap);
53 if (d1 <= 0.0 && d2 <= 0.0)
59 const DataType_ d3 = dot(ab, bp);
60 const DataType_ d4 = dot(ac, bp);
61 if (d3 >= 0.0 && d4 <= d3)
67 const DataType_ d5 = dot(ab, cp);
68 const DataType_ d6 = dot(ac, cp);
69 if (d6 >= 0.0 && d5 <= d6)
74 const DataType_ vc = (d1 * d4) - (d3 * d2);
75 if (vc <= 0.0 && d1 >= 0.0 && d3 <= 0.0)
77 const DataType_ v = d1 / (d1 - d3);
81 const DataType_ vb = (d5 * d2) - (d1 * d6);
82 if (vb <= 0.0 && d2 >= 0.0 && d6 <= 0.0)
84 const DataType_ v = d2 / (d2 - d6);
88 const DataType_ va = (d3 * d6) - (d5 * d4);
89 if (va <= 0.0 && (d4 - d3) >= 0.0 && (d5 - d6) >= 0.0)
91 const DataType_ v = (d4 - d3) / ((d4 - d3) + (d5 - d6));
92 return b + v * (c - b);
95 const DataType_ denom = 1.0 / (va + vb + vc);
96 const DataType_ v = vb * denom;
97 const DataType_ w = vc * denom;
98 return a + v * ab + w * ac;
103 template<
typename FacetShape_,
typename MeshType_>
106 using MeshType = MeshType_;
108 using VertexType =
typename MeshType_::VertexType;
110 static VertexType on_facet(
const MeshType& mesh,
Index facet,
const VertexType& p);
113 template<
typename MeshType_>
116 using MeshType = MeshType_;
118 using VertexType =
typename MeshType_::VertexType;
120 static VertexType on_facet(
const MeshType& mesh,
Index facet,
const VertexType& )
122 return mesh.get_vertex_set()[facet];
126 template<
typename MeshType_>
129 using MeshType = MeshType_;
131 using VertexType =
typename MeshType_::VertexType;
133 static VertexType on_facet(
const MeshType& mesh,
Index facet,
const VertexType& p)
135 const auto& vertices = mesh.get_vertex_set();
136 const auto& indices = mesh.template get_index_set<1, 0>();
137 const VertexType a = vertices[indices(facet, 0)];
138 const VertexType b = vertices[indices(facet, 1)];
143 template<
typename MeshType_>
146 using MeshType = MeshType_;
148 using VertexType =
typename MeshType_::VertexType;
150 static VertexType on_facet(
const MeshType& mesh,
Index facet,
const VertexType& p)
152 const auto& vertices = mesh.get_vertex_set();
153 const auto& indices = mesh.template get_index_set<1, 0>();
154 const VertexType a = vertices[indices(facet, 0)];
155 const VertexType b = vertices[indices(facet, 1)];
160 template<
typename MeshType_>
163 using MeshType = MeshType_;
165 using VertexType =
typename MeshType_::VertexType;
167 static VertexType on_facet(
const MeshType& mesh,
Index facet,
const VertexType& p)
169 const auto& vertices = mesh.get_vertex_set();
170 const auto& indices = mesh.template get_index_set<2, 0>();
171 const VertexType a = vertices[indices(facet, 0)];
172 const VertexType b = vertices[indices(facet, 1)];
173 const VertexType c = vertices[indices(facet, 2)];
178 template<
typename MeshType_>
181 using MeshType = MeshType_;
183 using VertexType =
typename MeshType_::VertexType;
185 static VertexType on_facet(
const MeshType& mesh,
Index facet,
const VertexType& p)
187 const auto& vertices = mesh.get_vertex_set();
188 const auto& indices = mesh.template get_index_set<2, 0>();
189 const VertexType a = vertices[indices(facet, 0)];
190 const VertexType b = vertices[indices(facet, 1)];
191 const VertexType c = vertices[indices(facet, 2)];
192 const VertexType d = vertices[indices(facet, 3)];
197 if((p1 - p).norm_euclid_sqr() < (p2 - p).norm_euclid_sqr())
209 template<
typename MeshType_,
int dim_ = MeshType_::world_dim - 1>
210 typename MeshType_::VertexType project_onto_mesh_part(
211 const MeshType_& mesh,
213 const typename MeshType_::VertexType& p)
215 using DataType =
typename MeshType_::CoordType;
216 using VertexType =
typename MeshType_::VertexType;
220 const auto& vertices = mesh.get_vertex_set();
222 VertexType closest_point = vertices[0];
223 if constexpr (dim_ > 0)
225 closest_point = project_onto_mesh_part<MeshType_, dim_ - 1>(mesh, mesh_part, p);
228 const auto& target_set = mesh_part.template get_target_set<dim_>();
229 DataType distance_to_closest = (p - closest_point).norm_euclid_sqr();
232 VertexType candidate = ClosestPoint<FacetShape, MeshType_>::on_facet(mesh, target_set[i], p);
233 DataType distance = (p - candidate).norm_euclid_sqr();
234 if(distance < distance_to_closest)
236 closest_point = candidate;
237 distance_to_closest = distance;
241 return closest_point;
246 template<
typename MeshType_,
typename DT_,
typename IT_>
262 static constexpr int BlockSize = MeshType::world_dim;
264 static constexpr std::array<Index, 4> empty_mesh_part_size = {{0, 0, 0, 0}};
272 static_assert(BlockSize > 1,
"BlockSize has to be >= 2 in ProjectionFilter!");
343 other.clone(*
this, clone_mode);
379 _entries.emplace_back(dof, position, type);
385 _entries.emplace_back(dof, position, EntryType::Boundary);
391 _entries.emplace_back(dof, position, EntryType::Feature);
397 _entries.emplace_back(dof, position, EntryType::Fixed);
428 for(
auto& [dof, position, type] :
_entries)
432 DataType speed = velocity.norm_euclid();
437 ValueType displaced = position + scale * velocity;
443 case EntryType::Boundary:
446 case EntryType::Feature:
447 projected = Intern::project_onto_mesh_part(*_mesh,
_feature_network, displaced);
449 case EntryType::Fixed:
450 projected = position;
455 view[dof] = (projected - position) * (1.0 / scale);
Class template for partial meshes.
Index get_num_entities(int dim) const
Returns the number of entities.
Blocked Dense data vector class template.
Enforces homogenous Neumann boundary conditions in normal direction by projecting onto the boundary.
ProjectionFilter(const ProjectionFilter &other)=delete
Copy constructor.
ProjectionFilter & operator=(const ProjectionFilter &other)=delete
Copy constructor.
void filter_sol(VectorType &vector) const
Applies the filter onto the solution vector.
void add(Index dof, ValueType position, EntryType type)
Add a DoF to the filter.
ProjectionFilter & operator=(ProjectionFilter &&other)=default
Move-assignment.
void filter_rhs(VectorType &vector) const
Applies the filter onto the right-hand-side vector.
ProjectionFilter clone(CloneMode clone_mode=CloneMode::Deep)
Create a clone of this filter.
std::vector< FilterEntry > _entries
Filter entries.
void add_fixed_dof(Index dof, ValueType position)
Add a fixed DoF. See ProjectionFilter::add for details.
void filter_def(VectorType &vector) const
Applies the filter onto a defect vector.
void filter_cor(VectorType &vector) const
Applies the filter onto a correction vector.
Geometry::MeshPart< MeshType_ > _feature_network
Features to project onto.
void add_boundary_dof(Index dof, ValueType position)
Add a boundary DoF. See ProjectionFilter::add for details.
void clone(const ProjectionFilter &other, CloneMode=CloneMode::Deep)
Clone a ProjectionFiler. This is always a deep clone.
MeshType_ MeshType
Mesh type this filter works on.
void add_feature_dof(Index dof, ValueType position)
Add a feature DoF. See ProjectionFilter::add for details.
ProjectionFilter(ProjectionFilter &&other)=default
Move constructor.
Geometry::MeshPart< MeshType_ > _neumann_zero_boundary
Surface mesh chart to project onto.
EntryType
Type of filter entry.
Tiny::Vector< DataType, BlockSize > ValueType
Value type.
DenseVectorBlocked< DataType, IndexType, BlockSize > VectorType
Supported vector type.
ProjectionFilter(const MeshType *m, MeshPartType &&neumann_boundary, MeshPartType &&feature_network)
Constructor.
std::size_t bytes() const
Size of this filter in bytes.
ProjectionFilter()=default
Default constructor.
Tiny Vector class template.
LAFEM common type definitions.
T_ clamp(T_ x, T_ a, T_ b)
Clamps a value to a range.
CUDA_HOST_DEVICE T_ dot(const T_ &a, const T_ &b)
Computes the dot-product of two scalars.
std::uint64_t Index
Index data type.
Helper functions for determining closest points on a segment and triangle.
Closest point calculator.
Filter entry. Stores information on how to project a single DoF.
FilterEntry(Index d, ValueType p, EntryType t)
Constructor.
ValueType position
Position of this DoF. Used as origin in projections.
EntryType type
The type of this DoF, determines how DoF is projected.
Face traits tag struct template.