PSCF v1.1
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, 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//#include <util/space/Tensor.h>
16
17namespace Util
18{
19
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 FArray<Average, Dimension*(Dimension+1)/2 > accumulators_;
142
144 int nSamplePerBlock_;
145
147 int iBlock_;
148
151
153 SymmTensorAverage& operator = (const SymmTensorAverage& other);
154
155 };
156
157 // Inline method definitions
158
159 /*
160 * Get nSamplePerBlock, number of samples per block average.
161 */
163 { return nSamplePerBlock_; }
164
165 /*
166 * Get iBlock, number of samples in current block average.
167 */
168 inline int SymmTensorAverage::iBlock() const
169 { return iBlock_; }
170
171 /*
172 * Is the current block average complete?
173 */
175 { return (iBlock_ && (iBlock_ == nSamplePerBlock_)); }
176
177 /*
178 * Serialize this Average.
179 */
180 template <class Archive>
181 void SymmTensorAverage::serialize(Archive& ar, const unsigned int version)
182 {
183 ar & nSamplePerBlock_;
184 ar & iBlock_;
185 int i, j, k;
186 k = 0;
187 for (i = 0; i < Dimension; ++i) {
188 for (j = 0; j <= i; ++j) {
189 ar & accumulators_[k];
190 ++k;
191 }
192 }
193 }
194
195}
196#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.
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.
virtual ~SymmTensorAverage()
Destructor.
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.
Definition: accumulators.mod:1