DOLFIN
DOLFIN C++ interface
TimeSeries.h
1 // Copyright (C) 2009-2016 Anders Logg
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef __TIME_SERIES_H
19 #define __TIME_SERIES_H
20 
21 #ifdef HAS_HDF5
22 
23 #include <string>
24 #include <vector>
25 #include <dolfin/common/MPI.h>
26 #include <dolfin/common/Variable.h>
27 
28 namespace dolfin
29 {
30 
31  // Forward declarations
32  class GenericVector;
33  class Mesh;
34 
45 
46  class TimeSeries : public Variable
47  {
48  public:
49 
57  TimeSeries(std::string name)
58  : TimeSeries(MPI_COMM_WORLD, name) {}
59 
67  TimeSeries(MPI_Comm mpi_comm, std::string name);
68 
70  ~TimeSeries();
71 
79  void store(const GenericVector& vector, double t);
80 
88  void store(const Mesh& mesh, double t);
89 
100  void retrieve(GenericVector& vector, double t,
101  bool interpolate=true) const;
102 
110  void retrieve(Mesh& mesh, double t) const;
111 
117  std::vector<double> vector_times() const;
118 
124  std::vector<double> mesh_times() const;
125 
127  void clear();
128 
130  std::string str(bool verbose) const;
131 
134  {
135  Parameters p("time_series");
136  p.add("clear_on_write", true);
137  return p;
138  }
139 
140  private:
141 
142  template <typename T>
143  void store_object(MPI_Comm comm, const T& object, double t,
144  std::vector<double>& times,
145  std::string series_name,
146  std::string group_name);
147 
148  // Check if values are strictly increasing
149  static bool monotone(const std::vector<double>& times);
150 
151  // Find index closest to given time
152  static std::size_t find_closest_index(double t,
153  const std::vector<double>& times,
154  std::string series_name,
155  std::string type_name);
156 
157  // Find index pair closest to given time
158  static std::pair<std::size_t, std::size_t>
159  find_closest_pair(double t, const std::vector<double>& times,
160  std::string series_name, std::string type_name);
161 
162  // Name of series
163  std::string _name;
164 
165  // List of times
166  std::vector<double> _vector_times;
167  std::vector<double> _mesh_times;
168 
169  // True if series has been cleared
170  bool _cleared;
171 
172  };
173 
174 }
175 
176 #endif
177 #endif
void retrieve(GenericVector &vector, double t, bool interpolate=true) const
Definition: TimeSeries.cpp:183
Common base class for DOLFIN variables.
Definition: Variable.h:35
~TimeSeries()
Destructor.
Definition: TimeSeries.cpp:155
static Parameters default_parameters()
Default parameter values.
Definition: TimeSeries.h:133
Definition: adapt.h:29
std::vector< double > mesh_times() const
Definition: TimeSeries.cpp:280
void add(std::string key)
Definition: Parameters.h:128
TimeSeries(std::string name)
Definition: TimeSeries.h:57
std::vector< double > vector_times() const
Definition: TimeSeries.cpp:275
Definition: Parameters.h:94
void clear()
Clear time series.
Definition: TimeSeries.cpp:285
std::string name() const
Return name.
Definition: Variable.cpp:71
Definition: TimeSeries.h:46
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: TimeSeries.cpp:292
void store(const GenericVector &vector, double t)
Definition: TimeSeries.cpp:160
This class defines a common interface for vectors.
Definition: GenericVector.h:47
Definition: Mesh.h:82