FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
mesh_concentration_function.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
6#pragma once
7
9#include <kernel/shape.hpp>
10
11#include <kernel/analytic/common.hpp>
12#include <kernel/geometry/mesh_node.hpp>
13#include <kernel/geometry/intern/face_index_mapping.hpp>
14#include <kernel/meshopt/rumpf_trafo.hpp>
16#include <kernel/util/property_map.hpp>
17#include <kernel/util/dist.hpp>
18
19#include <deque>
20
21namespace FEAT
22{
23 namespace Meshopt
24 {
25
27
28 // Forward declarations
29 template<typename DT_>
30 class ConcentrationFunctionDefault;
31
32 template<typename DT_>
33 class ConcentrationFunctionPowOfDist;
35
52 template<typename DT_, typename ShapeType_>
53#ifndef DOXYGEN
54 struct AlignmentPenalty;
55#else
56 // Note: The following block is only visible for Doxygen. The implementation has to be provided by specializations
57 // in ShapeType_
59 {
61 typedef DT_ DataType;
64
89 template<typename Mesh_, typename Dist_, typename EdgeFreqs_>
90 static DataType compute_constraint(const Mesh_& DOXY(mesh), const Dist_& DOXY(dist),
91 const EdgeFreqs_& DOXY(edge_freqs))
92 {
93 }
94
118 template<typename Mesh_, typename Dist_>
119 static DataType compute_constraint(DataType* constraint_vec, const Mesh_& mesh, const Dist_& dist)
120 {
121 }
122
163 template<typename Vector_, typename Mesh_, typename Dist_, typename GradDist_, typename EdgeFreqs_>
165 Vector_& DOXY(grad), const DataType DOXY(alignment_fval), const DataType DOXY(fac),
166 const Mesh_& DOXY(mesh), const Dist_& DOXY(dist), const GradDist_& DOXY(grad_dist),
167 const EdgeFreqs_& DOXY(edge_freqs))
168 {
169 }
170
171 };
172#endif
173
175 template<typename DT_, int shape_dim>
176 struct AlignmentPenalty<DT_, Shape::Simplex<shape_dim>>
177 {
178 typedef DT_ DataType;
180
181 template<typename Mesh_, typename Dist_, typename EdgeFreqs_>
182 static DataType compute_constraint(const Mesh_& mesh, const Dist_& dist, const EdgeFreqs_& edge_freqs)
183 {
184 DataType constraint(0);
185 const auto& edge_idx = mesh.template get_index_set<1,0>();
186 const auto vd = dist.elements_view_r();
187 const auto vef = edge_freqs.elements_view_r();
188 for(Index edge(0); edge < mesh.get_num_entities(1); ++edge)
189 {
190 constraint += vef(edge)*FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
191 eval( - vd(edge_idx(edge,0)) * vd(edge_idx(edge,1)));
192 }
193
194 return constraint;
195 }
196
197 template<typename Mesh_, typename Dist_>
198 static DataType compute_constraint(DataType* constraint_vec, const Mesh_& mesh, const Dist_& dist)
199 {
200 XASSERT(constraint_vec != nullptr);
201 typedef Geometry::Intern::FaceIndexMapping<ShapeType, 1, 0> FimType;
202
203 DataType constraint(0);
204 const auto& idx = mesh.template get_index_set<ShapeType::dimension,0>();
205 const auto vd = dist.elements_view_r();
206 for(Index cell(0); cell < mesh.get_num_entities(ShapeType::dimension); ++cell)
207 {
208 constraint_vec[cell] = DataType(0);
209 for(int edge(0); edge < Shape::FaceTraits<ShapeType,1>::count; ++edge)
210 {
211 //These are the indices of the vertices on edge
212 int i(FimType::map(edge,0));
213 int j(FimType::map(edge,1));
214 DataType my_constraint(FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
215 eval(- DataType(1)*vd(idx(cell, i)) * vd(idx(cell, j))) );
216
217 constraint_vec[cell] += my_constraint;
218
219 constraint += my_constraint;
220 }
221
222 }
223
224 return constraint;
225 }
226
227 template<typename Vector_, typename Mesh_, typename Dist_, typename GradDist_, typename EdgeFreqs_>
228 static void add_constraint_grad(
229 Vector_& grad, const DataType alignment_fval, const DataType fac, const Mesh_& mesh, const Dist_& dist, const GradDist_& grad_dist, const EdgeFreqs_& edge_freqs)
230 {
231 const auto& edge_idx = mesh.template get_index_set<1,0>();
233 typedef Tiny::Vector<DataType, Mesh_::world_dim> WorldPoint;
234
235 WorldPoint grad_loc(DataType(0));
236 auto vg = grad.elements_view_w();
237 const auto vd = dist.elements_view_r();
238 const auto vgd = grad_dist.elements_view_r();
239 const auto vef = edge_freqs.elements_view_r();
240 for(Index edge(0); edge < mesh.get_num_entities(1); ++edge)
241 {
242 Index i(edge_idx(edge,0));
243 Index j(edge_idx(edge,1));
244
245 auto dist_prod = vd(i) * vd(j);
246 // Derivative of the heaviside function
247 auto heaviside_der = FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::der_x(-dist_prod);
248
249 grad_loc = (-fac * alignment_fval * heaviside_der * vd(j)) * vgd(i);
250 vg[i] += vef(edge)*grad_loc;
251
252 grad_loc = (-fac * alignment_fval * heaviside_der * vd(i)) * vgd(j);
253 vg[j] += vef(edge)*grad_loc;
254 }
255 }
256
257 };
258
259 template<typename DT_>
260 struct AlignmentPenalty<DT_, Shape::Hypercube<2>>
261 {
262
263 typedef DT_ DataType;
264 typedef Shape::Hypercube<2> ShapeType;
265
266 template<typename Mesh_, typename Dist_, typename EdgeFreqs_>
267 static DataType compute_constraint(const Mesh_& mesh, const Dist_& dist, const EdgeFreqs_& edge_freqs)
268 {
269 DataType constraint(0);
270 const auto& edge_idx = mesh.template get_index_set<1,0>();
271 const auto vd = dist.elements_view_r();
272 const auto vef = edge_freqs.elements_view_r();
273 for(Index edge(0); edge < mesh.get_num_entities(1); ++edge)
274 {
275 constraint += vef(edge)*FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
276 eval( - vd(edge_idx(edge,0)) * vd(edge_idx(edge,1)));
277 }
278
279 const auto& cell_idx = mesh.template get_index_set<ShapeType::dimension,0>();
280 for(Index cell(0); cell < mesh.get_num_entities(ShapeType::dimension); ++cell)
281 {
282 constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
283 eval( - vd(cell_idx(cell,0)) * vd(cell_idx(cell,3)));
284 constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
285 eval( - vd(cell_idx(cell,1)) * vd(cell_idx(cell,2)));
286 }
287
288 return constraint;
289 }
290
291 template<typename Mesh_, typename Dist_>
292 static DataType compute_constraint(DataType* constraint_vec, const Mesh_& mesh, const Dist_& dist)
293 {
294 XASSERT(constraint_vec != nullptr);
295 typedef Geometry::Intern::FaceIndexMapping<ShapeType, 1, 0> FimType;
296
297 DataType constraint(0);
298 const auto& idx = mesh.template get_index_set<ShapeType::dimension,0>();
299 const auto vd = dist.elements_view_r();
300 for(Index cell(0); cell < mesh.get_num_entities(ShapeType::dimension); ++cell)
301 {
302 constraint_vec[cell] = DataType(0);
303 for(int edge(0); edge < Shape::FaceTraits<ShapeType,1>::count; ++edge)
304 {
305 //These are the indices of the vertices on edge
306 int i(FimType::map(edge,0));
307 int j(FimType::map(edge,1));
308 DataType my_constraint(FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
309 eval(- DataType(1)*vd(idx(cell, i)) * vd(idx(cell, j))) );
310
311 constraint_vec[cell] += my_constraint;
312
313 constraint += my_constraint;
314 }
315
316 DataType my_constraint(FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
317 eval( - vd(idx(cell,0)) * vd(idx(cell,3))));
318 my_constraint = FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
319 eval( - vd(idx(cell,1)) * vd(idx(cell,2)));
320
321 constraint_vec[cell] += my_constraint;
322
323 constraint += my_constraint;
324
325 }
326
327 return constraint;
328 }
329
330 template<typename Vector_, typename Mesh_, typename Dist_, typename GradDist_, typename EdgeFreqs_>
331 static void add_constraint_grad(
332 Vector_& grad, const DataType alignment_fval, const DataType fac, const Mesh_& mesh, const Dist_& dist,
333 const GradDist_& grad_dist, const EdgeFreqs_& edge_freqs)
334 {
335 const auto& edge_idx = mesh.template get_index_set<1,0>();
337 typedef Tiny::Vector<DataType, Mesh_::world_dim> WorldPoint;
338
339 WorldPoint grad_loc(DataType(0));
340 const auto vd = dist.elements_view_r();
341 auto vg = grad.elements_view_rw();
342 const auto vgd = grad_dist.elements_view_r();
343 const auto vef = edge_freqs.elements_view_r();
344
345 for(Index edge(0); edge < mesh.get_num_entities(1); ++edge)
346 {
347 Index i(edge_idx(edge,0));
348 Index j(edge_idx(edge,1));
349
350 auto dist_prod = vd(i) * vd(j);
351 // Derivative of the heaviside function
352 auto heaviside_der = FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::der_x(-dist_prod);
353
354 grad_loc = (-fac * alignment_fval * heaviside_der * vd(j)) * vgd(i);
355 vg[i] += vef(edge)*grad_loc;
356
357 grad_loc = (-fac * alignment_fval * heaviside_der * vd(i)) * vgd(j);
358 vg[j] += vef(edge)*grad_loc;
359 }
360
361 const auto& cell_idx = mesh.template get_index_set<ShapeType::dimension,0>();
362 for(Index cell(0); cell < mesh.get_num_entities(ShapeType::dimension); ++cell)
363 {
364 Index i(cell_idx(cell,Index(0)));
365 Index j(cell_idx(cell,Index(3)));
366
367 auto dist_prod = vd(i) * vd(j);
368 // Derivative of the heaviside function
369 auto heaviside_der = FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::der_x(-dist_prod);
370
371 grad_loc = (-fac * alignment_fval * heaviside_der * vd(j)) * vgd(i);
372 vg[i] += grad_loc;
373
374 grad_loc = (-fac * alignment_fval * heaviside_der * vd(i)) * vgd(j);
375 vg[j] += grad_loc;
376
377 i = cell_idx(cell,Index(1));
378 j = cell_idx(cell,Index(2));
379
380 dist_prod = vd(i) * vd(j);
381 // Derivative of the heaviside function
382 heaviside_der = FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::der_x(-dist_prod);
383
384 grad_loc = (-fac * alignment_fval * heaviside_der * vd(j)) * vgd(i);
385 vg[i] += grad_loc;
386
387 grad_loc = (-fac * alignment_fval * heaviside_der * vd(i)) * vgd(j);
388 vg[j] += grad_loc;
389 }
390 }
391 };
392
393 template<typename DT_>
394 struct AlignmentPenalty<DT_, Shape::Hypercube<3>>
395 {
396
397 typedef DT_ DataType;
398 typedef Shape::Hypercube<3> ShapeType;
399
400 template<typename Mesh_, typename Dist_, typename EdgeFreqs_>
401 static DataType compute_constraint(const Mesh_& mesh, const Dist_& dist, const EdgeFreqs_& edge_freqs)
402 {
403 DataType constraint(0);
404 const auto& edge_idx = mesh.template get_index_set<1,0>();
405 const auto vd = dist.elements_view_r();
406 const auto vef = edge_freqs.elements_view_r();
407 for(Index edge(0); edge < mesh.get_num_entities(1); ++edge)
408 {
409 constraint += vef(edge)*FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
410 eval( - vd(edge_idx(edge,0)) * vd(edge_idx(edge,1)));
411 }
412
413 const auto& face_idx = mesh.template get_index_set<2,0>();
414 for(Index face(0); face < mesh.get_num_entities(2); ++face)
415 {
416 constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
417 eval( - vd(face_idx(face,0)) * vd(face_idx(face,3)));
418 constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
419 eval( - vd(face_idx(face,1)) * vd(face_idx(face,2)));
420 }
421
422 const auto& cell_idx = mesh.template get_index_set<3,0>();
423 for(Index cell(0); cell < mesh.get_num_entities(3); ++cell)
424 {
425 constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
426 eval( - vd(cell_idx(cell,0)) * vd(cell_idx(cell,7)));
427 constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
428 eval( - vd(cell_idx(cell,1)) * vd(cell_idx(cell,6)));
429 constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
430 eval( - vd(cell_idx(cell,2)) * vd(cell_idx(cell,5)));
431 constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
432 eval( - vd(cell_idx(cell,3)) * vd(cell_idx(cell,4)));
433 }
434
435 return constraint;
436 }
437
438 template<typename Mesh_, typename Dist_>
439 static DataType compute_constraint(DataType* constraint_vec, const Mesh_& mesh, const Dist_& dist)
440 {
441 XASSERT(constraint_vec != nullptr);
442 typedef Geometry::Intern::FaceIndexMapping<ShapeType, 1, 0> VertAtEdge;
443 typedef Geometry::Intern::FaceIndexMapping<ShapeType, 2, 0> VertAtFace;
444
445 DataType constraint(0);
446 const auto vd = dist.elements_view_r();
447 const auto& idx = mesh.template get_index_set<ShapeType::dimension,0>();
448 for(Index cell(0); cell < mesh.get_num_entities(ShapeType::dimension); ++cell)
449 {
450 constraint_vec[cell] = DataType(0);
451
452 for(int edge(0); edge < Shape::FaceTraits<ShapeType,1>::count; ++edge)
453 {
454 //These are the indices of the vertices on edge
455 int i(VertAtEdge::map(edge,0));
456 int j(VertAtEdge::map(edge,1));
457 DataType my_constraint(FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
458 eval(- DataType(1)*vd(idx(cell, Index(i))) * vd(idx(cell, Index(j)))) );
459
460 constraint_vec[cell] += my_constraint;
461
462 constraint += my_constraint;
463 }
464
465 for(int face(0); face < Shape::FaceTraits<ShapeType,2>::count; ++face)
466 {
467 // These are the indices of the vertices on edge
468 int i0(VertAtFace::map(face,0));
469 int i1(VertAtFace::map(face,1));
470 int i2(VertAtFace::map(face,2));
471 int i3(VertAtFace::map(face,3));
472
473 DataType my_constraint(0);
474 my_constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
475 eval(- DataType(1)*vd(idx(cell, Index(i0))) * vd(idx(cell, Index(i3))));
476 my_constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
477 eval(- DataType(1)*vd(idx(cell, Index(i1))) * vd(idx(cell, Index(i2))));
478
479 constraint_vec[cell] += my_constraint;
480
481 constraint += my_constraint;
482 }
483
484 DataType my_constraint(0);
485 my_constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
486 eval( - vd(idx(cell,0)) * vd(idx(cell,7)));
487 my_constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
488 eval( - vd(idx(cell,1)) * vd(idx(cell,6)));
489 my_constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
490 eval( - vd(idx(cell,2)) * vd(idx(cell,5)));
491 my_constraint += FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::
492 eval( - vd(idx(cell,3)) * vd(idx(cell,4)));
493
494 constraint_vec[cell] += my_constraint;
495
496 constraint += my_constraint;
497
498 }
499
500 return constraint;
501 }
502
503 template<typename Vector_, typename Mesh_, typename Dist_, typename GradDist_, typename EdgeFreqs_>
504 static void add_constraint_grad(
505 Vector_& grad, const DataType alignment_fval, const DataType fac, const Mesh_& mesh, const Dist_& dist,
506 const GradDist_& grad_dist, const EdgeFreqs_& edge_freqs)
507 {
508 const auto& edge_idx = mesh.template get_index_set<1,0>();
510 typedef Tiny::Vector<DataType, Mesh_::world_dim> WorldPoint;
511
512 WorldPoint grad_loc(DataType(0));
513 auto vg = grad.elements_view_w();
514 const auto vd = dist.elements_view_r();
515 const auto vgd = grad_dist.elements_view_r();
516 const auto vef = edge_freqs.elements_view_r();
517
518 for(Index edge(0); edge < mesh.get_num_entities(1); ++edge)
519 {
520 Index i(edge_idx(edge,0));
521 Index j(edge_idx(edge,1));
522
523 auto dist_prod = vd(i) * vd(j);
524 // Derivative of the heaviside function
525 auto heaviside_der = FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::der_x(-dist_prod);
526
527 grad_loc = (-fac * alignment_fval * heaviside_der * vd(j)) * vgd(i);
528 vg[i] += vef(edge)*grad_loc;
529
530 grad_loc = (-fac * alignment_fval * heaviside_der * vd(i)) * vgd(j);
531 vg[j] += vef(edge)*grad_loc;
532 }
533
534 const auto& face_idx = mesh.template get_index_set<2,0>();
535 for(Index face(0); face < mesh.get_num_entities(2); ++face)
536 {
537 Index i(face_idx(face,Index(0)));
538 Index j(face_idx(face,Index(3)));
539
540 auto dist_prod = vd(i) * vd(j);
541 // Derivative of the heaviside function
542 auto heaviside_der = FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::der_x(-dist_prod);
543
544 grad_loc = (-fac * alignment_fval * heaviside_der * vd(j)) * vgd(i);
545 vg[i] += grad_loc;
546
547 grad_loc = (-fac * alignment_fval * heaviside_der * vd(i)) * vgd(j);
548 vg[j] += grad_loc;
549
550 i = face_idx(face,Index(1));
551 j = face_idx(face,Index(2));
552
553 dist_prod = vd(i) * vd(j);
554 // Derivative of the heaviside function
555 heaviside_der = FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::der_x(-dist_prod);
556
557 grad_loc = (-fac * alignment_fval * heaviside_der * vd(j)) * vgd(i);
558 vg[i] += grad_loc;
559
560 grad_loc = (-fac * alignment_fval * heaviside_der * vd(i)) * vgd(j);
561 vg[j] += grad_loc;
562 }
563
564 const auto& cell_idx = mesh.template get_index_set<3,0>();
565 for(Index cell(0); cell < mesh.get_num_entities(2); ++cell)
566 {
567 Index i[4]{cell_idx(cell,Index(0)), cell_idx(cell,Index(1)),cell_idx(cell,Index(2)),cell_idx(cell,Index(3))};
568 Index j[4]{cell_idx(cell,Index(7)), cell_idx(cell,Index(6)),cell_idx(cell,Index(5)),cell_idx(cell,Index(2))};
569
570 for(int k(0); k < 4; ++k)
571 {
572
573 auto dist_prod = vd(i[k]) * vd(j[k]);
574 // Derivative of the heaviside function
575 auto heaviside_der = FEAT::Analytic::Common::template HeavisideRegStatic<DataType>::der_x(-dist_prod);
576
577 grad_loc = (-fac * alignment_fval * heaviside_der * vd(j[k])) * vgd(i[k]);
578 vg[i[k]] += grad_loc;
579
580 grad_loc = (-fac * alignment_fval * heaviside_der * vd(i[k])) * vgd(j[k]);
581 vg[j[k]] += grad_loc;
582 }
583
584 }
585 }
586 };
588
610 template
611 <
612 typename Trafo_,
613 typename RefCellTrafo_ = RumpfTrafo<Trafo_, typename Trafo_::CoordType>
614 >
616 {
617 public:
619 typedef Trafo_ TrafoType;
620
622 typedef typename TrafoType::MeshType MeshType;
624 typedef typename MeshType::ShapeType ShapeType;
626 typedef typename MeshType::CoordType CoordType;
627
630
640 public:
643 {
644 }
645
649 virtual String info() const = 0;
650
660 virtual std::shared_ptr<MeshConcentrationFunctionBase> create_empty_clone() const = 0;
661
665 virtual void compute_dist() = 0;
666
670 virtual void compute_conc() = 0;
671
675 virtual void compute_grad_conc() = 0;
676
705 virtual void compute_grad_h(const CoordType& DOXY(sum_det)) = 0;
706
712 virtual const ScalarVectorType& get_conc() const = 0;
713
719 virtual const ScalarVectorType& get_dist() const = 0;
720
726 virtual const VectorType& get_grad_dist() const = 0;
727
733 virtual GradHType& get_grad_h() = 0;
734
740 virtual const GradHType& get_grad_h() const = 0;
741
751 virtual void set_mesh_node(const Geometry::RootMeshNode<MeshType>* DOXY(mesh_node_)) = 0;
752
758 virtual bool use_derivative() const = 0;
759
766 virtual CoordType compute_constraint() const = 0;
767
779 virtual CoordType compute_constraint(CoordType* DOXY(constraint_at_vtx)) const = 0;
780
794 virtual void add_constraint_grad(VectorType& DOXY(grad), const CoordType DOXY(constraint), const CoordType DOXY(fac)) const = 0;
795
803 virtual void compute_grad_sum_det(const VectorType& DOXY(coords)) = 0;
804
812 virtual void add_sync_vecs(std::set<VectorType*>& DOXY(sync_vecs)) = 0;
813
819 virtual CoordType& get_sum_conc() = 0;
820
821 };
822
840 template
841 <
842 typename ElementalFunction_,
843 typename Trafo_,
845 >
846 class MeshConcentrationFunction : public MeshConcentrationFunctionBase<Trafo_, RefCellTrafo_>
847 {
848 public:
851
853 typedef ElementalFunction_ ElementalFunction;
855 typedef Trafo_ TrafoType;
856
858 typedef typename TrafoType::MeshType MeshType;
860 typedef typename MeshType::CoordType CoordType;
861
864
866 typedef typename MeshType::ShapeType ShapeType;
878
879 protected:
884
900 // Each entry in the DenseVectorBlocked represents one cell. Each cell's block contains
901 // world_dim*(number of local vertices) entries. Has to be serialized like this because there is no
902 // DenseVector that saves a Tiny::Matrix
904
914 _mesh_node(nullptr),
915 _func(func_),
916 _edge_freqs(),
917 _dist(),
918 _grad_dist(),
920 _conc(),
921 _grad_conc(),
923 _grad_h()
924 {
925 }
926
928 // *
929 // */
930 //explicit MeshConcentrationFunction(const MeshConcentrationFunction& other) :
931 // _mesh_node(other._mesh_node),
932 // _func(other._func),
933 // _sum_conc(other._sum_conc)
934 // {
935 // _dist.clone(other._dist, LAFEM::CloneMode::Deep);
936 // _grad_dist.clone(other._grad_dist, LAFEM::CloneMode::Deep);
937 // _grad_conc.clone(other._grad_conc, LAFEM::CloneMode::Deep);
938 // _grad_sum_det.clone(other._grad_sum_det, LAFEM::CloneMode::Deep);
939 // _grad_h.clone(other._grad_h, LAFEM::CloneMode::Deep);
940 // }
941
942 public:
945 {
946 }
947
949 virtual void add_sync_vecs(std::set<VectorType*>& sync_vecs) override
950 {
951 if(_func.use_derivative)
952 {
953 sync_vecs.insert(&_grad_sum_det);
954 sync_vecs.insert(&_grad_conc);
955 }
956 }
957
959 virtual const ScalarVectorType& get_conc() const override
960 {
961 return _conc;
962 }
963
965 virtual const ScalarVectorType& get_dist() const override
966 {
967 return _dist;
968 }
969
971 virtual const VectorType& get_grad_dist() const override
972 {
973 return _grad_dist;
974 }
975
977 virtual GradHType& get_grad_h() override
978 {
979 return _grad_h;
980 }
981
983 virtual const GradHType& get_grad_h() const override
984 {
985 return _grad_h;
986 }
987
989 virtual CoordType& get_sum_conc() override
990 {
991 return _sum_conc;
992 }
993
995 virtual String info() const override
996 {
997 return _func.info();
998 }
999
1001 virtual void set_mesh_node(const Geometry::RootMeshNode<MeshType>* mesh_node_) override
1002 {
1003 XASSERT(_mesh_node == nullptr);
1004
1005 _mesh_node = mesh_node_;
1006
1007 _sum_conc = CoordType(0);
1008
1009 Index ndofs(_mesh_node->get_mesh()->get_num_entities(0));
1010 Index nedges(_mesh_node->get_mesh()->get_num_entities(1));
1011 Index ncells(_mesh_node->get_mesh()->get_num_entities(ShapeType::dimension));
1012
1014 _dist = ScalarVectorType(ndofs, CoordType(0));
1015 _grad_dist = VectorType(ndofs,CoordType(0));
1016 _conc = ScalarVectorType(ncells);
1017 _grad_conc = VectorType(ndofs, CoordType(0));
1018 _grad_h = GradHType(ncells,CoordType(0));
1019 _grad_sum_det = VectorType(ndofs, CoordType(0));
1020
1021 for(const auto& it: _mesh_node->get_mesh_part_names())
1022 {
1023 auto vef = _edge_freqs.elements_view_rw();
1024 if(it.starts_with("_halo"))
1025 {
1026 const auto& edge_ts = _mesh_node->find_mesh_part(it)->template get_target_set<1>();
1027 for(Index edge(0); edge < edge_ts.get_num_entities(); ++edge)
1028 vef[edge_ts[edge]] += CoordType(1);
1029 }
1030 }
1032 }
1033
1035 virtual bool use_derivative() const override
1036 {
1037 return _func.use_derivative;
1038 }
1039
1048 virtual void compute_conc() override
1049 {
1050 // Total number of cells in the mesh
1051 const Index ncells(_mesh_node->get_mesh()->get_num_entities(ShapeType::dimension));
1052 // Index set for local/global numbering
1053 const auto& idx = _mesh_node->get_mesh()->template get_index_set<ShapeType::dimension,0>();
1054
1055 this->_conc.format(CoordType(0));
1056
1057 _sum_conc = CoordType(0);
1058
1059 auto vc = this->_conc.elements_view_rw();
1060 const auto vd = this->_dist.elements_view_r();
1061 for(Index cell(0); cell < ncells; ++cell)
1062 {
1063 CoordType avg_dist(0);
1064
1065 for(int j(0); j < Shape::FaceTraits<ShapeType,0>::count; ++j)
1066 {
1067 avg_dist += vd(idx(cell,j));
1068 }
1069
1071
1072 vc[cell] = _func.conc_val(avg_dist);
1073 _sum_conc += vc[cell];
1074 }
1075 }
1076
1084 virtual void compute_grad_sum_det(const VectorType& coords) override
1085 {
1086 if(_func.use_derivative)
1087 {
1088 RefCellTrafo_::compute_grad_sum_det(_grad_sum_det, coords, *(_mesh_node->get_mesh()));
1089 }
1090 }
1091
1114 template<typename Tgrad_, typename Tl_, typename Tgradl_>
1115 void compute_grad_conc_local(Tgrad_& grad_loc_, const Tl_& dist_loc_, const Tgradl_& grad_dist_loc_)
1116 {
1117 grad_loc_.format(CoordType(0));
1118
1119 // This will be the average of the levelset values at the vertices
1120 CoordType val(0);
1121 for(int i(0); i < Shape::FaceTraits<ShapeType,0>::count; ++i)
1122 {
1123 val += dist_loc_(i);
1124 }
1125
1127
1128 for(int i(0); i < Shape::FaceTraits<ShapeType,0>::count; ++i)
1129 {
1130 grad_loc_[i] = _func.conc_der(val)/CoordType(Shape::FaceTraits<ShapeType,0>::count) * grad_dist_loc_[i];
1131 }
1132 }
1133
1135 virtual void compute_grad_h(const CoordType& sum_det) override
1136 {
1137 XASSERT(_mesh_node != nullptr);
1138
1139 _grad_h.format();
1140
1141 if(_func.use_derivative)
1142 {
1143
1144 // Index set for local/global numbering
1145 auto& idx = _mesh_node->get_mesh()->template get_index_set<ShapeType::dimension,0>();
1146 // This will hold the levelset values at the mesh vertices for one element
1148 // This will hold the levelset gradient values for one element for passing to other routines
1150 // This will hold the local gradient values for one element for passing to other routines
1152 // This will hold the computed local gradient values for one element for copy assigning to the blocked
1153 // datatype
1155
1156 CoordType exponent(CoordType(1)/CoordType(MeshType::world_dim) - CoordType(1));
1157
1158 const auto vc = this->_conc.elements_view_r();
1159 const auto vgc = this->_grad_conc.elements_view_r();
1160 const auto vd = _dist.elements_view_r();
1161 const auto vgd = _grad_dist.elements_view_r();
1162 const auto vgsd = _grad_sum_det.elements_view_r();
1163 auto vgh = _grad_h.elements_view_w();
1164 for(Index cell(0); cell < _mesh_node->get_mesh()->get_num_entities(ShapeType::dimension); ++cell)
1165 {
1166 grad_loc.format();
1167 for(int j(0); j < Shape::FaceTraits<ShapeType,0>::count; ++j)
1168 {
1169 Index i(idx(cell, j));
1170 // Get levelset
1171 dist_loc(j) = vd(i);
1172 // Get levelset gradient
1173 grad_dist_loc[j] = vgd(i);
1174 }
1175
1176 compute_grad_conc_local(grad_loc, dist_loc, grad_dist_loc);
1177
1178 for(int d(0); d < MeshType::world_dim; ++d)
1179 {
1180 for(int j(0); j < Shape::FaceTraits<ShapeType,0>::count; ++j)
1181 {
1182 Index i(idx(cell, j));
1183
1184 tmp(j*MeshType::world_dim +d) =
1185 CoordType(1)/CoordType(MeshType::world_dim)*Math::pow(vc(cell)/_sum_conc*sum_det,exponent)
1186 *( vc(cell)*(vgsd(i)(d)*_sum_conc + sum_det*vgc(i)(d) )
1187 + grad_loc(j,d) * sum_det *_sum_conc)
1189 }
1190 }
1191 vgh[cell] += tmp;
1192
1193 }
1194 } // _func.use_derivative
1195
1196 } // compute_grad_h
1197
1207 virtual void compute_grad_conc() override
1208 {
1209 // Clear the old gradient
1211
1212 // Index set for local/global numbering
1213 auto& idx = _mesh_node->get_mesh()->template get_index_set<ShapeType::dimension,0>();
1214
1215 // This will hold the coordinates for one element for passing to other routines
1216 FEAT::Tiny::Matrix <CoordType, Shape::FaceTraits<ShapeType,0>::count, MeshType::world_dim> x;
1217 // Local cell dimensions for passing to other routines
1218 FEAT::Tiny::Vector <CoordType,MeshType::world_dim> h;
1219 // This will hold the local gradient for one element for passing to other routines
1220 FEAT::Tiny::Matrix <CoordType, Shape::FaceTraits<ShapeType,0>::count, MeshType::world_dim> grad_loc;
1221 // This will hold the levelset values at the mesh vertices for one element
1222 FEAT::Tiny::Vector <CoordType, Shape::FaceTraits<ShapeType,0>::count> grad_dist_loc;
1223 // This will hold the levelset gradient values for one element for passing to other routines
1224 FEAT::Tiny::Matrix <CoordType, Shape::FaceTraits<ShapeType,0>::count, MeshType::world_dim> dist_loc;
1225
1226 // Compute the functional value for each cell
1227 auto vc = this->_grad_conc.elements_view_rw();
1228 const auto vd = _dist.elements_view_r();
1229 const auto vgd = _grad_dist.elements_view_r();
1230 for(Index cell(0); cell < _mesh_node->get_mesh()->get_num_entities(ShapeType::dimension); ++cell)
1231 {
1232 // Collect levelset and levelset grad values
1233 for(int j(0); j < Shape::FaceTraits<ShapeType,0>::count; ++j)
1234 {
1235 // Global vertex/dof index
1236 Index i(idx(cell, j));
1237 // Get levelset
1238 grad_dist_loc(j) = vd(i);
1239 // Get levelset gradient
1240 dist_loc[j] = vgd(i);
1241 }
1242
1243 // Compute gradient of the concentration on this cell
1244 compute_grad_conc_local(grad_loc, grad_dist_loc, dist_loc);
1245
1246 // Add local contributions to global gradient vector
1247 for(int j(0); j < Shape::FaceTraits<ShapeType,0>::count; ++j)
1248 {
1249 vc[idx(cell, j)] += grad_loc[j];
1250 }
1251 }
1252
1253 } // compute_grad_conc()
1254
1256 virtual CoordType compute_constraint() const override
1257 {
1258 return PenaltyFunction::compute_constraint(*(_mesh_node->get_mesh()), this->_dist, this->_edge_freqs);
1259 }
1260
1272 virtual CoordType compute_constraint(CoordType* constraint_at_vtx) const override
1273 {
1274 XASSERT(constraint_at_vtx != nullptr);
1275 return PenaltyFunction::compute_constraint(constraint_at_vtx, *(_mesh_node->get_mesh()), this->_dist);
1276 }
1277
1280 VectorType& grad, const CoordType constraint, const CoordType fac) const override
1281 {
1283 grad, constraint, fac, *(_mesh_node->get_mesh()), _dist, _grad_dist, this->_edge_freqs);
1284 }
1285
1286 }; // class MeshConcentrationFunction
1287
1307 template
1308 <
1309 typename ElementalFunction_,
1310 typename Trafo_,
1311 typename RefCellTrafo_ = RumpfTrafo<Trafo_, typename Trafo_::CoordType>
1312 >
1313 class ChartDistanceFunction : public MeshConcentrationFunction<ElementalFunction_, Trafo_, RefCellTrafo_>
1314 {
1315 public:
1317 typedef ElementalFunction_ ElementalFunction;
1319 typedef Trafo_ TrafoType;
1321 typedef typename TrafoType::MeshType MeshType;
1323 typedef typename MeshType::CoordType CoordType;
1326
1333
1335 typedef typename MeshType::ShapeType ShapeType;
1340
1341 protected:
1343 std::deque<String> _chart_list;
1346
1347 public:
1350
1364 ChartDistanceFunction(const ElementalFunction& func_, const std::deque<String>& chart_list_, const String& operation_):
1365 DirectBaseClass(func_),
1366 _chart_list(),
1367 _operation(operation_)
1368 {
1369 XASSERTM(chart_list_.size() > size_t(0), "Empty chart list.");
1370
1371 for(const auto& it:chart_list_)
1372 _chart_list.push_back(it);
1373 }
1374
1375 //explicit ChartDistanceFunction(const ChartDistanceFunction& other) :
1376 // BaseClass(other.BaseClass),
1377 // _chart_list(other._chart_list)
1378 // {
1379 // }
1380
1383 {
1384 }
1385
1387 virtual std::shared_ptr<BaseClass> create_empty_clone() const override
1388 {
1389 std::shared_ptr<BaseClass> result(nullptr);
1390 result = std::make_shared<ChartDistanceFunction>(this->_func, _chart_list, _operation);
1391 return result;
1392 }
1393
1395 virtual void compute_dist() override
1396 {
1397 if(_operation == "add")
1399 else if(_operation == "max")
1401 else if(_operation == "min")
1403 else
1404 XABORTM("Unknown operation "+_operation);
1405 }
1406
1409 {
1410 XASSERT(this->_mesh_node != nullptr);
1411
1412 const auto& vtx = this->_mesh_node->get_mesh()->get_vertex_set();
1413
1414 WorldPoint my_dist_vec(CoordType(0));
1415 WorldPoint tmp(CoordType(0));
1416
1417 auto vd = this->_dist.elements_view_w();
1418 auto vgd = this->_grad_dist.elements_view_w();
1419 for(Index i(0); i < this->_mesh_node->get_mesh()->get_num_entities(0); ++i)
1420 {
1421 CoordType my_dist(0);
1422 my_dist_vec.format(CoordType(0));
1423
1424 for(const auto& it:_chart_list)
1425 {
1426 auto* chart = this->_mesh_node->get_atlas()->find_mesh_chart(it);
1427 if(chart == nullptr)
1428 XABORTM("Could not find chart "+it);
1429
1430 my_dist += Math::abs(chart->signed_dist(vtx[i], tmp));
1431 my_dist_vec += tmp;
1432
1433 }
1434 vd[i] = my_dist;
1435
1436 // Because we added distance function gradient vectors, we have to normalize again if possible
1437 CoordType my_norm(my_dist_vec.norm_euclid());
1438 if(my_norm > Math::eps<CoordType>())
1439 my_dist_vec *= (CoordType(1)/my_norm);
1440
1441 vgd[i] = my_dist_vec;
1442 }
1443 }
1444
1447 {
1448 XASSERT(this->_mesh_node != nullptr);
1449
1450 const auto& vtx = this->_mesh_node->get_mesh()->get_vertex_set();
1451
1452 WorldPoint my_dist_vec(CoordType(0));
1453 WorldPoint tmp(CoordType(0));
1454
1455 auto vd = this->_dist.elements_view_w();
1456 auto vgd = this->_grad_dist.elements_view_w();
1457 for(Index i(0); i < this->_mesh_node->get_mesh()->get_num_entities(0); ++i)
1458 {
1459 CoordType my_dist(-Math::huge<CoordType>());
1460 my_dist_vec.format(CoordType(0));
1461
1462 for(const auto& it:_chart_list)
1463 {
1464 auto* chart = this->_mesh_node->get_atlas()->find_mesh_chart(it);
1465 if(chart == nullptr)
1466 XABORTM("Could not find chart "+it);
1467
1468 CoordType this_dist = chart->signed_dist(vtx[i], tmp);
1469 if(this_dist > my_dist)
1470 {
1471 my_dist = this_dist;
1472 my_dist_vec = tmp;
1473 }
1474
1475 }
1476
1477 vd[i] = my_dist;
1478 vgd[i] = my_dist_vec;
1479 }
1480 }
1483 {
1484 XASSERT(this->_mesh_node != nullptr);
1485
1486 const auto& vtx = this->_mesh_node->get_mesh()->get_vertex_set();
1487
1488 WorldPoint my_dist_vec(CoordType(0));
1489 WorldPoint tmp(CoordType(0));
1490
1491 auto vd = this->_dist.elements_view_w();
1492 auto vgd = this->_grad_dist.elements_view_w();
1493 for(Index i(0); i < this->_mesh_node->get_mesh()->get_num_entities(0); ++i)
1494 {
1495 CoordType my_dist(Math::huge<CoordType>());
1496 my_dist_vec.format(CoordType(0));
1497
1498 for(const auto& it:_chart_list)
1499 {
1500 auto* chart = this->_mesh_node->get_atlas()->find_mesh_chart(it);
1501 if(chart == nullptr)
1502 XABORTM("Could not find chart "+it);
1503
1504 CoordType this_dist = chart->signed_dist(vtx[i], tmp);
1505 if(Math::abs(this_dist) < Math::abs(my_dist))
1506 {
1507 my_dist = this_dist;
1508 my_dist_vec = tmp;
1509 }
1510
1511 }
1512
1513 vd[i] = my_dist;
1514 vgd[i] = my_dist_vec;
1515 }
1516 }
1517
1523 static String name()
1524 {
1525 return "ChartDistanceFunction<"+ElementalFunction::name()+">";
1526 }
1527
1529 virtual String info() const override
1530 {
1531 const Index width(30);
1532
1533 String msg = name() + ":\n";
1534
1535 msg += DirectBaseClass::info() + "\n";
1536 msg += String("Operation").pad_back(width, '.') + String(": ") + _operation;
1537
1538 for(const auto& it:_chart_list)
1539 {
1540 msg += String("\nDistance chart").pad_back(width, '.') + String(": ") + it;
1541 }
1542
1543 return msg;
1544 }
1545
1546 }; // class ChartDistanceFunction
1547
1558 template<typename Trafo_, typename RefCellTrafo_>
1560 {
1562 typedef typename Trafo_::MeshType MeshType;
1564 typedef typename MeshType::CoordType CoordType;
1565
1577 static std::shared_ptr<MeshConcentrationFunctionBase<Trafo_, RefCellTrafo_>>
1578 create(const String& section_key, PropertyMap* config)
1579 {
1580 XASSERT(config != nullptr);
1581
1582 std::shared_ptr<MeshConcentrationFunctionBase<Trafo_, RefCellTrafo_>> result(nullptr);
1583
1584 // Get the configuration section
1585 auto my_section = config->query_section(section_key);
1586 XASSERTM(my_section != nullptr, "Config is missing the referenced "+section_key+" section.");
1587
1588 auto type_p = my_section->query("type");
1589 XASSERTM(type_p.second, "Section "+section_key+" is missing the mandatory type key.");
1590
1591 if(type_p.first== "ChartDistance")
1592 {
1593 auto chart_list_p = my_section->query("chart_list");
1594 XASSERTM(chart_list_p.second, "Section "+section_key+" is missing the mandatory chart_list key.");
1595
1596 String operation("min");
1597 auto operation_p = my_section->query("operation");
1598 if(operation_p.second)
1599 operation = operation_p.first;
1600
1601 std::deque<String> chart_list = chart_list_p.first.split_by_whitespaces();
1602
1603 auto function_type_p = my_section->query("function_type");
1604 if(function_type_p.second)
1605 {
1606 // At the moment, there are only default and PowOfDist
1607 if(function_type_p.first == "PowOfDist")
1608 {
1609 CoordType minval(0);
1610 CoordType exponent(1);
1611 bool use_derivative(true);
1612
1613 auto minval_p = my_section->query("minval");
1614 if(minval_p.second)
1615 minval = std::stod(minval_p.first);
1616
1617 auto exponent_p = my_section->query("exponent");
1618 if(exponent_p.second)
1619 exponent = std::stod(exponent_p.first);
1620
1621 auto use_derivative_p = my_section->query("use_derivative");
1622 if(use_derivative_p.second)
1623 use_derivative = (std::stoi(use_derivative_p.first) == 1);
1624
1625 typedef ConcentrationFunctionPowOfDist<CoordType> ElementalFunction;
1626 ElementalFunction my_func(minval, exponent, use_derivative);
1627
1628 auto real_result = std::make_shared<ChartDistanceFunction<ElementalFunction, Trafo_, RefCellTrafo_>>
1629 (my_func, chart_list, operation);
1630
1631 result = real_result;
1632 }
1633 // Default case
1634 else
1635 {
1636 typedef ConcentrationFunctionDefault<CoordType> ElementalFunction;
1637 ElementalFunction my_func;
1638
1639 auto real_result = std::make_shared<ChartDistanceFunction<ElementalFunction, Trafo_, RefCellTrafo_>>
1640 (my_func, chart_list, operation);
1641
1642 result = real_result;
1643 }
1644 }
1645
1646 }
1647
1648 XASSERTM(result != nullptr, "Unknown conc_function type!");
1649
1650 return result;
1651 }
1652 };
1653
1661 template<typename DT_>
1663 {
1664 public:
1666 typedef DT_ DataType;
1667
1669 const bool use_derivative;
1670
1677 use_derivative(false)
1678 {
1679 }
1680
1690 {
1691 }
1692
1697 {
1698 }
1699
1705 static String name()
1706 {
1707 return "ConcentrationFunctionDefault";
1708 }
1709
1713 virtual String info() const
1714 {
1715 const Index pad_width(30);
1716
1717 String msg = name() + String(":\n");
1718
1719 msg += String("Function").pad_back(pad_width, '.') + String(": c(d) = |d|\n");
1720 msg += String("use_derivative").pad_back(pad_width, '.') + String(": ") += stringify(use_derivative);
1721
1722 return msg;
1723 }
1724
1733 DataType conc_val(DT_ dist) const
1734 {
1735 return Math::abs(dist);
1736 }
1737
1746 DataType conc_der(DT_ DOXY(dist)) const
1747 {
1748 return DataType(0);
1749 }
1750 };
1751
1762 template<typename DT_>
1764 {
1765 public:
1767 typedef DT_ DataType;
1769 const bool use_derivative;
1770
1771 private:
1776
1777 public:
1791 explicit ConcentrationFunctionPowOfDist(DataType minval_, DataType exponent_, bool use_derivative_ = true):
1792 use_derivative(use_derivative_),
1793 _minval(minval_),
1794 _exponent(exponent_)
1795 {
1796 }
1797
1798 //ConcentrationFunctionPowOfDist(const ConcentrationFunctionPowOfDist& other) :
1799 // use_derivative(other.use_derivative),
1800 // _minval(other._minval),
1801 // _exponent(other._exponent)
1802 // {
1803 // }
1804
1807
1813 {
1814 }
1815
1821 static String name()
1822 {
1823 return "ConcentrationFunctionPowOfDist";
1824 }
1825
1829 virtual String info() const
1830 {
1831 const Index pad_width(30);
1832
1833 String msg = name() + String(":\n");
1834
1835 msg += String("Function").pad_back(pad_width, '.') + String(": c(d) = (alpha + |d|^beta)\n");
1836 msg += String("alpha").pad_back(pad_width, '.') + String(": ") + stringify_fp_sci(_minval) + "\n";
1837 msg += String("beta").pad_back(pad_width, '.') + String(": ") + stringify_fp_sci(_exponent) + "\n";
1838 msg += String("use_derivative").pad_back(pad_width, '.') + String(": ") + stringify(use_derivative);
1839
1840 return msg;
1841 }
1842
1852 {
1853 return Math::pow(_minval + Math::abs(dist), _exponent);
1854 }
1855
1865 {
1867 }
1868 };
1869 } // namespace Meshopt
1870} // namespace FEAST
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
MeshChartType * find_mesh_chart(const String &name)
Searches for a mesh chart.
Definition: mesh_atlas.hpp:162
MeshPartType * find_mesh_part(const String &part_name)
Searches this container for a MeshPart.
Definition: mesh_node.hpp:398
std::deque< String > get_mesh_part_names(bool no_internals=false) const
Returns the names of all mesh parts of this node.
Definition: mesh_node.hpp:251
MeshType * get_mesh()
Returns the mesh of this node.
Definition: mesh_node.hpp:225
Root mesh node class template.
Definition: mesh_node.hpp:748
const MeshAtlasType * get_atlas() const
Definition: mesh_node.hpp:820
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.
Dense data vector class template.
void component_invert(const DenseVector &x, const DT_ alpha=DT_(1))
Performs .
Class to compute a desired concentration for the mesh cell distribution base on distance to Charts.
MeshConcentrationFunctionBase< Trafo_, RefCellTrafo_ > BaseClass
Our base class.
Tiny::Vector< CoordType, MeshType::world_dim > WorldPoint
Type for one mesh vertex.
MeshType::ShapeType ShapeType
ShapeType of said mesh.
ElementalFunction_ ElementalFunction
Type for the function mapping distance to concentration.
virtual String info() const override
Prints relevant information.
LAFEM::DenseVector< CoordType, IndexType > ScalarVectorType
Vector type for element sizes etc.
void compute_dist_max()
Computes the distance information.
ChartDistanceFunction(const ElementalFunction &func_, const std::deque< String > &chart_list_, const String &operation_)
Constructor setting the ElementalFunction_ and the list of charts.
MeshConcentrationFunction< ElementalFunction_, Trafo_, RefCellTrafo_ > DirectBaseClass
Our direct base class.
static String name()
Returns the class name as String.
Trafo_ TrafoType
Type for the transformation.
ChartDistanceFunction()=delete
Explicitly delete the empty default constructor.
void compute_dist_add()
Computes the distance information.
MeshType::CoordType CoordType
The precision of the mesh coordinates.
virtual std::shared_ptr< BaseClass > create_empty_clone() const override
Creates an empty clone of itself.
void compute_dist_min()
Computes the distance information.
TrafoType::MeshType MeshType
The mesh the transformation is defined on.
std::deque< String > _chart_list
List of charts to compute the distance to.
LAFEM::DenseVectorBlocked< CoordType, IndexType, MeshType::world_dim > VectorType
Vector type for element scales etc.
virtual void compute_dist() override
Computes the distance information.
const String _operation
How to mangle more than one distance (add, max, min)
Default elemental distance concentration function.
ConcentrationFunctionDefault(const ConcentrationFunctionDefault &other)
Copy constructor.
static String name()
Returns a descriptive String.
virtual String info() const
Prints relevant information.
DataType conc_val(DT_ dist) const
Computes the concentration according to a distance.
const bool use_derivative
Does this utilize the derivative of the input wrt. some other DoF?
DataType conc_der(DT_ dist) const
Computes the derivative of the concentration according to a distance.
Default elemental distance concentration function.
const bool use_derivative
Does this utilize the derivative of the input wrt. some other DoF?
static String name()
Returns a descriptive String.
DataType conc_der(DataType dist) const
Computes the concentration according to a distance.
virtual String info() const
Prints relevant information.
ConcentrationFunctionPowOfDist(DataType minval_, DataType exponent_, bool use_derivative_=true)
Constructor setting alpha, beta and use_derivative.
DataType conc_val(DataType dist) const
Computes the concentration according to a distance.
Base class for mesh concentration functions.
virtual bool use_derivative() const =0
Returns whether this function make use of the derivative of h wrt. the vertex coordinates.
virtual void add_sync_vecs(std::set< VectorType * > &sync_vecs)=0
Adds pointers to vectors that need synchronising (type-0 to type-1 vectors)
virtual std::shared_ptr< MeshConcentrationFunctionBase > create_empty_clone() const =0
Creates an empty clone of itself.
virtual void compute_conc()=0
Computes the concentration for each cell according to the distance information.
virtual const VectorType & get_grad_dist() const =0
Returns a const reference to the gradient of the distance function.
MeshType::CoordType CoordType
The precision of the mesh coordinates.
virtual void add_constraint_grad(VectorType &grad, const CoordType constraint, const CoordType fac) const =0
Adds the scaled gradient of the constraint wrt. the vertex coordinates.
LAFEM::DenseVectorBlocked< CoordType, IndexType, MeshType::world_dim > VectorType
Vector type for element scales etc.
virtual GradHType & get_grad_h()=0
Returns a reference to gradient of the optimal scales wrt. the vertex coordinates.
LAFEM::DenseVector< CoordType, IndexType > ScalarVectorType
Vector type for element sizes etc.
virtual CoordType & get_sum_conc()=0
Returns the sum of the mesh concentration over all cells.
Tiny::Vector< CoordType, MeshType::world_dim > WorldPoint
Type of a mesh vertex.
LAFEM::DenseVectorBlocked< CoordType, IndexType, MeshType::world_dim *Shape::FaceTraits< ShapeType, 0 >::count > GradHType
Vector type for the gradient of h wrt. the DoF.
virtual void compute_grad_h(const CoordType &sum_det)=0
Computes the local gradient of the optimal scales.
virtual const GradHType & get_grad_h() const =0
Returns a const reference to gradient of the optimal scales wrt. the vertex coordinates.
virtual const ScalarVectorType & get_conc() const =0
Returns a const reference to the concentration.
virtual void compute_grad_sum_det(const VectorType &coords)=0
Computes the gradient of the sum of all determinants of the trafo.
virtual void compute_grad_conc()=0
Computes the gradient of the mesh concentration for each cell according to the distance information.
virtual CoordType compute_constraint() const =0
Computes the surface alignment constraint.
virtual void compute_dist()=0
Computes the distance information.
virtual String info() const =0
Prints relevant information.
MeshType::ShapeType ShapeType
ShapeType of said mesh.
TrafoType::MeshType MeshType
The mesh the transformation is defined on.
virtual CoordType compute_constraint(CoordType *constraint_at_vtx) const =0
Computes the surface alignment constraint at every vertex.
virtual const ScalarVectorType & get_dist() const =0
Returns a const reference to the distance information.
virtual void set_mesh_node(const Geometry::RootMeshNode< MeshType > *mesh_node_)=0
Sets this object's mesh node.
Class to compute a desired concentration for the mesh cell distribution.
ElementalFunction _func
The scalar function mapping distance to concentration.
VectorType _grad_dist
For all vertices, this holds the gradient of the distance function.
MeshType::CoordType CoordType
The precision of the mesh coordinates.
MeshConcentrationFunction(const ElementalFunction &func_)
Constructor setting the elemantal function.
virtual void add_sync_vecs(std::set< VectorType * > &sync_vecs) override
Adds pointers to vectors that need synchronising (type-0 to type-1 vectors)
virtual const ScalarVectorType & get_conc() const override
Returns a const reference to the concentration.
VectorType _grad_sum_det
Gradient of _sum_det wrt. the mesh vertices.
virtual const ScalarVectorType & get_dist() const override
Returns a const reference to the distance information.
virtual void compute_grad_conc() override
Computes the gradient of the sum of all mesh concentrations.
MeshType::ShapeType ShapeType
ShapeType of said mesh.
virtual void compute_grad_h(const CoordType &sum_det) override
Computes the local gradient of the optimal scales.
ElementalFunction_ ElementalFunction
The scalar function that computes the concentration from something.
LAFEM::DenseVectorBlocked< CoordType, Index, MeshType::world_dim *Shape::FaceTraits< ShapeType, 0 >::count > GradHType
Vector type for the gradient of h wrt. the DoF.
virtual void add_constraint_grad(VectorType &grad, const CoordType constraint, const CoordType fac) const override
Adds the scaled gradient of the constraint wrt. the vertex coordinates.
ScalarVectorType _conc
Vector for saving the mesh concentration, one entry per cell.
const Geometry::RootMeshNode< MeshType > * _mesh_node
The mesh node this function works with.
LAFEM::DenseVector< CoordType, IndexType > ScalarVectorType
Vector type for element sizes etc.
virtual void compute_conc() override
Computes the mesh concentration function for each cell.
TrafoType::MeshType MeshType
The mesh the transformation is defined on.
VectorType _grad_conc
Gradient of the mesh concentration wrt. the world coordinates.
virtual void set_mesh_node(const Geometry::RootMeshNode< MeshType > *mesh_node_) override
Sets this object's mesh node.
virtual bool use_derivative() const override
Returns whether this function make use of the derivative of h wrt. the vertex coordinates.
GradHType _grad_h
Gradient of the local optimal scales h wrt. the vertex coordinates.
virtual const GradHType & get_grad_h() const override
Returns a reference to gradient of the optimal scales wrt. the vertex coordinates.
ScalarVectorType _dist
For all vertices, this holds their scalar "distance" to whatever.
void compute_grad_conc_local(Tgrad_ &grad_loc_, const Tl_ &dist_loc_, const Tgradl_ &grad_dist_loc_)
Computes the local gradient of the concentration function wrt. the vertices.
virtual CoordType & get_sum_conc() override
Returns the sum of the mesh concentration over all cells.
MeshConcentrationFunctionBase< Trafo_, RefCellTrafo_ > BaseClass
Our base class.
Tiny::Vector< CoordType, MeshType::world_dim > WorldPoint
Type for one mesh vertex.
LAFEM::DenseVectorBlocked< CoordType, IndexType, MeshType::world_dim > VectorType
Vector type for element scales etc.
virtual CoordType compute_constraint(CoordType *constraint_at_vtx) const override
Computes the surface alignment constraint at every vertex.
virtual const VectorType & get_grad_dist() const override
Returns a const reference to the gradient of the distance function.
AlignmentPenalty< CoordType, ShapeType > PenaltyFunction
Surface alignment penalty function.
virtual CoordType compute_constraint() const override
Computes the surface alignment constraint.
virtual GradHType & get_grad_h() override
Returns a reference to gradient of the optimal scales wrt. the vertex coordinates.
virtual String info() const override
copydoc BaseClass::info()
virtual void compute_grad_sum_det(const VectorType &coords) override
Computes the gradient of the sum of all determinants of the trafo.
CoordType _sum_conc
The sum of all entries in _conc.
ScalarVectorType _edge_freqs
For each edge, this contains 1/(# halos it is present in)
A class organizing a tree of key-value pairs.
PropertyMap * query_section(String sec_path)
Queries a section by its section path.
String class implementation.
Definition: string.hpp:47
std::deque< String > split_by_whitespaces() const
Splits the string by white-spaces.
Definition: string.hpp:519
String pad_back(size_type len, char c=' ') const
Pads the back of the string up to a desired length.
Definition: string.hpp:416
Tiny Matrix class template.
CUDA_HOST_DEVICE void format(DataType alpha=DataType(0))
Formats the matrix.
Tiny Vector class template.
CUDA_HOST_DEVICE void format(DataType alpha=DataType(0))
Formats the vector.
CUDA_HOST_DEVICE DataType norm_euclid() const
Computes the euclid norm of this vector.
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
T_ pow(T_ x, T_ y)
Returns x raised to the power of y.
Definition: math.hpp:643
T_ sqr(T_ x)
Returns the square of a value.
Definition: math.hpp:95
T_ signum(T_ x)
Returns the sign of a value.
Definition: math.hpp:250
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:993
String stringify_fp_sci(DataType_ value, int precision=0, int width=0, bool sign=false)
Prints a floating point value to a string in scientific notation.
Definition: string.hpp:1137
@ grad
specifies whether the space should supply basis function gradients
std::uint64_t Index
Index data type.
Wrapper class for functionality around aligning meshes to (implicit) surfaces.
static void add_constraint_grad(Vector_ &grad, const DataType alignment_fval, const DataType fac, const Mesh_ &mesh, const Dist_ &dist, const GradDist_ &grad_dist, const EdgeFreqs_ &edge_freqs)
Adds the gradient of the constraint violation term.
static DataType compute_constraint(const Mesh_ &mesh, const Dist_ &dist, const EdgeFreqs_ &edge_freqs)
Computes the constraint (violation) for a given mesh.
Shape::Simplex< shape_dim > ShapeType
The mesh's shape type.
static DataType compute_constraint(DataType *constraint_vec, const Mesh_ &mesh, const Dist_ &dist)
Computes the constraint (violation) on every cell of a given mesh.
MeshType::CoordType CoordType
Floating point precision of the mesh vertex coordinates.
static std::shared_ptr< MeshConcentrationFunctionBase< Trafo_, RefCellTrafo_ > > create(const String &section_key, PropertyMap *config)
Creates a MeshConcentrationFunction according to a PropertyMap.
Computes quantities associated with the transformation to Rumpf reference cells.
Definition: rumpf_trafo.hpp:44
Face traits tag struct template.
Definition: shape.hpp:106
Simplex shape tag struct template.
Definition: shape.hpp:44
static constexpr int dimension
Simplex dimension.
Definition: shape.hpp:48