OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
world_queries.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
29#pragma once
30
31#include "csys.hpp"
32#include "types.hpp"
33#include "world.hpp"
34#include <vector>
35
36namespace pfc {
37namespace world {
38
41using pfc::types::Real3;
42
43// ============================================================================
44// Core Property Queries
45// ============================================================================
46
75template <typename T> inline Int3 get_size(const World<T> &world) noexcept {
76 return world.m_size;
77}
78
106template <typename T> inline int get_size(const World<T> &world, int index) {
107 return get_size(world).at(index);
108}
109
140template <typename T> inline size_t get_total_size(const World<T> &world) noexcept {
141 return get_size(world, 0) * get_size(world, 1) * get_size(world, 2);
142}
143
149inline const auto &get_lower(const CartesianWorld &world) noexcept {
150 return world.m_lower;
151}
152
159inline const auto &get_lower(const CartesianWorld &world, int index) {
160 return get_lower(world).at(index);
161}
162
168inline const auto &get_upper(const CartesianWorld &world) noexcept {
169 return world.m_upper;
170}
171
178inline auto get_upper(const CartesianWorld &world, int index) {
179 return get_upper(world).at(index);
180}
181
182// ============================================================================
183// Coordinate System Queries
184// ============================================================================
185
191template <typename T>
192inline const auto &get_coordinate_system(const World<T> &world) noexcept {
193 return world.m_cs;
194}
195
227inline const Real3 &get_spacing(const CartesianWorld &world) noexcept {
228 return get_spacing(get_coordinate_system(world));
229}
230
255inline double get_spacing(const CartesianWorld &world, int index) noexcept {
256 return get_spacing(get_coordinate_system(world), index);
257}
258
290inline const Real3 &get_origin(const CartesianWorld &world) noexcept {
291 return get_offset(get_coordinate_system(world));
292}
293
317inline double get_origin(const CartesianWorld &world, int index) noexcept {
318 return get_offset(get_coordinate_system(world), index);
319}
320
321// ============================================================================
322// Coordinate Transformations
323// ============================================================================
324
365template <typename T>
366inline auto to_coords(const World<T> &world, const Int3 &indices) noexcept {
367 return to_coords(get_coordinate_system(world), indices);
368}
369
420template <typename T>
421inline auto to_indices(const World<T> &world, const Real3 &coords) noexcept {
422 return to_index(get_coordinate_system(world), coords);
423}
424
425// ============================================================================
426// Physical Domain Queries
427// ============================================================================
428
449template <typename T> inline double physical_volume(const World<T> &world) noexcept {
450 const auto spacing = get_spacing(world);
451 const auto size = get_size(world);
452 return spacing[0] * spacing[1] * spacing[2] * size[0] * size[1] * size[2];
453}
454
471template <typename T> inline bool is_1d(const World<T> &world) noexcept {
472 const auto size = get_size(world);
473 return (size[0] > 1) && (size[1] == 1) && (size[2] == 1);
474}
475
492template <typename T> inline bool is_2d(const World<T> &world) noexcept {
493 const auto size = get_size(world);
494 return (size[0] > 1) && (size[1] > 1) && (size[2] == 1);
495}
496
513template <typename T> inline bool is_3d(const World<T> &world) noexcept {
514 const auto size = get_size(world);
515 return (size[0] > 1) && (size[1] > 1) && (size[2] > 1);
516}
517
535template <typename T> inline int dimensionality(const World<T> &world) noexcept {
536 if (is_3d(world)) return 3;
537 if (is_2d(world)) return 2;
538 if (is_1d(world)) return 1;
539 return 0; // Degenerate case (all dimensions size 1)
540}
541
558template <typename T> inline Real3 get_lower_bounds(const World<T> &world) noexcept {
559 return to_coords(world, {0, 0, 0});
560}
561
578template <typename T> inline Real3 get_upper_bounds(const World<T> &world) noexcept {
579 const auto size = get_size(world);
580 return to_coords(world, {size[0] - 1, size[1] - 1, size[2] - 1});
581}
582
583} // namespace world
584} // namespace pfc
585
586namespace pfc {
587namespace world {
588
606template <typename T>
607inline std::array<std::vector<double>, 3>
608coordinates(const World<T> &world) noexcept {
609 std::array<std::vector<double>, 3> result;
610 const auto size = get_size(world);
611 const auto origin = get_origin(world);
612 const auto spacing = get_spacing(world);
613 for (int d = 0; d < 3; ++d) {
614 result[d].resize(size[d]);
615 for (int i = 0; i < size[d]; ++i) {
616 result[d][i] = origin[d] + i * spacing[d];
617 }
618 }
619 return result;
620}
621
622} // namespace world
623} // namespace pfc
std::array< int, 3 > Int3
Type aliases for clarity.
Definition types.hpp:45
Extensible coordinate system framework.
const Real3 & get_spacing(const CartesianCS &cs) noexcept
Get the spacing of the coordinate system.
Definition csys.hpp:252
const Int3 to_index(const CartesianCS &cs, const Real3 &xyz) noexcept
Convert physical coordinates to grid indices.
Definition csys.hpp:307
const Real3 to_coords(const CartesianCS &cs, const Int3 &idx) noexcept
Convert grid indices to physical coordinates.
Definition csys.hpp:291
const Real3 & get_offset(const CartesianCS &cs) noexcept
Get the offset of the coordinate system.
Definition csys.hpp:234
bool is_3d(const World< T > &world) noexcept
Check if domain is 3D (all dimensions have > 1 point)
Definition world_queries.hpp:513
int dimensionality(const World< T > &world) noexcept
Get dimensionality as integer.
Definition world_queries.hpp:535
bool is_1d(const World< T > &world) noexcept
Check if domain is 1D (only x-direction has > 1 point)
Definition world_queries.hpp:471
const auto & get_upper(const CartesianWorld &world) noexcept
Get the upper bounds of the world in a specific dimension.
Definition world_queries.hpp:168
const auto & get_lower(const CartesianWorld &world) noexcept
Get the lower bounds of the world.
Definition world_queries.hpp:149
Real3 get_lower_bounds(const World< T > &world) noexcept
Get physical lower bounds (origin corner)
Definition world_queries.hpp:558
World< CartesianTag > CartesianWorld
Type alias for Cartesian 3D World (most common usage)
Definition world.hpp:134
bool is_2d(const World< T > &world) noexcept
Check if domain is 2D (x and y have > 1 point, z has 1)
Definition world_queries.hpp:492
double physical_volume(const World< T > &world) noexcept
Compute physical volume of domain.
Definition world_queries.hpp:449
const auto & get_coordinate_system(const World< T > &world) noexcept
Get the coordinate system of the world.
Definition world_queries.hpp:192
Real3 get_upper_bounds(const World< T > &world) noexcept
Get physical upper bounds (far corner)
Definition world_queries.hpp:578
Primary template for defining coordinate systems by tag.
Definition csys.hpp:87
Represents the global simulation domain (the "world").
Definition world.hpp:91
const Int3 m_lower
Lower index bounds.
Definition world.hpp:92
const CoordinateSystem< T > m_cs
Coordinate system.
Definition world.hpp:95
const Int3 m_upper
Upper index bounds.
Definition world.hpp:93
const Int3 m_size
Grid dimensions: {nx, ny, nz}.
Definition world.hpp:94
Common type aliases used throughout OpenPFC.
World class definition and unified interface.