25 std::set<double>
pts = geometry->getPointsAlong(
dir);
26 std::vector<double>
ptsv;
29 for (
double p :
pts)
ptsv.push_back(p);
32 for (
double p :
pts) {
33 std::vector<double>::reverse_iterator
it;
35 ptsv.insert(
it.base(), p - split);
36 ptsv.push_back(p + split);
48 writelog(
LOG_DETAIL,
"mesh.Rectangular1D.SimpleGenerator: Generating new mesh ({0})", mesh->size());
57 mesh->setOptimalIterationOrder();
63 writelog(
LOG_DETAIL,
"mesh.Rectangular2D.SimpleGenerator: Generating new mesh ({0}x{1})", mesh->axis[0]->size(),
64 mesh->axis[1]->size());
78 mesh->setOptimalIterationOrder();
84 writelog(
LOG_DETAIL,
"mesh.Rectangular3D.SimpleGenerator: Generating new mesh ({0}x{1}x{2})", mesh->axis[0]->size(),
85 mesh->axis[1]->size(), mesh->axis[2]->size());
92 for (
size_t i = 1; i < axis->size(); ++i) {
93 total += size_t(
max(
round((axis->at(i) - axis->at(i - 1)) / spacing), 1.));
95 std::vector<double> points;
96 points.reserve(total);
97 for (
size_t i = 1; i < axis->size(); ++i) {
98 const double offset = axis->at(i - 1);
99 const double range = axis->at(i) - offset;
102 for (
size_t j = 0,
n = std::size_t(
steps); j <
n; ++j) {
103 points.push_back(offset +
double(j) * step);
106 points.push_back(axis->at(axis->size() - 1));
107 assert(points.size() == total);
113 writelog(
LOG_DETAIL,
"mesh.Rectangular1D.RegularGenerator: Generating new mesh ({0})", mesh->size());
120 writelog(
LOG_DETAIL,
"mesh.Rectangular2D.RegularGenerator: Generating new mesh ({0}x{1})", mesh->axis[0]->size(),
121 mesh->axis[1]->size());
129 writelog(
LOG_DETAIL,
"mesh.Rectangular3D.RegularGenerator: Generating new mesh ({0}x{1}x{2})", mesh->axis[0]->size(),
130 mesh->axis[1]->size(), mesh->axis[2]->size());
136 for (
size_t i = 1; i != axis->size(); ++i) {
137 double L = axis->at(i) - axis->at(i - 1);
141 return std::pair<double, double>(
min,
max);
147 for (
size_t i = 1; i != axis->size(); ++i) {
148 double L = axis->at(i) - axis->at(i - 1);
151 newpoint = 0.5 * (axis->at(i - 1) + axis->at(i));
168 for (
auto ref : this->refinements[
dir]) {
169 auto object = ref.first.first.lock();
173 auto path = ref.first.second;
174 auto boxes = geometry->getObjectBoundingBoxes(*
object, path);
175 auto origins = geometry->getObjectPositions(*
object, path);
176 if (
boxes.size() == 0)
writelog(
LOG_WARNING,
"DivideGenerator: Refinement defined for object absent from the geometry");
180 for (
auto x : ref.second) {
192 return processAxis(axis, geometry,
dir);
198 getAxis(mesh, geometry, 0);
199 writelog(
LOG_DETAIL,
"mesh.Rectilinear1D::{}: Generating new mesh ({:d})", name(), mesh->size());
207 getAxis(
axis0, geometry, 0);
208 getAxis(
axis1, geometry, 1);
214 if (
asp0 > aspect) divideLargestSegment(
axis0);
215 if (
asp1 > aspect) divideLargestSegment(
axis1);
222 mesh->setOptimalIterationOrder();
223 writelog(
LOG_DETAIL,
"mesh.Rectangular2D::{}: Generating new mesh ({:d}x{:d}, max. aspect {:.0f}:1)", name(),
224 mesh->axis[0]->size(), mesh->axis[1]->size(),
max(
asp0,
asp1));
233 getAxis(
axis0, geometry, 0);
234 getAxis(
axis1, geometry, 1);
235 getAxis(
axis2, geometry, 2);
242 if (
asp0 > aspect) divideLargestSegment(
axis0);
243 if (
asp1 > aspect) divideLargestSegment(
axis1);
244 if (
asp2 > aspect) divideLargestSegment(
axis2);
253 mesh->setOptimalIterationOrder();
254 writelog(
LOG_DETAIL,
"mesh.Rectangular3D::{}: Generating new mesh ({:d}x{:d}x{:d}, max. aspect {:.0f}:1)", name(),
255 mesh->axis[0]->size(), mesh->axis[1]->size(), mesh->axis[2]->size(),
max(
asp0,
max(
asp1,
asp2)));
267 if (pre_divisions[
dir] == 0) pre_divisions[
dir] = 1;
268 if (post_divisions[
dir] == 0) post_divisions[
dir] = 1;
273 double x = *
result.begin();
274 std::vector<double> points;
275 points.reserve((pre_divisions[
dir] - 1) * (
result.size() - 1));
276 for (
auto i =
result.begin() + 1; i !=
result.end(); ++i) {
278 for (
size_t j = 1; j != pre_divisions[
dir]; ++j) points.push_back(x + w *
double(j) /
double(pre_divisions[
dir]));
281 result.addOrderedPoints(points.begin(), points.end());
284 if (
result.size() > 2 && getGradual(
dir)) {
285 size_t end =
result.size() - 2;
287 for (
size_t i = 0; i <= end;) {
296 }
else if (w > 2.001 *
w_next) {
321 points.reserve((post_divisions[
dir] - 1) * (
result.size() - 1));
322 for (
auto i =
result.begin() + 1; i !=
result.end(); ++i) {
324 for (
size_t j = 1; j != post_divisions[
dir]; ++j) points.push_back(x + w *
double(j) /
double(post_divisions[
dir]));
328 result.addOrderedPoints(points.begin(), points.end());
350 double x = *axis->begin();
351 std::vector<double> points;
352 for (
auto i = axis->begin() + 1; i != axis->end(); ++i) {
353 double width = *i - x;
355 if (factor[
dir] == 1.) {
356 double m =
ceil(width / finestep[
dir]);
357 double d = width / m;
358 for (
size_t i = 1,
n =
size_t(m); i <
n; ++i) points.push_back(x +
double(i) * d);
370 size_t n = size_t(m);
371 double end = finestep[
dir] * (pow(factor[
dir], m) - 1.) / (factor[
dir] - 1.);
372 double last = finestep[
dir] * pow(factor[
dir], m);
374 lin = size_t(
ceil((width - 2. * end) / last));
375 }
else if (width - 2. * end <= last) {
380 double s = finestep[
dir] * 0.5 * width / (end + 0.5 *
double(
lin) * last);
382 for (
size_t i = 0; i <
n; ++i) {
385 points.push_back(x +
dx);
387 for (
size_t i = 0; i <
lin; ++i) {
389 points.push_back(x +
dx);
391 for (
size_t i = 1; i <
n; ++i) {
394 points.push_back(x +
dx);
398 axis->addOrderedPoints(points.begin(), points.end());
421 if (!
object.lock()) {
434 double objsize =
object.lock()->getBoundingBox().size()[
unsigned(direction)];
435 for (
unsigned i = 1; i < *
by; ++i) {
437 addRefinement(direction,
object, path, pos);
440 double objsize =
object.lock()->getBoundingBox().size()[
unsigned(direction)];
449 addRefinement(direction,
object, path,
loop.pos);
450 }
else if (
auto pos = reader.
getAttribute<
double>(
"at")) {
451 addRefinement(direction,
object, path, *pos);
480static RegisterMeshGeneratorReader ordered_simplegenerator_reader(
"ordered.simple",
482static RegisterMeshGeneratorReader rectangular2d_simplegenerator_reader(
"rectangular2d.simple",
484static RegisterMeshGeneratorReader rectangular3d_simplegenerator_reader(
"rectangular3d.simple",
490 while (reader.requireTagOrEnd()) {
491 if (reader.getNodeName() ==
"spacing") {
492 spacing = reader.getAttribute<
double>(
"every", spacing);
493 reader.requireTagEnd();
494 }
else if (reader.getNodeName() ==
"boundaries") {
495 split = reader.getAttribute<
bool>(
"split", split);
496 reader.requireTagEnd();
498 throw XMLUnexpectedElementException(reader,
"<spacing>, <boundaries>");
506 while (reader.requireTagOrEnd()) {
507 if (reader.getNodeName() ==
"spacing") {
508 if (reader.hasAttribute(
"every")) {
509 if (reader.hasAttribute(
"every0"))
throw XMLConflictingAttributesException(reader,
"every",
"every0");
510 if (reader.hasAttribute(
"every1"))
throw XMLConflictingAttributesException(reader,
"every",
"every1");
511 spacing0 = spacing1 = reader.requireAttribute<
double>(
"every");
513 spacing0 = reader.getAttribute<
double>(
"every0", spacing0);
514 spacing1 = reader.getAttribute<
double>(
"every1", spacing1);
516 reader.requireTagEnd();
517 }
else if (reader.getNodeName() ==
"boundaries") {
518 split = reader.getAttribute<
bool>(
"split", split);
519 reader.requireTagEnd();
521 throw XMLUnexpectedElementException(reader,
"<spacing>, <boundaries>");
529 while (reader.requireTagOrEnd()) {
530 if (reader.getNodeName() ==
"spacing") {
531 if (reader.hasAttribute(
"every")) {
532 if (reader.hasAttribute(
"every0"))
throw XMLConflictingAttributesException(reader,
"every",
"every0");
533 if (reader.hasAttribute(
"every1"))
throw XMLConflictingAttributesException(reader,
"every",
"every1");
534 if (reader.hasAttribute(
"every2"))
throw XMLConflictingAttributesException(reader,
"every",
"every2");
535 spacing0 = spacing1 = reader.requireAttribute<
double>(
"every");
537 spacing0 = reader.getAttribute<
double>(
"every0", spacing0);
538 spacing1 = reader.getAttribute<
double>(
"every1", spacing1);
539 spacing2 = reader.getAttribute<
double>(
"every2", spacing2);
541 reader.requireTagEnd();
542 }
else if (reader.getNodeName() ==
"boundaries") {
543 split = reader.getAttribute<
bool>(
"split", split);
544 reader.requireTagEnd();
546 throw XMLUnexpectedElementException(reader,
"<spacing>, <boundaries>");
551static RegisterMeshGeneratorReader ordered_regulargenerator_reader(
"ordered.regular", readRegularGenerator1);
552static RegisterMeshGeneratorReader rectangular2d_regulargenerator_reader(
"rectangular2d.regular", readRegularGenerator2);
553static RegisterMeshGeneratorReader rectangular3d_regulargenerator_reader(
"rectangular3d.regular", readRegularGenerator3);
558 std::set<std::string> read;
569 for (
int i = 0; i < dim; ++i)
result->pre_divisions[i] = *
into;
571 for (
int i = 0; i < dim; ++i)
result->pre_divisions[i] = reader.
getAttribute<
size_t>(format(
"by{0}", i), 1);
580 for (
int i = 0; i < dim; ++i)
result->post_divisions[i] = *
into;
582 for (
int i = 0; i < dim; ++i)
result->post_divisions[i] = reader.
getAttribute<
size_t>(format(
"by{0}", i), 1);
591 result->gradual = (*gradual) ? 7 : 0;
593 for (
int i = 0; i < dim; ++i) {
600 result->fromXML(reader, manager);
618 std::set<std::string> read;
632 for (
int i = 0; i < dim; ++i)
639 for (
int i = 0; i < dim; ++i)
result->maxstep[i] = *
large;
641 for (
int i = 0; i < dim; ++i)
643 plask::optional<double> factor = reader.
getAttribute<
double>(
"factor");
648 for (
int i = 0; i < dim; ++i)
result->factor[i] = *factor;
650 for (
int i = 0; i < dim; ++i)
657 result->fromXML(reader, manager);