13 #include "libmesh/parallel_sync.h" 27 "A reporter which can map full solution fields to a latent space for given variables.");
28 params.
addRequiredParam<UserObjectName>(
"mapping",
"Name of the mapping object.");
30 "variables",
"The names of the variables which need to be mapped to the latent space.");
31 params.
addParam<std::string>(
"parallel_storage",
32 "The storage space where the snapshots are stored. These snapshots " 33 "are used to build the mapping. If this parameter is not specified, " 34 "the reporter will fetch the variable from the nonlinear system.");
37 "Sampler be able to identify how the samples are distributed among " 38 "the processes. Only needed if parallel storage is defined. It is important to have the " 39 "same sampler here as the one used to prepare the snapshots in the parallel storage.");
46 _parallel_storage(isParamValid(
"parallel_storage")
49 _sampler(isParamValid(
"sampler") ? &getSampler(
"sampler") : nullptr),
50 _mapping_name(getParam<UserObjectName>(
"mapping")),
51 _variable_names(getParam<
std::vector<VariableName>>(
"variables"))
68 "We need a sampler object if the parallel storage is supplied! The sampler object " 69 "shall be the same as the one used to generate the solution fields in the " 70 "parallel storage object.");
119 std::vector<std::tuple<unsigned int, unsigned int, std::vector<Real>>>>
124 for (
const auto sample_i :
make_range(rank_config.num_local_sims))
134 std::vector<Real> local_vector;
140 const auto & full_vector =
145 if (full_vector.size() != 1)
146 mooseError(
"MappingReporter is only supported for simulations with one solution " 154 if (rank_config.is_first_local_rank)
157 send_map[rank_config.my_first_rank].emplace_back(
158 var_i, sample_i, std::move(local_vector));
164 auto receive_functor =
166 const std::vector<std::tuple<unsigned int, unsigned int, std::vector<Real>>> & vectors)
169 for (
const auto & [var_i, sample_i, vector] : vectors)
174 Parallel::push_parallel_packed_range(
_communicator, send_map, (
void *)
nullptr, receive_functor);
188 DenseVector<Real> serialized_solution;
191 : std::vector<dof_id_type>());
T & declareValueByName(const ReporterValueName &value_name, Args &&... args)
Sampler *const _sampler
We only need the sampler to check which coefficients would go to which processor in case a ParallelSo...
virtual void execute() override
static InputParameters validParams()
VariableMappingBase * _mapping
Link to the mapping object, we need this to be a pointer due to the fact that we can only fetch this ...
NumericVector< Number > & solution()
const ReporterMode REPORTER_MODE_ROOT
static InputParameters validParams()
A tool to reduce solution fields to coordinates in the latent space.
std::vector< Real > getNextLocalRow()
const std::vector< VariableName > & _variable_names
The variables we would like to map.
dof_id_type getLocalRowBegin() const
const Parallel::Communicator & _communicator
MappingReporter(const InputParameters ¶meters)
const UserObjectName & _mapping_name
The name of the mapping object we would like to use.
const ParallelSolutionStorage *const _parallel_storage
If we already have solution fields stored from previous runs, we can use their ParallelStorageObject ...
uint8_t processor_id_type
virtual void buildMapping(const VariableName &vname)=0
Abstract function for building mapping for a given variable.
registerMooseObject("StochasticToolsApp", MappingReporter)
VariableMappingBase & getMappingByName(const UserObjectName &name) const
Get the mapping by supplying the name of the object in the warehouse.
const std::vector< dof_id_type > & getVariableGlobalDoFs()
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
bool hasGlobalSample(unsigned int global_sample_i, const VariableName &variable) const
Determine if we have the solution vector with a given global sample index for a given variable...
void paramError(const std::string ¶m, Args... args) const
const LocalRankConfig & getRankConfig(bool batch_mode) const
void mapParallelStorageData()
Map the available data in a parallel storage into the latent space.
virtual void map(const VariableName &vname, const DenseVector< Real > &full_order_vector, std::vector< Real > &reduced_order_vector) const =0
Map a full-order solution vector (in DenseVector format) for a given variable into a reduced-order ve...
An interface class that helps getting access to Mapping objects.
FEProblemBase & _fe_problem
static InputParameters validParams()
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
const std::vector< DenseVector< Real > > & getGlobalSample(unsigned int global_sample_i, const VariableName &variable) const
Get the serialized solution field which is associated with a given global sample index and variable...
std::vector< std::vector< Real > * > _vector_real_values
std::vector< std::vector< std::vector< Real > > * > _vector_real_values_parallel_storage
void mapVariableData()
Map the available data in variables into the latent space.
void setVariableGlobalDoFs(const std::string &var_name)
processor_id_type processor_id() const
static InputParameters validParams()
void initialSetup() override
auto index_range(const T &sizable)
A Reporter which stores serialized solution fields for given variables in a distributed fashion...
virtual void localize(std::vector< Number > &v_local) const =0