chombo-discharge
CD_CdrIteratorImplem.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_CdrIteratorImplem_H
13 #define CD_CdrIteratorImplem_H
14 
15 // Our includes
16 #include <CD_CdrIterator.H>
17 #include <CD_NamespaceHeader.H>
18 
19 template <class T>
21 {
22  CH_TIME("CdrIterator<T>::CdrIterator(CdrLayout<T>, SpeciesIteration)");
23 
24  // Default settings
25  m_solvers = a_layout.getSolvers();
26  m_species = a_layout.getSpecies();
27  m_numSolvers = m_solvers.size();
28  m_mode = a_mode;
29 
30  m_isDefined = true;
31 
32  reset();
33 }
34 
35 template <class T>
37 {
38  CH_TIME("CdrIterator<T>::~CdrIterator()");
39 }
40 
41 template <class T>
42 int
44 {
45  CH_TIME("CdrIterator<T>::getNumberOfSolvers()");
46 
47  CH_assert(m_isDefined);
48 
49  return m_numSolvers;
50 }
51 
52 template <class T>
53 int
55 {
56  CH_TIME("CdrIterator<T>::index()");
57 
58  CH_assert(m_isDefined);
59 
60  return m_isolver;
61 }
62 
63 template <class T>
64 void
66 {
67  CH_TIME("CdrIterator<T>::reset()");
68 
69  CH_assert(m_isDefined);
70 
71  m_isolver = 0;
72 }
73 
74 template <class T>
75 bool
77 {
78  CH_TIME("CdrIterator<T>::ok()");
79 
80  CH_assert(m_isDefined);
81 
82  return (m_isolver < m_numSolvers);
83 }
84 
85 template <class T>
86 void
88 {
89  CH_TIME("CdrIterator<T>::operator++()");
90 
91  CH_assert(m_isDefined);
92 
93  if (m_mode == SpeciesIteration::All) {
94  m_isolver++;
95  }
96  else {
97  m_isolver++;
98 
99  for (int isolver = m_isolver; this->ok(); ++isolver) {
100  const RefCountedPtr<CdrSpecies>& species = m_species[isolver];
101 
102  if (m_mode == SpeciesIteration::Charged) {
103  if (species->getChargeNumber() != 0) {
104  m_isolver = isolver;
105  break;
106  }
107  }
108  else if (m_mode == SpeciesIteration::Negative) {
109  if (species->getChargeNumber() < 0) {
110  m_isolver = isolver;
111  break;
112  }
113  }
114  else if (m_mode == SpeciesIteration::Positive) {
115  if (species->getChargeNumber() > 0) {
116  m_isolver = isolver;
117  break;
118  }
119  }
120  else if (m_mode == SpeciesIteration::Neutral) {
121  if (species->getChargeNumber() == 0) {
122  m_isolver = isolver;
123  break;
124  }
125  }
126  }
127  }
128 }
129 
130 template <class T>
131 RefCountedPtr<T>&
133 {
134  CH_TIME("CdrIterator<T>::operator()");
135 
136  CH_assert(m_isDefined);
137  CH_assert(m_isolver < m_numSolvers);
138 
139  return m_solvers[m_isolver];
140 }
141 
142 template <class T>
143 RefCountedPtr<CdrSpecies>&
145 {
146  CH_TIME("CdrIterator<T>::getSpecies()");
147 
148  CH_assert(m_isDefined);
149  CH_assert(m_isolver < m_numSolvers);
150 
151  return m_species[m_isolver];
152 }
153 
154 #include <CD_NamespaceFooter.H>
155 
156 #endif
Declaration of an iterator class for CdrLayout (for iterating through subsets of solvers).
virtual void reset()
Reset iterator.
Definition: CD_CdrIteratorImplem.H:65
virtual bool ok() const
Ok or not.
Definition: CD_CdrIteratorImplem.H:76
virtual int index() const
Get current solver number (i.e. index in CdrLayouts solvers).
Definition: CD_CdrIteratorImplem.H:54
virtual RefCountedPtr< CdrSpecies > & getSpecies()
Return the current species.
Definition: CD_CdrIteratorImplem.H:144
virtual RefCountedPtr< T > & operator()()
Return the current solver.
Definition: CD_CdrIteratorImplem.H:132
virtual void operator++()
Increment. This is different for different iteration modes.
Definition: CD_CdrIteratorImplem.H:87
CdrIterator()=delete
Disallowed weak construction. Always use the full constructor.
SpeciesIteration
Enum class for iterating through subsets of species.
Definition: CD_CdrIterator.H:33
virtual ~CdrIterator()
Destructor (does nothing).
Definition: CD_CdrIteratorImplem.H:36
virtual int getNumberOfSolvers()
Get number of solvers.
Definition: CD_CdrIteratorImplem.H:43
Class for holding a set of CdrSolvers.
Definition: CD_CdrLayout.H:37
virtual Vector< RefCountedPtr< T > > & getSolvers()
Get solvers.
Definition: CD_CdrLayoutImplem.H:366
virtual Vector< RefCountedPtr< CdrSpecies > > & getSpecies()
Get species.
Definition: CD_CdrLayoutImplem.H:378