From 2ee9fe7c2cf76577eb387dd56d5ab15fe027a3b5 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Thu, 26 Sep 2019 17:17:07 +0200 Subject: [PATCH] [PL] Return flat vector of previous staggerd sols. The vector has same structure as for the monolithic case. --- .../CoupledSolutionsForStaggeredScheme.cpp | 24 +++++++++++++------ .../CoupledSolutionsForStaggeredScheme.h | 6 ++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp b/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp index 2e780eb6117..01c6349ae32 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 3fe07a282e7..f6e51623feb 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); -- GitLab