chombo-discharge
Loading...
Searching...
No Matches
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#include <CH_Timer.H>
16
17// Our includes
18#include <CD_KMCDualState.H>
19#include <CD_NamespaceHeader.H>
20
21template <typename T>
23{
24 CH_TIME("KMCDualState::KMCDualState");
25
27
28 CH_assert(m_reactiveState.size() > 0);
29}
30
31template <typename T>
34
35template <typename T>
36inline void
38{
39 CH_TIME("KMCDualState::define");
40
41 m_numReactiveSpecies = a_numReactiveSpecies;
42 m_numNonReactiveSpecies = a_numNonReactiveSpecies;
43
44 m_reactiveState.resize(a_numReactiveSpecies);
45 m_nonReactiveState.resize(a_numNonReactiveSpecies);
46}
47
48template <typename T>
49inline bool
51{
52 CH_TIME("KMCDualState::isValidState");
53
54 bool isValid = true;
55
56 for (const auto& p : m_reactiveState) {
57 if (p < 0) {
58 isValid = false;
59
60 break;
61 }
62 }
63
64 for (const auto& p : m_nonReactiveState) {
65 if (p < 0) {
66 isValid = false;
67
68 break;
69 }
70 }
71
72 return isValid;
73}
74
75template <typename T>
76inline std::vector<T>
78{
80
81 out.insert(out.end(), m_reactiveState.begin(), m_reactiveState.end());
82 out.insert(out.end(), m_nonReactiveState.begin(), m_nonReactiveState.end());
83
84 return out;
85}
86
87template <typename T>
88inline void
90{
91 for (size_t i = 0; i < m_numReactiveSpecies; i++) {
92 m_reactiveState[i] = a_linearizedState[i];
93 }
94
95 for (size_t i = 0; i < m_numNonReactiveSpecies; i++) {
96 m_nonReactiveState[i] = a_linearizedState[m_numReactiveSpecies + i];
97 }
98}
99
100template <typename T>
101inline typename KMCDualState<T>::State&
103{
104 return m_reactiveState;
105}
106
107template <typename T>
108inline const typename KMCDualState<T>::State&
110{
111 return m_reactiveState;
112}
113
114template <typename T>
115inline typename KMCDualState<T>::State&
117{
118 return m_nonReactiveState;
119}
120
121template <typename T>
122inline const typename KMCDualState<T>::State&
124{
125 return m_nonReactiveState;
126}
127
128template <typename T>
131{
132 ostr << "KMCDualState : \n";
133
134 // Print position.
135 const auto& reactiveState = a_state.getReactiveState();
136 const auto& nonReactiveState = a_state.getNonReactiveState();
137
138 ostr << "\t Reactive = (";
139 for (size_t i = 0; i < reactiveState.size(); i++) {
140 ostr << reactiveState[i];
141 if (i < reactiveState.size() - 1) {
142 ostr << ",";
143 }
144 }
145 ostr << ")\n";
146
147 ostr << "\t Non-reactive = (";
148 for (size_t i = 0; i < nonReactiveState.size(); i++) {
150 if (i < nonReactiveState.size() - 1) {
151 ostr << ",";
152 }
153 }
154 ostr << ")\n";
155
156 return ostr;
157}
158
159#include <CD_NamespaceFooter.H>
160
161#endif
std::ostream & operator<<(std::ostream &ostr, const KMCDualState< T > &a_state)
State printing function.
Definition CD_KMCDualStateImplem.H:130
Declaration of a simple state vector for running Kinetic Monte Carlo for plasma problems.
State & getNonReactiveState() noexcept
Get modifiable non-reactive state.
Definition CD_KMCDualStateImplem.H:116
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:50
void define(const size_t a_numReactiveSpecies, const size_t a_numNonReactiveSpecies) noexcept
Define function constructor.
Definition CD_KMCDualStateImplem.H:37
void linearIn(const std::vector< T > &a_linearizedState) noexcept
Linearize the input buffer.
Definition CD_KMCDualStateImplem.H:89
virtual ~KMCDualState()
Destructor.
Definition CD_KMCDualStateImplem.H:32
std::vector< T > linearOut() const noexcept
Linearize the state onto an output vector.
Definition CD_KMCDualStateImplem.H:77
State & getReactiveState() noexcept
Get modifiable reactive state.
Definition CD_KMCDualStateImplem.H:102
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:37
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:25