PSCF v1.5.0
SymmTensorAverage.h
1#ifndef UTIL_SYMM_TENSOR_AVERAGE_H
2#define UTIL_SYMM_TENSOR_AVERAGE_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, David Morse (morse012@um.edu)
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/global.h>
12#include <util/param/ParamComposite.h> // base class
13#include <util/accumulators/Average.h> // member template argument
14#include <util/containers/DArray.h> // member template
15
16namespace Util
17{
18
19 // Forward declaration
20 class Tensor;
21
32 {
33
34 public:
35
41 SymmTensorAverage(int blockFactor = 2);
42
46 virtual ~SymmTensorAverage();
47
60
68 void readParameters(std::istream& in);
69
75 virtual void loadParameters(Serializable::IArchive &ar);
76
82 virtual void save(Serializable::OArchive &ar);
83
90 template <class Archive>
91 void serialize(Archive& ar, const unsigned int version);
92
96 void clear();
97
103 void sample(const Tensor& value);
104
112 const Average& operator () (int i, int j);
113
121 int nSamplePerBlock() const;
122
130 int iBlock() const;
131
137 bool isBlockComplete() const;
138
139 private:
140
141 // Array of accumulators, one per distinct tensor element.
142 DArray< Average > accumulators_;
143
145 int nSamplePerBlock_;
146
148 int iBlock_;
149
152
154 SymmTensorAverage& operator = (SymmTensorAverage const & other);
155
156 };
157
158 // Inline method definitions
159
160 /*
161 * Get nSamplePerBlock, number of samples per block average.
162 */
164 { return nSamplePerBlock_; }
165
166 /*
167 * Get iBlock, number of samples in current block average.
168 */
169 inline int SymmTensorAverage::iBlock() const
170 { return iBlock_; }
171
172 /*
173 * Is the current block average complete?
174 */
176 { return (iBlock_ && (iBlock_ == nSamplePerBlock_)); }
177
178 /*
179 * Serialize this Average.
180 */
181 template <class Archive>
182 void SymmTensorAverage::serialize(Archive& ar, const unsigned int version)
183 {
184 ar & nSamplePerBlock_;
185 ar & iBlock_;
186 int i, j, k;
187 k = 0;
188 for (i = 0; i < Dimension; ++i) {
189 for (j = 0; j <= i; ++j) {
190 ar & accumulators_[k];
191 ++k;
192 }
193 }
194 }
195
196}
197#endif
Calculates the average and variance of a sampled property.
Definition Average.h:44
Dynamically allocatable contiguous array template.
Definition DArray.h:32
ParamComposite()
Constructor.
BinaryFileIArchive IArchive
Type of input archive used by load method.
BinaryFileOArchive OArchive
Type of output archive used by save method.
SymmTensorAverage(int blockFactor=2)
Constructor.
bool isBlockComplete() const
Is the current block average complete?
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
void serialize(Archive &ar, const unsigned int version)
Serialize this to or from an archive.
void readParameters(std::istream &in)
Read parameter nSamplePerBlock from file and initialize.
const Average & operator()(int i, int j)
Access the Average object for one tensor component.
void clear()
Clear all accumulators, set to empty initial state.
int iBlock() const
Get number of samples in current block average.
void sample(const Tensor &value)
Add a sampled value to the ensemble.
void setNSamplePerBlock(int nSamplePerBlock)
Set nSamplePerBlock.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
int nSamplePerBlock() const
Get number of samples per block average.
A Tensor represents a Cartesian tensor.
Definition Tensor.h:33
File containing preprocessor macros for error handling.
const int Dimension
Dimensionality of space.
Definition Dimension.h:19
Utility classes for scientific computation.