MCPcopy Create free account
hub / github.com/Cantera/cantera / setComponent

Method setComponent

src/base/SolutionArray.cpp:734–767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

732}
733
734void SolutionArray::setComponent(const string& name, const AnyValue& data)
735{
736 if (!hasComponent(name)) {
737 throw CanteraError("SolutionArray::setComponent",
738 "Unknown component '{}'.", name);
739 }
740 if (m_extra->count(name)) {
741 _setExtra(name, data);
742 return;
743 }
744
745 size_t size = data.vectorSize();
746 if (size == npos) {
747 throw CanteraError("SolutionArray::setComponent",
748 "Invalid type of component '{}': expected simple array type, "
749 "but received '{}'.", name, data.type_str());
750 }
751 if (size != m_size) {
752 throw CanteraError("SolutionArray::setComponent",
753 "Invalid size of component '{}': expected size {} but received {}.",
754 name, m_size, size);
755 }
756
757 auto& vec = data.asVector<double>();
758 size_t ix = m_sol->thermo()->speciesIndex(name);
759 if (ix == npos) {
760 ix = m_sol->thermo()->nativeState()[name];
761 } else {
762 ix += m_stride - m_sol->thermo()->nSpecies();
763 }
764 for (size_t k = 0; k < m_size; ++k) {
765 (*m_data)[m_active[k] * m_stride + ix] = vec[k];
766 }
767}
768
769void SolutionArray::setLoc(int loc, bool restore)
770{

Callers 4

TESTFunction · 0.45
testSingleColFunction · 0.45
testMultiColFunction · 0.45
asArrayMethod · 0.45

Calls 7

CanteraErrorClass · 0.85
vectorSizeMethod · 0.80
type_strMethod · 0.80
speciesIndexMethod · 0.45
thermoMethod · 0.45
nativeStateMethod · 0.45
nSpeciesMethod · 0.45

Tested by 3

TESTFunction · 0.36
testSingleColFunction · 0.36
testMultiColFunction · 0.36