25#include <blockforest/Initialization.h>
26#include <blockforest/StructuredBlockForest.h>
27#include <core/DataTypes.h>
28#include <core/cell/Cell.h>
29#include <domain_decomposition/IBlock.h>
34#include <initializer_list>
43 unsigned int n_ghost_layers)
44 : m_grid_dimensions{grid_dimensions}, m_n_ghost_layers{n_ghost_layers} {
45 using walberla::real_t;
46 using walberla::uint_c;
48 for (
auto const i : {0u, 1u, 2u}) {
49 if (m_grid_dimensions[i] % node_grid[i] != 0) {
50 throw std::runtime_error(
51 "Lattice grid dimensions and MPI node grid are not compatible.");
55 auto constexpr lattice_constant = real_t{1};
58 m_blocks = walberla::blockforest::createUniformBlockGrid(
60 uint_c(node_grid[0]), uint_c(node_grid[1]), uint_c(node_grid[2]),
62 uint_c(cells_block[0]), uint_c(cells_block[1]), uint_c(cells_block[2]),
65 uint_c(node_grid[0]), uint_c(node_grid[1]), uint_c(node_grid[2]),
68 for (IBlock &
block : *m_blocks) {
69 m_cached_blocks.push_back(&
block);
73[[nodiscard]] std::pair<Utils::Vector3d, Utils::Vector3d>
77 assert(++(m_blocks->begin()) == m_blocks->end());
79 auto const ab = m_blocks->begin()->getAABB();
80 return {to_vector3d(ab.min()), to_vector3d(ab.max())};
86 return ::walberla::get_block_and_cell(*
this, node,
false) != std::nullopt;
90 return ::walberla::get_block_and_cell(*
this, node,
true) != std::nullopt;
94 return ::walberla::get_block(*
this, pos,
false) !=
nullptr;
98 return ::walberla::get_block(*
this, pos,
true) !=
nullptr;
104 auto const grid_dimensions =
106 static_cast<int>(std::round(box_size[1] / agrid)),
107 static_cast<int>(std::round(box_size[2] / agrid))}};
108 for (
auto const i : {0u, 1u, 2u}) {
109 if (std::abs(grid_dimensions[i] * agrid - box_size[i]) / box_size[i] >
110 std::numeric_limits<double>::epsilon()) {
111 throw std::runtime_error(
112 "Box length not commensurate with agrid in direction " +
113 std::to_string(i) +
" length " + std::to_string(box_size[i]) +
114 " agrid " + std::to_string(agrid));
117 return grid_dimensions;
Vector implementation and trait types for boost qvm interoperability.
bool pos_in_local_halo(Utils::Vector3d const &pos) const
static Utils::Vector3i calc_grid_dimensions(Utils::Vector3d const &box_size, double agrid)
bool node_in_local_halo(Utils::Vector3i const &node) const
std::pair< Utils::Vector3d, Utils::Vector3d > get_local_domain() const
LatticeWalberla(Utils::Vector3i const &grid_dimensions, Utils::Vector3i const &node_grid, unsigned int n_ghost_layers)
bool node_in_local_domain(Utils::Vector3i const &node) const
bool pos_in_local_domain(Utils::Vector3d const &pos) const
static double * block(double *p, std::size_t index, std::size_t size)
auto hadamard_division(Vector< T, N > const &a, Vector< U, N > const &b)
Utils::Vector3d to_vector3d(Vector3< float > const &v)