MaMiCo
1.2
Toggle main menu visibility
Loading...
Searching...
No Matches
coupling
datastructures
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
9
namespace
coupling
{
10
namespace
datastructures {
11
template
<
class
CellIndexT,
unsigned
int
dim>
class
CellContainer
;
12
}
// namespace datastructures
13
}
// namespace coupling
14
26
template
<
class
CellIndexT,
unsigned
int
dim>
class
coupling::datastructures::CellContainer
{
27
28
public
:
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
41
coupling::datastructures::CouplingCell<dim>
*
operator[]
(CellIndexT index)
const
{
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
54
void
operator<<
(
coupling::datastructures::CouplingCell<dim>
* couplingCell) {
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++() {
91
++
_itCouplingCells
;
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
124
protected
:
130
std::vector<coupling::datastructures::CouplingCell<dim>*>
_couplingCells
;
131
};
coupling::datastructures::CellContainer::Iterator
Provides iterator functionality (increment, access as <*cell, index> pair, equality).
Definition
CellContainer.h:77
coupling::datastructures::CellContainer::Iterator::_itIdx
CellIndexT::IndexIterator _itIdx
Definition
CellContainer.h:115
coupling::datastructures::CellContainer::Iterator::operator*
const std::pair< coupling::datastructures::CouplingCell< dim > *, CellIndexT > operator*() const
Definition
CellContainer.h:88
coupling::datastructures::CellContainer::Iterator::_itCouplingCells
CouplingCellIterator _itCouplingCells
Definition
CellContainer.h:108
coupling::datastructures::CellContainer
provides access to the coupling cells. Base class for the class coupling::datastructures::LinkedCellC...
Definition
CellContainer.h:26
coupling::datastructures::CellContainer::end
Iterator end() const
Definition
CellContainer.h:122
coupling::datastructures::CellContainer::operator<<
void operator<<(coupling::datastructures::CouplingCell< dim > *couplingCell)
Definition
CellContainer.h:54
coupling::datastructures::CellContainer::operator[]
coupling::datastructures::CouplingCell< dim > * operator[](CellIndexT index) const
Definition
CellContainer.h:41
coupling::datastructures::CellContainer::size
unsigned int size() const
Definition
CellContainer.h:72
coupling::datastructures::CellContainer::_couplingCells
std::vector< coupling::datastructures::CouplingCell< dim > * > _couplingCells
Definition
CellContainer.h:130
coupling::datastructures::CellContainer::begin
Iterator begin() const
Definition
CellContainer.h:119
coupling::datastructures::CouplingCell
defines the cell type with cell-averaged quantities only (no linked cells).
Definition
CouplingCell.h:29
coupling
everything necessary for coupling operations, is defined in here
Definition
AdditiveMomentumInsertion.h:15
Generated by
1.17.0