11#include <kernel/util/dist.hpp>
12#include <kernel/geometry/mesh_node.hpp>
13#include <kernel/assembly/unit_filter_assembler.hpp>
14#include <kernel/lafem/dense_vector.hpp>
15#include <kernel/lafem/dense_vector_blocked.hpp>
16#include <kernel/lafem/sparse_matrix_csr.hpp>
17#include <kernel/lafem/sparse_matrix_bcsr.hpp>
18#include <kernel/lafem/unit_filter.hpp>
19#include <kernel/lafem/unit_filter_blocked.hpp>
20#include <kernel/global/matrix.hpp>
61 template<
typename MeshType_>
68 static constexpr int shape_dim = MeshType::shape_dim;
196 const std::size_t num_halos = halo_map.size();
198 static constexpr std::size_t dim1(
shape_dim + 1);
201 std::vector<std::array<std::vector<int>, dim1>> send_bufs, recv_bufs;
202 send_bufs.resize(num_halos);
203 recv_bufs.resize(num_halos);
207 send_reqs.
reserve(num_halos*dim1);
208 recv_reqs.
reserve(num_halos*dim1);
211 auto it = halo_map.begin();
212 for(
Index h(0); h < num_halos; ++h, ++it)
215 for(std::size_t d(0); d < dim1; ++d)
226 send_bufs[h][d].resize(n);
227 recv_bufs[h][d].resize(n);
228 int* sbuf = send_bufs[h][d].data();
231 recv_reqs.
push_back(comm.
irecv(recv_bufs[h][d].data(), n, it->first));
234 for(
Index i(0); i < n; ++i)
246 it = halo_map.begin();
247 for(
Index h(0); h < num_halos; ++h, ++it)
250 for(std::size_t d(0); d < dim1; ++d)
260 int* rbuf = recv_bufs[h][d].data();
263 for(
Index i(0); i < n; ++i)
286 Index c0(0u), c1(0u);
365 template<
typename DT_,
typename IT_,
typename Space_>
367 const DT_ val_outside = DT_(0),
const DT_ val_inside = DT_(1),
const DT_ val_intface = DT_(1))
const
378 filter_i.get_filter_vector().format(val_intface);
379 filter_o.get_filter_vector().format(val_inside);
381 vector.
format(val_outside);
395 template<
typename DT_,
typename IT_,
typename Space_>
399 this->_unit_asm_inside->assemble(filter, space);
411 template<
typename DT_,
typename IT_,
typename Space_,
int dim_>
415 this->_unit_asm_inside->assemble(filter, space);
439 template<
typename DT_,
typename IT_,
typename Space_>
444 this->_unit_asm_interface->assemble(filter, space);
447 filter.get_filter_vector().format(DT_(1));
454 filter.get_filter_vector().format(diag_a.max_abs_element() / diag_m.max_abs_element());
479 template<
typename DT_,
typename IT_,
typename Space_,
int bh_,
int bw_>
484 this->_unit_asm_interface->assemble(filter, space);
487 filter.get_filter_vector().format(DT_(1));
490 auto diag_a = matrix_a.create_vector_l();
491 auto diag_m = matrix_m.create_vector_l();
494 filter.get_filter_vector().format(diag_a.max_abs_element() / diag_m.max_abs_element());
515 template<
typename DT_,
typename IT_,
typename Space_,
typename Mirror_>
521 this->_unit_asm_interface->assemble(filter, space);
524 filter.get_filter_vector().format(DT_(1));
527 auto diag_a = matrix_a.create_vector_l();
528 auto diag_m = matrix_m.create_vector_l();
529 matrix_a.extract_diag(diag_a,
true);
530 matrix_m.extract_diag(diag_m,
true);
531 filter.get_filter_vector().format(diag_a.max_abs_element() / diag_m.max_abs_element());
552 template<
typename DT_,
typename IT_,
typename Space_,
typename Mirror_,
int bh_,
int bw_>
558 this->_unit_asm_interface->assemble(filter, space);
561 filter.get_filter_vector().format(DT_(1));
564 auto diag_a = matrix_a.create_vector_l();
565 auto diag_m = matrix_m.create_vector_l();
566 matrix_a.extract_diag(diag_a,
true);
567 matrix_m.extract_diag(diag_m,
true);
568 filter.get_filter_vector().format(diag_a.max_abs_element() / diag_m.max_abs_element());
576 std::vector<int>& mask =
_fbm_masks.at(std::size_t(dim));
578 for(
Index i(0); i < n; ++i)
579 mask.at(target_set[i]) |= 3;
585 const std::vector<int>& mask =
_fbm_masks.at(std::size_t(dim));
587 for(
Index i(0), k(0); i < mask.size(); ++i)
589 if(mask[i] == mask_value)
598 template<
typename Shape_>
601 XASSERT(Shape_::dimension >= dim);
602 typedef typename Shape::FaceTraits<Shape_, Shape_::dimension - 1>::ShapeType FacetType;
603 if(Shape_::dimension == dim)
604 return tsh.template get_target_set<Shape_::dimension>();
606 return _get_target_set(
static_cast<const Geometry::TargetSetHolder<FacetType>&
>(tsh), dim);
613 return tsh.template get_target_set<0>();
617 template<
typename Shape_>
620 XASSERT(Shape_::dimension >= dim);
621 typedef typename Shape::FaceTraits<Shape_, Shape_::dimension - 1>::ShapeType FacetType;
622 if(Shape_::dimension == dim)
623 return tsh.template get_target_set<Shape_::dimension>();
625 return _get_target_set(
static_cast<Geometry::TargetSetHolder<FacetType>&
>(tsh), dim);
632 return tsh.template get_target_set<0>();
658 for(
Index i(0); i < n; ++i)
661 int bit1 = (shape_mask[i] >> 1) & 1;
662 for(
int j(0); j < m; ++j)
663 bit1 &= (face_mask[faces_at_shape(i,j)] & 1);
664 shape_mask[i] = (shape_mask[i] & 1) | (bit1 << 1);
669 template<
typename Shape_,
int face_dim_, std::
size_t n_>
670 static void _process_masks(std::array<std::vector<int>, n_>& masks,
const Geometry::IndexSetWrapper<Shape_, face_dim_>& idx_wrapper)
672 _process_masks(masks,
static_cast<const Geometry::IndexSetWrapper<Shape_, face_dim_-1
>&>(idx_wrapper));
673 _process_mask(masks.at(Shape_::dimension), masks.at(std::size_t(face_dim_)), idx_wrapper.template get_index_set<face_dim_>());
677 template<
typename Shape_, std::
size_t n_>
678 static void _process_masks(std::array<std::vector<int>, n_>& masks,
const Geometry::IndexSetWrapper<Shape_, 0>& idx_wrapper)
680 _process_mask(masks.at(Shape_::dimension), masks.front(), idx_wrapper.template get_index_set<0>());
684 template<
typename Shape_, std::
size_t n_>
685 static void _process_shapes(std::array<std::vector<int>, n_>& masks,
const Geometry::IndexSetHolder<Shape_>& idx_holder)
687 typedef typename Shape::FaceTraits<Shape_, Shape_::dimension-1>::ShapeType FacetType;
688 _process_shapes(masks,
static_cast<const Geometry::IndexSetHolder<FacetType>&
>(idx_holder));
689 _process_masks(masks, idx_holder.template get_index_set_wrapper<Shape_::dimension>());
693 template<std::
size_t n_>
694 static void _process_shapes(std::array<std::vector<int>, n_>&,
const Geometry::IndexSetHolder<Shape::Vertex>&)
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Stokes Fictitious Boundary Method assembler class.
virtual ~StokesFBMAssembler()
virtual destructor
const Assembly::UnitFilterAssembler< MeshType > & get_unit_asm_inside() const
Returns a reference to the internal unit-filter assembler inside the FBM region.
static void _process_masks(std::array< std::vector< int >, n_ > &masks, const Geometry::IndexSetWrapper< Shape_, face_dim_ > &idx_wrapper)
auxiliary function: process masks for all face dimensions for a given shape
const std::vector< int > & get_fbm_mask_vector(int dim) const
Returns a reference to an internal FBM mask vector.
void _add_fbm_target_set(const Geometry::TargetSet &target_set, int dim)
auxiliary function: add a target set to the FBM mask vector
static const Geometry::TargetSet & _get_target_set(const Geometry::TargetSetHolder< Shape::Vertex > &tsh, int dim)
auxiliary function: get a target set from a target set holder (recursion end overload)
void assemble_characteristic_vector(LAFEM::DenseVector< DT_, IT_ > &vector, const Space_ &space, const DT_ val_outside=DT_(0), const DT_ val_inside=DT_(1), const DT_ val_intface=DT_(1)) const
Assembles a characteristic vector on the FBM region.
void assemble_interface_filter(LAFEM::UnitFilter< DT_, IT_ > &filter, const Space_ &space, const LAFEM::SparseMatrixCSR< DT_, IT_ > &matrix_a, const LAFEM::SparseMatrixCSR< DT_, IT_ > &matrix_m, bool no_scale=false) const
Assembles a UnitFilter on the FBM interface (non-parallel version)
void assemble_interface_filter(LAFEM::UnitFilterBlocked< DT_, IT_, bh_ > &filter, const Space_ &space, const Global::Matrix< LAFEM::SparseMatrixBCSR< DT_, IT_, bh_, bw_ >, Mirror_, Mirror_ > &matrix_a, const Global::Matrix< LAFEM::SparseMatrixBCSR< DT_, IT_, bh_, bw_ >, Mirror_, Mirror_ > &matrix_m, bool no_scale=false) const
Assembles a UnitFilterBlocked on the FBM interface (parallel version)
std::unique_ptr< Geometry::MeshPart< MeshType > > _fbm_meshpart_interface
the meshpart representing the FBM interface region
std::array< std::vector< int >, shape_dim+1 > _fbm_masks
Array of FBM mask vectors.
static Geometry::TargetSet & _get_target_set(Geometry::TargetSetHolder< Shape::Vertex > &tsh, int dim)
auxiliary function: get a target set from a target set holder (recursion end overload)
static const Geometry::TargetSet & _get_target_set(const Geometry::TargetSetHolder< Shape_ > &tsh, int dim)
auxiliary function: get a target set from a target set holder
bool _compiled
already compiled?
void add_fbm_meshpart(const Geometry::MeshPart< MeshType > &fbm_part)
Adds a FBM mesh-part to the assembler.
StokesFBMAssembler(const MeshType &mesh_)
Constructor.
static void _process_shapes(std::array< std::vector< int >, n_ > &masks, const Geometry::IndexSetHolder< Shape_ > &idx_holder)
auxiliary function: process masks shape dimensions
const Geometry::MeshPart< MeshType > & get_meshpart_inside() const
Returns a reference to the mesh-part representing the FBM inside region.
const Geometry::MeshPart< MeshType > & get_meshpart_interface() const
Returns a reference to the mesh-part representing the FBM interface.
void clear()
Clears the assembler.
void _build_tbm_target_set(Geometry::TargetSet &target_set, int dim, int mask_value)
auxiliary function: build target set from mask vector
static constexpr int shape_dim
our shape dimension
void assemble_interface_filter(LAFEM::UnitFilter< DT_, IT_ > &filter, const Space_ &space, const Global::Matrix< LAFEM::SparseMatrixCSR< DT_, IT_ >, Mirror_, Mirror_ > &matrix_a, const Global::Matrix< LAFEM::SparseMatrixCSR< DT_, IT_ >, Mirror_, Mirror_ > &matrix_m, bool no_scale=false) const
Assembles a UnitFilter on the FBM interface (parallel version)
void assemble_interface_filter(LAFEM::UnitFilterBlocked< DT_, IT_, bh_ > &filter, const Space_ &space, const LAFEM::SparseMatrixBCSR< DT_, IT_, bh_, bw_ > &matrix_a, const LAFEM::SparseMatrixBCSR< DT_, IT_, bh_, bw_ > &matrix_m, bool no_scale=false) const
Assembles a UnitFilterBlocked on the FBM interface (non-parallel version)
static Geometry::TargetSet & _get_target_set(Geometry::TargetSetHolder< Shape_ > &tsh, int dim)
auxiliary function: get a target set from a target set holder
MeshType_ MeshType
our mesh type
static void _process_masks(std::array< std::vector< int >, n_ > &masks, const Geometry::IndexSetWrapper< Shape_, 0 > &idx_wrapper)
auxiliary function: process masks for all face dimensions for a given shape (recursion end)
std::unique_ptr< Assembly::UnitFilterAssembler< MeshType_ > > _unit_asm_inside
unit-filter assembler on inside mesh-part
static void _process_shapes(std::array< std::vector< int >, n_ > &, const Geometry::IndexSetHolder< Shape::Vertex > &)
auxiliary function: process masks shape dimensions (recursion end)
static void _process_mask(std::vector< int > &shape_mask, const std::vector< int > &face_mask, const Geometry::IndexSet< m_ > &faces_at_shape)
Auxiliary function: update bit 1 of the mask vector for a shape based on a bit 0 of its face mask vec...
void compile()
Compiles the assembler.
void sync(const Geometry::RootMeshNode< MeshType > &mesh_node, const Dist::Comm &comm)
Synchronizes the assembler over all processes in a parallel simulation.
std::unique_ptr< Geometry::MeshPart< MeshType > > _fbm_meshpart_inside
the meshpart representing the FBM inside region
const MeshType & _mesh
a reference to our mesh object
std::unique_ptr< Assembly::UnitFilterAssembler< MeshType_ > > _unit_asm_interface
unit-filter assembler on interface mesh-part
void assemble_inside_filter(LAFEM::UnitFilter< DT_, IT_ > &filter, const Space_ &space) const
Assembles a UnitFilter inside the FBM region.
const Assembly::UnitFilterAssembler< MeshType > & get_unit_asm_interface() const
Returns a reference to the internal unit-filter assembler on the FBM interface.
void assemble_inside_filter(LAFEM::UnitFilterBlocked< DT_, IT_, dim_ > &filter, const Space_ &space) const
Assembles a UnitFilterBlocked inside the FBM region.
Unit-Filter assembly class template.
Request irecv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag=0) const
Nonblocking Receive.
Request isend(const void *buffer, std::size_t count, const Datatype &datatype, int dest, int tag=0) const
Nonblocking Send.
Communication Request vector class.
void push_back(Request &&request)
Inserts a new request at the end of the request vector.
void reserve(std::size_t size_)
Reserves sufficient space for a specified number of requests.
void wait_all()
Blocks until all active requests are fulfilled.
Conformal Index-Set class template.
Index get_index_bound() const
Returns the index bound.
Index get_num_entities() const
Returns the number of entities.
int get_num_indices() const
Returns the number of indices per entity.
Class template for partial meshes.
Root mesh node class template.
const std::map< int, std::unique_ptr< MeshPartType > > & get_halo_map() const
Index get_num_entities() const
Returns the number of entities.
Global Matrix wrapper class template.
void format()
Reset all elements of the container to a given value or zero if missing.
Dense data vector class template.
bool empty() const
Checks whether the vector is empty, i.e. if it has size 0.
CSR based blocked sparse matrix.
void extract_diag(VectorTypeL &diag) const
extract main diagonal vector from matrix
void extract_diag(VectorTypeL &diag) const
extract main diagonal vector from matrix
VectorTypeL create_vector_l() const
Returns a new compatible L-Vector.
Unit Filter Blocked class template.
Unit Filter class template.
void filter_sol(DenseVector< DT_, IT_ > &vector) const
Applies the filter onto the solution vector.
std::uint64_t Index
Index data type.
Face traits tag struct template.