53template <
typename T,
size_t D>
class Array {
65 Array(
const FFT &fft, std::true_type)
66 : index(get_outbox(fft).size, get_outbox(fft).
low) {}
74 Array(
const FFT &fft, std::false_type)
75 : index(get_inbox(fft).size, get_inbox(fft).
low) {}
78 template <
typename U>
struct is_complex : std::false_type {};
79 template <
typename U>
struct is_complex<std::complex<U>> : std::true_type {};
89 Array(
const std::array<int, D> &dimensions,
90 const std::array<int, D> &
offsets = {0})
92 data.resize(index.get_linear_size());
105 data.resize(index.get_linear_size());
108 typename std::vector<T>::iterator begin() {
return data.begin(); }
109 typename std::vector<T>::iterator end() {
return data.end(); }
110 typename std::vector<T>::const_iterator begin()
const {
return data.begin(); }
111 typename std::vector<T>::const_iterator end()
const {
return data.end(); }
127 T &operator[](
const std::array<int, D> &indices) {
128 return operator[](index.to_linear(indices));
131 T &operator[](
int idx) {
return data.operator[](idx); }
133 T &operator()(
const std::array<int, D> &indices) {
return operator[](indices); }
140 std::array<int, D>
get_size()
const {
return index.get_size(); }
147 std::array<int, D>
get_offset()
const {
return index.get_offset(); }
157 return index.inbounds(indices);
169 std::is_convertible_v<std::invoke_result_t<Func, std::array<int, D>>, T>,
170 "Func must be invocable with std::array<int, D> and return a type "
172 auto it = index.begin();
182 operator std::vector<T> &() {
return data; }
184 void set_data(
const std::vector<T> &
new_data) {
185 if (
new_data.size() != index.get_linear_size()) {
186 throw std::runtime_error(
"Dimension mismatch, set_data failed");
188 this->data = std::move(new_data);
201 <<
">(begin = " << utils::array_to_string(index.get_begin())
202 <<
", end = " << utils::array_to_string(index.get_end())
203 <<
", size = " << utils::array_to_string(index.get_size())
204 <<
", linear_size = " << index.get_linear_size() <<
")";
209template <
typename T,
size_t D>
void show(Array<T, D> &array) {
210 utils::show(array.get_data(), array.get_index().get_size(),
211 array.get_index().get_begin());
Convert std::array to string representation.
friend std::ostream & operator<<(std::ostream &os, const Array< T, D > &array)
Outputs the array to the specified output stream.
Definition array.hpp:198
std::array< int, D > get_size() const
Get the size object.
Definition array.hpp:140
bool inbounds(const std::array< int, D > &indices)
Checks if the specified indices are in bounds.
Definition array.hpp:156
const MultiIndex< D > & get_index() const
Get the index object.
Definition array.hpp:118
std::array< int, D > get_offset() const
Get the offset object.
Definition array.hpp:147
std::vector< T > & get_data()
Get the data object.
Definition array.hpp:125
Array(const Decomposition &decomp)
Constructs an Array object from Decomposition object. Array dimension and offset depends from the typ...
Definition array.hpp:104
Array(const std::array< int, D > &dimensions, const std::array< int, D > &offsets={0})
Constructs an Array object with the specified dimensions and offsets.
Definition array.hpp:89
void apply(Func &&func)
Applies the specified function to each element of the array.
Definition array.hpp:167
Domain decomposition for parallel MPI simulations.
Fast Fourier Transform interface for spectral methods.
Multi-dimensional indexing utilities.
Pretty-print 3D arrays to console.
Definition typename.hpp:48
Describes a static, pure partitioning of the global simulation domain into local subdomains.
Definition decomposition.hpp:182
FFT class for distributed-memory parallel Fourier transforms.
Definition fft.hpp:248
Represents the global simulation domain (the "world").
Definition world.hpp:91
Get human-readable type names at runtime.