diff --git a/ProcessLib/Process.h b/ProcessLib/Process.h index cd1c68436b8bf9f5eb395e0f2d29a3f80ca301d6..338e893307b827683440c07ac4fab0025349929f 100644 --- a/ProcessLib/Process.h +++ b/ProcessLib/Process.h @@ -272,31 +272,11 @@ private: _x->copyValues(x_copy); std::size_t const n = _mesh.getNNodes(); - for (ProcessVariable const& pv : _process_variables) + for (ProcessVariable& pv : _process_variables) { - std::string const property_name = pv.getName(); - // Get or create a property vector for results. - boost::optional<MeshLib::PropertyVector<double>&> result; - if (_mesh.getProperties().hasPropertyVector(property_name)) - { - result = - _mesh.getProperties().template getPropertyVector<double>( - property_name); - } - else - { - result = _mesh.getProperties() - .template createNewPropertyVector<double>( - property_name, MeshLib::MeshItemType::Node); - } - - assert(result); + auto& output_data = pv.getOrCreateMeshProperty(); int const n_components = pv.getTupleSize(); - // result's resize function is from std::vector not accounting the - // tuple size. - result->resize(x_copy.size() * n_components); - for (std::size_t i = 0; i < n; ++i) { MeshLib::Location const l(_mesh.getID(), diff --git a/ProcessLib/ProcessVariable.cpp b/ProcessLib/ProcessVariable.cpp index 3f9d64a5eb8d8bb1a68cc511a0458af5983c2423..a59717318fef20d9204fc4662ec56cb790dbbb55 100644 --- a/ProcessLib/ProcessVariable.cpp +++ b/ProcessLib/ProcessVariable.cpp @@ -114,4 +114,24 @@ MeshLib::Mesh const& ProcessVariable::getMesh() const return _mesh; } +MeshLib::PropertyVector<double>& ProcessVariable::getOrCreateMeshProperty() +{ + boost::optional<MeshLib::PropertyVector<double>&> result; + if (_mesh.getProperties().hasPropertyVector(_name)) + { + result = + _mesh.getProperties().template getPropertyVector<double>(_name); + assert(result); + assert(result->size() == _mesh.getNNodes() * _tuple_size); + } + else + { + result = _mesh.getProperties().template createNewPropertyVector<double>( + _name, MeshLib::MeshItemType::Node); + assert(result); + result->resize(_mesh.getNNodes() * _tuple_size); + } + return *result; +} + } // namespace ProcessLib diff --git a/ProcessLib/ProcessVariable.h b/ProcessLib/ProcessVariable.h index 3efe3671772638a6fbdef7e42cf63495cefd43c1..6e16f4df674802239bfe49f69e2551914f172722 100644 --- a/ProcessLib/ProcessVariable.h +++ b/ProcessLib/ProcessVariable.h @@ -96,6 +96,10 @@ public: return _initial_condition->getValue(n, component_id); } + // Get or create a property vector for results. + // The returned mesh property size is number of mesh nodes times tuple size. + MeshLib::PropertyVector<double>& getOrCreateMeshProperty(); + private: std::string const _name; MeshLib::Mesh& _mesh;