FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
parti_domain_control.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
10#include <kernel/geometry/mesh_file_reader.hpp>
11#include <kernel/geometry/boundary_factory.hpp>
12#include <kernel/geometry/common_factories.hpp>
13#include <kernel/geometry/hit_test_factory.hpp>
14
15#include <control/domain/parti_domain_control_base.hpp>
16
17namespace FEAT
18{
19 namespace Control
20 {
21 namespace Domain
22 {
33 {
34 args.support("parti-type", "<types...>\n"
35 "Specifies which partitioner types are allowed to be used.\n"
36 "May contain the following types:\n"
37 "2level extern genetic metis naive scotch zoltan"
38 );
39 args.support("parti-extern-name", "<names...>\n"
40 "Specifies the names of the allowed extern partitions."
41 );
42 args.support("parti-rank-elems", "<count>\n"
43 "Specifies the minimum number of elements per rank for a-posteriori partitioning."
44 );
45 args.support("parti-genetic-time", "<time-init> <time-mutate>\n"
46 "Specifies the time for initial distribution and mutation for the genetic partitioner."
47 );
48 }
49
61 template<typename DomainLevel_>
64 {
65 public:
69 using typename BaseClass::LevelType;
71 using typename BaseClass::LayerType;
73 using typename BaseClass::MeshType;
75 using typename BaseClass::AtlasType;
77 using typename BaseClass::MeshNodeType;
79 using typename BaseClass::MeshPartType;
81 using typename BaseClass::Ancestor;
83 using typename BaseClass::WeightType;
84
86 static constexpr int shape_dim = MeshType::shape_dim;
87
89 typedef typename MeshType::CoordType CoordType;
90
91 protected:
94
99
101 std::deque<String> _extern_parti_names;
102
105
106 public:
116 explicit PartiDomainControl(const Dist::Comm& comm_, bool support_multi_layered) :
117 BaseClass(comm_, support_multi_layered),
121 _permutation_strategy(Geometry::PermutationStrategy::none)
122 {
123 }
124
127 {
128 }
129
142 virtual bool parse_args(SimpleArgParser& args) override
143 {
144 if(!BaseClass::parse_args(args))
145 return false;
146
147 // parse --parti-extern-name <names...>
148 {
149 auto it = args.query("parti-extern-name");
150 if(it != nullptr)
151 _extern_parti_names = it->second;
152 }
153
154 // okay
155 return true;
156 }
157
168 virtual bool parse_property_map(const PropertyMap& pmap) override
169 {
171 return false;
172
173 auto parti_extern_name_p = pmap.query("parti-extern-name");
174 if(parti_extern_name_p.second)
175 {
176 this->_extern_parti_names = parti_extern_name_p.first.split_by_whitespaces();
177 }
178
179 return true;
180 }
181
191 virtual void create(const std::deque<String>& filenames, String dirpath = "")
192 {
193 // create a mesh file reader
194 Geometry::MeshFileReader mesh_reader;
195
196 // add the files
197 mesh_reader.add_mesh_files(this->_comm, filenames, dirpath);
198
199 // finally, create the control
200 this->create(mesh_reader);
201 }
202
209 virtual void create(Geometry::MeshFileReader& mesh_reader)
210 {
211 // ensure that the domain control is still empty
212 XASSERTM(!this->_was_created, "domain has already been created");
213 XASSERT(this->size_physical() == std::size_t(0));
214 XASSERT(this->size_virtual() == std::size_t(0));
215
216 TimeStamp stamp_create;
217
218 // parse mesh and create control
219 this->create(mesh_reader.parse(this->_atlas, &_parti_set));
220
221 // clear partition set after creation
222 _parti_set.clear();
223
224 // collect partition statistics
226 }
227
234 virtual void create(std::unique_ptr<MeshNodeType> base_mesh_node)
235 {
236 TimeStamp stamp_create;
237
238 // call base-class create
239 this->_create(std::move(base_mesh_node));
240
241 // finally, apply mesh permutation
242 this->_was_created = false;
244 this->_was_created = true;
245
246 // collect partition statistics
248 }
249
258 virtual void create_unit_hypercube(Index num_elems_x, Index num_elems_y = 0u, Index num_elems_z = 0u)
259 {
260 // ensure that the domain control is still empty
261 XASSERTM(!this->_was_created, "domain has already been created");
262 XASSERT(this->size_physical() == std::size_t(0));
263 XASSERT(this->size_virtual() == std::size_t(0));
264
265 TimeStamp stamp_create;
266
267 // allocate a base-mesh node and create mesh
268 std::unique_ptr<MeshNodeType> base_mesh_node = MeshNodeType::make_unique(
269 Geometry::StructUnitCubeFactory<MeshType>::make_unique_from(num_elems_x, num_elems_y, num_elems_z));
270
271 // get mesh and create boundary
272 {
273 Geometry::BoundaryFactory<MeshType> bnd_factory(*base_mesh_node->get_mesh());
274 base_mesh_node->add_mesh_part("bnd", bnd_factory.make_unique());
275 }
276
277 // create control
278 this->create(std::move(base_mesh_node));
279
280 // collect partition statistics
282 }
283
292 virtual void create_rectilinear(Index num_elems_x, Index num_elems_y = 0u, Index num_elems_z = 0u)
293 {
294 // ensure that the domain control is still empty
295 XASSERTM(!this->_was_created, "domain has already been created");
296 XASSERT(this->size_physical() == std::size_t(0));
297 XASSERT(this->size_virtual() == std::size_t(0));
298
299 TimeStamp stamp_create;
300
301 // allocate a base-mesh node and create mesh
302 std::unique_ptr<MeshNodeType> base_mesh_node = MeshNodeType::make_unique(
303 Geometry::StructUnitCubeFactory<MeshType>::make_unique_from(num_elems_x, num_elems_y, num_elems_z));
304
305 // get mesh and create boundary
306 {
307 Geometry::BoundaryFactory<MeshType> bnd_factory(*base_mesh_node->get_mesh());
308 base_mesh_node->add_mesh_part("bnd", bnd_factory.make_unique());
309 }
310
311 // create control
312 this->create(std::move(base_mesh_node));
313
314 // collect partition statistics
316 }
317
333 virtual void create_rectilinear(Index num_elems_x, CoordType x_min, CoordType x_max,
334 Index num_elems_y = 0u, CoordType y_min = CoordType(0), CoordType y_max = CoordType(0),
335 Index num_elems_z = 0u, CoordType z_min = CoordType(0), CoordType z_max = CoordType(0))
336 {
337 // ensure that the domain control is still empty
338 XASSERTM(!this->_was_created, "domain has already been created");
339 XASSERT(this->size_physical() == std::size_t(0));
340 XASSERT(this->size_virtual() == std::size_t(0));
341
342 TimeStamp stamp_create;
343
344 // allocate a base-mesh node and create mesh
345 std::unique_ptr<MeshNodeType> base_mesh_node = MeshNodeType::make_unique(
346 Geometry::StructUnitCubeFactory<MeshType>::make_unique_from(num_elems_x, num_elems_y, num_elems_z));
347
348 {
350 // add meshparts for left
351 {
352 auto hit = [tol](auto p){return p[0] < tol;};
353 FEAT::Geometry::HitTestFactory<decltype(hit), MeshType> factory(hit, *base_mesh_node->get_mesh());
354 base_mesh_node->add_mesh_part("bnd:l", factory.make_unique());
355 }
356 // add meshparts for right
357 {
358 auto hit = [tol](auto p){return p[0] > (CoordType(1)-tol);};
359 FEAT::Geometry::HitTestFactory<decltype(hit), MeshType> factory(hit, *base_mesh_node->get_mesh());
360 base_mesh_node->add_mesh_part("bnd:r", factory.make_unique());
361 }
362 // add meshparts for bottom
363 if constexpr(shape_dim >= 2)
364 {
365 {
366 auto hit = [tol](auto p){return p[1] < tol;};
367 FEAT::Geometry::HitTestFactory<decltype(hit), MeshType> factory(hit, *base_mesh_node->get_mesh());
368 base_mesh_node->add_mesh_part("bnd:b", factory.make_unique());
369 }
370 // add meshparts for top
371 {
372 auto hit = [tol](auto p){return p[1] > (CoordType(1)-tol);};
373 FEAT::Geometry::HitTestFactory<decltype(hit), MeshType> factory(hit, *base_mesh_node->get_mesh());
374 base_mesh_node->add_mesh_part("bnd:t", factory.make_unique());
375 }
376 }
377 if constexpr(shape_dim >= 3)
378 {
379 // add meshparts for far
380 {
381 auto hit = [tol](auto p){return p[2] < tol;};
382 FEAT::Geometry::HitTestFactory<decltype(hit), MeshType> factory(hit, *base_mesh_node->get_mesh());
383 base_mesh_node->add_mesh_part("bnd:f", factory.make_unique());
384 }
385 // add meshparts for top
386 {
387 auto hit = [tol](auto p){return p[2] > (CoordType(1)-tol);};
388 FEAT::Geometry::HitTestFactory<decltype(hit), MeshType> factory(hit, *base_mesh_node->get_mesh());
389 base_mesh_node->add_mesh_part("bnd:n", factory.make_unique());
390 }
391 }
392 }
393
394 // get the node's vertex set
395 auto& vtx = base_mesh_node->get_mesh()->get_vertex_set();
396 Index n = vtx.get_num_vertices();
397 for(Index i(0); i < n; ++i)
398 {
399 vtx[i][0] = x_min + (x_max - x_min) * vtx[i][0];
400 if constexpr(shape_dim >= 2)
401 vtx[i][1] = y_min + (y_max - y_min) * vtx[i][1];
402 if constexpr(shape_dim >= 3)
403 vtx[i][2] = z_min + (z_max - z_min) * vtx[i][2];
404 }
405
406 // create control
407 this->create(std::move(base_mesh_node));
408
409 // collect partition statistics
411 }
412
420 {
421 XASSERTM(!this->_was_created, "This function has to be called before domain control creation!");
422 _permutation_strategy = strategy;
423 }
424
427 {
429 }
430
435 {
436 // nothing to do?
438 return;
439
440 // loop over all levels and permute
441 for(std::size_t i(0); i < this->size_physical(); ++i)
442 {
443 this->at(i)->get_mesh_node()->create_permutation(this->_permutation_strategy);
444 }
445 }
446
447 protected:
454 virtual void _reset_parti_types() override
455 {
458 }
459
468 virtual bool _parse_parti_type(const String& type) override
469 {
470 if(type.compare_no_case("extern") == 0)
471 return _allow_parti_extern = true;
472 else if(type.compare_no_case("2level") == 0)
473 return _allow_parti_2level = true;
474 else
475 return BaseClass::_parse_parti_type(type);
476 }
477
484 virtual void _create(std::unique_ptr<MeshNodeType> base_mesh_node)
485 {
486 // ensure that the domain control is still empty
487 XASSERTM(!this->_was_created, "domain has already been created");
488 XASSERT(this->size_physical() == std::size_t(0));
489 XASSERT(this->size_virtual() == std::size_t(0));
490
491 TimeStamp stamp_create;
492
493 // create the domain control
494#ifdef FEAT_HAVE_MPI
495 if(this->_comm.size() == 1)
496 {
497 // We've got just one process, so it's a simple choice:
498 this->_create_single_process(std::move(base_mesh_node));
499 }
500 else if(this->_support_multi_layered && (this->_desired_levels.size() > std::size_t(2)))
501 {
502 // The application supports multi-layered domain controls and
503 // the user wants that, so create a multi-layered one:
504 this->_create_multi_layered(std::move(base_mesh_node));
505 }
506 else
507 {
508 // Create a single-layered domain control:
509 this->_create_single_layered(std::move(base_mesh_node));
510 }
511#else // not FEAT_HAVE_MPI
512 {
513 // In the non-MPI case, we always have only one process:
514 this->_create_single_process(std::move(base_mesh_node));
515 }
516#endif // FEAT_HAVE_MPI
517
518 // compile virtual levels
519 this->compile_virtual_levels();
520
521 // collect partition statistics
523
524 // domain created
525 this->_was_created = true;
526 }
527
539 virtual void _create_single_process(std::unique_ptr<MeshNodeType> base_mesh_node)
540 {
541 // create and push single layer
542 this->push_layer(std::make_shared<LayerType>(this->_comm.comm_dup(), 0));
543
544 // create single ancestry
546 Ancestor& ancestor = this->_ancestry.front();
547
548 // use the whole base mesh here
549 ancestor.parti_info = "Using base-mesh";
550
551 // refine up to desired minimum level
552 int lvl = 0;
553 for(; lvl < ancestor.desired_level_min; ++lvl)
554 {
555 // refine the patch mesh
556 base_mesh_node = base_mesh_node->refine_unique(this->_adapt_mode);
557 }
558
559 // save chosen minimum level if it is not equal to the desired maximum level
560 if(lvl < ancestor.desired_level_max)
561 this->_chosen_levels.push_front(std::make_pair(lvl, 0));
562
563 // refine up to maximum level and push to control
564 for(; lvl < ancestor.desired_level_max; ++lvl)
565 {
566 // refine the base mesh
567 auto refined_node = base_mesh_node->refine_unique(this->_adapt_mode);
568
569 // push this level
570 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
571
572 // continue with refined node
573 base_mesh_node = std::move(refined_node);
574 }
575
576 // save chosen maximum level
577 this->_chosen_levels.push_front(std::make_pair(lvl, 1));
578
579 // push finest level
580 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
581 }
582
583 // Note: all following member functions are only required for parallel builds,
584 // so we enclose them in the following #if-block to reduce compile times.
585
586#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
587
594 virtual void _create_single_layered(std::unique_ptr<MeshNodeType> base_mesh_node)
595 {
596 // create and push single layer
597 std::shared_ptr<LayerType> layer = std::make_shared<LayerType>(this->_comm.comm_dup(), 0);
598 this->push_layer(layer);
599
600 // create single-layered ancestry
602 Ancestor& ancestor = this->_ancestry.front();
603
604 // do we have to keep the base-mesh levels on this process?
605 const bool keep_base = this->_keep_base_levels && (this->_comm.rank() == 0);
606
607 // choose a partitioning strategy
608 this->_check_parti(ancestor, *base_mesh_node, true);
609
610 // refine up to chosen partition level
611 int lvl = 0;
612 for(; lvl < ancestor.parti_level; ++lvl)
613 {
614 // refine the base mesh
615 base_mesh_node = base_mesh_node->refine_unique(this->_adapt_mode);
616 }
617
618 // apply partitioner
619 if(!this->_apply_parti(ancestor, *base_mesh_node))
620 {
621 XABORTM("Failed to find a suitable partitioning");
622 }
623
624 // extract our patch
625 std::vector<int> neighbor_ranks;
626 std::unique_ptr<MeshNodeType> patch_mesh_node(
627 base_mesh_node->extract_patch(neighbor_ranks, ancestor.parti_graph, this->_comm.rank()));
628
629 // set the neighbor ranks of our child layer
630 layer->set_neighbor_ranks(neighbor_ranks);
631
632 // if we have to keep the base-mesh levels, then we also need the patches
633 if(keep_base)
634 {
635 // Note: patch mesh-part for rank = 0 was already created by 'extract_patch' call
636 for(int i(1); i < ancestor.num_parts; ++i)
637 {
638 base_mesh_node->create_patch_meshpart(ancestor.parti_graph, i);
639 }
640 }
641
642 // refine up to minimum level
643 for(; lvl < ancestor.desired_level_min; ++lvl)
644 {
645 // refine the patch mesh
646 patch_mesh_node = patch_mesh_node->refine_unique(this->_adapt_mode);
647
648 // keep base mesh node?
649 if(keep_base)
650 base_mesh_node = base_mesh_node->refine_unique(this->_adapt_mode);
651 }
652
653 // save chosen minimum level
654 if(lvl < ancestor.desired_level_max)
655 this->_chosen_levels.push_front(std::make_pair(lvl, 0));
656
657 // refine up to maximum level
658 for(; lvl < ancestor.desired_level_max; ++lvl)
659 {
660 // refine the patch mesh
661 auto refined_node = patch_mesh_node->refine_unique(this->_adapt_mode);
662
663 // push this (unrefined) level
664 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(patch_mesh_node)));
665
666 // continue with refined node
667 patch_mesh_node = std::move(refined_node);
668
669 // keep base mesh node?
670 if(keep_base)
671 {
672 // refine base-mesh node
673 auto refined_base_mesh_node = base_mesh_node->refine_unique(this->_adapt_mode);
674
675 // push this (unrefined) level
676 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
677
678 // continue with refined node
679 base_mesh_node = std::move(refined_base_mesh_node);
680 }
681 }
682
683 // save chosen maximum level
684 this->_chosen_levels.push_front(std::make_pair(lvl, this->_comm.size()));
685
686 // push finest level
687 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(patch_mesh_node)));
688
689 // keep base mesh node?
690 if(keep_base)
691 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
692 }
693
700 virtual void _create_multi_layered(std::unique_ptr<MeshNodeType> base_mesh_node)
701 {
702 // create layers
704
705 // create ancestry
707
708 // do we have to keep the base-mesh levels on this process?
709 const bool keep_base = this->_keep_base_levels && (this->_comm.rank() == 0);
710
711 // make sure we have at most 2 layers if we want to keep the base-mesh levels
712 XASSERTM(!keep_base || (this->_ancestry.size() <= std::size_t(1)), "cannot keep base levels for more than 2 domain layers (yet)");
713
714 // we start counting at level 0
715 int lvl = 0;
716
717 // move the base-mesh pointer to a new parent-mesh pointer;
718 // the base-mesh is always the one on the layer with only 1 process
719 std::unique_ptr<MeshNodeType> parent_mesh_node = std::move(base_mesh_node);
720 base_mesh_node.reset();
721
722 // loop over all global layers in reverse order (coarse to fine)
723 for(std::size_t slayer = this->_ancestry.size(); slayer > std::size_t(0); )
724 {
725 // is this the base-mesh layer aka the 1-process layer?
726 const bool is_base_layer = (slayer == this->_ancestry.size());
727
728 --slayer;
729
730 // get the ancestor object
731 Ancestor& ancestor = this->_ancestry.at(slayer);
732
733 // determine the minimum desired level of our parent layer
734 int parent_min_lvl = -1;
735 if(!is_base_layer)
736 parent_min_lvl = this->_chosen_levels.front().first;
737 else if(this->_ancestry.size() + 1u < this->_desired_levels.size())
738 parent_min_lvl = this->_desired_levels.back().first;
739
740 // check available partitioning strategies
741 this->_check_parti(ancestor, *parent_mesh_node, is_base_layer);
742
743 // the check_parti function returns the partitioning level w.r.t. the current
744 // level (which may be > 0), so we have to compensate that by adding our current level:
745 ancestor.parti_level += lvl;
746
747 // Note: each progeny group within the main communicator may have chosen a different
748 // partitioning level at this point. We will compensate this by adjusting the minimum
749 // refinement level of the child layer after the partitioning step below.
750
751 // refine up to the chosen partitioning level
752 for(; lvl < ancestor.parti_level; ++lvl)
753 {
754 // refine the base-mesh node
755 auto refined_node = parent_mesh_node->refine_unique(this->_adapt_mode);
756
757 // push the base mesh into our parent layer if desired
758 if((ancestor.layer_p >= 0) && (parent_min_lvl >= 0) && (lvl >= parent_min_lvl))
759 {
760 this->push_level_front(ancestor.layer_p, std::make_shared<LevelType>(lvl, std::move(parent_mesh_node)));
761 }
762
763 // continue with refined node
764 parent_mesh_node = std::move(refined_node);
765
766 // refine base-mesh node if we have one
767 if(base_mesh_node)
768 {
769 // refine base-mesh node
770 auto refined_base_mesh_node = base_mesh_node->refine_unique(this->_adapt_mode);
771
772 // push this (unrefined) level
773 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
774
775 // continue with refined node
776 base_mesh_node = std::move(refined_base_mesh_node);
777 }
778 }
779
780 // we're now at the partitioning level, so apply the partitioner
781 if(!this->_apply_parti(ancestor, *parent_mesh_node))
782 {
783 XABORTM("Failed to find a suitable partitioning");
784 }
785
786 // extract our patch
787 std::vector<int> neighbor_ranks;
788 std::unique_ptr<MeshNodeType> patch_mesh_node(
789 parent_mesh_node->extract_patch(neighbor_ranks, ancestor.parti_graph, ancestor.progeny_child));
790
791 // translate neighbor ranks by progeny group to obtain the neighbor ranks
792 // w.r.t. this layer's communicator
793 {
794 std::map<int,int> halo_map;
795 for(auto& i : neighbor_ranks)
796 {
797 int old_i(i);
798 halo_map.emplace(old_i, i += ancestor.progeny_group);
799 }
800 patch_mesh_node->rename_halos(halo_map);
801 }
802
803 // does this process participate in the parent layer or do we need to keep the base-meshes anyways?
804 if((ancestor.layer_p >= 0) || (keep_base && is_base_layer))
805 {
806 // Note: patch mesh-part for rank = 0 was already created by 'extract_patch' call
807 for(int i(1); i < ancestor.num_parts; ++i)
808 {
809 parent_mesh_node->create_patch_meshpart(ancestor.parti_graph, i);
810 }
811 }
812
813 // make sure we choose the same minimum level for all processes, because we may
814 // have chosen different partitioning levels for each patch
815 int global_level_min = Math::max(ancestor.desired_level_min, ancestor.parti_level);
816 this->_comm.allreduce(&global_level_min, &global_level_min, std::size_t(1), Dist::op_max);
817
818 // make sure our minimum level is greater than the minimum level of the previous layer,
819 // because each layer must contain at least one non-ghost level
820 if(!is_base_layer)
821 global_level_min = Math::max(global_level_min, this->_chosen_levels.front().first+1);
822
823 // refine up to desired minimum level of this layer
824 for(; lvl < global_level_min; ++lvl)
825 {
826 // refine the base mesh node
827 std::unique_ptr<MeshNodeType> coarse_mesh_node(std::move(parent_mesh_node));
828 parent_mesh_node = coarse_mesh_node->refine_unique(this->_adapt_mode);
829
830 // push base mesh to parent layer if desired
831 if((ancestor.layer_p >= 0) && (parent_min_lvl >= 0) && (lvl >= parent_min_lvl))
832 {
833 // clear patches before pushing this node as they are redundant here
834 coarse_mesh_node->clear_patches();
835 this->push_level_front(ancestor.layer_p, std::make_shared<LevelType>(lvl, std::move(coarse_mesh_node)));
836 }
837
838 // refine the patch mesh
839 patch_mesh_node = patch_mesh_node->refine_unique(this->_adapt_mode);
840
841 // refine base-mesh node if we have one
842 if(base_mesh_node)
843 {
844 // refine base-mesh node
845 auto refined_base_mesh_node = base_mesh_node->refine_unique(this->_adapt_mode);
846
847 // push this (unrefined) level
848 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
849
850 // continue with refined node
851 base_mesh_node = std::move(refined_base_mesh_node);
852 }
853 }
854
855 // split the halos of our base-mesh and compute the halos of our patches from that
856 this->_split_basemesh_halos(ancestor, *parent_mesh_node, *patch_mesh_node, neighbor_ranks);
857
858 // does this process participate in the child layer?
859 if(ancestor.layer >= 0)
860 {
861 // set the neighbor ranks in our child layer
862 this->_layers.at(std::size_t(ancestor.layer))->set_neighbor_ranks(neighbor_ranks);
863 }
864
865 // set chosen minimum level for this layer
866 if(!is_base_layer)
867 this->_chosen_levels.push_front(std::make_pair(lvl, this->_ancestry.at(slayer+1u).num_procs));
868 else if(parent_min_lvl < 0)
869 this->_chosen_levels.push_front(std::make_pair(lvl, 0));
870 else
871 {
872 this->_chosen_levels.push_front(std::make_pair(parent_min_lvl, 0));
873 this->_chosen_levels.push_front(std::make_pair(lvl, 1));
874 }
875
876 // if we have to keep the base-mesh, then we have to create a clone here if we're still on the base layer;
877 // we don't need to worry that this is a clone, because it will get refined in the next layer anyways
878 if(keep_base && is_base_layer)
879 {
880 XASSERT(base_mesh_node.get() == nullptr);
881 base_mesh_node = parent_mesh_node->clone_unique();
882 }
883
884 // push the finest base-mesh
885 if(ancestor.layer_p >= 0)
886 {
887 this->push_level_front(ancestor.layer_p, std::make_shared<LevelType>(lvl, std::move(parent_mesh_node)));
888 }
889
890 // continue with the next layer
891 parent_mesh_node = std::move(patch_mesh_node);
892 }
893
894 // get the desired maximum level
895 // if we have more than one layer, make sure that the finest one contains at
896 // least one level, as otherwise the finest global level would be a ghost level
897 int desired_level_max = Math::max(this->_ancestry.front().desired_level_max, lvl+1);
898
899 for(; lvl < desired_level_max; ++lvl)
900 {
901 // refine the patch mesh
902 auto refined_node = parent_mesh_node->refine_unique(this->_adapt_mode);
903
904 // push patch mesh to this level
905 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(parent_mesh_node)));
906
907 // continue with refined node
908 parent_mesh_node = std::move(refined_node);
909
910 // refine base-mesh node if we have one
911 if(base_mesh_node)
912 {
913 // refine base-mesh node
914 auto refined_base_mesh_node = base_mesh_node->refine_unique(this->_adapt_mode);
915
916 // push this (unrefined) level
917 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
918
919 // continue with refined node
920 base_mesh_node = std::move(refined_base_mesh_node);
921 }
922 }
923
924 // push finest level
925 this->push_level_front(0, std::make_shared<LevelType>(lvl, std::move(parent_mesh_node)));
926
927 // set chosen maximum level for finest layer
928 this->_chosen_levels.push_front(std::make_pair(lvl, this->_comm.size()));
929
930 // refine base-mesh node if we have one
931 if(base_mesh_node)
932 this->_base_levels.push_front(std::make_shared<LevelType>(lvl, std::move(base_mesh_node)));
933 }
934
960 virtual bool _check_parti(Ancestor& ancestor, const MeshNodeType& mesh_node, bool is_base_layer) override
961 {
962 // Try to find an appropriate a-priori partitioning first:
963 if(is_base_layer && this->_check_parti_extern(ancestor))
964 return true;
965
966 if(this->_check_parti_2level(ancestor, mesh_node))
967 return true;
968
969 // call base class
970 return BaseClass::_check_parti(ancestor, mesh_node, is_base_layer);
971 }
972
983 {
984 // is this even allowed?
985 if(!this->_allow_parti_extern)
986 return false;
987
988 // check whether we have a suitable partition
989 const Geometry::Partition* part = this->_parti_set.find_partition(ancestor.num_parts, _extern_parti_names);
990 if(part == nullptr)
991 return false;
992
993 // set our ancestor partitioning
994 ancestor.parti_apriori = true;
995 ancestor.parti_info = String("Found extern partition '") + part->get_name() + "'";
996 ancestor.parti_level = part->get_level();
997 ancestor.parti_graph = part->get_patches().clone();
998 return true;
999 }
1000
1013 bool _check_parti_2level(Ancestor& ancestor, const MeshNodeType& base_mesh_node)
1014 {
1015 // is this even allowed?
1016 if(!this->_allow_parti_2level)
1017 return false;
1018
1019 // create a 2-level partitioner
1020 Geometry::Parti2Lvl<MeshType> partitioner(*base_mesh_node.get_mesh(), Index(ancestor.num_parts));
1021
1022 // successful?
1023 if(!partitioner.success())
1024 return false;
1025
1026 // found a valid 2-level partitioning
1027 ancestor.parti_apriori = true;
1028 ancestor.parti_info = String("Found 2-level partition");
1029 ancestor.parti_level = int(partitioner.parti_level());
1030 ancestor.parti_graph = partitioner.build_elems_at_rank();
1031 return true;
1032 }
1033#endif // defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
1034 }; // class PartiDomainControl<...>
1035 } // namespace Domain
1036 } // namespace Control
1037} // namespace FEAT
#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.
Graph clone() const
Clones this graph.
Definition: graph.hpp:311
bool _keep_base_levels
keep base-mesh levels on root process?
bool parti_apriori
specifies whether the chosen partitioning is an a-priori partitioning strategy
int desired_level_max
the desired minimum and maximum refinement levels for this layer
int parti_level
the refinement level on which the patch is to be partitioned
String parti_info
a string containing some information about the chosen partitioning
Adjacency::Graph parti_graph
this is the actual elements-at-rank partitioning graph
int layer_p
the index of the parent layer or -1, if this process is not part of the parent layer
int layer
the index of the layer that this ancestor object belongs to
int num_parts
the number of partitions for each patch of the parent layer
int progeny_child
Which direct child this process belongs to in its progeny group.
Base-Class for Hierarchical Domain Control implementations.
virtual void _reset_parti_types()
Resets/disables all partitioner types.
std::deque< std::pair< int, int > > _desired_levels
desired level deque
std::deque< std::pair< int, int > > _chosen_levels
chosen level deque
virtual void _create_ancestry_scattered()
Creates the layers for a multi-layered domain control in a scattered fashion.
Real WeightType
weight type for partitioner element weights; always Real
std::deque< Ancestor > _ancestry
the partition ancestry deque
virtual bool parse_args(SimpleArgParser &args)
Parses the partitioner options from an argument parser.
Geometry::RootMeshNode< MeshType > MeshNodeType
our root mesh node type
virtual bool _parse_parti_type(const String &type)
Parses a partitioner type.
LevelType::PartType MeshPartType
our mesh-part type
virtual void _create_ancestry_single()
Creates the ancestry for a single layer (or a single process)
Geometry::AdaptMode _adapt_mode
the adapt mode for refinement
bool _was_created
specifies whether the domain control was already created
virtual bool parse_property_map(const PropertyMap &pmap)
Parses the partitioner options from a PropertyMap.
virtual bool _check_parti(Ancestor &ancestor, const MeshNodeType &mesh_node, bool is_base_layer)
Checks for an appropriate partitioning strategy.
bool _support_multi_layered
support multi-layered hierarchy?
virtual bool _apply_parti(Ancestor &ancestor, MeshNodeType &base_mesh_node)
Applies an a-posteriori partitioner.
virtual void _create_multi_layers_scattered()
Creates the layers for a multi-layered domain control in a scattered fashion.
virtual void _split_basemesh_halos(const Ancestor &ancestor, const MeshNodeType &base_mesh_node, MeshNodeType &patch_mesh_node, std::vector< int > &neighbor_ranks)
Splits the base-mesh halos and computes the inter-patch-mesh halos.
Recursively Partitioned Domain Control.
PartiDomainControl(const Dist::Comm &comm_, bool support_multi_layered)
Constructor.
bool _allow_parti_extern
allow extern partitioner?
virtual void _create(std::unique_ptr< MeshNodeType > base_mesh_node)
Creates a domain control from a base-mesh node.
virtual void create_rectilinear(Index num_elems_x, Index num_elems_y=0u, Index num_elems_z=0u)
Creates a domain control from a structured rectilinear base mesh.
virtual bool _parse_parti_type(const String &type) override
Parses a partitioner type.
virtual void _create_multi_layered(std::unique_ptr< MeshNodeType > base_mesh_node)
Creates a multi-layered mesh hierarchy.
Geometry::PermutationStrategy get_permutation_strategy() const
MeshType::CoordType CoordType
coordinate type
static constexpr int shape_dim
shape dimension
bool _allow_parti_2level
allow 2-level partitioner?
Geometry::PartitionSet _parti_set
the extern partition sets
Control::Domain::PartiDomainControlBase< DomainLevel_ > BaseClass
Our base class.
virtual void create_unit_hypercube(Index num_elems_x, Index num_elems_y=0u, Index num_elems_z=0u)
Creates a domain control from a structured rectilinear base mesh.
Geometry::PermutationStrategy _permutation_strategy
the permutation strategy for the mesh permutation
virtual void _create_single_process(std::unique_ptr< MeshNodeType > base_mesh_node)
Creates a single-layered mesh hierarchy for a single process.
virtual void _create_single_layered(std::unique_ptr< MeshNodeType > base_mesh_node)
Creates a single-layered mesh hierarchy.
virtual bool parse_args(SimpleArgParser &args) override
Parses the partitioner options from an argument parser.
bool _check_parti_2level(Ancestor &ancestor, const MeshNodeType &base_mesh_node)
Checks whether the 2-level partitioner can be applied.
virtual void create(Geometry::MeshFileReader &mesh_reader)
Creates a domain control from a MeshFileReader.
virtual void create(std::unique_ptr< MeshNodeType > base_mesh_node)
Creates a domain control from a base-mesh node.
virtual void create_mesh_permutations()
Creates the mesh permutations based on the chosen permutation strategy.
void set_permutation_strategy(Geometry::PermutationStrategy strategy)
Sets the permutation strategy for mesh permutation.
bool _check_parti_extern(Ancestor &ancestor)
Checks whether an extern partition is given.
virtual void create(const std::deque< String > &filenames, String dirpath="")
Creates a domain control from a list of filenames.
virtual void create_rectilinear(Index num_elems_x, CoordType x_min, CoordType x_max, Index num_elems_y=0u, CoordType y_min=CoordType(0), CoordType y_max=CoordType(0), Index num_elems_z=0u, CoordType z_min=CoordType(0), CoordType z_max=CoordType(0))
Creates a domain control from a structured rectilinear base mesh for specific size and add standard b...
std::deque< String > _extern_parti_names
required partition name for extern partitioning
virtual void _reset_parti_types() override
Resets/disables all partitioner types.
virtual bool _check_parti(Ancestor &ancestor, const MeshNodeType &mesh_node, bool is_base_layer) override
Checks for an appropriate partitioning strategy.
virtual bool parse_property_map(const PropertyMap &pmap) override
Parses the partitioner options from a PropertyMap.
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 size() const
Returns the size of this communicator.
Definition: dist.hpp:1814
Comm comm_dup() const
Creates a copy of this communicator.
Definition: dist.cpp:462
int rank() const
Returns the rank of this process in this communicator.
Definition: dist.hpp:1802
BoundaryFactory implementation.
Hit-Test Factory class template.
void add_mesh_files(const Dist::Comm &comm, const std::deque< String > &filenames, String dirpath="")
Adds a list of mesh files to the list of streams to be parsed.
void parse(MeshNodeLinker< RootMesh_ > &linker, RootMeshNode< RootMesh_ > &root_mesh_node, MeshAtlas< RootMesh_ > &mesh_atlas, PartitionSet *part_set=nullptr)
Parses the mesh file into a mesh node and a mesh atlas.
MeshType * get_mesh()
Returns the mesh of this node.
Definition: mesh_node.hpp:225
2-Level-Partitioner class template declaration
Definition: parti_2lvl.hpp:38
const Adjacency::Graph & get_patches() const
const Partition * find_partition(int size, const String &name="", int prio=0) const
Tries to find a suitable partition in the set.
static std::unique_ptr< RootMeshNode > make_unique(std::unique_ptr< MeshType > mesh, MeshAtlasType *atlas=nullptr)
Creates a new RootMeshNode on the heap and returns a unique pointer to it.
Definition: mesh_node.hpp:837
Structured unit-cube mesh factory.
Math Limits class template.
Definition: math.hpp:1475
A class organizing a tree of key-value pairs.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
Simple argument parser implementation.
const std::pair< int, std::deque< String > > * query(const String &option) const
Query the parameters of an option.
void support(const String &option, const String &description=String())
Adds an option to the set of supported options.
static double toe_partition
time of partitioning in seconds, needs initialization
Definition: statistics.hpp:167
String class implementation.
Definition: string.hpp:47
int compare_no_case(const String &other) const
Compares two strings without regard to case.
Definition: string.hpp:680
Time stamp class.
Definition: time_stamp.hpp:54
double elapsed_now() const
Calculates the time elapsed between the time stamp and now.
Definition: time_stamp.hpp:121
void add_supported_pdc_args(SimpleArgParser &args)
Adds the supported arguments of the PartiDomainControl to an argument parser.
const Operation op_max(MPI_MAX)
Operation wrapper for MPI_MAX.
Definition: dist.hpp:573
PermutationStrategy
Mesh permutation strategy enumeration.
@ none
no permutation strategy
T_ pow(T_ x, T_ y)
Returns x raised to the power of y.
Definition: math.hpp:643
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Definition: math.hpp:137
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.