Loading...
Searching...
No Matches
TimeSeries.h
// Copyright (C) 2009-2016 Anders Logg
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
#ifndef __TIME_SERIES_H
#define __TIME_SERIES_H
#ifdef HAS_HDF5
#include <string>
#include <vector>
#include <dolfin/common/MPI.h>
#include <dolfin/common/Variable.h>
namespace dolfin
{
// Forward declarations
class GenericVector;
class Mesh;
class TimeSeries : public Variable
{
public:
TimeSeries(std::string name)
: TimeSeries(MPI_COMM_WORLD, name) {}
TimeSeries(MPI_Comm mpi_comm, std::string name);
~TimeSeries();
void store(const GenericVector& vector, double t);
void store(const Mesh& mesh, double t);
void retrieve(GenericVector& vector, double t,
bool interpolate=true) const;
void retrieve(Mesh& mesh, double t) const;
std::vector<double> vector_times() const;
std::vector<double> mesh_times() const;
void clear();
std::string str(bool verbose) const;
static Parameters default_parameters()
{
Parameters p("time_series");
p.add("clear_on_write", true);
return p;
}
private:
template <typename T>
void store_object(MPI_Comm comm, const T& object, double t,
std::vector<double>& times,
std::string series_name,
std::string group_name);
// Check if values are strictly increasing
static bool monotone(const std::vector<double>& times);
// Find index closest to given time
static std::size_t find_closest_index(double t,
const std::vector<double>& times,
std::string series_name,
std::string type_name);
// Find index pair closest to given time
static std::pair<std::size_t, std::size_t>
find_closest_pair(double t, const std::vector<double>& times,
std::string series_name, std::string type_name);
// Name of series
std::string _name;
// List of times
std::vector<double> _vector_times;
std::vector<double> _mesh_times;
// True if series has been cleared
bool _cleared;
};
}
#endif
#endif
dolfin::GenericVector
This class defines a common interface for vectors.
Definition GenericVector.h:48
dolfin::Mesh
Definition Mesh.h:84
dolfin::Parameters
Definition Parameters.h:95
dolfin::Parameters::add
void add(std::string key)
Definition Parameters.h:128
dolfin::TimeSeries::~TimeSeries
~TimeSeries()
Destructor.
Definition TimeSeries.cpp:155
dolfin::TimeSeries::default_parameters
static Parameters default_parameters()
Default parameter values.
Definition TimeSeries.h:133
dolfin::TimeSeries::retrieve
void retrieve(GenericVector &vector, double t, bool interpolate=true) const
Definition TimeSeries.cpp:183
dolfin::TimeSeries::store
void store(const GenericVector &vector, double t)
Definition TimeSeries.cpp:160
dolfin::TimeSeries::str
std::string str(bool verbose) const
Return informal string representation (pretty-print).
Definition TimeSeries.cpp:292
dolfin::TimeSeries::clear
void clear()
Clear time series.
Definition TimeSeries.cpp:285
dolfin::TimeSeries::mesh_times
std::vector< double > mesh_times() const
Definition TimeSeries.cpp:280
dolfin::TimeSeries::TimeSeries
TimeSeries(std::string name)
Definition TimeSeries.h:57
dolfin::TimeSeries::vector_times
std::vector< double > vector_times() const
Definition TimeSeries.cpp:275
dolfin::Variable::name
std::string name() const
Return name.
Definition Variable.cpp:71
dolfin::Variable::Variable
Variable()
Create unnamed variable.
Definition Variable.cpp:31
dolfin
Definition adapt.h:30