8#include <kernel/assembly/grid_transfer.hpp>
9#include <kernel/assembly/mirror_assembler.hpp>
10#include <kernel/assembly/unit_filter_assembler.hpp>
11#include <kernel/assembly/slip_filter_assembler.hpp>
12#include <kernel/lafem/sparse_matrix_csr.hpp>
13#include <kernel/lafem/sparse_matrix_bcsr.hpp>
14#include <kernel/lafem/sparse_matrix_bwrappedcsr.hpp>
15#include <kernel/lafem/transfer.hpp>
16#include <kernel/lafem/vector_mirror.hpp>
17#include <kernel/geometry/mesh_file_writer.hpp>
18#include <kernel/global/filter.hpp>
19#include <kernel/global/gate.hpp>
20#include <kernel/global/matrix.hpp>
21#include <kernel/global/muxer.hpp>
22#include <kernel/global/nonlinear_functional.hpp>
23#include <kernel/global/transfer.hpp>
24#include <kernel/global/vector.hpp>
26#include <control/domain/domain_control.hpp>
39 template<
typename,
typename,
template<
typename,
typename>
class>
40 class MeshoptSystemLevel;
42 template<
typename,
typename,
template<
typename,
typename>
class>
43 class QuadraticSystemLevel;
45 template<
typename,
typename,
template<
typename,
typename>
class>
46 class NonlinearSystemLevel;
60 template<
typename DomainControl_>
69 typedef typename DomainControl_::MeshType
MeshType;
72 static constexpr int world_dim = DomainControl_::MeshType::world_dim;
74 typedef typename DomainControl_::MeshType::CoordType
CoordType;
101 const std::deque<String>& slip_boundaries)
277 int lvl_index = -1)
const
291 for(std::size_t i(0u); i <
_dom_ctrl.size_physical(); ++i)
294 if(dom_lvl.get_level_index() == lvl_index)
296 const auto& my_mesh = dom_lvl.get_mesh();
298 Index ncells(my_mesh.get_num_entities(MeshType::shape_dim));
302 my_mesh.template get_index_set<MeshType::shape_dim, 0>(), my_mesh.get_vertex_set(), qi_cellwise);
308 my_mesh.template get_index_set<MeshType::shape_dim, 0>(), my_mesh.get_vertex_set(), edge_angle_cellwise);
339 typename DT_,
typename IT_,
340 template<
typename,
typename>
class Functional_
452 template<
typename... Args_>
456 const std::deque<String>& dirichlet_list,
457 const std::deque<String>& slip_list,
459 local_functional(rmn, trafo, dirichlet_list, slip_list, std::forward<Args_>(args)...),
471 LocalSystemFilter local_filter (std::move(slip_sequence), std::move(dirichlet_sequence));
540 auto& slip_filters =
filter_sys.local().template at<0>();
542 for(
auto& it : slip_filters)
545 auto& slip_filter_vector = it.second.get_filter_vector();
547 if(slip_filter_vector.used_elements() > 0)
551 auto* tmp_elements = tmp.template elements<LAFEM::Perspective::native>();
552 auto* sfv_elements = slip_filter_vector.template elements<LAFEM::Perspective::native>();
555 for(
Index isparse(0); isparse < slip_filter_vector.used_elements(); ++isparse)
557 Index idense(slip_filter_vector.indices()[isparse]);
558 tmp_elements[idense] = sfv_elements[isparse];
564 for(
Index isparse(0); isparse < slip_filter_vector.used_elements(); ++isparse)
566 Index idense(slip_filter_vector.indices()[isparse]);
567 sfv_elements[isparse] = tmp_elements[idense];
591 XASSERTM(!
empty(),
"Assemble_rhs_vector for empty functional");
609 XASSERTM(!
empty(),
"Assemble_sol_vector for empty functional");
628 template<
typename DomainLayer_>
636 for(
Index i(0); i < dom_layer.neighbor_count(); ++i)
638 int rank(dom_layer.neighbor_rank(i));
642 XASSERTM(halo !=
nullptr,
"Halo not found.");
681 LocalSystemTransfer& loc_trans = glob_trans.
local();
688 if (loc_prol.
empty())
697 auto& loc_vec_weight = glob_vec_weight.
local();
704 loc_vec_weight.format();
714 loc_vec_weight.component_invert(loc_vec_weight);
717 loc_prol.
scale_rows(loc_prol, loc_vec_weight);
744 typename DT_,
typename IT_,
745 template<
typename,
typename>
class Functional_
847 template<
typename... Args_>
851 const std::deque<String>& dirichlet_list,
852 const std::deque<String>& slip_list,
854 BaseClass(level_index, rmn, trafo, dirichlet_list, slip_list, std::forward<Args_>(args)...),
886 typename DT_,
typename IT_,
887 template<
typename,
typename>
class Functional_
987 template<
typename... Args_>
991 const std::deque<String>& dirichlet_list,
992 const std::deque<String>& slip_list,
994 BaseClass(level_index, rmn, trafo, dirichlet_list, slip_list, std::forward<Args_>(args)...),
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
static void assemble_prolongation(Matrix_ &matrix, Vector_ &vector, const FineSpace_ &fine_space, const CoarseSpace_ &coarse_space, const String &cubature_name)
Assembles a prolongation matrix and its corresponding weight vector.
static void assemble_mirror(LAFEM::VectorMirror< DataType_, IndexType_ > &vec_mirror, const Space_ &space, const MeshPart_ &mesh_part)
Assembles a VectorMirror from a space and a mesh-part.
static void assemble_matrix_2lvl(MatrixType_ &matrix, const FineSpace_ &fine_space, const CoarseSpace_ &coarse_space)
Assembles a 2-level matrix structure from a fine-coarse-space pair.
Base class for Meshopt control objects.
DomainControl_::MeshType MeshType
The type of mesh the DomainControl uses.
DomainControl & _dom_ctrl
The domain control whose mesh objects can be modified.
DomainControl_::MeshType::CoordType CoordType
Floating point type for coordinates.
std::deque< String > _dirichlet_boundaries
List of all meshparts with dirichlet boundary conditions.
virtual String name() const =0
Returns a descriptive String.
virtual void mesh_to_buffer()=0
Copies the mesh's vertex coordinates to the buffer vector.
void compute_mesh_quality(CoordType &edge_angle, CoordType &qi_min, CoordType &qi_mean, CoordType *edge_angle_cellwise=nullptr, CoordType *qi_cellwise=nullptr, int lvl_index=-1) const
Computes mesh quality heuristics.
DomainControl_ DomainControl
The type of the underlying domain control.
virtual ~MeshoptControlBase()
Empty virtual destructor.
DomainControl_::LevelType DomainLevel
The type of levels of DomainControl.
const std::deque< String > & get_dirichlet_boundaries() const
Gets the names of all Dirichlet boundaries.
virtual void add_to_vtk_exporter(Geometry::ExportVTK< MeshType > &exporter, const int lvl_index) const
Adds quantities of the underlying mesh quality functional to a given exporter object.
virtual void optimize()=0
Optimizes the current mesh.
LAFEM::DenseVectorBlocked< CoordType, Index, world_dim > LocalCoordsBuffer
Global::Vector< LocalCoordsBuffer, CoordsMirror > GlobalCoordsBuffer
The global version of LocalCoordsBuffer, needed for prepare setting the internal state variable.
std::deque< String > _slip_boundaries
List of all meshparts with slipboundary conditions.
LAFEM::VectorMirror< CoordType, Index > CoordsMirror
corresponding vector mirror
static constexpr int world_dim
The world dimension, i.e. number of coordinates.
virtual CoordType compute_cell_size_defect(CoordType &lambda_min, CoordType &lambda_max, CoordType &vol_min, CoordType &vol_max, CoordType &vol) const =0
**
virtual String info() const =0
Prints settings of the control object.
virtual size_t get_num_levels() const =0
Get the number of levels in this object.
Geometry::ExportVTK< MeshType > VTKExporterType
Type of the vtk exporter this (and derived classes) can write to.
virtual void prepare(const GlobalCoordsBuffer &vec_state)=0
Sets the internal state variable.
const std::deque< String > & get_slip_boundaries() const
Gets the names of all slip boundaries.
virtual void buffer_to_mesh()=0
Copies the contents of the buffer vector to the mesh's vertex coordinates.
MeshoptControlBase(DomainControl &dom_ctrl_, const std::deque< String > &dirichlet_boundaries, const std::deque< String > &slip_boundaries)
The simplest constructor possible.
virtual GlobalCoordsBuffer & get_coords()=0
Gets the coordinates buffer vector.
DT_ DataType
Floating point precision for the solver.
LAFEM::SparseMatrixBWrappedCSR< DT_, IT_, LocalFunctional::MeshType::world_dim > LocalSystemTransferMatrix
Local inter-level transfer matrix.
Global::Transfer< LocalSystemTransfer, SystemMirror > GlobalSystemTransfer
Global system transfer operator.
Global::Vector< LocalSystemVectorL, SystemMirror > GlobalSystemVectorL
Global left-vectors.
GlobalSystemTransfer transfer_sys
The global transfer operator from this level to the next coarser one.
int get_level_index() const
Returns the level index.
void assemble_gates(const DomainLayer_ &dom_layer)
Assembles the gates on this level on a given DomainLayer.
LocalFunctional::SlipFilterSequence LocalSlipFilterSequence
This is comprised of a sequence of SlipFilters...
GlobalSystemVectorL create_vector_l() const
Creates a new (left) vector.
LocalFunctional::DirichletFilterSequence LocalDirichletFilterSequence
... and a sequence of UnitFilters
virtual ~MeshoptSystemLevel()
Empty virtual destructor.
LocalFunctional::VectorTypeL LocalSystemVectorL
Local left-vectors (dual space)
MeshoptSystemLevel()=delete
Explicitly delete default constructor.
IT_ IndexType
Index type for the solver.
LocalFunctional::TrafoType TrafoType
The underlying transformation.
bool empty() const
Returns if the local functional is empty.
LAFEM::VectorMirror< DT_, IT_ > SystemMirror
Mirrors for system vectors.
LocalFunctional::ScalarVectorType LocalScalarVector
Local vectors of scalar quantities.
MeshoptSystemLevel(const MeshoptSystemLevel &)=delete
Explicitly delete the copy constructor.
LocalFunctional::VectorTypeR LocalSystemVectorR
Local right-vectors (primal space)
SystemGate gate_sys
The system gate.
Global::Filter< LocalSystemFilter, SystemMirror > GlobalSystemFilter
Global system filter type.
GlobalCoordsBuffer coords_buffer
This contains a shallow copy of the operator's coords_buffer.
void sync_system_filter()
Synchronizes the system filters.
Functional_< DT_, IT_ > LocalFunctional
The (patch-)local mesh quality functional.
Global::Gate< LocalSystemVectorR, SystemMirror > SystemGate
Gates for the system.
Global::Vector< LocalSystemVectorR, SystemMirror > GlobalSystemVectorR
Global right-vectors.
GlobalSystemVectorR assemble_sol_vector() const
Assembles an intial guess vector.
const int _level_index
This is the number of refines it took from the mesh at the file level to here.
MeshoptSystemLevel(const int level_index, Geometry::RootMeshNode< MeshType > *rmn, TrafoType &trafo, const std::deque< String > &dirichlet_list, const std::deque< String > &slip_list, Args_ &&... args)
Variadic template constructor.
GlobalSystemMuxer coarse_muxer_sys
The global partition muxer on this level.
Global::Gate< LocalScalarVector, ScalarMirror > ScalarGate
Gates for scalar vectors.
LocalFunctional::CoordsBufferType LocalCoordsBuffer
Local coordinates buffer type for passing information to or from the mesh.
LAFEM::VectorMirror< DT_, IT_ > ScalarMirror
Mirrors for scalar vectors.
Global::Vector< LocalScalarVector, ScalarMirror > GlobalScalarVector
Global scalar vector type.
LocalFunctional local_functional
The (patch-)local mesh quality functional.
GlobalSystemVectorR create_vector_r() const
Creates a new (right) vector.
Global::Muxer< LocalSystemVectorR, SystemMirror > GlobalSystemMuxer
The global muxer for mapping data from one partitioning to the other on this level.
GlobalSystemVectorL assemble_rhs_vector() const
Assembles a right hand side vector.
LocalFunctional::FilterType LocalSystemFilter
Filter for the local system.
void assemble_system_transfer(const MeshoptSystemLevel &level_coarse)
Assembles the transfer operators from this level to a coarser one.
ScalarGate gate_scalar
The scalar gate.
TrafoType::MeshType MeshType
The type of mesh we use.
LocalFunctional::SpaceType SpaceType
The finite element space.
LAFEM::Transfer< LocalSystemTransferMatrix > LocalSystemTransfer
Local transfer operator.
Global::Vector< LocalCoordsBuffer, SystemMirror > GlobalCoordsBuffer
Global coordinates buffer.
GlobalSystemFilter filter_sys
The global filter.
MeshoptSystemLevel(MeshoptSystemLevel &&)=delete
Explicitly delete the move constructor. This could be useful to have, though.
(Non)linear system of equations on one mesh refinement level
LocalFunctional::DirichletFilterSequence LocalDirichletFilterSequence
... and a sequence of UnitFilters
Functional_< DT_, IT_ > LocalFunctional
(Patch-) Local mesh quality functional type
LAFEM::VectorMirror< DT_, IT_ > SystemMirror
Mirrors for system vectors.
LocalFunctional::SlipFilterSequence LocalSlipFilterSequence
This is comprised of a sequence of SlipFilters...
MeshoptSystemLevel< DT_, IT_, Functional_ > BaseClass
Our base class.
LocalFunctional::VectorTypeL LocalSystemVectorL
Local left-vectors (dual space)
Global::Filter< LocalSystemFilter, SystemMirror > GlobalSystemFilter
Global system filter type.
DT_ DataType
Floating point precision for the solver.
NonlinearSystemLevel(const int level_index, Geometry::RootMeshNode< MeshType > *rmn, TrafoType &trafo, const std::deque< String > &dirichlet_list, const std::deque< String > &slip_list, Args_ &&... args)
Variadic template constructor.
LocalFunctional::TrafoType TrafoType
The underlying transformation.
Global::Vector< LocalCoordsBuffer, SystemMirror > GlobalCoordsBuffer
Global coordinates buffer.
virtual ~NonlinearSystemLevel()
Empty virtual destructor.
LocalFunctional::SpaceType SpaceType
The finite element space.
LAFEM::VectorMirror< DT_, IT_ > ScalarMirror
Mirrors for scalar vectors.
IT_ IndexType
Index type for the solver.
TrafoType::MeshType MeshType
The type of mesh we use.
Global::Vector< LocalScalarVector, ScalarMirror > GlobalScalarVector
Global scalar vector type.
LocalFunctional::CoordsBufferType LocalCoordsBuffer
Local coordinates buffer type for passing information to or from the mesh.
Global::Vector< LocalSystemVectorR, SystemMirror > GlobalSystemVectorR
Global right-vectors.
LocalFunctional::FilterType LocalSystemFilter
Filter for the local system.
LocalFunctional::VectorTypeR LocalSystemVectorR
Local right-vectors (primal space)
Global::Gate< LocalScalarVector, ScalarMirror > ScalarGate
Gates for scalar vectors.
Global::Vector< LocalSystemVectorL, SystemMirror > GlobalSystemVectorL
Global left-vectors.
Global::Muxer< LocalSystemVectorR, SystemMirror > GlobalSystemMuxer
The global muxer for mapping data from one partitioning to the other on this level.
Global::NonlinearFunctional< LocalFunctional, SystemMirror, SystemMirror > GlobalFunctional
Global mesh quality functional type.
LocalFunctional::ScalarVectorType LocalScalarVector
Local vectors of scalar quantities.
Global::Gate< LocalSystemVectorR, SystemMirror > SystemGate
Gates for the system.
LAFEM::Transfer< LocalSystemTransferMatrix > LocalSystemTransfer
Local transfer operator.
LAFEM::SparseMatrixBWrappedCSR< DT_, IT_, LocalFunctional::MeshType::world_dim > LocalSystemTransferMatrix
Local inter-level transfer matrix.
GlobalFunctional global_functional
The global nonlinear functional.
Global::Transfer< LocalSystemTransfer, SystemMirror > GlobalSystemTransfer
Global system transfer operator.
SystemLevel for a quadratic mesh quality functional leading to a linear system.
Global::Vector< LocalSystemVectorR, SystemMirror > GlobalSystemVectorR
Global right-vectors.
IT_ IndexType
Index type for the solver.
BaseClass::SystemMirror SystemMirror
Mirrors for system vectors.
Functional_< DT_, IT_ > LocalFunctional
(Patch-) Local mesh quality functional type
LocalFunctional::SlipFilterSequence LocalSlipFilterSequence
This is comprised of a sequence of SlipFilters...
virtual ~QuadraticSystemLevel()
Empty virtual destructor.
DT_ DataType
Floating point precision for the solver.
Global::Filter< LocalSystemFilter, SystemMirror > GlobalSystemFilter
Global system filter type.
TrafoType::MeshType MeshType
The type of mesh we use.
Global::Vector< LocalScalarVector, ScalarMirror > GlobalScalarVector
Global scalar vector type.
QuadraticSystemLevel(const int level_index, Geometry::RootMeshNode< MeshType > *rmn, TrafoType &trafo, const std::deque< String > &dirichlet_list, const std::deque< String > &slip_list, Args_ &&... args)
Variadic template constructor.
GlobalSystemMatrix matrix_sys
The global system matrix.
BaseClass::LocalSystemVectorL LocalSystemVectorL
Local left-vectors (dual space)
BaseClass::LocalCoordsBuffer LocalCoordsBuffer
Local coordinates buffer type for passing information to or from the mesh.
LocalFunctional::DirichletFilterSequence LocalDirichletFilterSequence
... and a sequence of UnitFilters
Global::Muxer< LocalSystemVectorR, SystemMirror > GlobalSystemMuxer
The global muxer for mapping data from one partitioning to the other on this level.
LocalFunctional::FilterType LocalSystemFilter
Filter for the local system.
LAFEM::Transfer< LocalSystemTransferMatrix > LocalSystemTransfer
Local transfer operator.
LAFEM::VectorMirror< DT_, IT_ > ScalarMirror
Mirrors for scalar vectors.
BaseClass::LocalScalarVector LocalScalarVector
Local vectors of scalar quantities.
Global::Vector< LocalSystemVectorL, SystemMirror > GlobalSystemVectorL
Global left-vectors.
LocalFunctional::MatrixType LocalMatrix
The local system matrix type (for the gradient)
LocalFunctional::TrafoType TrafoType
The underlying transformation.
Global::Transfer< LocalSystemTransfer, SystemMirror > GlobalSystemTransfer
Global system transfer operator.
Global::Vector< LocalCoordsBuffer, SystemMirror > GlobalCoordsBuffer
Global coordinates buffer.
MeshoptSystemLevel< DT_, IT_, Functional_ > BaseClass
Our base class.
LAFEM::SparseMatrixBWrappedCSR< DT_, IT_, LocalFunctional::MeshType::world_dim > LocalSystemTransferMatrix
Local inter-level transfer matrix.
Global::Matrix< LocalMatrix, SystemMirror, SystemMirror > GlobalSystemMatrix
Global mesh quality functional type.
Global::Gate< LocalScalarVector, ScalarMirror > ScalarGate
Gates for scalar vectors.
BaseClass::LocalSystemVectorR LocalSystemVectorR
Local right-vectors (primal space)
BaseClass::SystemGate SystemGate
Gates for the system.
LocalFunctional::SpaceType SpaceType
The finite element space.
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
VTK exporter class template.
Root mesh node class template.
Global Filter wrapper class template.
Global gate implementation.
void compile(LocalVector_ &&vector)
Compiles the gate to finish its setup.
void sync_0(LocalVector_ &vector) const
Synchronizes a type-0 vector, resulting in a type-1 vector.
void push(int rank, Mirror_ &&mirror)
Adds a mirror for a neighbor process.
void set_comm(const Dist::Comm *comm_)
Sets the communicator for this gate.
Global Matrix wrapper class template.
Global multiplexer/demultiplexer implementation.
Global NonlinearFunctional wrapper class template.
Global grid-transfer operator class template.
Global vector wrapper class template.
void format(DataType alpha=DataType(0))
Reset all elements of the container to a given value or zero if missing.
LocalVector_ & local()
Returns a reference to the internal local LAFEM vector object.
void sync_0()
Performs a type-0 synchronization of the vector, i.e. sums up all local DOF contributions.
bool empty() const
Checks whether the container is empty.
void format(DT_ value=DT_(0))
Reset all elements of the container to a given value or zero if missing.
Blocked Dense data vector class template.
Wraps a SparseMatrixCSR to SparseMatrixBCSR.
SparseMatrixCSR transpose() const
Calculate .
VectorTypeL create_vector_l() const
Returns a new compatible L-Vector.
void scale_rows(const SparseMatrixCSR &x, const DenseVector< DT_, IT_ > &s)
Calculate .
Grid-Transfer operator class template.
Handles vector prolongation, restriction and serialization.
String class implementation.
const Operation op_min(MPI_MIN)
Operation wrapper for MPI_MIN.
const Operation op_sum(MPI_SUM)
Operation wrapper for MPI_SUM.
String stringify(const T_ &item)
Converts an item into a String.
std::uint64_t Index
Index data type.
Helper class for computing heuristic mesh quality.
static VtxType_::CoordType compute(const IdxType_ &idx, const VtxType_ &vtx)
Computes minimum cell quality.