1#ifndef DUNE_GENEO_PARTITIONOFUNITY_HH
2#define DUNE_GENEO_PARTITIONOFUNITY_HH
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) {
10 auto part_unity = std::make_shared<X>(gfs, 1);
12 Dune::PDELab::set_constrained_dofs(cc,0.0,*part_unity);
14 Dune::PDELab::AddDataHandle<GFS,X> parth(gfs,*part_unity);
15 gfs.gridView().communicate(parth,Dune::All_All_Interface,Dune::ForwardCommunication);
17 Dune::PDELab::set_constrained_dofs(cc,0.0,*part_unity);
19 for (
auto iter = part_unity->begin(); iter != part_unity->end(); iter++) {
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;
30 int my_rank = gfs.gridView().comm().rank();
32 auto part_unity = std::make_shared<X>(gfs, 1);
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);
39 for (
auto it = gfs.gridView().template begin<0>(); it != gfs.gridView().template end<0>(); ++it) {
43 auto geo = it->geometry();
44 const auto gt = geo.type();
45 const auto& ref_el = Dune::ReferenceElements<double, dim>::general(gt);
47 auto& coeffs = lfs.finiteElement().localCoefficients();
49 for (std::size_t i = 0; i < coeffs.size(); ++i) {
51 auto local_pos = ref_el.position (coeffs.localKey(i).subEntity(), coeffs.localKey(i).codim());
53 auto global_pos = geo.global(local_pos);
55 auto subindex = gfs.entitySet().indexSet().subIndex(*it, coeffs.localKey(i).subEntity(), coeffs.localKey(i).codim());
57 double Hx = 1.0 / (double)partition_x;
58 double Hy = 1.0 / (double)partition_y;
59 double h = (double)overlap / cells;
61 int row = std::floor(my_rank / partition_x);
62 int col = my_rank - partition_x * row;
64 double dx1 = (col + 1) * Hx + h - global_pos[0];
65 double dx2 = global_pos[0] - (col * Hx - h);
67 double dy1 = (row + 1) * Hy + h - global_pos[1];
68 double dy2 = global_pos[1] - (row * Hy - h);
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;
75 native(*part_unity)[subindex] = std::min(std::min(std::min(dx1, dx2), dy1), dy2);
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);
84 auto iter_sum = sum_dists.begin();
85 for (
auto iter = part_unity->begin(); iter != part_unity->end(); iter++) {
87 *iter *= 1.0 / *iter_sum;
91 Dune::PDELab::set_constrained_dofs(cc,0.0,*part_unity);