9#include <kernel/assembly/base.hpp>
10#include <kernel/assembly/unit_filter_assembler.hpp>
11#include <kernel/lafem/slip_filter.hpp>
12#include <kernel/lafem/sparse_vector_blocked.hpp>
13#include <kernel/geometry/mesh_node.hpp>
14#include <kernel/geometry/intern/face_index_mapping.hpp>
15#include <kernel/space/lagrange1/element.hpp>
16#include <kernel/space/lagrange2/element.hpp>
30 template<
typename Space_,
int shape_dim_ = Space_::shape_dim>
31 class Lagrange2InterpolatorWrapper;
60 template<
typename Trafo_>
75 static constexpr int facet_dim = ShapeType::dimension-1;
77 static constexpr int world_dim = MeshType::world_dim;
110 const auto& idx_vert_at_facet(mesh.template get_index_set<facet_dim, 0>());
111 const auto& idx_vert_at_shape(mesh.template get_index_set<ShapeType::dimension, 0>());
112 const auto& idx_facet_at_shape(mesh.template get_index_set<ShapeType::dimension, facet_dim>());
115 typename MeshType::template IndexSet<facet_dim, 0>::Type::IndexTupleType reference_numbering;
117 typename MeshType::template IndexSet<facet_dim, 0>::Type::IndexTupleType my_numbering;
118 Index num_elements = mesh.get_num_elements();
121 FEAT_PRAGMA_OMP(parallel
for)
122 for(
Index k = 0; k < num_elements; ++k)
125 for(
int l(0); l < Shape::FaceTraits<ShapeType, facet_dim>::count; ++l)
128 Index parent_l(idx_facet_at_shape[k][l]);
131 if(facets[parent_l] != ~
Index(0))
134 for(
int i(0); i <
nvt_loc; ++i)
137 int j(Geometry::Intern::FaceIndexMapping<ShapeType, facet_dim, 0>::map(l,i));
138 reference_numbering[i] = idx_vert_at_shape[k][j];
141 my_numbering[i] = idx_vert_at_facet[parent_l][i];
146 int orientation_code = Geometry::Intern::CongruencySampler<FacetType>::compare(reference_numbering, my_numbering);
151 Geometry::Intern::CongruencySampler<FacetType>::orientation(orientation_code)
187 template<
typename VectorType_,
typename TrafoType_>
192 const TrafoType_& trafo)
194 typedef typename VectorType_::DataType DataType;
195 typedef typename VectorType_::IndexType IndexType;
196 typedef typename VectorType_::ValueType ValueType;
200 const auto& idx(trafo.get_mesh().template get_index_set<facet_dim,0>());
204 std::map<IndexType, ValueType> nu_map;
207 typename TrafoType_::template Evaluator<FacetType, CoordType>::Type facet_evaluator(trafo);
211 for(
Index k(0); k < trafo.get_mesh().get_num_entities(
facet_dim); ++k)
213 if(facets[k] != ~
Index(0) )
215 facet_evaluator.prepare(k);
216 CoordType vol = facet_evaluator.volume();
217 facet_evaluator.finish();
224 for(
int l(0); l <
nvt_loc; ++l)
228 auto it = nu_map.find(IndexType(idx[k][l]));
229 if(it != nu_map.end())
230 (it->second) += DataType(orientation[k]*vol) * nu_loc[l];
232 nu_map.emplace(IndexType(idx[k][l]), DataType(orientation[k]*vol) * nu_loc[l]);
238 nu = VectorType_(trafo.get_mesh().get_num_vertices(), nu_map.size());
242 auto it = nu_map.begin();
243 auto it_end = nu_map.end();
244 for(
Index i = 0; it != it_end; ++i, ++it)
246 nu_idx[i] = it->first;
247 nu_val[i] = it->second;
272 template<
typename TrafoType_>
276 typedef typename TrafoType_::template Evaluator<FacetType, CoordType>::Type FaceEvaluator;
278 typedef typename FaceEvaluator::JacobianMatrixType JacobianMatrixType;
281 FaceEvaluator trafo_eval(trafo);
282 trafo_eval.prepare(k);
286 for(
int i(0); i <
nvt_loc; ++i)
288 for(
int d(0); d < ShapeType::dimension - 1 ; ++d)
299 for(
int i(0); i <
nvt_loc; ++i)
305 trafo_eval.calc_jac_mat(
jac_mat, xloc[i]);
332 template<
typename Trafo_>
380 for(
int i(0); i < MeshType::shape_dim+1; ++i)
410 this->_recompute =
true;
411 const auto& facet_target(meshpart.template get_target_set<facet_dim>());
413 for(
Index l(0); l < facet_target.get_num_entities(); l++)
446 Geometry::Intern::template TargetSetComputer<facet_dim, 0>::top_to_bottom(
472 template<
typename DataType_,
typename IndexType_>
476 if(filter.get_nu().size() ==
Index(0))
493 filter.get_filter_vector().clone(filter.get_nu());
521 template<
typename DataType_,
typename IndexType_>
527 const auto& mesh = space.
get_trafo().get_mesh();
530 if(filter.get_nu().empty())
547 if(filter.get_nu().num_nzes() >
Index(0))
549 Intern::Lagrange2InterpolatorWrapper<SpaceType>::project(
554 auto nu = filter.get_nu().elements_view_rw();
555 for(
Index i(0); i < filter.num_nzes(); ++i)
572 template<
typename Vector_,
typename Space_,
int shape_dim_>
573 struct Lagrange2InterpolatorCore
576 template<
typename TSH_>
577 static void project(Vector_& lagrange_2_vector,
const Vector_& lagrange_1_vector,
const Space_& space,
const TSH_* tsh)
579 typedef typename Vector_::DataType DataType;
580 typedef typename Vector_::IndexType IndexType;
581 typedef typename Vector_::ValueType ValueType;
584 typedef typename Space_::template DofAssignment<shape_dim_, DataType>::Type DofAssignType;
585 DofAssignType dof_assign(space);
588 if(dof_assign.get_max_assigned_dofs() < 1)
592 auto& idx(space.get_trafo().get_mesh().template get_index_set<shape_dim_, 0>());
593 const auto l1_idx = lagrange_1_vector.indices_view_r();
594 const auto l1_val = lagrange_1_vector.elements_view_r();
595 const auto* l1_beg = l1_idx.get_r();
596 const auto* l1_end = l1_beg + lagrange_1_vector.num_nzes();
602 const Index num_shapes = space.get_mesh().get_num_entities(shape_dim_);
604 for(
Index shape(0); shape < num_shapes; ++shape)
606 ValueType tmp(DataType(0));
609 for(
int j(0); j < idx.get_num_indices(); ++j)
611 auto it = std::lower_bound(l1_beg, l1_end, idx(shape, j));
612 XASSERTM(it != l1_end,
"vertex index not found in Lagrange-1 nu vector");
613 tmp += l1_val[
Index(it - l1_beg)];
616 tmp *= DataType(1)/DataType(idx.get_num_indices());
620 dof_assign.prepare(shape);
623 Index dof_index(dof_assign.get_index(0));
624 l2_factory.add(dof_index, tmp);
632 auto& ts = tsh->template get_target_set<shape_dim_>();
635 const Index num_shapes = ts.get_num_entities();
637 for(Index shape(0); shape < num_shapes; ++shape)
639 ValueType tmp(DataType(0));
642 for(
int j(0); j < idx.get_num_indices(); ++j)
644 auto it = std::lower_bound(l1_beg, l1_end, idx(ts[shape], j));
645 XASSERTM(it != l1_end,
"vertex index not found in Lagrange-1 nu vector");
646 tmp += l1_val[
Index(it - l1_beg)];
649 tmp *= DataType(1)/DataType(idx.get_num_indices());
653 dof_assign.prepare(ts[shape]);
656 Index dof_index(dof_assign.get_index(0));
657 l2_factory.add(dof_index, tmp);
664 lagrange_2_vector = l2_factory.make_svb();
668 template<
typename Vector_,
typename Space_>
669 struct Lagrange2InterpolatorCore<Vector_, Space_, 0>
672 template<
typename TSH_>
673 static void project(Vector_& lagrange_2_vector,
const Vector_& lagrange_1_vector,
const Space_& space,
const TSH_* tsh)
675 typedef typename Vector_::DataType DataType;
676 typedef typename Vector_::IndexType IndexType;
680 typedef typename Space_::template DofAssignment<0, DataType>::Type DofAssignType;
681 DofAssignType dof_assign(space);
683 const auto l1_idx = lagrange_1_vector.indices_view_r();
684 const auto l1_val = lagrange_1_vector.elements_view_r();
685 const IndexType* l1_beg = l1_idx.get_r();
686 const IndexType* l1_end = l1_beg + lagrange_1_vector.num_nzes();
687 LAFEM::SparseVectorFactory<DataType, IndexType, Vector_::block_size> l2_factory(space.get_num_dofs());
692 const Index num_verts = space.get_mesh().get_num_entities(0);
693 for(Index vert(0); vert < num_verts; ++vert)
696 dof_assign.prepare(vert);
699 Index dof_index(dof_assign.get_index(0));
702 auto it = std::lower_bound(l1_beg, l1_end, vert);
703 XASSERTM(it != l1_end,
"vertex index not found in Lagrange-1 nu vector");
704 l2_factory.add(dof_index, l1_val[
Index(it - l1_beg)]);
712 auto& ts = tsh->template get_target_set<0>();
714 const Index num_verts = ts.get_num_entities();
715 for(Index vert(0); vert < num_verts; ++vert)
718 dof_assign.prepare(ts[vert]);
721 Index dof_index(dof_assign.get_index(0));
724 auto it = std::lower_bound(l1_beg, l1_end, ts[vert]);
725 XASSERTM(it != l1_end,
"vertex index not found in Lagrange-1 nu vector");
726 l2_factory.add(dof_index, l1_val[
Index(it - l1_beg)]);
732 lagrange_2_vector = l2_factory.make_svb();
736 template<
typename Space_,
int shape_dim_>
737 class Lagrange2InterpolatorWrapper
740 template<
typename Vector_,
typename TSH_>
741 static void project(Vector_& lagrange_2_vector,
const Vector_& lagrange_1_vector,
const Space_& space,
const TSH_* tsh)
744 Lagrange2InterpolatorWrapper<Space_, shape_dim_ - 1>::project(lagrange_2_vector, lagrange_1_vector, space, tsh);
747 Lagrange2InterpolatorCore<Vector_, Space_, shape_dim_>::project(lagrange_2_vector, lagrange_1_vector, space, tsh);
751 template<
typename Space_>
752 class Lagrange2InterpolatorWrapper<Space_, 0>
755 template<
typename Vector_,
typename TSH_>
756 static void project(Vector_& lagrange_2_vector,
const Vector_& lagrange_1_vector,
const Space_& space,
const TSH_* tsh)
759 Lagrange2InterpolatorCore<Vector_, Space_, 0>::project(lagrange_2_vector, lagrange_1_vector, space, tsh);
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Helper class that computes a weighted outer unit normal field.
MeshType::CoordType CoordType
Floating point type.
static void compute_orientations(CoordType *orientation, const Index *facets, const MeshType &mesh)
Computes facet orientations.
TrafoType::MeshType MeshType
The underlying mesh type.
static constexpr int facet_dim
The shape dimension of the boundary faces.
static constexpr int world_dim
The number of coordinates for each vertex.
Shape::FaceTraits< ShapeType, ShapeType::dimension-1 >::ShapeType FacetType
Shape of the facets that make up the boundary we want to compute the normals for,.
static Tiny::Matrix< CoordType, nvt_loc, MeshType::world_dim > compute_oriented_normals(const TrafoType_ &trafo, Index k)
Computes all oriented normals on one face.
Trafo_ TrafoType
Type for the transformation.
static constexpr int nvt_loc
The number of vertices that make up a Facet, i.e. 4 for a Hypercube<2>
MeshType::ShapeType ShapeType
Shape of the mesh's cells.
static void compute_outer_unit_normal(VectorType_ &nu, const Index *facets, const CoordType *orientation, const TrafoType_ &trafo)
Computes an outer unit normal field.
Contains routines to assemble slip filters.
virtual ~SlipFilterAssembler()
Virtual destructor.
SlipFilterAssembler(const TrafoType &trafo)
Constructor from mesh.
SlipFilterAssembler & operator=(SlipFilterAssembler &&)=delete
Explicitly delete the move assignment operator.
static constexpr int world_dim
The number of coordinates for each vertex.
bool _recompute
Flag when to recompute _facets and _orientation (i.e. if MeshParts get added)
void assemble(LAFEM::SlipFilter< DataType_, IndexType_, world_dim > &filter, const Space::Lagrange2::Element< Trafo_ > &space)
Assembles a homogeneous SlipFilter for a Lagrange 2 FE space.
void add_mesh_part(const Geometry::MeshPart< MeshType > &meshpart)
Adds a MeshPart to the assembler.
Trafo_ TrafoType
the trafo type
SlipFilterAssembler(SlipFilterAssembler &&)=delete
Explicitly delete the move constructor.
MeshType::CoordType CoordType
Floating point type.
Geometry::TargetSetHolder< typename MeshType::ShapeType > TargetSetHolderType
Type for the mapping of slip boundary entities to mesh entities.
std::vector< CoordType > _orientation
For every facet in the mesh, this is its orientation in the mesh.
TrafoType::MeshType MeshType
The mesh type.
static constexpr int facet_dim
shape dimension
void recompute_target_set_holder(const MeshType &mesh)
Recomputes the target mapping for geometric entities.
const TrafoType & _trafo
a reference to the trafo that we want to assemble on
std::vector< Index > _facets
Facets for the slip condition get marked by this.
Index _num_entities[MeshType::shape_dim+1]
Number of entities of various shape dimensions in the slip boundary represented by this filter.
void assemble(LAFEM::SlipFilter< DataType_, IndexType_, world_dim > &filter, const Space::Lagrange1::Element< Trafo_ > &space)
Assembles a homogeneous SlipFilter for a Lagrange 1 FE space.
SlipFilterAssembler(const SlipFilterAssembler &)=delete
Explicitly delete the copy constructor.
TargetSetHolderType _target_set_holder
Mapping of boundary entities to mesh entities (i.e. vertices, edges, facets)
Class template for partial meshes.
Slip Filter class template.
Factory for SparseVector and SparseVectorBlocked construction.
TrafoType & get_trafo()
Returns a reference to the trafo.
Standard Lagrange-1 Finite-Element space class template.
Index get_num_dofs() const
Returns the number of dofs.
Standard Lagrange-2 Finite-Element space class template.
Index get_num_dofs() const
Returns the number of dofs.
Tiny Matrix class template.
Vector< T_, m_ > orthogonal(const Matrix< T_, m_, m_-1, sm_, sn_ > &tau)
Computes the positively oriented orthogonal vector to the columns of a m_ x (m_-1) Matrix.
std::uint64_t Index
Index data type.
@ jac_mat
specifies whether the trafo should supply jacobian matrices
Face traits tag struct template.
Reference cell traits structure.