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

Method getComponent

src/base/SolutionArray.cpp:670–725  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

668}
669
670AnyValue SolutionArray::getComponent(const string& name) const
671{
672 if (!hasComponent(name)) {
673 throw CanteraError("SolutionArray::getComponent",
674 "Unknown component '{}'.", name);
675 }
676
677 AnyValue out;
678 if (m_extra->count(name)) {
679 // extra component
680 const auto& extra = m_extra->at(name);
681 if (extra.is<void>()) {
682 return AnyValue();
683 }
684 if (m_size == m_dataSize) {
685 return extra; // slicing not necessary
686 }
687 if (extra.isVector<long int>()) {
688 return getSingle<long int>(extra, m_active);
689 }
690 if (extra.isVector<double>()) {
691 return getSingle<double>(extra, m_active);
692 }
693 if (extra.isVector<string>()) {
694 return getSingle<string>(extra, m_active);
695 }
696 if (extra.isVector<vector<double>>()) {
697 return getMulti<double>(extra, m_active);
698 }
699 if (extra.isVector<vector<long int>>()) {
700 return getMulti<long int>(extra, m_active);
701 }
702 if (extra.isVector<vector<string>>()) {
703 return getMulti<string>(extra, m_active);
704 }
705 throw NotImplementedError("SolutionArray::getComponent",
706 "Unable to get sliced data for component '{}' with type '{}'.",
707 name, extra.type_str());
708 }
709
710 // component is part of state information
711 vector<double> data(m_size);
712 size_t ix = m_sol->thermo()->speciesIndex(name);
713 if (ix == npos) {
714 // state other than species
715 ix = m_sol->thermo()->nativeState()[name];
716 } else {
717 // species information
718 ix += m_stride - m_sol->thermo()->nSpecies();
719 }
720 for (size_t k = 0; k < m_size; ++k) {
721 data[k] = (*m_data)[m_active[k] * m_stride + ix];
722 }
723 out = data;
724 return out;
725}
726
727bool isSimpleVector(const AnyValue& any) {

Callers 5

TESTFunction · 0.80
testSingleColFunction · 0.80
testMultiColFunction · 0.80
legacyH5Function · 0.80
fromArrayMethod · 0.80

Calls 8

CanteraErrorClass · 0.85
NotImplementedErrorClass · 0.85
type_strMethod · 0.80
AnyValueClass · 0.50
speciesIndexMethod · 0.45
thermoMethod · 0.45
nativeStateMethod · 0.45
nSpeciesMethod · 0.45

Tested by 3

TESTFunction · 0.64
testSingleColFunction · 0.64
testMultiColFunction · 0.64