FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
mesh_deformer.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5#pragma once
6
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>
46
47namespace FEAT::MeshOpt
48{
49 namespace
50 {
52 template<typename T_>
53 struct ViewRange
54 {
55 Memory::TypedView<T_> view;
56
57 T_* begin()
58 {
59 return &view[0];
60 }
61
62 const T_* begin() const
63 {
64 return &view[0];
65 }
66
67 T_* end()
68 {
69 return &view[view.size()];
70 }
71
72 const T_* end() const
73 {
74 return &view[view.size()];
75 }
76 };
77 } // namespace
78
81 {
86 };
87
98 template<typename MeshType_>
100 {
101 public:
103 using MeshType = MeshType_;
107 static constexpr int dim = MeshType::world_dim;
109 using VertexType = typename MeshType::VertexType;
115 using DataType = typename MeshType::CoordType;
143 using SolverFactory = std::function<std::shared_ptr<SolverType>(const MatrixType&, const FilterType&)>;
146
147 protected:
150 { return Solver::new_gmres(m, f, 10); };
151
154
157
160
162 GateType* _gate = nullptr;
165
166 public:
168 explicit MeshDeformer(GateType* gate) : _gate(gate), _comm(_gate->get_comm()->comm_dup())
169 {
170 }
171
190 {
192 }
193
211 {
212 _blend_steps = steps;
213 }
214
226 {
227 _solver_factory = std::move(factory);
228 }
229
231 void keep_boundary_fixed(bool fixed)
232 {
233 _keep_boundary_fixed = fixed;
234 }
235
248 template<typename MonitorFn_>
249 MeshDeformerQuality deform(Geometry::RootMeshNode<MeshType_>& mesh_node, const MonitorFn_& monitor_fn)
250 {
251 const Real blend_delta = Real(1) / Real(_blend_steps);
252
253 // Prepare for deformation
254 MeshType& mesh = *mesh_node.get_mesh();
255 TrafoType trafo(mesh);
256 SpaceType space(trafo);
257
258 // Determine mesh boundary for handling boundary values
260 for(auto& [rank, halo] : mesh_node.get_halo_map())
261 {
262 boundary_factory.add_halo(rank, *halo);
263 }
264 boundary_factory.compile(_comm);
265 Geometry::MeshPart<MeshType> boundary(boundary_factory);
266
267 // Determine surface features we want to maintain
269
270 // Assemble projection filter to enforce strong boundary conditions
271 ProjectionFilterType projection_filter;
273 {
274 const auto& tgs = boundary.template get_target_set<0>();
275 const auto& vertices = mesh.get_vertex_set();
276 for(Index i(0); i < boundary.get_num_entities(0); i++)
277 {
278 projection_filter.add_fixed_dof(tgs[i], vertices[tgs[i]]);
279 }
280 }
281 else
282 {
283 // Normal boundary conditions
284 // Project boundary back onto boundary or onto closest feature
285 Assembly::ProjectionFilterAssembler<MeshType> projection_filter_assembler;
286 projection_filter_assembler.add_mesh_part(boundary);
287 projection_filter_assembler.add_feature_mesh_part(features);
288 projection_filter_assembler.assemble(projection_filter, space, _gate);
289 }
290
291 Assembly::DomainAssembler<TrafoType> domain_assembler(trafo);
292 domain_assembler.compile_all_elements();
293
294 // Iteratively deform
295
296 MeshDeformerQuality current_quality{};
297
298 // Blend loop. Interpolate between current area function and target monitor function.
299 // Loop i blends with factor (i + 1) * blend_delta
300 for(Index i(0); i < _blend_steps; i++)
301 {
302 // Iterative loop
303 // Re-assemble the Poisson problem on the already deformed mesh to get a better solution on the next solve.
304 for(Index j(0); j < _max_iters_per_blend_step; j++)
305 {
306 // Deform the mesh
307 _deform(
308 mesh,
309 trafo,
310 space,
311 domain_assembler,
312 projection_filter,
313 monitor_fn,
314 DataType(i + 1) * blend_delta);
315
316 // Determine quality of deformed mesh
317 current_quality = _quality(mesh, space, domain_assembler, monitor_fn);
318
319 // Exit early upon reaching sufficient quality
320 // Value of 0.05 is taken from the paper
321 if(current_quality.l2norm < 0.05)
322 {
323 break;
324 }
325 }
326 }
327
328 return current_quality;
329 }
330
336 template<typename MonitorFn_>
337 MeshDeformerQuality quality(Geometry::RootMeshNode<MeshType>& mesh_node, const MonitorFn_& monitor_fn)
338 {
339 // Set up trafo, space, and domain assembler
340 MeshType& mesh = *mesh_node.get_mesh();
341
342 TrafoType trafo(mesh);
343 SpaceType space(trafo);
344
345 Assembly::DomainAssembler<TrafoType> domain_assembler(trafo);
346 domain_assembler.compile_all_elements();
347
348 // Calculate quality
349 return _quality(mesh, space, domain_assembler, monitor_fn);
350 }
351
352 protected:
354 template<typename MonitorFn_>
356 MeshType& mesh,
357 const TrafoType& trafo,
358 const SpaceType& space,
359 Assembly::DomainAssembler<TrafoType>& domain_assembler,
360 const ProjectionFilterType& projection_filter,
361 const MonitorFn_& monitor_lambda,
362 Real blend_factor = 1.0)
363 {
364 // Compute area function g and monitor function f
365 VectorType area_fn = _area_function(mesh);
366 VectorType monitor_fn(_gate, space.get_num_dofs());
367 {
368 const auto& vertices = mesh.get_vertex_set();
369 Memory::TypedView<DataType> view = monitor_fn.local().elements_view_w();
370 for(Index i(0); i < space.get_num_dofs(); i++)
371 {
372 view[i] = monitor_lambda(vertices[i]);
373 }
374 }
375
376 // We assume that the monitor_function will produce the same value for the same point on all ranks,
377 // so no synchronization of monitor_fn is necessary.
378
379 // Create inverse functions
380 VectorType inv_area_fn(_gate, space.get_num_dofs());
381 VectorType inv_monitor_fn(_gate, space.get_num_dofs());
382 {
383 if(blend_factor != DataType(1))
384 {
385 scale_to_same_integral_mean(domain_assembler, monitor_fn, area_fn, space);
386
387 // Blend
388 monitor_fn.scale(monitor_fn, blend_factor);
389 monitor_fn.axpy(area_fn, DataType(1) - blend_factor);
390 }
391
392 // Invert
393 inv_monitor_fn.component_invert(monitor_fn);
394 inv_area_fn.component_invert(area_fn);
395
396 scale_to_same_integral_mean(domain_assembler, inv_monitor_fn, inv_area_fn, space);
397 }
398
399 // Compute rhs (inv_monitor_fn - inv_area_fn)
400 VectorType rhs(_gate, space.get_num_dofs());
401 rhs.format();
402 {
403 VectorType tmp = inv_monitor_fn.clone();
404 tmp.axpy(inv_area_fn, DataType(-1));
405
408 domain_assembler,
409 rhs.local(),
410 tmp.local(),
411 op,
412 space,
413 "auto-degree:5");
414 rhs.sync_0();
415 }
416
417 // Solve -laplace w = rhs with integral mean 0
418 VectorType solution(_gate, space.get_num_dofs());
419 {
420 solution.local().format();
421
422 MatrixType matrix(_gate, _gate);
424 matrix.local().format();
425
426 Assembly::Common::LaplaceOperator laplace_operator;
428 domain_assembler,
429 matrix.local(),
430 laplace_operator,
431 space,
432 "auto-degree:3");
433
434 Assembly::MeanFilterAssembler mean_assembler;
435 FilterType mean_filter;
436 mean_assembler.assemble(mean_filter.local(), space, "auto-degree:3", DataType(0.0));
437
438 mean_filter.local().filter_mat(matrix.local());
439 mean_filter.filter_rhs(rhs);
440 mean_filter.filter_sol(solution);
441
442 auto solver = _solver_factory(matrix, mean_filter);
443
444 solver->init();
445 Solver::solve(*solver, solution, rhs, matrix, mean_filter);
446 solver->done();
447 }
448
449 LocalBlockedVectorType velocity(space.get_num_dofs());
450 velocity.format();
452
453 // Strictly enforce boundary conditions by projecting velocity onto the boundary
454 projection_filter.filter_def(velocity);
455
456 LocalInverseMappingType inv_mapping(trafo, 0.1, 1E-2);
457 InverseMappingType global_unmapping(_comm, inv_mapping);
458
459 // Solve ODEs
460 {
461 // Copy vertices into blocked vector so that we can do math on them
462 LocalBlockedVectorType vertices(mesh.get_num_vertices());
463 {
464 const auto& mesh_vertices = mesh.get_vertex_set();
465 Memory::TypedView<VertexType> view = vertices.elements_view_w();
466 for(Index i(0); i < mesh.get_num_vertices(); i++)
467 {
468 view[i] = mesh_vertices[i];
469 }
470 }
471
472 auto moved_vertices = runge_kutta_3(
473 vertices,
474 [&](DataType t, const LocalBlockedVectorType& vs)
475 {
476 LocalBlockedVectorType ode_rhs(mesh.get_num_vertices());
477 Memory::TypedView<VertexType> view_out = ode_rhs.elements_view_w();
478
479 // TODO: Abstract the following into a Global::DiscreteEvaluator class
480
481 // Unmap all points
482 std::vector<Global::GlobalInverseMappingData<DataType, dim>> unmapping =
483 global_unmapping.unmap_points(ViewRange<VertexType>{vs.elements_view_r()});
484
485 // Eval f, g, v
486 struct EvalResult
487 {
488 DataType f;
489 DataType g;
490 VertexType v;
491
492 static Dist::Typemap typemap()
493 {
494 return Dist::Typemap{}
495 .template add_entry<DataType>(offsetof(EvalResult, f))
496 .template add_entry<DataType>(offsetof(EvalResult, g))
497 .template add_entry<VertexType>(offsetof(EvalResult, v));
498 }
499 };
500
501 std::vector<int> ranks;
502 std::vector<Index> indices;
503 std::vector<std::tuple<VertexType, Index, int>> args;
504
505 for(Index i(0); i < unmapping.size(); i++)
506 {
507 if(unmapping[i].size() == 0)
508 {
509 // Unmapping for this point failed.
510 // We call the lambda with the index of the vertex as a fallback
511 ranks.push_back(_comm.rank());
512 indices.push_back(i);
513 args.emplace_back(VertexType(0.0), i, 0);
514 }
515 else
516 {
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);
520 }
521 }
522
523 Global::ScalarRemoteLambda<EvalResult(VertexType, Index, int)> remote_eval(_comm);
524 std::vector<EvalResult> evals = remote_eval.call(
525 ranks,
526 indices,
527 args,
528 [&](VertexType dom_point, Index cell, int success)
529 {
530 if(success == 0)
531 {
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);
535
536 return EvalResult{f, g, v};
537 }
538 else
539 {
541 inv_map_data.cells.push_back(cell);
542 inv_map_data.dom_points.push_back(dom_point);
543
544 const DataType f =
545 Assembly::DiscreteEvaluator::eval_fe_function(inv_map_data, inv_monitor_fn.local(), space)
546 .mean_value();
547 const DataType g =
548 Assembly::DiscreteEvaluator::eval_fe_function(inv_map_data, inv_area_fn.local(), space)
549 .mean_value();
550 const VertexType v =
551 Assembly::DiscreteEvaluator::eval_fe_function(inv_map_data, velocity, space).mean_value();
552
553 return EvalResult{f, g, v};
554 }
555 });
556
557 FEAT_PRAGMA_OMP(parallel for)
558 for(Index i = 0; i < mesh.get_num_vertices(); i++)
559 {
560 const DataType f = evals[i].f;
561 const DataType g = evals[i].g;
562 const VertexType v = evals[i].v;
563 const DataType denom = t * f + (DataType(1.0) - t) * g;
564
565 view_out[i] = (DataType(1.0) / denom) * v;
566 }
567
568 return std::move(ode_rhs);
569 });
570
571 // Copy moved vertices back into mesh
572 {
573 auto& mesh_vertices = mesh.get_vertex_set();
574 Memory::TypedView<VertexType> view = moved_vertices.elements_view_r();
575 for(Index i(0); i < mesh.get_num_vertices(); i++)
576 {
577 mesh_vertices[i] = view(i);
578 }
579 }
580 }
581 }
582
583 template<typename MonitorFn_>
584 MeshDeformerQuality _quality(
585 MeshType& mesh,
586 const SpaceType& space,
588 const MonitorFn_& monitor_fn)
589 {
590 VectorType area = _area_function(mesh);
591 VectorType monitor(_gate, mesh.get_num_vertices());
592 {
593 const auto& vertices = mesh.get_vertex_set();
594
595 Memory::TypedView<DataType> monitor_view = monitor.local().elements_view_w();
596
597 for(Index i(0); i < mesh.get_num_vertices(); i++)
598 {
599 monitor_view[i] = monitor_fn(vertices[i]);
600 }
601 }
602
603 // Scale deformed_area_function
604 scale_to_same_integral_mean(assembler, monitor, area, space);
605
606 area.component_invert(area);
607 VectorType quality_function(_gate, space.get_num_dofs());
608 quality_function.component_product(area, monitor);
609
610 double quality = Math::sqrt(
611 Assembly::integrate_error_function<0>(
612 assembler,
613 Analytic::Common::ConstantFunction<dim>(1.0),
614 quality_function.local(),
615 space,
616 "auto-degree:5")
617 .norm_h0_sqr);
618 double quality_max = Math::abs(quality_function.max_abs_element() - 1.0);
619
621 _comm.allreduce(&quality_max, &quality_max, 1, Dist::op_max);
622
623 return {quality, quality_max};
624 }
625
639 Assembly::DomainAssembler<TrafoType>& domain_assembler,
640 const VectorType& a,
641 VectorType& b,
642 const SpaceType& space)
643 {
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;
646
647 // Add up integrals on all ranks
648 _comm.allreduce(&int_a, &int_a, 1, Dist::op_sum);
649 _comm.allreduce(&int_b, &int_b, 1, Dist::op_sum);
650
651 // Choose alpha such that alpha * int_b = int_a
652 b.scale(b, int_a / int_b);
653 }
654
656 VectorType _area_function(MeshType_& mesh)
657 {
658 TrafoType trafo(mesh);
659 VectorType area_fn(_gate, mesh.get_num_vertices(), 0);
660
661 // Precompute cell volumes
662 std::vector<DataType> cell_volumes(mesh.get_num_entities(dim));
663 for(Index i(0); i < mesh.get_num_entities(dim); i++)
664 {
665 cell_volumes[i] = trafo.compute_vol(i);
666 }
667
668 // Render cells@vertices
669 const Adjacency::Graph c_at_v(Adjacency::RenderType::transpose, mesh.template get_index_set<dim, 0>());
670
671 // Create frequency vector
672 VectorType freqs(_gate, mesh.get_num_vertices());
673 {
674 Memory::TypedView<DataType> view = freqs.local().elements_view_w();
675 for(Index i(0); i < mesh.get_num_vertices(); i++)
676 {
677 view[i] = DataType(c_at_v.degree(i));
678 }
679 }
680
681 // Sync number of adjacent cells
682 freqs.sync_0();
683
684 {
685 Memory::TypedView<DataType> view = area_fn.local().elements_view_w();
686 Memory::TypedView<DataType> freq_view = freqs.local().elements_view_r();
687 for(Index i(0); i < mesh.get_num_vertices(); i++)
688 {
689 // Compute average cell area
690 DataType area(0.0);
691 for(auto it = c_at_v.image_begin(i); it != c_at_v.image_end(i); ++it)
692 {
693 area += cell_volumes[*it];
694 }
695
696 view[i] = area / freq_view(i);
697 }
698 }
699
700 area_fn.sync_0();
701
702 return area_fn;
703 }
704
706 template<typename Rhs_>
707 static LocalBlockedVectorType runge_kutta_3(const LocalBlockedVectorType& initial, const Rhs_& rhs)
708 {
709 const Real t_start(0);
710 const Real t_end(1.0);
711 const Real stepsize(0.05);
712
713 LocalBlockedVectorType x = initial.clone();
714
715 // Perform 100 steps of Runge-Kutta 3
716 for(Real t(t_start); t < t_end; t += stepsize)
717 {
718 // std::cerr << "x = " << x << "\n";
719 const LocalBlockedVectorType k1 = rhs(t, x);
720 // std::cerr << "k1 = " << k1 << "\n";
721 LocalBlockedVectorType x_tmp = x.clone();
722 x_tmp.axpy(k1, stepsize / DataType(2));
723 const LocalBlockedVectorType k2 = rhs(t + (stepsize / Real(2)), x_tmp);
724 // std::cerr << "k2 = " << k2 << "\n";
725 x_tmp = x.clone();
726 x_tmp.axpy(k1, -stepsize);
727 x_tmp.axpy(k2, DataType(2) * stepsize);
728 const LocalBlockedVectorType k3 = rhs(t + stepsize, x_tmp);
729 // std::cerr << "k3 = " << k3 << "\n";
730
731 x.axpy(k1, stepsize / DataType(6));
732 x.axpy(k2, stepsize / DataType(6) * 4);
733 x.axpy(k3, stepsize / DataType(6));
734 // std::cerr << "x = " << x << "\n";
735 }
736
737 return x;
738 }
739 };
740
741} // namespace FEAT::MeshOpt
FEAT Kernel base header.
Adjacency Graph implementation.
Definition: graph.hpp:34
ImageIterator image_begin(Index domain_node) const
Returns an iterator for the first adjacent image node.
Definition: graph.hpp:964
ImageIterator image_end(Index domain_node) const
Returns an iterator for the first position past the last adjacent image node.
Definition: graph.hpp:972
Index degree(Index domain_node) const
Returns the degree of a domain node.
Definition: graph.hpp:333
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.
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.
Communicator class.
Definition: dist.hpp:1657
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
Definition: dist.cpp:658
int rank() const
Returns the rank of this process in this communicator.
Definition: dist.hpp:1802
static Comm world()
Returns a copy of the world communicator.
Definition: dist.cpp:432
MPI typemap description.
Definition: dist.hpp:228
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.
Definition: mesh_node.hpp:225
Class template for partial meshes.
Definition: mesh_part.hpp:90
Index get_num_entities(int dim) const
Returns the number of entities.
Definition: mesh_part.hpp:311
Root mesh node class template.
Definition: mesh_node.hpp:748
const std::map< int, std::unique_ptr< MeshPartType > > & get_halo_map() const
Definition: mesh_node.hpp:896
Global Filter wrapper class template.
Definition: filter.hpp:21
Global gate implementation.
Definition: gate.hpp:78
Global inverse mapping.
std::vector< InvMapDataType > unmap_points(const PointRange_ &points)
Unmap a range of points.
Global Matrix wrapper class template.
Definition: matrix.hpp:40
LocalMatrix_ & local()
Returns a reference to the internal local LAFEM matrix object.
Definition: matrix.hpp:136
MPI-abstraction for running scalar lambdas on other ranks.
Global vector wrapper class template.
Definition: vector.hpp:68
void format(DataType alpha=DataType(0))
Reset all elements of the container to a given value or zero if missing.
Definition: vector.hpp:318
Vector clone(LAFEM::CloneMode mode=LAFEM::CloneMode::Weak) const
Creates and returns a clone of this global vector.
Definition: vector.hpp:285
void component_invert(const Vector &x, const DataType alpha=DataType(1))
Computes the component-wise inverse of a vector.
Definition: vector.hpp:483
LocalVector_ & local()
Returns a reference to the internal local LAFEM vector object.
Definition: vector.hpp:122
void axpy(const Vector &x, const DataType alpha=DataType(1))
Performs an AXPY operation: this <- this + alpha*x.
Definition: vector.hpp:366
void scale(const Vector &x, const DataType alpha)
Sets this to a scaled vector: this <- alpha*x.
Definition: vector.hpp:380
void sync_0()
Performs a type-0 synchronization of the vector, i.e. sums up all local DOF contributions.
Definition: vector.hpp:188
void format()
Reset all elements of the container to a given value or zero if missing.
Definition: container.hpp:831
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.
Definition: mean_filter.hpp:22
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.
CSR based sparse matrix.
Handles vector prolongation, restriction and serialization.
Typed memory view class.
Deforms mesh towards target cell sizes.
VectorType _area_function(MeshType_ &mesh)
Returns a vector of average cell areas of all cells surrounding each vertex.
Index _max_iters_per_blend_step
Maximum number of iterations for each blend step.
void keep_boundary_fixed(bool fixed)
If set to true, no vertex on the boundary will be moved.
void set_solver_factory(SolverFactory &&factory)
Set solver factory.
void set_blend_steps(Index steps)
Set number of blend steps.
GateType * _gate
Gate for synchronization in MPI parallel build.
MeshType_ MeshType
Mesh type.
std::function< std::shared_ptr< SolverType >(const MatrixType &, const FilterType &)> SolverFactory
Solver factory type for setting which solver to use for Poisson-Problem.
Index _blend_steps
Number of blend steps.
Global::Vector< LocalVectorType, MirrorType > VectorType
Global scalar vector type.
Space::Lagrange1::Element< TrafoType > SpaceType
Space type. This is the space that gets used to discretize the Poisson-Problem.
void set_max_iters_per_blend_step(Index iters)
Sets the maximum number of iterations during each blend step.
SolverFactory _solver_factory
Solver factory function.
void _deform(MeshType &mesh, const TrafoType &trafo, const SpaceType &space, Assembly::DomainAssembler< TrafoType > &domain_assembler, const ProjectionFilterType &projection_filter, const MonitorFn_ &monitor_lambda, Real blend_factor=1.0)
Deform the given mesh towards the cells sizes given by the monitor function.
void scale_to_same_integral_mean(Assembly::DomainAssembler< TrafoType > &domain_assembler, const VectorType &a, VectorType &b, const SpaceType &space)
Scale pair of vectors such that their integrals agree.
MeshDeformer(GateType *gate)
Constructor.
typename MeshType::CoordType DataType
Data type.
static constexpr int dim
Number of coords of vertices.
MeshDeformerQuality deform(Geometry::RootMeshNode< MeshType_ > &mesh_node, const MonitorFn_ &monitor_fn)
Deform mesh to match monitor function.
typename MeshType::VertexType VertexType
Vertex type.
MeshDeformerQuality quality(Geometry::RootMeshNode< MeshType > &mesh_node, const MonitorFn_ &monitor_fn)
Calculate the quality of the given mesh compared to the given monitor function.
bool _keep_boundary_fixed
If true, boundary vertices are not allowed to move at all.
static LocalBlockedVectorType runge_kutta_3(const LocalBlockedVectorType &initial, const Rhs_ &rhs)
Solve ODE via RK3.
Dist::Comm _comm
MPI Communicator.
Polymorphic solver interface.
Definition: base.hpp:183
Standard Lagrange-1 Finite-Element space class template.
Definition: element.hpp:39
Index get_num_dofs() const
Returns the number of dofs.
Definition: element.hpp:120
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.
Definition: mapping.hpp:39
CoordType_ compute_vol(const Index cell) const
Computes the volume of one cell.
Definition: mapping.hpp:99
@ 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.
Definition: dist.hpp:573
const Operation op_sum(MPI_SUM)
Operation wrapper for MPI_SUM.
Definition: dist.hpp:571
T_ sqrt(T_ x)
Returns the square-root of a value.
Definition: math.hpp:300
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
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.
Definition: base.hpp:347
double Real
Real data type.
std::uint64_t Index
Index data type.
@ dom_point
specifies whether the trafo should supply domain point coordinates
Quality measures of mesh deformation.
Real l2norm
Quality measure in L2 norm.
Real maxnorm
Quality measure in point-wise maximum norm.