|
27 | 27 |
|
28 | 28 | #include <basis/Defaults.h>
|
29 | 29 | #include <basis/GenerateMesh.h>
|
| 30 | +#include <cmath> |
30 | 31 |
|
31 | 32 | namespace dftefe
|
32 | 33 | {
|
@@ -204,7 +205,7 @@ namespace dftefe
|
204 | 205 | i =
|
205 | 206 | std::pow(2,
|
206 | 207 | round(log2(
|
207 |
| - (std::max(4.0, largestMeshSizeAroundAtom) /*4.0*/) / |
| 208 | + (std::max(8.0, largestMeshSizeAroundAtom) /*4.0*/) / |
208 | 209 | largestMeshSizeAroundAtom))) *
|
209 | 210 | largestMeshSizeAroundAtom;
|
210 | 211 | }
|
@@ -384,21 +385,129 @@ namespace dftefe
|
384 | 385 | return isAnyCellRefined;
|
385 | 386 | }
|
386 | 387 |
|
| 388 | + bool |
| 389 | + GenerateMesh::refineInsideSystemNonPeriodicAlgorithm( |
| 390 | + TriangulationBase & triangulation, |
| 391 | + std::vector<double> &maxAtomCoordinates, |
| 392 | + std::vector<double> &minAtomCoordinates) |
| 393 | + { |
| 394 | + auto cell = triangulation.beginLocal(); |
| 395 | + auto endc = triangulation.endLocal(); |
| 396 | + |
| 397 | + double currentMeshSize = (*cell)->minimumVertexDistance(); |
| 398 | + bool isAnyCellRefined = false; |
| 399 | + size_type cellIndex = 0; |
| 400 | + for (; cell != endc; ++cell) |
| 401 | + { |
| 402 | + utils::Point center(d_dim, 0.0); |
| 403 | + (*cell)->center(center); |
| 404 | + |
| 405 | + bool cellRefineFlag = false; |
| 406 | + |
| 407 | + double boundingBoxDom = 0; |
| 408 | + for (int i = 0; i < d_dim; i++) |
| 409 | + { |
| 410 | + double axesLen = std::max(std::abs(maxAtomCoordinates[i]), |
| 411 | + std::abs(minAtomCoordinates[i])) + |
| 412 | + std::max(15.0, d_radiusAroundAtom); |
| 413 | + if (boundingBoxDom < axesLen) |
| 414 | + boundingBoxDom = axesLen; |
| 415 | + } |
| 416 | + bool val = true; |
| 417 | + for (int i = 0; i < d_dim; i++) |
| 418 | + { |
| 419 | + if (std::abs(center[i]) > boundingBoxDom) |
| 420 | + { |
| 421 | + val = false; |
| 422 | + break; |
| 423 | + } |
| 424 | + // val += std::pow((center[i]/ axesLen),2); |
| 425 | + } |
| 426 | + if (val && currentMeshSize > 4) |
| 427 | + { |
| 428 | + cellRefineFlag = true; |
| 429 | + } |
| 430 | + |
| 431 | + size_type cellRefineFlagSizeType = (size_type)cellRefineFlag; |
| 432 | + |
| 433 | + utils::mpi::MPIAllreduce<utils::MemorySpace::HOST>( |
| 434 | + utils::mpi::MPIInPlace, |
| 435 | + &cellRefineFlagSizeType, |
| 436 | + 1, |
| 437 | + utils::mpi::Types<size_type>::getMPIDatatype(), |
| 438 | + utils::mpi::MPIMax, |
| 439 | + d_mpiInterpoolCommunicator); |
| 440 | + |
| 441 | + cellRefineFlag = cellRefineFlagSizeType; |
| 442 | + |
| 443 | + // |
| 444 | + // set coarsen flags |
| 445 | + if (cellRefineFlag) |
| 446 | + { |
| 447 | + (*cell)->setRefineFlag(); |
| 448 | + isAnyCellRefined = true; |
| 449 | + } |
| 450 | + cellIndex += 1; |
| 451 | + } |
| 452 | + return isAnyCellRefined; |
| 453 | + } |
| 454 | + |
387 | 455 | void
|
388 | 456 | GenerateMesh::createMesh(TriangulationBase &triangulation)
|
389 | 457 | {
|
390 | 458 | triangulation.initializeTriangulationConstruction();
|
391 | 459 | generateCoarseMesh(triangulation, d_isPeriodicFlags);
|
392 | 460 |
|
| 461 | + bool refineFlag = true; |
| 462 | + // all directions non periodic, note, can be extended to some dicrecs. |
| 463 | + // non-periodic |
| 464 | + if (!(std::any_of(d_isPeriodicFlags.begin(), |
| 465 | + d_isPeriodicFlags.end(), |
| 466 | + [](bool v) { return v; }))) |
| 467 | + { |
| 468 | + std::vector<double> maxAtomCoordinates(d_dim, 0); |
| 469 | + std::vector<double> minAtomCoordinates(d_dim, 0); |
| 470 | + |
| 471 | + for (int j = 0; j < d_dim; j++) |
| 472 | + { |
| 473 | + for (int i = 0; i < d_atomCoordinates.size(); i++) |
| 474 | + { |
| 475 | + if (maxAtomCoordinates[j] < d_atomCoordinates[i][j]) |
| 476 | + maxAtomCoordinates[j] = d_atomCoordinates[i][j]; |
| 477 | + if (minAtomCoordinates[j] > d_atomCoordinates[i][j]) |
| 478 | + minAtomCoordinates[j] = d_atomCoordinates[i][j]; |
| 479 | + } |
| 480 | + } |
| 481 | + refineFlag = |
| 482 | + refineInsideSystemNonPeriodicAlgorithm(triangulation, |
| 483 | + maxAtomCoordinates, |
| 484 | + minAtomCoordinates); |
| 485 | + |
| 486 | + // This sets the global refinement sweep flag |
| 487 | + size_type refineFlagSizeType = (size_type)refineFlag; |
| 488 | + |
| 489 | + utils::mpi::MPIAllreduce<utils::MemorySpace::HOST>( |
| 490 | + utils::mpi::MPIInPlace, |
| 491 | + &refineFlagSizeType, |
| 492 | + 1, |
| 493 | + utils::mpi::Types<size_type>::getMPIDatatype(), |
| 494 | + utils::mpi::MPIMax, |
| 495 | + d_mpiDomainCommunicator); |
| 496 | + |
| 497 | + refineFlag = refineFlagSizeType; |
| 498 | + } |
| 499 | + triangulation.executeCoarseningAndRefinement(); |
| 500 | + triangulation.finalizeTriangulationConstruction(); |
| 501 | + |
393 | 502 | d_triaCurrentRefinement.clear();
|
394 | 503 |
|
395 | 504 | //
|
396 | 505 | // Call only refinementAlgorithm. Multilevel refinement is
|
397 | 506 | // performed until refinementAlgorithm does not set refinement flags on
|
398 | 507 | // any cell.
|
399 | 508 | //
|
400 |
| - size_type numLevels = 0; |
401 |
| - bool refineFlag = true; |
| 509 | + size_type numLevels = 0; |
| 510 | + refineFlag = true; |
402 | 511 | while (refineFlag)
|
403 | 512 | {
|
404 | 513 | refineFlag = false;
|
|
0 commit comments