7 #include "GmshConfig.h"
20 #if defined(HAVE_MESH)
45 return "Plugin(SimplePartition) partitions the current mesh into "
46 "`NumSlicesX', `NumSlicesY' and `NumSlicesZ' slices along the X-, Y- "
47 "and Z-axis, respectively. The distribution of these slices is "
48 "governed by `MappingX', `MappingY' and `MappingZ', where `t' is a "
49 "normalized absissa along each direction. (Setting `MappingX' to "
50 "`t' will thus lead to equidistant slices along the X-axis.)";
75 #if defined(HAVE_MESH)
79 std::vector<std::string> exprX(1), exprY(1), exprZ(1);
87 Msg::Error(
"Plugin(SimplePartition) requires a mesh");
91 if(numSlicesX < 1 || numSlicesY < 1 || numSlicesZ < 1) {
92 Msg::Error(
"Number of slices should be strictly positive");
98 double pminX = bbox.
min()[0], pmaxX = bbox.
max()[0];
99 double pminY = bbox.
min()[1], pmaxY = bbox.
max()[1];
100 double pminZ = bbox.
min()[2], pmaxZ = bbox.
max()[2];
101 std::vector<double> ppX(numSlicesX + 1);
102 std::vector<double> ppY(numSlicesY + 1);
103 std::vector<double> ppZ(numSlicesZ + 1);
104 std::vector<std::string> variables(1,
"t");
105 std::vector<double> values(1), res(1);
109 for(
int p = 0; p <= numSlicesX; p++) {
110 double t = values[0] = (double)p / (
double)numSlicesX;
111 if(
f.eval(values, res)) t = res[0];
112 ppX[p] = pminX + t * (pmaxX - pminX);
115 bool emptyX = (ppX[0] == ppX[numSlicesX]);
118 for(
int p = 0; p <= numSlicesY; p++) {
119 double t = values[0] = (double)p / (
double)numSlicesY;
120 if(
f.eval(values, res)) t = res[0];
121 ppY[p] = pminY + t * (pmaxY - pminY);
124 bool emptyY = (ppY[0] == ppY[numSlicesY]);
127 for(
int p = 0; p <= numSlicesZ; p++) {
128 double t = values[0] = (double)p / (
double)numSlicesZ;
129 if(
f.eval(values, res)) t = res[0];
130 ppZ[p] = pminZ + t * (pmaxZ - pminZ);
133 bool emptyZ = (ppZ[0] == ppZ[numSlicesZ]);
135 std::vector<GEntity *> entities;
137 std::vector<std::pair<MElement *, int> > elmToPartition;
138 for(std::size_t i = 0; i < entities.size(); i++) {
144 for(
int kx = 0; kx < numSlicesX; kx++) {
146 for(
int ky = 0; ky < numSlicesY; ky++) {
148 for(
int kz = 0; kz < numSlicesZ; kz++) {
150 if((emptyX || (kx == 0 && ppX[0] == point[0]) ||
151 (ppX[kx] < point[0] && point[0] <= ppX[kx + 1])) &&
152 (emptyY || (ky == 0 && ppY[0] == point[1]) ||
153 (ppY[ky] < point[1] && point[1] <= ppY[ky + 1])) &&
154 (emptyZ || (kz == 0 && ppZ[0] == point[2]) ||
155 (ppZ[kz] < point[2] && point[2] <= ppZ[kz + 1]))) {
156 part = kx * numSlicesY * numSlicesZ + ky * numSlicesZ + kz + 1;
157 elmToPartition.push_back(
158 std::pair<MElement *, unsigned int>(e, part));
174 Msg::Error(
"Gmsh must be compiled with Mesh support to partition meshes");