PSCF v1.1
TensorAverage.h
1#ifndef UTIL_TENSOR_AVERAGE_H
2#define UTIL_TENSOR_AVERAGE_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
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/FArray.h> // member template
15
16#include <vector>
17
18namespace Util
19{
20
21 class Tensor;
22
33 {
34
35 public:
36
42 TensorAverage(int blockFactor = 2);
43
47 virtual ~TensorAverage();
48
61
69 void readParameters(std::istream& in);
70
76 virtual void loadParameters(Serializable::IArchive &ar);
77
83 virtual void save(Serializable::OArchive &ar);
84
91 template <class Archive>
92 void serialize(Archive& ar, const unsigned int version);
93
97 void clear();
98
104 void sample(const Tensor& value);
105
113 const Average& operator () (int i, int j);
114
122 int nSamplePerBlock() const;
123
131 int iBlock() const;
132
140 bool isBlockComplete() const;
141
142 private:
143
146
148 int nSamplePerBlock_;
149
151 int iBlock_;
152
154 TensorAverage(const TensorAverage& other);
155
157 TensorAverage& operator = (const TensorAverage& other);
158
159 };
160
161 // Inline method definitions
162
163 /*
164 * Get nSamplePerBlock, number of samples per block average.
165 */
167 { return nSamplePerBlock_; }
168
169 /*
170 * Get iBlock, number of samples in current block average.
171 */
172 inline int TensorAverage::iBlock() const
173 { return iBlock_; }
174
175 /*
176 * Is the current block average complete?
177 */
179 { return (iBlock_ && (iBlock_ == nSamplePerBlock_)); }
180
181 /*
182 * Serialize this Average.
183 */
184 template <class Archive>
185 void TensorAverage::serialize(Archive& ar, const unsigned int version)
186 {
187 ar & nSamplePerBlock_;
188 ar & iBlock_;
189 int i, j, k;
190 k = 0;
191 for (i = 0; i < Dimension; ++i) {
192 for (j = 0; j < Dimension; ++j) {
193 ar & accumulators_[k];
194 ++k;
195 }
196 }
197 }
198
199}
200#endif
Calculates the average and variance of a sampled property.
Definition: Average.h:44
Saving archive for binary istream.
Saving / output archive for binary ostream.
A fixed size (static) contiguous array template.
Definition: FArray.h:47
An object that can read multiple parameters from file.
Calculates averages of all components of a Tensor-valued variable.
Definition: TensorAverage.h:33
int nSamplePerBlock() const
Get number of samples per block average.
const Average & operator()(int i, int j)
Access the Average object for one tensor component.
void serialize(Archive &ar, const unsigned int version)
Serialize this to or from an archive.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
int iBlock() const
Get number of samples in current block average.
bool isBlockComplete() const
Is the current block average complete?
void setNSamplePerBlock(int nSamplePerBlock)
Set nSamplePerBlock.
void clear()
Clear all accumulators, set to empty initial state.
void readParameters(std::istream &in)
Read parameter nSamplePerBlock from file and initialize.
virtual ~TensorAverage()
Destructor.
void sample(const Tensor &value)
Add a sampled value to the ensemble.
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.
Definition: accumulators.mod:1