7#include <kernel/adjacency/base.hpp>
8#include <kernel/adjacency/graph.hpp>
9#include <kernel/analytic/common.hpp>
10#include <kernel/assembly/common_operators.hpp>
11#include <kernel/assembly/discrete_evaluator.hpp>
12#include <kernel/assembly/discrete_projector.hpp>
13#include <kernel/assembly/domain_assembler.hpp>
14#include <kernel/assembly/domain_assembler_basic_jobs.hpp>
15#include <kernel/assembly/mean_filter_assembler.hpp>
16#include <kernel/assembly/projection_filter_assembler.hpp>
17#include <kernel/assembly/symbolic_assembler.hpp>
18#include <kernel/assembly/trace_assembler_basic_jobs.hpp>
20#include <kernel/geometry/boundary_factory.hpp>
21#include <kernel/geometry/export_vtk.hpp>
22#include <kernel/geometry/mesh_node.hpp>
23#include <kernel/geometry/mesh_part.hpp>
24#include <kernel/global/filter.hpp>
25#include <kernel/global/gate.hpp>
26#include <kernel/global/inverse_mapping.hpp>
27#include <kernel/global/matrix.hpp>
28#include <kernel/global/remote_lambda.hpp>
29#include <kernel/global/vector.hpp>
30#include <kernel/lafem/dense_vector.hpp>
31#include <kernel/lafem/dense_vector_blocked.hpp>
32#include <kernel/lafem/mean_filter.hpp>
33#include <kernel/lafem/projection_filter.hpp>
34#include <kernel/lafem/sparse_matrix_csr.hpp>
35#include <kernel/lafem/sparse_vector_blocked.hpp>
36#include <kernel/lafem/vector_mirror.hpp>
37#include <kernel/solver/base.hpp>
38#include <kernel/solver/gmres.hpp>
39#include <kernel/solver/pcg.hpp>
40#include <kernel/solver/ssor_precond.hpp>
41#include <kernel/space/lagrange1/element.hpp>
42#include <kernel/trafo/inverse_mapping.hpp>
43#include <kernel/trafo/standard/mapping.hpp>
44#include <kernel/util/dist.hpp>
45#include <kernel/util/memory_arbiter.hpp>
47namespace FEAT::MeshOpt
55 Memory::TypedView<T_> view;
62 const T_* begin()
const
69 return &view[view.size()];
74 return &view[view.size()];
98 template<
typename MeshType_>
107 static constexpr int dim = MeshType::world_dim;
150 {
return Solver::new_gmres(m, f, 10); };
248 template<
typename MonitorFn_>
262 boundary_factory.
add_halo(rank, *halo);
274 const auto& tgs = boundary.template get_target_set<0>();
275 const auto& vertices = mesh.get_vertex_set();
288 projection_filter_assembler.
assemble(projection_filter, space,
_gate);
317 current_quality = _quality(mesh, space, domain_assembler, monitor_fn);
321 if(current_quality.l2norm < 0.05)
328 return current_quality;
336 template<
typename MonitorFn_>
349 return _quality(mesh, space, domain_assembler, monitor_fn);
354 template<
typename MonitorFn_>
361 const MonitorFn_& monitor_lambda,
362 Real blend_factor = 1.0)
368 const auto& vertices = mesh.get_vertex_set();
372 view[i] = monitor_lambda(vertices[i]);
388 monitor_fn.
scale(monitor_fn, blend_factor);
420 solution.
local().format();
424 matrix.
local().format();
436 mean_assembler.
assemble(mean_filter.local(), space,
"auto-degree:3",
DataType(0.0));
438 mean_filter.local().filter_mat(matrix.
local());
439 mean_filter.filter_rhs(rhs);
440 mean_filter.filter_sol(solution);
464 const auto& mesh_vertices = mesh.get_vertex_set();
466 for(
Index i(0); i < mesh.get_num_vertices(); i++)
468 view[i] = mesh_vertices[i];
482 std::vector<Global::GlobalInverseMappingData<DataType, dim>> unmapping =
483 global_unmapping.
unmap_points(ViewRange<VertexType>{vs.elements_view_r()});
495 .template add_entry<DataType>(offsetof(EvalResult, f))
496 .template add_entry<DataType>(offsetof(EvalResult, g))
497 .template add_entry<VertexType>(offsetof(EvalResult, v));
501 std::vector<int> ranks;
502 std::vector<Index> indices;
503 std::vector<std::tuple<VertexType, Index, int>> args;
505 for(
Index i(0); i < unmapping.size(); i++)
507 if(unmapping[i].size() == 0)
512 indices.push_back(i);
517 ranks.push_back(unmapping[i].ranks[0]);
518 indices.push_back(i);
519 args.emplace_back(unmapping[i].dom_points[0], unmapping[i].cells[0], 1);
524 std::vector<EvalResult> evals = remote_eval.call(
532 const DataType f = inv_monitor_fn.
local().elements_view_r()(cell);
533 const DataType g = inv_area_fn.
local().elements_view_r()(cell);
534 const VertexType v = velocity.elements_view_r()(cell);
536 return EvalResult{f, g, v};
541 inv_map_data.
cells.push_back(cell);
553 return EvalResult{f, g, v};
557 FEAT_PRAGMA_OMP(parallel
for)
558 for(
Index i = 0; i < mesh.get_num_vertices(); i++)
565 view_out[i] = (
DataType(1.0) / denom) * v;
568 return std::move(ode_rhs);
573 auto& mesh_vertices = mesh.get_vertex_set();
575 for(
Index i(0); i < mesh.get_num_vertices(); i++)
577 mesh_vertices[i] = view(i);
583 template<
typename MonitorFn_>
588 const MonitorFn_& monitor_fn)
593 const auto& vertices = mesh.get_vertex_set();
597 for(
Index i(0); i < mesh.get_num_vertices(); i++)
599 monitor_view[i] = monitor_fn(vertices[i]);
606 area.component_invert(area);
608 quality_function.component_product(area, monitor);
611 Assembly::integrate_error_function<0>(
613 Analytic::Common::ConstantFunction<dim>(1.0),
614 quality_function.local(),
618 double quality_max =
Math::abs(quality_function.max_abs_element() - 1.0);
644 auto int_a = Assembly::integrate_discrete_function<0>(domain_assembler, a.
local(), space,
"auto-degree:5").value;
645 auto int_b = Assembly::integrate_discrete_function<0>(domain_assembler, b.
local(), space,
"auto-degree:5").value;
652 b.
scale(b, int_a / int_b);
662 std::vector<DataType> cell_volumes(mesh.get_num_entities(
dim));
663 for(
Index i(0); i < mesh.get_num_entities(
dim); i++)
675 for(
Index i(0); i < mesh.get_num_vertices(); i++)
687 for(
Index i(0); i < mesh.get_num_vertices(); i++)
693 area += cell_volumes[*it];
696 view[i] = area / freq_view(i);
706 template<
typename Rhs_>
709 const Real t_start(0);
710 const Real t_end(1.0);
711 const Real stepsize(0.05);
716 for(
Real t(t_start); t < t_end; t += stepsize)
726 x_tmp.
axpy(k1, -stepsize);
Adjacency Graph implementation.
ImageIterator image_begin(Index domain_node) const
Returns an iterator for the first adjacent image node.
ImageIterator image_end(Index domain_node) const
Returns an iterator for the first position past the last adjacent image node.
Index degree(Index domain_node) const
Returns the degree of a domain node.
Identity operator implementation.
-Laplace operator implementation
static ScalarDiscreteEvalData< DT_, dim_ > eval_fe_function(const Tiny::Vector< DTP_, dim_, s_ > &point, const LAFEM::DenseVector< DT_, IT_ > &vector, const Space_ &space)
Evaluates a scalar finite-element function in a given point.
static void project_gradient(VectorOut_ &vector, const VectorIn_ &coeff, const Space_ &space)
Projects the gradient of a scalar discrete function into the vertices.
Domain Integral Assembler class template.
void compile_all_elements()
Compiles the assembler for all elements of the underlying mesh.
static MeshPart make(Mesh_ &mesh, const MeshPart &boundary, typename Mesh_::CoordType critial_angle=0.34)
Creates a MeshPart whose target sets contain all feature entities of the given boundary.
Mean Filter assembler class.
static void assemble(LAFEM::DenseVector< DataType_, IndexType_ > &vec_prim, LAFEM::DenseVector< DataType_, IndexType_ > &vec_dual, const Space_ &space, const String &cubature_name)
Assembles an integral mean filter.
ProjectionFilter assembler class template.
void assemble(LAFEM::ProjectionFilter< MeshType, DataType_, IndexType_ > &filter, Space_ &space, const Gate_ *gate=nullptr) const
Assemble a ProjectionFilter.
void add_mesh_part(const Geometry::MeshPart< MeshType > &mesh_part)
Adds the given MeshPart to the Neumann boundary.
void add_feature_mesh_part(const Geometry::MeshPart< MeshType > &mesh_part)
Adds the given MeshPart to the boundary features.
static void assemble_matrix_std1(MatrixType_ &matrix, const Space_ &space)
Assembles a standard matrix structure from a single space.
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
int rank() const
Returns the rank of this process in this communicator.
static Comm world()
Returns a copy of the world communicator.
GlobalMaskedBoundaryFactory implementation.
void compile(const Dist::Comm &comm)
Compiles the factory.
void add_halo(int rank, const MeshPart< ParentMeshType > &halo)
Adds a halo to the mask and saves it for synchronization.
MeshType * get_mesh()
Returns the mesh of this node.
Class template for partial meshes.
Index get_num_entities(int dim) const
Returns the number of entities.
Root mesh node class template.
const std::map< int, std::unique_ptr< MeshPartType > > & get_halo_map() const
Global Filter wrapper class template.
Global gate implementation.
std::vector< InvMapDataType > unmap_points(const PointRange_ &points)
Unmap a range of points.
Global Matrix wrapper class template.
LocalMatrix_ & local()
Returns a reference to the internal local LAFEM matrix object.
MPI-abstraction for running scalar lambdas on other ranks.
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.
Vector clone(LAFEM::CloneMode mode=LAFEM::CloneMode::Weak) const
Creates and returns a clone of this global vector.
void component_invert(const Vector &x, const DataType alpha=DataType(1))
Computes the component-wise inverse of a vector.
LocalVector_ & local()
Returns a reference to the internal local LAFEM vector object.
void axpy(const Vector &x, const DataType alpha=DataType(1))
Performs an AXPY operation: this <- this + alpha*x.
void scale(const Vector &x, const DataType alpha)
Sets this to a scaled vector: this <- alpha*x.
void sync_0()
Performs a type-0 synchronization of the vector, i.e. sums up all local DOF contributions.
void format()
Reset all elements of the container to a given value or zero if missing.
Blocked Dense data vector class template.
void axpy(const DenseVectorBlocked &x, const DT_ alpha=DT_(1))
Calculate .
DenseVectorBlocked clone(CloneMode clone_mode=CloneMode::Deep) const
Clone operation.
Dense data vector class template.
Mean Filter class template.
Enforces homogenous Neumann boundary conditions in normal direction by projecting onto the boundary.
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.
Handles vector prolongation, restriction and serialization.
Polymorphic solver interface.
Standard Lagrange-1 Finite-Element space class template.
Index get_num_dofs() const
Returns the number of dofs.
Data structure for InverseMapping evaluations.
std::vector< Index > cells
the indices of the cells that intersect with the image point
std::vector< DomainPointType > dom_points
the domain points on each cell that map onto the image point
Standard transformation mapping class template.
CoordType_ compute_vol(const Index cell) const
Computes the volume of one cell.
@ transpose
Render-Transpose mode.
void assemble_bilinear_operator_matrix_1(DomainAssembler< Trafo_ > &dom_asm, Matrix_ &matrix, const BilOp_ &bilinear_operator, const Space_ &space, const String &cubature, const typename Matrix_::DataType alpha=typename Matrix_::DataType(1))
Assembles a bilinear operator into a matrix with identical test- and trial-spaces.
void assemble_bilinear_operator_apply_vector_1(DomainAssembler< Trafo_ > &dom_asm, Vector_ &vector, const VectorSol_ &vec_sol, const BilOp_ &bilinear_operator, const Space_ &space, const String &cubature, const typename Vector_::DataType alpha=typename Vector_::DataType(1))
Assembles the application of a bilinear operator into a vector with identical test- and trial-spaces.
const Operation op_max(MPI_MAX)
Operation wrapper for MPI_MAX.
const Operation op_sum(MPI_SUM)
Operation wrapper for MPI_SUM.
T_ sqrt(T_ x)
Returns the square-root of a value.
T_ abs(T_ x)
Returns the absolute value.
Status solve(SolverBase< Vector_ > &solver, Vector_ &vec_sol, const Vector_ &vec_rhs, const Matrix_ &matrix, const Filter_ &filter)
Solve linear system with initial solution guess.
double Real
Real data type.
std::uint64_t Index
Index data type.
@ dom_point
specifies whether the trafo should supply domain point coordinates