OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
types.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
35#pragma once
36
37#include <array>
38#include <stdexcept>
39
40namespace pfc {
41
42namespace types {
43
45using Int3 = std::array<int, 3>;
46using Real3 = std::array<double, 3>;
47using Bool3 = std::array<bool, 3>;
48
49// Forward declarations
50struct Size3;
51struct Periodic3;
52struct LowerBounds3;
53struct UpperBounds3;
54struct Spacing3;
55
56namespace utils {
65const Real3 compute_upper_bounds(const Size3 &size, const LowerBounds3 &lower,
66 const Spacing3 &spacing, const Periodic3 &periodic);
67
76Real3 compute_spacing(const Size3 &size, const LowerBounds3 &lower,
77 const UpperBounds3 &upper, const Periodic3 &periodic);
78
79} // namespace utils
80
84struct Size3 {
85
86 const std::array<int, 3> value;
87
88 explicit Size3(const std::array<int, 3> &v) : value(v) {
89 for (int dim : v) {
90 if (dim <= 0) {
91 throw std::invalid_argument("Size values must be positive.");
92 }
93 }
94 };
95};
96
100struct Periodic3 {
101
102 const std::array<bool, 3> value;
103
104 explicit Periodic3(const std::array<bool, 3> &v) : value(v) {}
105};
106
111
112 const std::array<double, 3> value;
113
114 explicit LowerBounds3(const std::array<double, 3> &v) : value(v) {}
115};
116
121
122 const std::array<double, 3> value;
123
124 explicit UpperBounds3(const std::array<double, 3> &v) : value(v) {}
125
131 UpperBounds3(const Size3 &size, const LowerBounds3 &lower, const Spacing3 &spacing,
132 const Periodic3 &periodic)
133 : UpperBounds3(utils::compute_upper_bounds(size, lower, spacing, periodic)) {}
134};
135
139struct Spacing3 {
140
141 const std::array<double, 3> value;
142
143 explicit Spacing3(const std::array<double, 3> &v) : value(v) {
144 for (double dim : v) {
145 if (dim <= 0.0) {
146 throw std::invalid_argument("Spacing values must be positive.");
147 }
148 }
149 };
150
160 Spacing3(const Size3 &size, const LowerBounds3 &lower, const UpperBounds3 &upper,
161 const Periodic3 &periodic)
162 : Spacing3(utils::compute_spacing(size, lower, upper, periodic)) {}
163};
164
165} // namespace types
166
167using Int3 = types::Int3;
168using Real3 = types::Real3;
169using Bool3 = types::Bool3;
170
171} // namespace pfc
const Real3 compute_upper_bounds(const Size3 &size, const LowerBounds3 &lower, const Spacing3 &spacing, const Periodic3 &periodic)
Computes the upper bounds based on size, lower bounds, and spacing.
std::array< int, 3 > Int3
Type aliases for clarity.
Definition types.hpp:45
Real3 compute_spacing(const Size3 &size, const LowerBounds3 &lower, const UpperBounds3 &upper, const Periodic3 &periodic)
Computes the spacing based on size, lower bounds, and upper bounds.
Represents the lower bounds of the 3d simulation domain.
Definition types.hpp:110
Represents the periodicity of the 3d simulation domain.
Definition types.hpp:100
Represents the size of the 3d simulation domain.
Definition types.hpp:84
Represents the spacing of the 3d simulation grid.
Definition types.hpp:139
Spacing3(const Size3 &size, const LowerBounds3 &lower, const UpperBounds3 &upper, const Periodic3 &periodic)
Constructs a Spacing3 object from a Size3, LowerBounds3, UpperBounds3, and Periodic3.
Definition types.hpp:160
Represents the upper bounds of the 3d simulation domain.
Definition types.hpp:120
UpperBounds3(const Size3 &size, const LowerBounds3 &lower, const Spacing3 &spacing, const Periodic3 &periodic)
Constructs an UpperBounds3 object from a Size3 and LowerBounds3.
Definition types.hpp:131
Represents the global simulation domain (the "world").
Definition world.hpp:91