Simpatico  v1.10
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 
18 namespace 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  */
178  inline bool TensorAverage::isBlockComplete() const
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
const Average & operator()(int i, int j)
Access the Average object for one tensor component.
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
Calculates the average and variance of a sampled property.
Definition: Average.h:43
bool isBlockComplete() const
Is the current block average complete?
int iBlock() const
Get number of samples in current block average.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
File containing preprocessor macros for error handling.
A Tensor represents a Cartesian tensor.
Definition: Tensor.h:32
void setNSamplePerBlock(int nSamplePerBlock)
Set nSamplePerBlock.
Saving / output archive for binary ostream.
TensorAverage(int blockFactor=2)
Constructor.
void readParameters(std::istream &in)
Read parameter nSamplePerBlock from file and initialize.
void clear()
Clear all accumulators, set to empty initial state.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Calculates averages of all components of a Tensor-valued variable.
Definition: TensorAverage.h:32
int nSamplePerBlock() const
Get number of samples per block average.
A fixed size (static) contiguous array template.
Definition: FArray.h:46
void sample(const Tensor &value)
Add a sampled value to the ensemble.
Saving archive for binary istream.
virtual ~TensorAverage()
Destructor.
void serialize(Archive &ar, const unsigned int version)
Serialize this to or from an archive.
An object that can read multiple parameters from file.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.