19 #ifndef PISM_DIAGNOSTIC_HH
20 #define PISM_DIAGNOSTIC_HH
26 #include "pism/util/ConfigInterface.hh"
27 #include "pism/util/VariableMetadata.hh"
28 #include "pism/util/io/IO_Flags.hh"
29 #include "pism/util/array/Scalar.hh"
30 #include "pism/util/error_handling.hh"
31 #include "pism/util/io/File.hh"
32 #include "pism/util/io/io_helpers.hh"
65 typedef std::shared_ptr<Diagnostic>
Ptr;
69 static Ptr wrap(
const T &input);
75 std::shared_ptr<array::Array>
compute()
const;
83 void init(
const File &input,
unsigned int time);
105 std::shared_ptr<T>
allocate(
const std::string &name)
const {
106 auto result = std::make_shared<T>(
m_grid, name);
107 for (
unsigned int k = 0;
k < result->ndof(); ++
k) {
120 std::vector<SpatialVariableMetadata>
m_vars;
137 for (
unsigned int j = 0; j < input.ndof(); ++j) {
138 m_vars.emplace_back(input.metadata(j));
144 auto result =
m_input.duplicate();
146 result->set_name(
m_input.get_name());
147 for (
unsigned int k = 0;
k <
m_vars.size(); ++
k) {
159 template <
typename T>
165 template <
class Model>
229 unsigned int t_start = time_length > 0 ? time_length - 1 : 0;
250 auto result = Diagnostic::allocate<array::Scalar>(
"diagnostic");
280 typedef std::shared_ptr<TSDiagnostic>
Ptr;
282 TSDiagnostic(std::shared_ptr<const Grid>
g,
const std::string &name);
285 void update(
double t0,
double t1);
289 void init(
const File &output_file, std::shared_ptr<std::vector<double> > requested_times);
308 void set_units(
const std::string &units,
const std::string &output_units);
355 void evaluate(
double t0,
double t1,
double v);
371 void evaluate(
double t0,
double t1,
double change);
403 template <
class D,
class M>
406 TSDiag(
const M *m,
const std::string &name)
407 :
D(m->grid(), name),
model(m) {
std::shared_ptr< const Config > ConstPtr
virtual void update_impl(double dt)
VariableMetadata m_time_since_reset
array::Scalar m_accumulator
virtual std::shared_ptr< array::Array > compute_impl() const
virtual void reset_impl()
virtual const array::Scalar & model_input()
void init_impl(const File &input, unsigned int time)
DiagAverageRate(const M *m, const std::string &name, InputKind kind)
void write_state_impl(const File &output) const
void define_state_impl(const File &output) const
DiagWithDedicatedStorage(const T &input)
std::shared_ptr< array::Array > compute_impl() const
A template derived from Diagnostic, adding a "Model".
void write_state(const File &output) const
virtual void write_state_impl(const File &output) const
static Ptr wrap(const T &input)
virtual void reset_impl()
virtual ~Diagnostic()=default
double m_fill_value
fill value (used often enough to justify storing it)
void define(const File &file, io::Type default_type) const
const units::System::Ptr m_sys
the unit system
double to_internal(double x) const
virtual std::shared_ptr< array::Array > compute_impl() const =0
std::vector< SpatialVariableMetadata > m_vars
metadata corresponding to NetCDF variables
virtual void define_state_impl(const File &output) const
std::shared_ptr< Diagnostic > Ptr
void init(const File &input, unsigned int time)
virtual void update_impl(double dt)
Diagnostic(std::shared_ptr< const Grid > g)
double to_external(double x) const
void define_state(const File &output) const
virtual void define_impl(const File &file, io::Type default_type) const
Define NetCDF variables corresponding to a diagnostic quantity.
unsigned int n_variables() const
Get the number of NetCDF variables corresponding to a diagnostic quantity.
std::shared_ptr< const Grid > m_grid
the grid
virtual void init_impl(const File &input, unsigned int time)
std::shared_ptr< T > allocate(const std::string &name) const
std::shared_ptr< array::Array > compute() const
Compute a diagnostic quantity and return a pointer to a newly-allocated Array.
SpatialVariableMetadata & metadata(unsigned int N=0)
Get a metadata object corresponding to variable number N.
const Config::ConstPtr m_config
Configuration flags and parameters.
Class representing diagnostic computations in PISM.
void read_variable(const std::string &variable_name, const std::vector< unsigned int > &start, const std::vector< unsigned int > &count, double *ip) const
VariableLookupData find_variable(const std::string &short_name, const std::string &std_name) const
Find a variable using its standard name and/or short name.
unsigned int dimension_length(const std::string &name) const
Get the length of a dimension.
High-level PISM I/O class.
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
TSDiag(const M *m, const std::string &name)
const units::System::Ptr m_sys
the unit system
std::vector< double > m_values
void set_units(const std::string &units, const std::string &output_units)
std::shared_ptr< std::vector< double > > m_requested_times
requested times
VariableMetadata m_dimension
unsigned int m_current_time
index into m_times
unsigned int m_start
starting index used when flushing the buffer
VariableMetadata m_time_bounds
std::string m_time_name
time series object used to store computed values and metadata
std::vector< double > m_bounds
size_t m_buffer_size
size of the buffer used to store data
VariableMetadata m_variable
TSDiagnostic(std::shared_ptr< const Grid > g, const std::string &name)
std::string m_output_filename
const Config::ConstPtr m_config
Configuration flags and parameters.
std::vector< double > m_time
virtual double compute()=0
void init(const File &output_file, std::shared_ptr< std::vector< double > > requested_times)
const VariableMetadata & metadata() const
virtual void update_impl(double t0, double t1)=0
std::shared_ptr< const Grid > m_grid
the grid
std::shared_ptr< TSDiagnostic > Ptr
void update(double t0, double t1)
PISM's scalar time-series diagnostics.
void update_impl(double t0, double t1)
TSFluxDiagnostic(std::shared_ptr< const Grid > g, const std::string &name)
Scalar diagnostic reporting a "flux".
double m_accumulator
accumulator of changes (used to compute rates of change)
void update_impl(double t0, double t1)
TSRateDiagnostic(std::shared_ptr< const Grid > g, const std::string &name)
void evaluate(double t0, double t1, double change)
double m_v_previous
last two values, used to compute the change during a time step
Scalar diagnostic reporting the rate of change of a quantity modeled by PISM.
void evaluate(double t0, double t1, double v)
TSSnapshotDiagnostic(std::shared_ptr< const Grid > g, const std::string &name)
void update_impl(double t0, double t1)
Scalar diagnostic reporting a snapshot of a quantity modeled by PISM.
void add(double alpha, const Array2D< T > &x)
void read(const std::string &filename, unsigned int time)
void define(const File &file, io::Type default_type) const
Define variables corresponding to an Array in a file opened using file.
void write(const std::string &filename) const
const std::string & get_name() const
Get the name of an Array object.
void set(double c)
Result: v[j] <- c for all j.
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
std::shared_ptr< System > Ptr
#define PISM_ERROR_LOCATION
void write_timeseries(const File &file, const VariableMetadata &metadata, size_t t_start, const std::vector< double > &data)
Write a time-series data to a file.
void define_timeseries(const VariableMetadata &var, const std::string &dimension_name, const File &file, io::Type nctype)
Define a NetCDF variable corresponding to a time-series.
std::map< std::string, TSDiagnostic::Ptr > TSDiagnosticList
std::map< std::string, Diagnostic::Ptr > DiagnosticList