OpenPFC implements a basic multidimensional array to make it easier to work with indices. Implementation makes it possible to give offset for indices. This can help working with discrete fields of data, when the field is decomposed to several different machines using domain decomposition and MPI. Example will follow. Interally, Array<T,D> uses std::vector<T> to hold data of type T and MultiIndex<D> to make index manipulations. In this example, we introduce two arrays, one with offset like it would be in the case of domain decomposition, and fill in some values based on indices.
#include <algorithm>
#include <iostream>
using namespace pfc;
std::array<T, 9> data;
<< utils::array_to_string(
tensor.data);
}
};
int main() {
std::cout <<
arr0 << std::endl;
std::cout <<
arr1 << std::endl;
std::cout <<
"First item of arr0: " <<
arr0[{0, 0}] << std::endl;
std::cout <<
"First item of arr1: " <<
arr1[{8, 0}] << std::endl;
std::cout <<
"First item of arr0: " <<
arr0.get_data()[0] << std::endl;
std::cout <<
"First item of arr1: " <<
arr1.get_data()[0] << std::endl;
auto f = [&](
auto indices) {
const auto [
i,
j] = indices;
};
std::cout <<
"First item of arr0: " <<
arr0.get_data()[0]
<< std::endl;
std::cout <<
"First item of arr1: " <<
arr1.get_data()[0]
<< std::endl;
std::transform(
arr0.get_index().begin(),
arr0.get_index().end(),
arr0.get_data().begin(),
f);
std::transform(
arr1.get_index().begin(),
arr1.get_index().end(),
arr1.get_data().begin(),
f);
tensors[{1, 1}] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
<< std::endl;
}
return 0;
}
Multi-dimensional array container for field data.
Definition 07_array.cpp:25
Definition typename.hpp:48
Represents the global simulation domain (the "world").
Definition world.hpp:91
Get human-readable type names at runtime.
General utility functions.