8#include "tarch/la/Vector.h"
24enum class IndexTrait { vector, local, md2macro, noGhost };
25namespace TraitOperations {
31template <IndexTrait t1>
constexpr bool is_same(
const IndexTrait& t2) {
return t1 == t2; }
45template <IndexTrait t1, IndexTrait t2, IndexTrait... rest>
constexpr bool is_ordered() {
46 if constexpr (
sizeof...(rest) == 0) {
49 return t1 < t2 and is_ordered<t2, rest...>();
71template <
unsigned int dim, IndexTrait... traits>
class CellIndex;
81template <
unsigned int dim, IndexTrait... traits> tarch::la::Vector<dim, int> convertToVector(
const CellIndex<dim, traits...>&);
98 if constexpr (
sizeof...(traits) > 1) {
99 return coupling::indexing::TraitOperations::is_ordered<traits...>();
104 static_assert(
checkIndexTraitOrder(),
"Invalid order in IndexTrait parameter pack! Correct oder: "
105 "IndexTrait::vector < IndexTrait::local < IndexTrait::md2macro "
106 "< IndexTrait::noGhost");
111 using value_T = std::conditional_t<(coupling::indexing::TraitOperations::is_same<coupling::indexing::IndexTrait::vector>(traits) or ...),
129 template <coupling::indexing::IndexTrait... converted_traits>
operator CellIndex<dim, converted_traits...>()
const;
146 if constexpr (std::is_same_v<value_T, tarch::la::Vector<dim, int>>) {
153 if constexpr (dim == 3)
168 if constexpr (std::is_same_v<value_T, tarch::la::Vector<dim, int>>) {
175 if constexpr (dim == 3)
192 bool operator==(
const CellIndex& i)
const {
return _index == i.
get(); }
193 bool operator!=(
const CellIndex& i)
const {
return not(i == *
this); }
194 bool operator<(
const CellIndex& i)
const {
return convertToScalar<dim, traits...>(*this) < convertToScalar<dim, traits...>(i); };
195 bool operator<=(
const CellIndex& i)
const {
return convertToScalar<dim, traits...>(*this) <= convertToScalar<dim, traits...>(i); };
196 bool operator>(
const CellIndex& i)
const {
return convertToScalar<dim, traits...>(*this) > convertToScalar<dim, traits...>(i); };
197 bool operator>=(
const CellIndex& i)
const {
return convertToScalar<dim, traits...>(*this) >= convertToScalar<dim, traits...>(i); };
205 for (
unsigned int d = 0; d < dim; d++)
206 cellnum[d] = std::max(0, cellnum[d]);
210 for (
unsigned int d = 0; d < dim; d++)
214 for (
unsigned int d = 1; d < dim; d++)
227 static bool contains(
const coupling::indexing::BaseIndex<dim>& index) {
228 for (
unsigned int d = 0; d < dim; d++) {
239 BaseIndex<dim> globalIndex{*
this};
241 0.5 * IndexingService<dim>::getInstance().getCouplingCellSize());
242 for (
unsigned int d = 0; d < dim; d++)
243 cellMidPoint[d] += ((
double)(globalIndex.get()[d])) * IndexingService<dim>::getInstance().getCouplingCellSize()[d];
278 class IndexIterator {
281 IndexIterator(
const IndexIterator& a) : _idx(a._idx) {}
283 const CellIndex& operator*()
const {
return _idx; }
284 const CellIndex* operator->()
const {
return &_idx; }
287 IndexIterator& operator++() {
293 IndexIterator operator++(
int) {
294 IndexIterator tmp = *
this;
299 friend bool operator==(
const IndexIterator& a,
const IndexIterator& b) {
return a._idx == b._idx; };
300 friend bool operator!=(
const IndexIterator& a,
const IndexIterator& b) {
return a._idx != b._idx; };
307 if constexpr (std::is_same_v<unsigned int, value_T>) {
317 static IndexIterator end() {
325 static const char TNAME[];
330 template <coupling::indexing::IndexTrait T1, coupling::indexing::IndexTrait... other_traits>
CellIndex<dim, other_traits...> getScalarCellIndex(
int value) {
331 static_assert(T1 == coupling::indexing::IndexTrait::vector);
332 return CellIndex<dim, other_traits...>(value);
337#include "CellIndex.cpph"
Definition CellIndex.h:278
Definition CellIndex.h:85
static unsigned int linearNumberCellsInDomain
Definition CellIndex.h:270
static BaseIndex< dim > lowerBoundary
Definition CellIndex.h:252
static tarch::la::Vector< dim, unsigned int > divisionFactor
Definition CellIndex.h:276
static constexpr bool checkIndexTraitOrder()
Definition CellIndex.h:97
static void setDomainParameters()
Definition CellIndex.h:203
static tarch::la::Vector< dim, unsigned int > numberCellsInDomain
Definition CellIndex.h:264
static bool contains(const coupling::indexing::BaseIndex< dim > &index)
Definition CellIndex.h:227
static BaseIndex< dim > upperBoundary
Definition CellIndex.h:258
CellIndex & operator--()
Definition CellIndex.h:167
std::conditional_t<(coupling::indexing::TraitOperations::is_same< coupling::indexing::IndexTrait::vector >(traits) or ...), tarch::la::Vector< dim, int >, unsigned int > value_T
Definition CellIndex.h:111
CellIndex & operator++()
Definition CellIndex.h:145
value_T get() const
Definition CellIndex.h:138
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15