OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
decomposition.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 VTT Technical Research Centre of Finland Ltd
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
41#pragma once
42
44#include <array>
45#include <heffte.h>
46#include <ostream>
47#include <stdexcept>
48#include <vector>
49
50namespace pfc {
51
56namespace world {
57
61template <typename T>
62inline auto create(const World<T> &world, const heffte::box3d<int> &box) {
63 return World(box.low, box.high, get_coordinate_system(world));
64}
65
66template <typename T> inline auto to_indices(const World<T> &world) {
67 std::array<int, 3> lower = get_lower(world);
68 std::array<int, 3> upper = get_upper(world);
69 return heffte::box3d<int>(lower, upper);
70}
71
72template <typename T>
73inline auto split_world(const World<T> &world, const Int3 &grid) {
74 std::vector<World<T>> sub_worlds;
75 for (const auto &box : heffte::split_world(to_indices(world), grid)) {
76 sub_worlds.push_back(create(world, box));
77 }
78 return sub_worlds;
79}
80
81} // namespace world
82
83namespace decomposition {
84
86using pfc::types::Bool3;
88using pfc::types::Real3;
89
91using Int3 = pfc::types::Int3;
92
93using heffte::proc_setup_min_surface;
94
183
185 const std::array<int, 3> m_grid;
186 const std::vector<pfc::World> m_subworlds;
187
188 Decomposition(const World &world, const Int3 grid)
189 : m_global_world(world), m_grid(grid), m_subworlds(split_world(world, grid)) {}
190
191 friend std::ostream &operator<<(std::ostream &os, const Decomposition &d) {
192 os << "Decomposition:\n";
193 os << " Global World: " << d.m_global_world << "\n";
194 os << " Grid: [" << d.m_grid.at(0) << ", " << d.m_grid.at(1) << ", "
195 << d.m_grid.at(2) << "]\n";
196 os << " Sub-worlds:\n";
197 for (size_t i = 0; i < d.m_subworlds.size(); ++i) {
198 os << " Sub-world " << i << ": " << d.m_subworlds[i] << "\n";
199 }
200 return os;
201 }
202};
203
228inline const auto &get_global_world(const Decomposition &decomposition) noexcept {
229 return decomposition.m_global_world;
230}
231
240inline const auto &get_world(const Decomposition &decomposition) noexcept {
241 return get_global_world(decomposition);
242}
243
272inline const auto &get_grid(const Decomposition &decomposition) noexcept {
273 return decomposition.m_grid;
274}
275
306inline const auto &get_subworlds(const Decomposition &decomposition) noexcept {
307 return decomposition.m_subworlds;
308}
309
345inline const auto &get_subworld(const Decomposition &decomposition, int i) {
346 return get_subworlds(decomposition).at(i);
347}
348
391inline auto create(const World &world, const Int3 &grid) noexcept {
392 return Decomposition(world, grid);
393};
394
446inline auto create(const World &world, const int &nparts) noexcept {
447 auto indices = to_indices(world);
448 auto grid = proc_setup_min_surface(indices, nparts);
449 return create(world, grid);
450}
451
493inline int get_num_domains(const Decomposition &decomposition) noexcept {
494 return get_subworlds(decomposition).size();
495}
496
497} // namespace decomposition
498
499using Decomposition = decomposition::Decomposition;
500
501} // namespace pfc
std::array< int, 3 > Int3
Type aliases for clarity.
Definition types.hpp:45
const auto & get_world(const Decomposition &decomposition) noexcept
Alias for get_global_world()
Definition decomposition.hpp:240
const auto & get_upper(const CartesianWorld &world) noexcept
Get the upper bounds of the world in a specific dimension.
Definition world_queries.hpp:168
auto create(const World< T > &world, const heffte::box3d< int > &box)
Construct a new World object from an existing one and a box.
Definition decomposition.hpp:62
const auto & get_lower(const CartesianWorld &world) noexcept
Get the lower bounds of the world.
Definition world_queries.hpp:149
const auto & get_coordinate_system(const World< T > &world) noexcept
Get the coordinate system of the world.
Definition world_queries.hpp:192
Tag type for the 3D Cartesian coordinate system.
Definition csys.hpp:147
Describes a static, pure partitioning of the global simulation domain into local subdomains.
Definition decomposition.hpp:182
const std::vector< pfc::World > m_subworlds
The sub-worlds for each part.
Definition decomposition.hpp:186
const std::array< int, 3 > m_grid
The number of parts in each dimension.
Definition decomposition.hpp:185
const pfc::World & m_global_world
The World object.
Definition decomposition.hpp:184
Represents the global simulation domain (the "world").
Definition world.hpp:91
World(const Int3 &lower, const Int3 &upper, const CoordinateSystem< T > &cs)
Constructs a World object.
World class definition and unified interface.