Skip to content
Snippets Groups Projects

Resolve "HasStateBlocks::getState behaves in a non predictible way"

Files
2
@@ -341,11 +341,7 @@ inline void HasStateBlocks::setState(const StateStructure& _structure, const std
//// _structure can be either stateblock structure of the node or a subset of this structure
inline VectorXd HasStateBlocks::getStateVector(const StateStructure& _structure) const
{
StateStructure structure;
if (_structure == "")
structure = structure_;
else
structure = _structure;
const StateStructure& structure = (_structure == "" ? structure_ : _structure);
VectorXd state(getSize(structure));
@@ -353,8 +349,9 @@ inline VectorXd HasStateBlocks::getStateVector(const StateStructure& _structure)
for (const char key : structure)
{
const auto& sb = getStateBlock(key);
assert(sb != nullptr && "Requested StateBlock key not in the structure");
if (sb == nullptr){
throw std::runtime_error("Requested StateBlock key not in the structure");
}
state.segment(index,sb->getSize()) = sb->getState();
index += sb->getSize();
@@ -370,11 +367,12 @@ inline VectorComposite HasStateBlocks::getState(const StateStructure& _structure
for (const auto key : structure)
{
auto state_it = state_block_map_.find(key);
if (state_it != state_block_map_.end())
const auto& sb = getStateBlock(key);
if (sb == nullptr){
throw std::runtime_error("Requested StateBlock key not in the structure");
}
state.emplace(key, state_it->second->getState());
state.emplace(key, sb->getState());
}
return state;
Loading