diff --git a/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp b/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp index 2e780eb6117a0c4388a764e643f8b76cff5866ba..01c6349ae32aa56d4d058fbc743318cdd178c024 100644 --- a/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp +++ b/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp @@ -12,6 +12,8 @@ #include "CoupledSolutionsForStaggeredScheme.h" +#include <numeric> + #include "MathLib/LinAlg/LinAlg.h" #include "Process.h" @@ -27,7 +29,7 @@ CoupledSolutionsForStaggeredScheme::CoupledSolutionsForStaggeredScheme( } } -std::vector<std::vector<double>> getPreviousLocalSolutions( +std::vector<double> getPreviousLocalSolutions( const CoupledSolutionsForStaggeredScheme& cpl_xs, const std::vector<std::vector<GlobalIndexType>>& indices) { @@ -36,15 +38,23 @@ std::vector<std::vector<double>> getPreviousLocalSolutions( return {}; } - const auto number_of_coupled_solutions = cpl_xs.coupled_xs.size(); - std::vector<std::vector<double>> local_xs_t0; - local_xs_t0.reserve(number_of_coupled_solutions); + std::size_t const local_solutions_size = std::accumulate( + cbegin(indices), + cend(indices), + std::size_t(0), + [](GlobalIndexType const size, + std::vector<GlobalIndexType> const& process_indices) { + return size + process_indices.size(); + }); + std::vector<double> local_xs_t0; + local_xs_t0.reserve(local_solutions_size); - int coupling_id = 0; + int process_id = 0; for (auto const& x_t0 : cpl_xs.coupled_xs_t0) { - local_xs_t0.emplace_back(x_t0->get(indices[coupling_id])); - coupling_id++; + auto const& values = x_t0->get(indices[process_id]); + local_xs_t0.insert(cend(local_xs_t0), cbegin(values), cend(values)); + process_id++; } return local_xs_t0; } diff --git a/ProcessLib/CoupledSolutionsForStaggeredScheme.h b/ProcessLib/CoupledSolutionsForStaggeredScheme.h index 3fe07a282e78be40b7ba2f2aaa84c054752703b8..f6e51623feb8e062c16cb4403e2664441d80d289 100644 --- a/ProcessLib/CoupledSolutionsForStaggeredScheme.h +++ b/ProcessLib/CoupledSolutionsForStaggeredScheme.h @@ -49,7 +49,7 @@ struct CoupledSolutionsForStaggeredScheme */ struct LocalCoupledSolutions { - LocalCoupledSolutions(std::vector<std::vector<double>>&& local_coupled_xs0_, + LocalCoupledSolutions(std::vector<double>&& local_coupled_xs0_, std::vector<std::vector<double>>&& local_coupled_xs_) : local_coupled_xs0(std::move(local_coupled_xs0_)), local_coupled_xs(std::move(local_coupled_xs_)) @@ -57,7 +57,7 @@ struct LocalCoupledSolutions } /// Local solutions of the previous time step. - std::vector<std::vector<double>> const local_coupled_xs0; + std::vector<double> const local_coupled_xs0; /// Local solutions of the current time step. std::vector<std::vector<double>> const local_coupled_xs; }; @@ -69,7 +69,7 @@ struct LocalCoupledSolutions * @param indices Nodal indices of an element. * @return Nodal solutions of the previous time step of an element */ -std::vector<std::vector<double>> getPreviousLocalSolutions( +std::vector<double> getPreviousLocalSolutions( const CoupledSolutionsForStaggeredScheme& cpl_xs, const std::vector<std::vector<GlobalIndexType>>& indices);