https://mooseframework.inl.gov
DistributedData.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "libmesh/parallel_object.h"
13 #include "libmesh/parallel.h"
14 #include "MooseTypes.h"
15 
16 namespace StochasticTools
17 {
18 
23 template <typename T>
25 {
26 public:
28 
31  void initializeContainer(unsigned int num_global_entries);
32 
34  void changeEntry(unsigned int glob_i, const T & sample);
35 
37  void addNewEntry(unsigned int glob_i, const T & sample);
38 
41  void closeContainer() { _closed = true; };
42 
44  bool hasGlobalEntry(unsigned int glob_i) const;
45 
47  typename std::vector<T>::iterator localEntryBegin() { return _local_entries.begin(); };
48 
50  typename std::vector<T>::iterator localEntryEnd() { return _local_entries.end(); };
51 
53  typename std::vector<unsigned int>::iterator localEntryIDBegin()
54  {
55  return _local_entry_ids.begin();
56  };
57 
59  typename std::vector<unsigned int>::iterator localEntryIDEnd() { return _local_entry_ids.end(); };
60 
62  const T & getGlobalEntry(unsigned int glob_i) const;
63 
65  const T & getLocalEntry(unsigned int loc_i) const;
66 
68  const std::vector<T> & getLocalEntries() const { return _local_entries; };
69 
71  const std::vector<unsigned int> & getLocalEntryIDs() const { return _local_entry_ids; };
72 
74  unsigned int getNumberOfGlobalEntries() const;
75 
77  unsigned int getNumberOfLocalEntries() const { return _n_local_entries; };
78 
80  unsigned int getLocalIndex(unsigned int glob_i) const;
81 
83  unsigned int getGlobalIndex(unsigned int loc_i) const;
84 
85 protected:
87  std::vector<T> _local_entries;
88 
90  std::vector<unsigned int> _local_entry_ids;
91 
93  bool _closed;
94 
96  unsigned int _n_local_entries;
97 };
98 
99 } // StochasticTools namespace
std::vector< T >::iterator localEntryEnd()
Getting an iterator to the end of the locally owned samples.
DistributedData(const libMesh::Parallel::Communicator &comm_in)
unsigned int _n_local_entries
Number of local samples.
void closeContainer()
Closes the container meaning that no new samples can be added or the already existing samples canot b...
std::vector< T > _local_entries
The vector where the samples are stored.
unsigned int getLocalIndex(unsigned int glob_i) const
Getting the local index of a global sample if locally owned.
unsigned int getNumberOfGlobalEntries() const
Getting the number of global samples.
const T & getGlobalEntry(unsigned int glob_i) const
Getting a sample using its global index.
Enum for batch type in stochastic tools MultiApp.
bool hasGlobalEntry(unsigned int glob_i) const
Checking of sample with global ID is locally owned ot not.
bool _closed
Flag which shows if the container is closed or not.
const std::vector< unsigned int > & getLocalEntryIDs() const
Getting the vector of sample IDs for locally owned samples.
std::vector< unsigned int >::iterator localEntryIDBegin()
Getting an iterator to the beginning of the locally owned sample IDs.
void changeEntry(unsigned int glob_i, const T &sample)
Changing a sample with a global index if it is owned locally.
const T & getLocalEntry(unsigned int loc_i) const
Getting a sample using its local index.
std::vector< T >::iterator localEntryBegin()
Getting an itertor to the beginning of the local samples.
void initializeContainer(unsigned int num_global_entries)
Initialize the container with a given number of samples.
std::vector< unsigned int >::iterator localEntryIDEnd()
Getting an iterator to the end of the locally owned sample IDs.
unsigned int getGlobalIndex(unsigned int loc_i) const
Getting the global index of a locally owned sample.
std::vector< unsigned int > _local_entry_ids
The vector where the global sample IDs are stored.
const std::vector< T > & getLocalEntries() const
Getting all of the locally owned samples.
Templated class that specifies a distributed storage of a vector of given objects.
unsigned int getNumberOfLocalEntries() const
Getting the number of locally owned samples.
void addNewEntry(unsigned int glob_i, const T &sample)
Adding a new sample locally with a global index.