MaMiCo
1.2
Toggle main menu visibility
Loading...
Searching...
No Matches
coupling
datastructures
FlexibleCellContainer.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/datastructures/FlexibleCellContainer.h"
8
#include "coupling/indexing/IndexingService.h"
9
#include <cstddef>
10
#include <iostream>
11
#include <iterator>
12
#include <utility>
13
#include <vector>
14
15
namespace
coupling
{
16
namespace
datastructures {
17
template
<
unsigned
int
dim>
class
FlexibleCellContainer
;
18
}
19
}
// namespace coupling
20
29
30
template
<
unsigned
int
dim>
class
coupling::datastructures::FlexibleCellContainer
{
31
public
:
32
FlexibleCellContainer() {}
33
FlexibleCellContainer(std::vector<
coupling::datastructures::CouplingCell<dim>
*> couplingCells, std::vector<I01> idxs) {
34
#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
35
if
(couplingCells.size() != idxs.size()) {
36
std::cout <<
"ERROR size of index vector and coupling cell vector sent to FlexibleCellContainer constructor do not match"
;
37
exit(EXIT_FAILURE);
38
}
39
#endif
40
_couplingCells
.reserve(couplingCells.size());
41
_idxs
.reserve(idxs.size());
42
for
(std::size_t i = 0; i < couplingCells.size(); ++i) {
43
_couplingCells
.push_back(couplingCells[i]);
44
_idxs
.push_back(idxs[i]);
45
}
46
}
47
48
template
<
class
Container_T> FlexibleCellContainer(Container_T cells) {
49
if
constexpr
(std::is_same_v<Container_T, FlexibleCellContainer>) {
50
_idxs
= cells._idxs;
51
_couplingCells
= cells._couplingCells;
52
}
else
{
53
auto
numCells = cells.size();
54
_idxs
.reserve(numCells);
55
_couplingCells
.reserve(numCells);
56
for
(
auto
pair : cells)
57
*
this
<< pair;
58
}
59
}
60
64
void
operator<<
(std::pair<
coupling::datastructures::CouplingCell<dim>
*, I01> pair) {
65
I01 idx;
66
coupling::datastructures::CouplingCell<dim>
* couplingCell;
67
std::tie(couplingCell, idx) = pair;
68
_couplingCells
.push_back(couplingCell);
69
_idxs
.push_back(idx);
70
}
71
78
unsigned
int
size
()
const
{
return
_couplingCells
.size(); }
79
83
class
Iterator {
84
public
:
85
using
CouplingCellIterator =
typename
std::vector<coupling::datastructures::CouplingCell<dim>*>::const_iterator;
86
using
IndexIterator = std::vector<I01>::const_iterator;
87
88
Iterator(CouplingCellIterator itCouplingCells, IndexIterator itIdxs) :
_itCouplingCells
(itCouplingCells),
_itIdxs
(itIdxs) {}
89
95
const
std::pair<coupling::datastructures::CouplingCell<dim>*, I01>
operator*
()
const
{
return
std::make_pair(*
_itCouplingCells
, *
_itIdxs
); }
96
97
Iterator
& operator++() {
98
++
_itCouplingCells
;
99
++
_itIdxs
;
100
return
*
this
;
101
}
102
103
Iterator operator++(
int
) {
104
Iterator tmp = *
this
;
105
++(*this);
106
return
tmp;
107
}
108
109
friend
bool
operator==(
const
Iterator& a,
const
Iterator& b) {
return
a._itCouplingCells == b._itCouplingCells && a._itIdxs == b._itIdxs; }
110
111
friend
bool
operator!=(
const
Iterator& a,
const
Iterator& b) {
return
!(a == b); }
112
113
private
:
115
CouplingCellIterator
_itCouplingCells
;
116
118
IndexIterator
_itIdxs
;
119
};
120
121
Iterator
begin
()
const
{
return
Iterator
(
_couplingCells
.begin(),
_idxs
.begin()); }
122
124
Iterator
end
()
const
{
return
Iterator
(
_couplingCells
.end(),
_idxs
.end()); }
125
126
private
:
128
std::vector<coupling::datastructures::CouplingCell<dim>*>
_couplingCells
;
129
133
std::vector<I01>
_idxs
;
134
};
coupling::datastructures::CouplingCell
defines the cell type with cell-averaged quantities only (no linked cells).
Definition
CouplingCell.h:29
coupling::datastructures::FlexibleCellContainer::Iterator
Provides iterator functionality (increment, access as <*cell, index> pair, equality).
Definition
FlexibleCellContainer.h:83
coupling::datastructures::FlexibleCellContainer::Iterator::_itCouplingCells
CouplingCellIterator _itCouplingCells
Definition
FlexibleCellContainer.h:115
coupling::datastructures::FlexibleCellContainer::Iterator::operator*
const std::pair< coupling::datastructures::CouplingCell< dim > *, I01 > operator*() const
Definition
FlexibleCellContainer.h:95
coupling::datastructures::FlexibleCellContainer::Iterator::_itIdxs
IndexIterator _itIdxs
Definition
FlexibleCellContainer.h:118
coupling::datastructures::FlexibleCellContainer
provides access to coupling cells, which may belong to different indexing domains
Definition
FlexibleCellContainer.h:30
coupling::datastructures::FlexibleCellContainer::begin
Iterator begin() const
Definition
FlexibleCellContainer.h:121
coupling::datastructures::FlexibleCellContainer::_idxs
std::vector< I01 > _idxs
Definition
FlexibleCellContainer.h:133
coupling::datastructures::FlexibleCellContainer::size
unsigned int size() const
Definition
FlexibleCellContainer.h:78
coupling::datastructures::FlexibleCellContainer::_couplingCells
std::vector< coupling::datastructures::CouplingCell< dim > * > _couplingCells
Definition
FlexibleCellContainer.h:128
coupling::datastructures::FlexibleCellContainer::operator<<
void operator<<(std::pair< coupling::datastructures::CouplingCell< dim > *, I01 > pair)
Definition
FlexibleCellContainer.h:64
coupling::datastructures::FlexibleCellContainer::end
Iterator end() const
Definition
FlexibleCellContainer.h:124
coupling
everything necessary for coupling operations, is defined in here
Definition
AdditiveMomentumInsertion.h:15
Generated by
1.17.0