diff --git a/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp b/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp index 01c6349ae32aa56d4d058fbc743318cdd178c024..89ffff1e55ced0fe371d4459999e1f667a2da4c8 100644 --- a/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp +++ b/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp @@ -59,7 +59,7 @@ std::vector<double> getPreviousLocalSolutions( return local_xs_t0; } -std::vector<std::vector<double>> getCurrentLocalSolutions( +std::vector<double> getCurrentLocalSolutions( const CoupledSolutionsForStaggeredScheme& cpl_xs, const std::vector<std::vector<GlobalIndexType>>& indices) { @@ -68,15 +68,23 @@ std::vector<std::vector<double>> getCurrentLocalSolutions( return {}; } - const auto number_of_coupled_solutions = cpl_xs.coupled_xs.size(); - std::vector<std::vector<double>> local_xs_t1; - local_xs_t1.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_t1; + local_xs_t1.reserve(local_solutions_size); - int coupling_id = 0; - for (auto const* x_t1 : cpl_xs.coupled_xs) + int process_id = 0; + for (auto const& x_t1 : cpl_xs.coupled_xs) { - local_xs_t1.emplace_back(x_t1->get(indices[coupling_id])); - coupling_id++; + auto const& values = x_t1->get(indices[process_id]); + local_xs_t1.insert(cend(local_xs_t1), cbegin(values), cend(values)); + process_id++; } return local_xs_t1; } diff --git a/ProcessLib/CoupledSolutionsForStaggeredScheme.h b/ProcessLib/CoupledSolutionsForStaggeredScheme.h index f6e51623feb8e062c16cb4403e2664441d80d289..9762109f56d258dd37a9c8e8d99acd441818496c 100644 --- a/ProcessLib/CoupledSolutionsForStaggeredScheme.h +++ b/ProcessLib/CoupledSolutionsForStaggeredScheme.h @@ -50,7 +50,7 @@ struct CoupledSolutionsForStaggeredScheme struct LocalCoupledSolutions { LocalCoupledSolutions(std::vector<double>&& local_coupled_xs0_, - std::vector<std::vector<double>>&& local_coupled_xs_) + std::vector<double>&& local_coupled_xs_) : local_coupled_xs0(std::move(local_coupled_xs0_)), local_coupled_xs(std::move(local_coupled_xs_)) { @@ -59,7 +59,7 @@ struct LocalCoupledSolutions /// Local solutions of the previous time step. std::vector<double> const local_coupled_xs0; /// Local solutions of the current time step. - std::vector<std::vector<double>> const local_coupled_xs; + std::vector<double> const local_coupled_xs; }; /** @@ -80,7 +80,7 @@ std::vector<double> getPreviousLocalSolutions( * @param indices Nodal indices of an element. * @return Nodal solutions of the current time step of an element */ -std::vector<std::vector<double>> getCurrentLocalSolutions( +std::vector<double> getCurrentLocalSolutions( const CoupledSolutionsForStaggeredScheme& cpl_xs, const std::vector<std::vector<GlobalIndexType>>& indices); } // namespace ProcessLib