diff --git a/ProcessLib/SmallDeformation/SmallDeformationProcess.h b/ProcessLib/SmallDeformation/SmallDeformationProcess.h index f2d4c98cf74c152daf194368462ff5f1866db7bf..e307704da726f6f4e94c6b4568b842ce4b364c93 100644 --- a/ProcessLib/SmallDeformation/SmallDeformationProcess.h +++ b/ProcessLib/SmallDeformation/SmallDeformationProcess.h @@ -201,12 +201,21 @@ private: _local_assemblers, *_local_to_global_index_map, x, t, dt); } - void postTimestepConcreteProcess(GlobalVector const&) override + void postTimestepConcreteProcess(GlobalVector const& x) override { DBUG("PostTimestep SmallDeformationProcess."); + if (!_global_nodal_force_vector) + { + _global_nodal_force_vector + = MathLib::MatrixVectorTraits<GlobalVector>::newInstance(x); + } + ProcessLib::SmallDeformation::writeNodalForces( - *_nodal_forces, _local_assemblers, *_local_to_global_index_map); + *_global_nodal_force_vector, _local_assemblers, + *_local_to_global_index_map); + + _global_nodal_force_vector->copyValues(*_nodal_forces); } private: @@ -217,6 +226,7 @@ private: std::unique_ptr<NumLib::LocalToGlobalIndexMap> _local_to_global_index_map_single_component; MeshLib::PropertyVector<double>* _nodal_forces = nullptr; + std::unique_ptr<GlobalVector> _global_nodal_force_vector; }; } // namespace SmallDeformation diff --git a/ProcessLib/SmallDeformationCommon/Common.h b/ProcessLib/SmallDeformationCommon/Common.h index 5b65b7e31aed95cda56b1238d5d61fb1d11ba1f4..5181dc8f1047e1a76e973eb1fa0619716efb42e1 100644 --- a/ProcessLib/SmallDeformationCommon/Common.h +++ b/ProcessLib/SmallDeformationCommon/Common.h @@ -15,6 +15,8 @@ #include <vector> #include "MathLib/LinAlg/Eigen/EigenMapTools.h" +#include "MathLib/LinAlg/FinalizeVectorAssembly.h" +#include "MathLib/LinAlg/LinAlg.h" #include "NumLib/DOF/DOFTableUtil.h" #include "ProcessLib/Deformation/BMatrixPolicy.h" #include "ProcessLib/Deformation/LinearBMatrix.h" @@ -73,31 +75,30 @@ std::vector<double> const& getNodalForces( template <typename LocalAssemblerInterface> void writeNodalForces( - MeshLib::PropertyVector<double>& nodal_forces, + GlobalVector& nodal_force_vector, std::vector<std::unique_ptr<LocalAssemblerInterface>> const& local_assemblers, NumLib::LocalToGlobalIndexMap const& local_to_global_index_map) { DBUG("Compute nodal forces for small deformation process."); - // Zero-out the output vector before averaging. - std::fill(std::begin(nodal_forces), std::end(nodal_forces), 0); + MathLib::LinAlg::set(nodal_force_vector, 0.0); GlobalExecutor::executeDereferenced( [](const std::size_t mesh_item_id, LocalAssemblerInterface& local_assembler, const NumLib::LocalToGlobalIndexMap& dof_table, - std::vector<double>& node_values) { + GlobalVector& nodal_force_vec) { auto const indices = NumLib::getIndices(mesh_item_id, dof_table); std::vector<double> local_data; local_assembler.getNodalForces(local_data); assert(local_data.size() == indices.size()); - for (std::size_t i = 0; i < indices.size(); ++i) - node_values[indices[i]] += local_data[i]; + nodal_force_vec.add(indices, local_data); }, - local_assemblers, local_to_global_index_map, nodal_forces); + local_assemblers, local_to_global_index_map, nodal_force_vector); + MathLib::LinAlg::finalizeAssembly(nodal_force_vector); } } // namespace SmallDeformation