dune-composites (2.5.1)

partitionofunity.hh
1#ifndef DUNE_GENEO_PARTITIONOFUNITY_HH
2#define DUNE_GENEO_PARTITIONOFUNITY_HH
3
4namespace Dune{
5 namespace Geneo{
6
7 template<const int dim, class X, class GFS, class LFS, class CC>
8 std::shared_ptr<X> standardPartitionOfUnity(const GFS& gfs, LFS& lfs, const CC& cc) {
9
10 auto part_unity = std::make_shared<X>(gfs, 1);
11
12 Dune::PDELab::set_constrained_dofs(cc,0.0,*part_unity); // Zero on subdomain boundary
13
14 Dune::PDELab::AddDataHandle<GFS,X> parth(gfs,*part_unity);
15 gfs.gridView().communicate(parth,Dune::All_All_Interface,Dune::ForwardCommunication);
16
17 Dune::PDELab::set_constrained_dofs(cc,0.0,*part_unity); // Zero on subdomain boundary (Need that a 2nd time due to add comm before!)
18
19 for (auto iter = part_unity->begin(); iter != part_unity->end(); iter++) {
20 if (*iter > 0)
21 *iter = 1.0 / *iter;
22 }
23 return part_unity;
24 }
25
26 template<const int dim, class X, class GFS, class LFS, class CC>
27 std::shared_ptr<X> sarkisPartitionOfUnity(const GFS& gfs, LFS& lfs, const CC& cc) {
28 using Dune::PDELab::Backend::native;
29
30 int my_rank = gfs.gridView().comm().rank();
31
32 auto part_unity = std::make_shared<X>(gfs, 1);
33
34 int cells = configuration.get<int>("Grid.cells", 10);
35 int overlap = configuration.get<int>("Grid.overlap", 1);
36 int partition_x = configuration.get<int>("Grid.partition_x", 1);
37 int partition_y = configuration.get<int>("Grid.partition_y", 1);
38
39 for (auto it = gfs.gridView().template begin<0>(); it != gfs.gridView().template end<0>(); ++it) {
40
41 lfs.bind(*it);
42
43 auto geo = it->geometry();
44 const auto gt = geo.type();
45 const auto& ref_el = Dune::ReferenceElements<double, dim>::general(gt);
46
47 auto& coeffs = lfs.finiteElement().localCoefficients();
48
49 for (std::size_t i = 0; i < coeffs.size(); ++i) {
50
51 auto local_pos = ref_el.position (coeffs.localKey(i).subEntity(), coeffs.localKey(i).codim());
52
53 auto global_pos = geo.global(local_pos);
54
55 auto subindex = gfs.entitySet().indexSet().subIndex(*it, coeffs.localKey(i).subEntity(), coeffs.localKey(i).codim());
56
57 double Hx = 1.0 / (double)partition_x;
58 double Hy = 1.0 / (double)partition_y;
59 double h = (double)overlap / cells;
60
61 int row = std::floor(my_rank / partition_x);
62 int col = my_rank - partition_x * row;
63
64 double dx1 = (col + 1) * Hx + h - global_pos[0];
65 double dx2 = global_pos[0] - (col * Hx - h);
66
67 double dy1 = (row + 1) * Hy + h - global_pos[1];
68 double dy2 = global_pos[1] - (row * Hy - h);
69
70 if (row == 0) dy2 = 2*Hy;
71 if (row == partition_y - 1) dy1 = 2*Hy;
72 if (col == 0) dx2 = 2*Hx;
73 if (col == partition_x - 1) dx1 = 2*Hx;
74
75 native(*part_unity)[subindex] = std::min(std::min(std::min(dx1, dx2), dy1), dy2);
76 }
77 }
78
79 X sum_dists(gfs, 0.0);
80 sum_dists = *part_unity;
81 Dune::PDELab::AddDataHandle<GFS,X> addh_dists(gfs,sum_dists);
82 gfs.gridView().communicate(addh_dists,Dune::All_All_Interface,Dune::ForwardCommunication);
83
84 auto iter_sum = sum_dists.begin();
85 for (auto iter = part_unity->begin(); iter != part_unity->end(); iter++) {
86 if (*iter > 0)
87 *iter *= 1.0 / *iter_sum;
88 iter_sum++;
89 }
90
91 Dune::PDELab::set_constrained_dofs(cc,0.0,*part_unity); // Zero on Dirichlet domain boundary
92
93 return part_unity;
94 }
95
96 }
97}
98
99
100#endif //DUNE_GENEO_PARTITIONOFUNITY_HH
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 5, 22:35, 2025)