9#include <kernel/assembly/base.hpp>
10#include <kernel/analytic/function.hpp>
11#include <kernel/lafem/dense_vector.hpp>
12#include <kernel/lafem/sparse_vector_factory.hpp>
13#include <kernel/lafem/unit_filter.hpp>
14#include <kernel/lafem/unit_filter_blocked.hpp>
15#include <kernel/geometry/mesh_part.hpp>
30 template<
int shape_dim_>
31 struct UnitAsmWrapper;
43 template<
typename Mesh_>
52 static constexpr int shape_dim = MeshType::shape_dim;
76 Intern::UnitAsmWrapper<shape_dim>::merge(
_cells, mesh_part);
91 template<
typename DataType_,
typename IndexType_,
typename Space_>
102 svf.
add(filter.get_filter_vector());
106 Intern::UnitAsmWrapper<shape_dim>::assemble(svf, space,
_cells);
109 filter.get_filter_vector() = svf.make_sv();
127 template<
typename DTF_,
typename ITF_,
typename DTV_,
typename ITV_,
typename Space_>
141 svf.
add(filter.get_filter_vector());
148 Intern::UnitAsmWrapper<shape_dim>::assemble(svf, space,
_cells, vector);
151 filter.get_filter_vector() = svf.make_sv();
178 const Function_& function)
const
181 typedef typename Function_::ImageType FuncImageType;
182 static_assert(FuncImageType::is_scalar,
"only scalar functions are supported");
192 svf.
add(filter.get_filter_vector());
196 Intern::UnitAsmWrapper<shape_dim>::assemble(svf, space,
_cells, function);
199 filter.get_filter_vector() = svf.make_sv();
213 template<
typename DataType_,
typename IndexType_,
int block_size_,
typename Space_>
216 const Space_& space)
const
226 svf.
add(filter.get_filter_vector());
230 Intern::UnitAsmWrapper<shape_dim>::assemble(svf, space,
_cells);
233 filter.get_filter_vector() = svf.make_svb();
251 template<
typename DataType_,
typename IndexType_,
int block_size_,
typename Space_,
typename Function_>
255 const Function_& function)
const
258 typedef typename Function_::ImageType FuncImageType;
259 static_assert(FuncImageType::is_vector,
"only vector fields are supported");
260 static_assert(FuncImageType::image_dim == block_size_,
"invalid filter block size");
270 svf.
add(filter.get_filter_vector());
274 Intern::UnitAsmWrapper<shape_dim>::assemble(svf, space,
_cells, function);
277 filter.get_filter_vector() = svf.make_svb();
295 template<
typename DTF_,
typename ITF_,
typename DTV_,
typename ITV_,
int block_size_,
typename Space_>
309 svf.
add(filter.get_filter_vector());
316 Intern::UnitAsmWrapper<shape_dim>::assemble(svf, space,
_cells, vector);
319 filter.get_filter_vector() = svf.make_svb();
327 template<
int shape_dim_>
330 template<
typename MeshPart_>
331 static void merge(std::set<Index>& idx,
const MeshPart_& mesh_part)
334 const typename MeshPart_::template TargetSet<shape_dim_>::Type&
335 target_set(mesh_part.template get_target_set<shape_dim_>());
338 const Index num_entities = target_set.get_num_entities();
339 for(
Index i(0); i < num_entities; ++i)
341 idx.insert(target_set[i]);
346 template<
typename DT_,
typename IT_,
int block_size_,
typename Space_>
347 static void assemble(LAFEM::SparseVectorFactory<DT_, IT_, block_size_>& svf,
const Space_& space,
const std::set<Index>& cells)
350 typename Space_::template DofAssignment<shape_dim_>::Type dof_assign(space);
352 Tiny::Vector<DT_, block_size_> null_val;
356 std::set<Index>::const_iterator it(cells.begin());
357 std::set<Index>::const_iterator jt(cells.end());
358 for(; it != jt; ++it)
360 dof_assign.prepare(*it);
361 const int num_assign(dof_assign.get_num_assigned_dofs());
362 for(
int j(0); j < num_assign; ++j)
364 svf.add(IT_(dof_assign.get_index(j)), null_val);
371 template<
typename DT_,
typename IT_,
typename Space_,
typename Function_>
372 static void assemble(
373 LAFEM::SparseVectorFactory<DT_, IT_, 1>& svf,
375 const std::set<Index>& cells,
376 const Function_& function)
379 typedef typename Space_::template NodeFunctional<shape_dim_, DT_>::Type NodeFunc;
382 static constexpr Index max_dofs = NodeFunc::max_assigned_dofs;
387 NodeFunc node_func(space);
390 typename Space_::template DofAssignment<shape_dim_, DT_>::Type dof_assign(space);
393 Tiny::Vector<DT_, max_dofs+1> node_data;
396 std::set<Index>::const_iterator it(cells.begin());
397 std::set<Index>::const_iterator jt(cells.end());
398 for(; it != jt; ++it)
400 node_func.prepare(*it);
401 node_func(node_data, function);
404 dof_assign.prepare(*it);
406 const int num_assign(dof_assign.get_num_assigned_dofs());
407 for(
int j(0); j < num_assign; ++j)
409 svf.add(dof_assign.get_index(j), node_data[j]);
416 template<
typename DT_,
typename IT_,
int dim_,
typename Space_,
typename Function_>
417 static void assemble(
418 LAFEM::SparseVectorFactory<DT_, IT_, dim_>& svf,
420 const std::set<Index>& cells,
421 const Function_& function)
424 typedef typename Space_::template NodeFunctional<shape_dim_, DT_>::Type NodeFunc;
427 static constexpr Index max_dofs = NodeFunc::max_assigned_dofs;
432 NodeFunc node_func(space);
435 typename Space_::template DofAssignment<shape_dim_, DT_>::Type dof_assign(space);
437 typedef Tiny::Vector<DT_, dim_> ValueType;
440 Tiny::Vector<ValueType, max_dofs+1> node_data;
443 std::set<Index>::const_iterator it(cells.begin());
444 std::set<Index>::const_iterator jt(cells.end());
445 for(; it != jt; ++it)
447 node_func.prepare(*it);
448 node_func(node_data, function);
451 dof_assign.prepare(*it);
453 const int num_assign(dof_assign.get_num_assigned_dofs());
454 for(
int j(0); j < num_assign; ++j)
456 svf.add(dof_assign.get_index(j), node_data[j]);
463 template<
typename DT_,
typename IT_,
typename Space_,
typename DTV_,
typename ITV_>
464 static void assemble(
465 LAFEM::SparseVectorFactory<DT_, IT_, 1>& svf,
467 const std::set<Index>& cells,
468 const LAFEM::DenseVector<DTV_, ITV_>& vector)
471 typename Space_::template DofAssignment<shape_dim_, DT_>::Type dof_assign(space);
473 const Memory::TypedView<DTV_> val_view = vector.elements_view_r();
476 std::set<Index>::const_iterator it(cells.begin());
477 std::set<Index>::const_iterator jt(cells.end());
478 for(; it != jt; ++it)
480 dof_assign.prepare(*it);
482 const int num_assign(dof_assign.get_num_assigned_dofs());
483 for(
int j(0); j < num_assign; ++j)
485 const Index idx = dof_assign.get_index(j);
486 svf.add(idx, val_view(idx));
493 template<
typename DT_,
typename IT_,
int dim_,
typename Space_,
typename DTV_,
typename ITV_>
494 static void assemble(
495 LAFEM::SparseVectorFactory<DT_, IT_, dim_>& svf,
497 const std::set<Index>& cells,
498 const LAFEM::DenseVectorBlocked<DTV_, ITV_, dim_>& vector)
501 typename Space_::template DofAssignment<shape_dim_, DT_>::Type dof_assign(space);
503 typedef Tiny::Vector<DTV_, dim_> ValueType;
504 const Memory::TypedView<ValueType> val_view = vector.elements_view_r();
507 std::set<Index>::const_iterator it(cells.begin());
508 std::set<Index>::const_iterator jt(cells.end());
509 for(; it != jt; ++it)
511 dof_assign.prepare(*it);
513 const int num_assign(dof_assign.get_num_assigned_dofs());
514 for(
int j(0); j < num_assign; ++j)
516 const Index idx = dof_assign.get_index(j);
517 svf.add(idx, val_view(idx));
525 template<
int shape_dim_>
526 struct UnitAsmWrapper
528 template<
typename MeshPart_>
529 static void merge(std::set<Index>* idx,
const MeshPart_& mesh_part)
531 UnitAsmWrapper<shape_dim_ - 1>::merge(idx, mesh_part);
532 UnitAsmHelper<shape_dim_>::merge(idx[shape_dim_], mesh_part);
535 template<
typename DT_,
typename IT_,
int dim_,
typename Space_>
536 static void assemble(LAFEM::SparseVectorFactory<DT_, IT_, dim_>& svf,
const Space_& space,
const std::set<Index>* cells)
538 UnitAsmWrapper<shape_dim_ - 1>::assemble(svf, space, cells);
539 UnitAsmHelper<shape_dim_>::assemble(svf, space, cells[shape_dim_]);
542 template<
typename DT_,
typename IT_,
int dim_,
typename Space_,
typename Whatever_>
543 static void assemble(
544 LAFEM::SparseVectorFactory<DT_, IT_, dim_>& svf,
546 const std::set<Index>* cells,
547 const Whatever_& whatever)
549 UnitAsmWrapper<shape_dim_ - 1>::assemble(svf, space, cells, whatever);
550 UnitAsmHelper<shape_dim_>::assemble(svf, space, cells[shape_dim_], whatever);
555 struct UnitAsmWrapper<0>
557 template<
typename MeshPart_>
558 static void merge(std::set<Index>* idx,
const MeshPart_& mesh_part)
560 UnitAsmHelper<0>::merge(idx[0], mesh_part);
563 template<
typename DT_,
typename IT_,
int dim_,
typename Space_>
564 static void assemble(LAFEM::SparseVectorFactory<DT_, IT_, dim_>& svf,
const Space_& space,
const std::set<Index>* cells)
566 UnitAsmHelper<0>::assemble(svf, space, cells[0]);
569 template<
typename DT_,
typename IT_,
int dim_,
typename Space_,
typename Whatever_>
570 static void assemble(
571 LAFEM::SparseVectorFactory<DT_, IT_, dim_>& svf,
573 const std::set<Index>* cells,
574 const Whatever_& whatever)
576 UnitAsmHelper<0>::assemble(svf, space, cells[0], whatever);
#define XASSERT(expr)
Assertion macro definition.
Unit-Filter assembly class template.
void assemble(LAFEM::UnitFilterBlocked< DTF_, ITF_, block_size_ > &filter, const Space_ &space, const LAFEM::DenseVectorBlocked< DTV_, ITV_, block_size_ > &vector) const
Builds an inhomogeneous blocked unit filter.
void assemble(LAFEM::UnitFilter< DTF_, ITF_ > &filter, const Space_ &space, const LAFEM::DenseVector< DTV_, ITV_ > &vector) const
Builds an inhomogeneous unit-filter.
void add_mesh_part(const Geometry::MeshPart< MeshType > &mesh_part)
Adds the dofs on a mesh-part to the dof-set.
void assemble(LAFEM::UnitFilter< DataType_, IndexType_ > &filter, const Space_ &space) const
Builds a homogeneous unit-filter.
IdxSet _cells[shape_dim+1]
dof-index set
std::set< Index > IdxSet
dof-index set typedef
void assemble(LAFEM::UnitFilter< DataType_, IndexType_ > &filter, const Space_ &space, const Function_ &function) const
Builds an (inhomogeneous) unit-filter.
void assemble(LAFEM::UnitFilterBlocked< DataType_, IndexType_, block_size_ > &filter, const Space_ &space, const Function_ &function) const
Builds an inhomogeneous blocked unit filter.
void assemble(LAFEM::UnitFilterBlocked< DataType_, IndexType_, block_size_ > &filter, const Space_ &space) const
Builds a homogeneous blocked unit filter.
static constexpr int shape_dim
shape dimension
Class template for partial meshes.
Blocked Dense data vector class template.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Dense data vector class template.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Factory for SparseVector and SparseVectorBlocked construction.
Index size() const
Returns the total vector size.
void add(Index i, DT_ v_i)
Adds a new vector entry to the factory.
Unit Filter Blocked class template.
Unit Filter class template.
IntersectionData< DT_ > merge(const IntersectionData< DT_ > &a, const IntersectionData< DT_ > &b)
Merge two intersection datas.
std::uint64_t Index
Index data type.