[SolutionArray] Add species lock

This commit is contained in:
Ingmar Schoegl 2024-03-31 09:08:46 -05:00
parent fbd2d37df0
commit 46913c88cc
2 changed files with 9 additions and 2 deletions

View File

@ -39,7 +39,7 @@ private:
SolutionArray(const SolutionArray& arr, const vector<int>& indices);
public:
virtual ~SolutionArray() {}
virtual ~SolutionArray();
/**
* Instantiate a new SolutionArray reference.

View File

@ -44,11 +44,12 @@ SolutionArray::SolutionArray(const shared_ptr<Solution>& sol,
, m_dataSize(size)
, m_meta(meta)
{
if (!m_sol) {
if (!m_sol || !m_sol->thermo()) {
throw CanteraError("SolutionArray::SolutionArray",
"Unable to create SolutionArray from invalid Solution object.");
}
m_stride = m_sol->thermo()->stateSize();
m_sol->thermo()->addSpeciesLock();
m_data = make_shared<vector<double>>(m_dataSize * m_stride, 0.);
m_extra = make_shared<map<string, AnyValue>>();
m_order = make_shared<map<int, string>>();
@ -72,6 +73,7 @@ SolutionArray::SolutionArray(const SolutionArray& other,
, m_shared(true)
, m_active(selected)
{
m_sol->thermo()->addSpeciesLock();
for (auto loc : m_active) {
if (loc < 0 || loc >= (int)m_dataSize) {
IndexError("SolutionArray::SolutionArray", "indices", loc, m_dataSize);
@ -83,6 +85,11 @@ SolutionArray::SolutionArray(const SolutionArray& other,
}
}
SolutionArray::~SolutionArray()
{
m_sol->thermo()->removeSpeciesLock();
}
namespace { // restrict scope of helper functions to local translation unit
template<class T>