chombo-discharge
CD_ItoIteratorImplem.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2021 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_ItoIteratorImplem_H
13 #define CD_ItoIteratorImplem_H
14 
15 // Chombo includes
16 #include <CH_Timer.H>
17 
18 // Our includes
19 #include <CD_ItoIterator.H>
20 #include <CD_NamespaceHeader.H>
21 
22 template <class T>
24 {
25  CH_TIME("ItoIterator<T>::ItoIterator<T>");
26 
27  m_solvers = a_layout.getSolvers();
28  m_species = a_layout.getSpecies();
29  m_numSolvers = m_solvers.size();
30  m_mode = a_mode;
31  m_isDefined = true;
32 
33  this->reset();
34 }
35 
36 template <class T>
38 {
39  CH_TIME("ItoIterator<T>::~ItoIterator<T>");
40 }
41 
42 template <class T>
43 int
45 {
46  CH_assert(m_isDefined);
47 
48  return m_numSolvers;
49 }
50 
51 template <class T>
52 int
54 {
55  CH_assert(m_isDefined);
56 
57  return m_isolver;
58 }
59 
60 template <class T>
61 void
63 {
64  CH_assert(m_isDefined);
65 
66  m_isolver = 0;
67 }
68 
69 template <class T>
70 bool
72 {
73  return (m_isolver < m_numSolvers);
74 }
75 
76 template <class T>
77 void
79 {
80  CH_assert(m_isDefined);
81 
82  if (m_mode == SpeciesIteration::All) {
83  m_isolver++;
84  }
85  else {
86  m_isolver++;
87 
88  for (int isolver = m_isolver; this->ok(); ++isolver) {
89  const RefCountedPtr<ItoSpecies>& species = m_species[isolver];
90 
91  if (m_mode == SpeciesIteration::Charged) {
92  if (species->getChargeNumber() != 0) {
93  m_isolver = isolver;
94 
95  break;
96  }
97  }
98  else if (m_mode == SpeciesIteration::Negative) {
99  if (species->getChargeNumber() < 0) {
100  m_isolver = isolver;
101 
102  break;
103  }
104  }
105  else if (m_mode == SpeciesIteration::Positive) {
106  if (species->getChargeNumber() > 0) {
107  m_isolver = isolver;
108 
109  break;
110  }
111  }
112  else if (m_mode == SpeciesIteration::Neutral) {
113  if (species->getChargeNumber() == 0) {
114  m_isolver = isolver;
115 
116  break;
117  }
118  }
119  }
120  }
121 }
122 
123 template <class T>
124 RefCountedPtr<T>&
126 {
127  CH_assert(m_isDefined);
128  CH_assert(m_isolver < m_numSolvers);
129 
130  return m_solvers[m_isolver];
131 }
132 
133 template <class T>
134 RefCountedPtr<ItoSpecies>&
136 {
137  CH_assert(m_isDefined);
138  CH_assert(m_isolver < m_numSolvers);
139 
140  return m_species[m_isolver];
141 }
142 
143 #include <CD_NamespaceFooter.H>
144 
145 #endif
Declaration of an iterator class for ItoLayout.
"Iterator" class for going through solvers in an ItoLayout.
Definition: CD_ItoIterator.H:24
virtual void operator++()
Increment. This is different for different iteration modes.
Definition: CD_ItoIteratorImplem.H:78
virtual bool ok()
Ok or not.
Definition: CD_ItoIteratorImplem.H:71
virtual RefCountedPtr< T > & operator()()
Get current solver.
Definition: CD_ItoIteratorImplem.H:125
virtual int index() const
Get current solver number.
Definition: CD_ItoIteratorImplem.H:53
virtual RefCountedPtr< ItoSpecies > & getSpecies()
Get current species.
Definition: CD_ItoIteratorImplem.H:135
virtual void reset()
Reset iterator to the first solver.
Definition: CD_ItoIteratorImplem.H:62
virtual int getNumberOfSolvers()
Get number of solvers.
Definition: CD_ItoIteratorImplem.H:44
ItoIterator()=delete
Disallowed constructor – use the full constructor.
SpeciesIteration
Enum which specifies which species to iterate through.
Definition: CD_ItoIterator.H:30
Class for holding a set of ItoSolvers.
Definition: CD_ItoLayout.H:30
virtual Vector< RefCountedPtr< ItoSpecies > > & getSpecies()
Get species.
Definition: CD_ItoLayoutImplem.H:335
virtual Vector< RefCountedPtr< T > > & getSolvers()
Get solvers all solvers.
Definition: CD_ItoLayoutImplem.H:328