MaMiCo 1.2
Loading...
Searching...
No Matches
CellContainer.h
1// This file is part of the Mamico project. For conditions of distribution
2// and use, please see the copyright notice in Mamico's main folder
3#pragma once
4
5#include "coupling/CouplingMDDefinitions.h"
6#include "coupling/datastructures/CouplingCell.h"
7#include "coupling/indexing/IndexingService.h"
8
9namespace coupling {
10namespace datastructures {
11template <class CellIndexT, unsigned int dim> class CellContainer;
12} // namespace datastructures
13} // namespace coupling
14
26template <class CellIndexT, unsigned int dim> class coupling::datastructures::CellContainer {
27
28public:
29 CellContainer() { _couplingCells.reserve(CellIndexT::linearNumberCellsInDomain); }
30 CellContainer(std::vector<coupling::datastructures::CouplingCell<dim>*> couplingCells) {
31 _couplingCells.reserve(CellIndexT::linearNumberCellsInDomain);
32 for (auto cell : couplingCells) {
33 *this << cell;
34 }
35 }
36
42#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
43 if (_couplingCells.size() < CellIndexT::linearNumberCellsInDomain) {
44 std::cout << "CellContainer<" << CellIndexT::TNAME << "," << dim << "> accessed but not full " << std::endl;
45 std::exit(EXIT_FAILURE);
46 }
47#endif
48 return _couplingCells[indexing::convertToScalar(index)];
49 }
50
55#if (COUPLING_MD_ERROR == COUPLING_MD_YES)
56 if (_couplingCells.size() >= CellIndexT::linearNumberCellsInDomain) {
57 std::cout << "CellContainer<" << CellIndexT::TNAME << "," << dim << "> can only hold " << CellIndexT::linearNumberCellsInDomain << " coupling cells!"
58 << std::endl;
59 std::exit(EXIT_FAILURE);
60 }
61#endif
62 _couplingCells.push_back(couplingCell);
63 }
64
72 unsigned int size() const { return _couplingCells.size(); }
73
77 class Iterator {
78 public:
79 using CouplingCellIterator = typename std::vector<coupling::datastructures::CouplingCell<dim>*>::const_iterator;
80
81 Iterator(CouplingCellIterator itCouplingCells, typename CellIndexT::IndexIterator itIdx) : _itCouplingCells(itCouplingCells), _itIdx(itIdx) {}
82
88 const std::pair<coupling::datastructures::CouplingCell<dim>*, CellIndexT> operator*() const { return std::make_pair(*_itCouplingCells, *_itIdx); }
89
90 Iterator& operator++() {
92 ++_itIdx;
93 return *this;
94 }
95
96 Iterator operator++(int) {
97 Iterator tmp = *this;
98 ++(*this);
99 return tmp;
100 }
101
102 friend bool operator==(const Iterator& a, const Iterator& b) { return a._itCouplingCells == b._itCouplingCells; }
103
104 friend bool operator!=(const Iterator& a, const Iterator& b) { return !(a == b); }
105
106 private:
108 CouplingCellIterator _itCouplingCells;
109
115 typename CellIndexT::IndexIterator _itIdx;
116 };
117
119 Iterator begin() const { return Iterator(_couplingCells.begin(), CellIndexT::begin()); }
120
122 Iterator end() const { return Iterator(_couplingCells.end(), CellIndexT::end()); }
123
124protected:
130 std::vector<coupling::datastructures::CouplingCell<dim>*> _couplingCells;
131};
Provides iterator functionality (increment, access as <*cell, index> pair, equality)
Definition CellContainer.h:77
CellIndexT::IndexIterator _itIdx
Definition CellContainer.h:115
const std::pair< coupling::datastructures::CouplingCell< dim > *, CellIndexT > operator*() const
Definition CellContainer.h:88
CouplingCellIterator _itCouplingCells
Definition CellContainer.h:108
provides access to the coupling cells. Base class for the class coupling::datastructures::LinkedCellC...
Definition CellContainer.h:26
Iterator end() const
Definition CellContainer.h:122
void operator<<(coupling::datastructures::CouplingCell< dim > *couplingCell)
Definition CellContainer.h:54
coupling::datastructures::CouplingCell< dim > * operator[](CellIndexT index) const
Definition CellContainer.h:41
unsigned int size() const
Definition CellContainer.h:72
std::vector< coupling::datastructures::CouplingCell< dim > * > _couplingCells
Definition CellContainer.h:130
Iterator begin() const
Definition CellContainer.h:119
defines the cell type with cell-averaged quantities only (no linked cells).
Definition CouplingCell.h:29
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15