ryujin 2.1.1 revision 78f48c86fcb9c040da63d5afdaec959ac4463738
mpi_ensemble_container.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2020 - 2025 by the ryujin authors
4//
5
6#pragma once
7
8#include <compile_time_options.h>
9
10#include "mpi_ensemble.h"
11
12#include <deal.II/base/mpi.h>
13#include <deal.II/base/utilities.h>
14
15namespace ryujin
16{
34 template <typename T>
36 {
37 public:
43 template <typename... Args>
44 MPIEnsembleContainer(const MPIEnsemble &mpi_ensemble,
45 const std::string &subsection,
46 Args &&...args)
47 {
48 const auto &ensemble = mpi_ensemble.ensemble();
49 const auto &n_ensembles = mpi_ensemble.n_ensembles();
50 unsigned int digits = dealii::Utilities::needed_digits(n_ensembles);
51
52 payload_.resize(n_ensembles);
53 for (int n = 0; n < n_ensembles; ++n) {
54 /* Only append "/ensemble n" if we have more than one ensemble: */
55 auto modified = subsection;
56 if (n_ensembles > 1)
57 modified +=
58 "/ensemble " + dealii::Utilities::int_to_string(n, digits);
59 payload_[n] =
60 std::make_unique<T>(std::forward<Args>(args)..., modified);
61 }
62
63 ensemble_payload_ = payload_[ensemble].get();
64 }
65
70 const T &get() const
71 {
72 return *ensemble_payload_;
73 }
74
79 operator const T &() const
80 {
81 return *ensemble_payload_;
82 }
83
84 private:
85 std::vector<std::unique_ptr<T>> payload_;
86 T *ensemble_payload_;
87 };
88
89
90} /* namespace ryujin */
MPIEnsembleContainer(const MPIEnsemble &mpi_ensemble, const std::string &subsection, Args &&...args)
auto & ensemble() const
Definition: mpi_ensemble.h:72
auto & n_ensembles() const
Definition: mpi_ensemble.h:77