24 Primitive<3>::Direction
dir,
30 mesh->addOrderedPoints(
pts.begin(),
pts.end(),
pts.size());
32 std::vector<double>
ptsv;
34 for (
double p :
pts) {
35 std::vector<double>::reverse_iterator
it;
38 ptsv.insert(
it.base(),
p - split);
39 ptsv.push_back(p + split);
41 mesh->addOrderedPoints(
ptsv.begin(),
ptsv.end(),
ptsv.size());
53 writelog(
LOG_DETAIL,
"mesh.Rectangular1D.SimpleGenerator: Generating new mesh ({0})", mesh->size());
62 mesh->setOptimalIterationOrder();
68 writelog(
LOG_DETAIL,
"mesh.Rectangular2D.SimpleGenerator: Generating new mesh ({0}x{1})", mesh->axis[0]->size(),
69 mesh->axis[1]->size());
85 mesh->setOptimalIterationOrder();
91 writelog(
LOG_DETAIL,
"mesh.Rectangular3D.SimpleGenerator: Generating new mesh ({0}x{1}x{2})", mesh->axis[0]->size(),
92 mesh->axis[1]->size(), mesh->axis[2]->size());
99 for (
size_t i = 1; i < axis->size(); ++i) {
100 total += size_t(
max(
round((axis->at(i) - axis->at(i - 1)) / spacing), 1.));
102 std::vector<double> points;
103 points.reserve(total);
104 for (
size_t i = 1; i < axis->size(); ++i) {
105 const double offset = axis->at(i - 1);
106 const double range = axis->at(i) - offset;
109 for (
size_t j = 0,
n = std::size_t(
steps); j <
n; ++j) {
110 points.push_back(offset +
double(j) * step);
113 points.push_back(axis->at(axis->size() - 1));
114 assert(points.size() == total);
120 writelog(
LOG_DETAIL,
"mesh.Rectangular1D.RegularGenerator: Generating new mesh ({0})", mesh->size());
127 writelog(
LOG_DETAIL,
"mesh.Rectangular2D.RegularGenerator: Generating new mesh ({0}x{1})", mesh->axis[0]->size(),
128 mesh->axis[1]->size());
136 writelog(
LOG_DETAIL,
"mesh.Rectangular3D.RegularGenerator: Generating new mesh ({0}x{1}x{2})", mesh->axis[0]->size(),
137 mesh->axis[1]->size(), mesh->axis[2]->size());
143 for (
size_t i = 1; i != axis->size(); ++i) {
144 double L = axis->at(i) - axis->at(i - 1);
148 return std::pair<double, double>(
min,
max);
154 for (
size_t i = 1; i != axis->size(); ++i) {
155 double L = axis->at(i) - axis->at(i - 1);
158 newpoint = 0.5 * (axis->at(i - 1) + axis->at(i));
175 for (
auto ref : this->refinements[
dir]) {
176 auto object = ref.first.first.lock();
180 auto path = ref.first.second;
181 auto boxes = geometry->getObjectBoundingBoxes(*
object, path);
182 auto origins = geometry->getObjectPositions(*
object, path);
183 if (
boxes.size() == 0)
184 writelog(
LOG_WARNING,
"DivideGenerator: Refinement defined for object absent from the geometry");
188 for (
auto x : ref.second) {
201 return processAxis(axis, geometry,
dir);
207 getAxis(mesh, geometry, 0);
208 writelog(
LOG_DETAIL,
"mesh.Rectilinear1D::{}: Generating new mesh ({:d})", name(), mesh->size());
216 getAxis(
axis0, geometry, 0);
217 getAxis(
axis1, geometry, 1);
223 if (
asp0 > aspect) divideLargestSegment(
axis0);
224 if (
asp1 > aspect) divideLargestSegment(
axis1);
231 mesh->setOptimalIterationOrder();
232 writelog(
LOG_DETAIL,
"mesh.Rectangular2D::{}: Generating new mesh ({:d}x{:d}, max. aspect {:.0f}:1)", name(),
233 mesh->axis[0]->size(), mesh->axis[1]->size(),
max(
asp0,
asp1));
242 getAxis(
axis0, geometry, 0);
243 getAxis(
axis1, geometry, 1);
244 getAxis(
axis2, geometry, 2);
251 if (
asp0 > aspect) divideLargestSegment(
axis0);
252 if (
asp1 > aspect) divideLargestSegment(
axis1);
253 if (
asp2 > aspect) divideLargestSegment(
axis2);
262 mesh->setOptimalIterationOrder();
263 writelog(
LOG_DETAIL,
"mesh.Rectangular3D::{}: Generating new mesh ({:d}x{:d}x{:d}, max. aspect {:.0f}:1)", name(),
264 mesh->axis[0]->size(), mesh->axis[1]->size(), mesh->axis[2]->size(),
max(
asp0,
max(
asp1,
asp2)));
276 if (pre_divisions[
dir] == 0) pre_divisions[
dir] = 1;
277 if (post_divisions[
dir] == 0) post_divisions[
dir] = 1;
282 double x = *
result.begin();
283 std::vector<double> points;
284 points.reserve((pre_divisions[
dir] - 1) * (
result.size() - 1));
285 for (
auto i =
result.begin() + 1; i !=
result.end(); ++i) {
287 for (
size_t j = 1; j != pre_divisions[
dir]; ++j) points.push_back(x + w *
double(j) /
double(pre_divisions[
dir]));
290 result.addOrderedPoints(points.begin(), points.end());
293 if (
result.size() > 2 && getGradual(
dir)) {
294 size_t end =
result.size() - 2;
296 for (
size_t i = 0; i <= end;) {
305 }
else if (w > 2.001 *
w_next) {
330 points.reserve((post_divisions[
dir] - 1) * (
result.size() - 1));
331 for (
auto i =
result.begin() + 1; i !=
result.end(); ++i) {
333 for (
size_t j = 1; j != post_divisions[
dir]; ++j) points.push_back(x + w *
double(j) /
double(post_divisions[
dir]));
337 result.addOrderedPoints(points.begin(), points.end());
359 double x = *axis->begin();
360 std::vector<double> points;
361 for (
auto i = axis->begin() + 1; i != axis->end(); ++i) {
362 double width = *i - x;
364 if (factor[
dir] == 1.) {
365 double m =
ceil(width / finestep[
dir]);
366 double d = width / m;
367 for (
size_t i = 1,
n =
size_t(m); i <
n; ++i) points.push_back(x +
double(i) * d);
379 size_t n = size_t(m);
380 double end = finestep[
dir] * (pow(factor[
dir], m) - 1.) / (factor[
dir] - 1.);
381 double last = finestep[
dir] * pow(factor[
dir], m);
383 lin = size_t(
ceil((width - 2. * end) / last));
384 }
else if (width - 2. * end <= last) {
389 double s = finestep[
dir] * 0.5 * width / (end + 0.5 *
double(
lin) * last);
391 for (
size_t i = 0; i <
n; ++i) {
394 points.push_back(x +
dx);
396 for (
size_t i = 0; i <
lin; ++i) {
398 points.push_back(x +
dx);
400 for (
size_t i = 1; i <
n; ++i) {
403 points.push_back(x +
dx);
407 axis->addOrderedPoints(points.begin(), points.end());
430 if (!
object.lock()) {
443 double objsize =
object.lock()->getBoundingBox().size()[
unsigned(direction)];
444 for (
unsigned i = 1; i < *
by; ++i) {
446 addRefinement(direction,
object, path, pos);
449 double objsize =
object.lock()->getBoundingBox().size()[
unsigned(direction)];
458 addRefinement(direction,
object, path,
loop.pos);
459 }
else if (
auto pos = reader.
getAttribute<
double>(
"at")) {
460 addRefinement(direction,
object, path, *pos);
489static RegisterMeshGeneratorReader ordered_simplegenerator_reader(
"ordered.simple",
491static RegisterMeshGeneratorReader rectangular2d_simplegenerator_reader(
"rectangular2d.simple",
493static RegisterMeshGeneratorReader rectangular3d_simplegenerator_reader(
"rectangular3d.simple",
499 while (reader.requireTagOrEnd()) {
500 if (reader.getNodeName() ==
"spacing") {
501 spacing = reader.getAttribute<
double>(
"every", spacing);
502 reader.requireTagEnd();
503 }
else if (reader.getNodeName() ==
"boundaries") {
504 split = reader.getAttribute<
bool>(
"split", split);
505 reader.requireTagEnd();
507 throw XMLUnexpectedElementException(reader,
"<spacing>, <boundaries>");
515 while (reader.requireTagOrEnd()) {
516 if (reader.getNodeName() ==
"spacing") {
517 if (reader.hasAttribute(
"every")) {
518 if (reader.hasAttribute(
"every0"))
throw XMLConflictingAttributesException(reader,
"every",
"every0");
519 if (reader.hasAttribute(
"every1"))
throw XMLConflictingAttributesException(reader,
"every",
"every1");
520 spacing0 = spacing1 = reader.requireAttribute<
double>(
"every");
522 spacing0 = reader.getAttribute<
double>(
"every0", spacing0);
523 spacing1 = reader.getAttribute<
double>(
"every1", spacing1);
525 reader.requireTagEnd();
526 }
else if (reader.getNodeName() ==
"boundaries") {
527 split = reader.getAttribute<
bool>(
"split", split);
528 reader.requireTagEnd();
530 throw XMLUnexpectedElementException(reader,
"<spacing>, <boundaries>");
538 while (reader.requireTagOrEnd()) {
539 if (reader.getNodeName() ==
"spacing") {
540 if (reader.hasAttribute(
"every")) {
541 if (reader.hasAttribute(
"every0"))
throw XMLConflictingAttributesException(reader,
"every",
"every0");
542 if (reader.hasAttribute(
"every1"))
throw XMLConflictingAttributesException(reader,
"every",
"every1");
543 if (reader.hasAttribute(
"every2"))
throw XMLConflictingAttributesException(reader,
"every",
"every2");
544 spacing0 = spacing1 = reader.requireAttribute<
double>(
"every");
546 spacing0 = reader.getAttribute<
double>(
"every0", spacing0);
547 spacing1 = reader.getAttribute<
double>(
"every1", spacing1);
548 spacing2 = reader.getAttribute<
double>(
"every2", spacing2);
550 reader.requireTagEnd();
551 }
else if (reader.getNodeName() ==
"boundaries") {
552 split = reader.getAttribute<
bool>(
"split", split);
553 reader.requireTagEnd();
555 throw XMLUnexpectedElementException(reader,
"<spacing>, <boundaries>");
560static RegisterMeshGeneratorReader ordered_regulargenerator_reader(
"ordered.regular", readRegularGenerator1);
561static RegisterMeshGeneratorReader rectangular2d_regulargenerator_reader(
"rectangular2d.regular", readRegularGenerator2);
562static RegisterMeshGeneratorReader rectangular3d_regulargenerator_reader(
"rectangular3d.regular", readRegularGenerator3);
567 std::set<std::string> read;
578 for (
int i = 0; i < dim; ++i)
result->pre_divisions[i] = *
into;
580 for (
int i = 0; i < dim; ++i)
result->pre_divisions[i] = reader.
getAttribute<
size_t>(format(
"by{0}", i), 1);
589 for (
int i = 0; i < dim; ++i)
result->post_divisions[i] = *
into;
591 for (
int i = 0; i < dim; ++i)
result->post_divisions[i] = reader.
getAttribute<
size_t>(format(
"by{0}", i), 1);
600 result->gradual = (*gradual) ? 7 : 0;
602 for (
int i = 0; i < dim; ++i) {
609 result->fromXML(reader, manager);
627 std::set<std::string> read;
641 for (
int i = 0; i < dim; ++i)
648 for (
int i = 0; i < dim; ++i)
result->maxstep[i] = *
large;
650 for (
int i = 0; i < dim; ++i)
652 plask::optional<double> factor = reader.
getAttribute<
double>(
"factor");
657 for (
int i = 0; i < dim; ++i)
result->factor[i] = *factor;
659 for (
int i = 0; i < dim; ++i)
666 result->fromXML(reader, manager);