chombo-discharge
CD_KMCDualStateImplem.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2022 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_KMCDualStateImplem_H
13 #define CD_KMCDualStateImplem_H
14 
15 // Our includes
16 #include <CD_KMCDualState.H>
17 #include <CD_NamespaceHeader.H>
18 
19 template <typename T>
20 KMCDualState<T>::KMCDualState(const size_t a_numReactiveSpecies, const size_t a_numNonReactiveSpecies) noexcept
21 {
22  this->define(a_numReactiveSpecies, a_numNonReactiveSpecies);
23 
24  CH_assert(m_reactiveState.size() > 0);
25 }
26 
27 template <typename T>
29 {}
30 
31 template <typename T>
32 inline void
33 KMCDualState<T>::define(const size_t a_numReactiveSpecies, const size_t a_numNonReactiveSpecies) noexcept
34 {
35  m_reactiveState.resize(a_numReactiveSpecies);
36  m_nonReactiveState.resize(a_numNonReactiveSpecies);
37 }
38 
39 template <typename T>
40 inline bool
42 {
43  bool isValid = true;
44 
45  for (const auto& p : m_reactiveState) {
46  if (p < 0) {
47  isValid = false;
48 
49  break;
50  }
51  }
52 
53  for (const auto& p : m_nonReactiveState) {
54  if (p < 0) {
55  isValid = false;
56 
57  break;
58  }
59  }
60 
61  return isValid;
62 }
63 
64 template <typename T>
65 inline typename KMCDualState<T>::State&
67 {
68  return m_reactiveState;
69 }
70 
71 template <typename T>
72 inline const typename KMCDualState<T>::State&
74 {
75  return m_reactiveState;
76 }
77 
78 template <typename T>
79 inline typename KMCDualState<T>::State&
81 {
82  return m_nonReactiveState;
83 }
84 
85 template <typename T>
86 inline const typename KMCDualState<T>::State&
88 {
89  return m_nonReactiveState;
90 }
91 
92 template <typename T>
93 inline std::ostream&
94 operator<<(std::ostream& ostr, const KMCDualState<T>& a_state)
95 {
96  ostr << "KMCDualState : \n";
97 
98  // Print position.
99  const auto& reactiveState = a_state.getReactiveState();
100  const auto& nonReactiveState = a_state.getNonReactiveState();
101 
102  ostr << "\t Reactive = (";
103  for (size_t i = 0; i < reactiveState.size(); i++) {
104  ostr << reactiveState[i];
105  if (i < reactiveState.size() - 1) {
106  ostr << ",";
107  }
108  }
109  ostr << ")\n";
110 
111  ostr << "\t Non-reactive = (";
112  for (size_t i = 0; i < nonReactiveState.size(); i++) {
113  ostr << nonReactiveState[i];
114  if (i < nonReactiveState.size() - 1) {
115  ostr << ",";
116  }
117  }
118  ostr << ")\n";
119 
120  return ostr;
121 }
122 
123 #include <CD_NamespaceFooter.H>
124 
125 #endif
std::ostream & operator<<(std::ostream &ostr, const KMCDualState< T > &a_state)
State printing function.
Definition: CD_KMCDualStateImplem.H:94
Declaration of a simple state vector for running Kinetic Monte Carlo for plasma problems.
Declaration of a "dual state" for advancing with the Kinetic Monte Carlo module.
Definition: CD_KMCDualState.H:29
State & getNonReactiveState() noexcept
Get modifiable non-reactive state.
Definition: CD_KMCDualStateImplem.H:80
KMCDualState()=default
Default constructor.
bool isValidState() const noexcept
Check if state is a valid state. An invalid state will have a negative number of reactants/non-reacta...
Definition: CD_KMCDualStateImplem.H:41
void define(const size_t a_numReactiveSpecies, const size_t a_numNonReactiveSpecies) noexcept
Define function constructor.
Definition: CD_KMCDualStateImplem.H:33
virtual ~KMCDualState()
Destructor.
Definition: CD_KMCDualStateImplem.H:28
State & getReactiveState() noexcept
Get modifiable reactive state.
Definition: CD_KMCDualStateImplem.H:66