Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef APF_PARTITION_H
00009 #define APF_PARTITION_H
00010
00014 #include "apfMesh2.h"
00015
00016 namespace apf {
00017
00021 class Splitter
00022 {
00023 public:
00024 virtual ~Splitter() {}
00039 virtual Migration* split(MeshTag* weights, double tolerance,
00040 int multiple) = 0;
00041 };
00042
00046 class Balancer
00047 {
00048 public:
00049 virtual ~Balancer() {}
00063 virtual void balance(MeshTag* weights, double tolerance) = 0;
00064 };
00065
00067 struct Remap
00068 {
00069 virtual int operator()(int n) = 0;
00070 };
00071
00073 struct Divide : public Remap
00074 {
00075 Divide(int n):by(n) {}
00076 int operator()(int n) {return n / by;}
00077 private:
00078 int by;
00079 };
00080
00082 struct Multiply : public Remap
00083 {
00084 Multiply(int n):by(n) {}
00085 int operator()(int n) {return n * by;}
00086 private:
00087 int by;
00088 };
00089
00091 struct Modulo : public Remap
00092 {
00093 Modulo(int n):by(n) {}
00094 int operator()(int n) {return n % by;}
00095 private:
00096 int by;
00097 };
00098
00100 struct Unmodulo : public Remap
00101 {
00102 Unmodulo(int original, int factor)
00103 {
00104 offset = (original / factor) * factor;
00105 }
00106 int operator()(int n) {return n + offset;}
00107 private:
00108 int offset;
00109 };
00110
00112 struct Round : public Remap
00113 {
00114 Round(int n):factor(n) {}
00115 int operator()(int n) {return (n / factor) * factor;}
00116 private:
00117 int factor;
00118 };
00119
00120 struct Expand : public Remap
00121 {
00122 Expand(int nin, int nout):
00123 quotient(nout / nin),
00124 remainder(nout % nin)
00125 {}
00126 int operator()(int in)
00127 {
00128 if (in < remainder)
00129 return in * quotient + in;
00130 return in * quotient + remainder;
00131 }
00132 bool shouldOutBeIn(int out)
00133 {
00134 if (out < remainder * (quotient + 1))
00135 return out % (quotient + 1) == 0;
00136 return (out - remainder * (quotient + 1)) % quotient == 0;
00137 }
00138 private:
00139 int quotient;
00140 int remainder;
00141 };
00142
00143 struct Contract : public Remap
00144 {
00145 Contract(int nin, int nout):
00146 quotient(nout / nin),
00147 remainder(nout % nin)
00148 {}
00149 int operator()(int out)
00150 {
00151 if (out < remainder * (quotient + 1))
00152 return out / (quotient + 1);
00153 return (out - remainder * (quotient + 1)) / quotient + remainder;
00154 }
00155 bool isValid(int out)
00156 {
00157 if (out < remainder * (quotient + 1))
00158 return out % (quotient + 1) == 0;
00159 return (out - remainder * (quotient + 1)) % quotient == 0;
00160 }
00161 private:
00162 int quotient;
00163 int remainder;
00164 };
00165
00176 void remapPartition(apf::Mesh2* m, Remap& remap);
00177
00178 }
00179
00180 #endif