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