Merge branch 'upstream/OpenFOAM' into master
[freefoam.git] / src / lagrangian / molecularDynamics / molecularMeasurements / bufferedAccumulator / bufferedAccumulator.H
blob48321240c885c597272d669561683cf24d212cb7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::bufferedAccumulator
28 Description
30 SourceFiles
31     bufferedAccumulatorI.H
32     bufferedAccumulator.C
33     bufferedAccumulatorIO.C
35 \*---------------------------------------------------------------------------*/
37 #ifndef bufferedAccumulator_H
38 #define bufferedAccumulator_H
40 #include <OpenFOAM/Field.H>
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 template<class Type>
48 class bufferedAccumulator;
50 template<class Type>
51 Ostream& operator<<
53     Ostream&,
54     const bufferedAccumulator<Type>&
57 /*---------------------------------------------------------------------------*\
58                       Class bufferedAccumulator Declaration
59 \*---------------------------------------------------------------------------*/
61 template<class Type>
62 class bufferedAccumulator
64     public List< Field<Type> >
66     // Private data
68         label averagesTaken_;
70         List<label> bufferOffsets_;
73     // Private Member Functions
75         inline Field<Type>& accumulationBuffer();
77         inline const Field<Type>& accumulationBuffer() const;
79         void accumulateAndResetBuffer(const label b);
82 public:
84     //- Component type
85     typedef typename pTraits<Type>::cmptType cmptType;
88     // Static data members
90         static const char* const typeName;
93     // Constructors
95         //- Construct null
96         bufferedAccumulator();
98         //- Construct from components
99         bufferedAccumulator
100         (
101             const label nBuffers,
102             const label bufferLength,
103             const label bufferingInterval
104         );
106         //- Construct as copy
107         bufferedAccumulator(const bufferedAccumulator<Type>&);
110     // Destructor
112         ~bufferedAccumulator();
115     // Member Functions
117         label addToBuffers(const List<Type>& valuesToAdd);
119         Field<Type> averaged() const;
121         void resetAveraging();
124         // Access
126             inline label averagesTaken() const;
128             inline label nBuffers() const;
130             inline label bufferLength() const;
132             inline const List<label>& bufferOffsets() const;
135         // Edit
137             void setSizes
138             (
139                 const label nBuffers,
140                 const label bufferLength,
141                 const label bufferingInterval
142             );
145     // Member Operators
147         void operator=(const bufferedAccumulator<Type>&);
150     // IOstream Operators
152         friend Ostream& operator<< <Type>
153         (
154             Ostream&,
155             const bufferedAccumulator<Type>&
156         );
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 } // End namespace Foam
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 #include "bufferedAccumulatorI.H"
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170 #ifdef NoRepository
171 #   include "bufferedAccumulator.C"
172 #endif
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 #endif
178 // ************************ vim: set sw=4 sts=4 et: ************************ //