SCOREC core
Parallel unstructured mesh tools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
apfPartition.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Scientific Computation Research Center
3  *
4  * This work is open source software, licensed under the terms of the
5  * BSD license as described in the LICENSE file in the top-level directory.
6  */
7 
8 #ifndef APF_PARTITION_H
9 #define APF_PARTITION_H
10 
14 #include "apfMesh2.h"
15 
16 namespace apf {
17 
21 class Splitter
22 {
23  public:
24  virtual ~Splitter() {}
39  virtual Migration* split(MeshTag* weights, double tolerance,
40  int multiple) = 0;
41 };
42 
46 class Balancer
47 {
48  public:
49  virtual ~Balancer() {}
63  virtual void balance(MeshTag* weights, double tolerance) = 0;
64 };
65 
67 struct Remap
68 {
69  virtual int operator()(int n) = 0;
70 };
71 
73 struct Divide : public Remap
74 {
75  Divide(int n):by(n) {}
76  int operator()(int n) {return n / by;}
77 private:
78  int by;
79 };
80 
82 struct Multiply : public Remap
83 {
84  Multiply(int n):by(n) {}
85  int operator()(int n) {return n * by;}
86 private:
87  int by;
88 };
89 
91 struct Modulo : public Remap
92 {
93  Modulo(int n):by(n) {}
94  int operator()(int n) {return n % by;}
95 private:
96  int by;
97 };
98 
100 struct Unmodulo : public Remap
101 {
102  Unmodulo(int original, int factor)
103  {
104  offset = (original / factor) * factor;
105  }
106  int operator()(int n) {return n + offset;}
107 private:
108  int offset;
109 };
110 
112 struct Round : public Remap
113 {
114  Round(int n):factor(n) {}
115  int operator()(int n) {return (n / factor) * factor;}
116 private:
117  int factor;
118 };
119 
120 struct Expand : public Remap
121 {
122  Expand(int nin, int nout):
123  quotient(nout / nin),
124  remainder(nout % nin)
125  {}
126  int operator()(int in)
127  {
128  if (in < remainder)
129  return in * quotient + in;
130  return in * quotient + remainder;
131  }
132  bool shouldOutBeIn(int out)
133  {
134  if (out < remainder * (quotient + 1))
135  return out % (quotient + 1) == 0;
136  return (out - remainder * (quotient + 1)) % quotient == 0;
137  }
138 private:
139  int quotient;
140  int remainder;
141 };
142 
143 struct Contract : public Remap
144 {
145  Contract(int nin, int nout):
146  quotient(nout / nin),
147  remainder(nout % nin)
148  {}
149  int operator()(int out)
150  {
151  if (out < remainder * (quotient + 1))
152  return out / (quotient + 1);
153  return (out - remainder * (quotient + 1)) / quotient + remainder;
154  }
155  bool isValid(int out)
156  {
157  if (out < remainder * (quotient + 1))
158  return out % (quotient + 1) == 0;
159  return (out - remainder * (quotient + 1)) % quotient == 0;
160  }
161 private:
162  int quotient;
163  int remainder;
164 };
165 
176 void remapPartition(apf::Mesh2* m, Remap& remap);
177 
178 }
179 
180 #endif
multiply the part id
Definition: apfPartition.h:82
map to nearest multiple of n
Definition: apfPartition.h:112
Migration plan object: local elements to destinations.
Definition: apfMesh.h:453
a map from old part ids to new part ids
Definition: apfPartition.h:67
Load balance over all mesh parts.
Definition: apfPartition.h:46
divide the part id
Definition: apfPartition.h:73
void remapPartition(apf::Mesh2 *m, Remap &remap)
remap all part ids in the mesh structure
return part id modulo n
Definition: apfPartition.h:91
The APF Mesh modification interface.
inverse of apf::Modulo
Definition: apfPartition.h:100
virtual void balance(MeshTag *weights, double tolerance)=0
call collective load balancing
Extended mesh interface for modification.
Definition: apfMesh2.h:29
Splits a mesh part into many.
Definition: apfPartition.h:21
virtual Migration * split(MeshTag *weights, double tolerance, int multiple)=0
call the underlying split algorithm