Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
statistics.h
Go to the documentation of this file.
1
12#ifndef STATISTICS_H
13#define STATISTICS_H
14
15#include <array>
16#include <cstdint>
17#include <fstream>
18#include <memory>
19#include <string>
20#include <utility>
21#include <vector>
22
23#include <Kokkos_Core.hpp>
24#include <toml.hpp>
25
26#include "common_typedef.h"
27#include "data.h"
28#include "data_writer.h"
29#include "mesh.h"
30#include "state.h"
31
40 Kokkos::View<rtype *[N_PRIMITIVE]> P;
41
42 static constexpr int32_t RHO = 0;
43 static constexpr int32_t FIRST_PRIMITIVE = 1;
44 static constexpr int32_t FIRST_SPECIES = 1 + N_PRIMITIVE;
45
47 rtype operator()(const uint32_t c, const int32_t code) const {
48 if (code == RHO) return U(c, 0);
49 if (code < FIRST_SPECIES) return P(c, code - FIRST_PRIMITIVE);
50 return rhoY(c, code - FIRST_SPECIES) / U(c, 0);
51 }
52
54 static int32_t code(const std::string & name, const std::vector<std::string> & species_names,
55 const std::string & key);
56};
57
71 public:
73 void init(const toml::value & input, const std::vector<std::string> & species_names, uint32_t n_cells);
74
75 bool enabled() const { return !fields.empty(); }
76 bool due(uint64_t step, rtype t) const { return enabled() && step % interval == 0 && t > t_start; }
77
79 void sample(rtype t, const CellSampler & sampler, uint32_t n_owned);
80
82 std::vector<std::string> variables() const;
83 void register_data(std::vector<Data> & data) const;
85
91 void restore(const RestartData & restart, const std::string & file, rtype t);
93 void start(rtype t);
95
96 std::string summary() const;
97 uint64_t samples() const { return n_samples; }
99 const auto & host_means() const { return h_mean; }
100 const auto & host_covariances() const { return h_cov; }
101
102 private:
103 std::vector<std::string> fields;
104 std::vector<std::pair<uint32_t, uint32_t>> products; // indices into fields
105 uint64_t interval = 1;
106 rtype t_start = 0.0;
107 bool reset = false;
108
109 Kokkos::View<int32_t *> codes;
110 Kokkos::View<uint32_t *[2]> pairs;
111 Kokkos::View<rtype **, Kokkos::LayoutLeft> mean;
112 Kokkos::View<rtype **, Kokkos::LayoutLeft> cov;
113 Kokkos::View<rtype **, Kokkos::LayoutLeft>::host_mirror_type h_mean;
114 Kokkos::View<rtype **, Kokkos::LayoutLeft>::host_mirror_type h_cov;
115
116 rtype weight = 0.0;
117 rtype t_last = 0.0;
118 uint64_t n_samples = 0;
119};
120
128class Probes {
129 public:
131 void init(const toml::value & input, const Mesh & mesh, const std::vector<std::string> & species_names,
132 bool resume);
133
134 bool due(uint64_t step) const;
135 void write(uint64_t step, rtype t, const CellSampler & sampler);
136
137 std::vector<std::pair<std::string, std::string>> summary() const;
138 std::vector<std::string> files() const;
139
140 private:
141 struct Set {
142 std::string name;
143 std::string file;
144 uint64_t interval = 1;
145 std::vector<std::string> variables;
146 std::vector<std::array<double, N_DIM>> points;
147 std::vector<uint32_t> local_points; // points held by owned cells of this rank
148 Kokkos::View<uint32_t *> cells; // their cells
149 Kokkos::View<int32_t *> codes;
150 Kokkos::View<rtype **, Kokkos::LayoutRight> values; // (local point, variable)
151 std::shared_ptr<std::ofstream> out;
152 };
153 std::vector<Set> sets;
154};
155
161std::vector<int32_t> locate_points(const Mesh & mesh, const std::vector<std::array<double, N_DIM>> & points);
162
163#endif // STATISTICS_H
Definition mesh.h:111
Point and line probes: the values of the cells holding a set of points, written every interval steps ...
Definition statistics.h:128
void init(const toml::value &input, const Mesh &mesh, const std::vector< std::string > &species_names, bool resume)
Read [[probes]] and locate the points; resume appends to existing files.
Definition statistics.cpp:374
std::vector< std::pair< std::string, std::string > > summary() const
Definition statistics.cpp:480
void write(uint64_t step, rtype t, const CellSampler &sampler)
Definition statistics.cpp:446
std::vector< std::string > files() const
Definition statistics.cpp:492
bool due(uint64_t step) const
Definition statistics.cpp:442
Running time averages per owned cell: means of fields and covariances <a'b'> of pairs of them,...
Definition statistics.h:70
uint64_t samples() const
Definition statistics.h:97
void restore(const RestartData &restart, const std::string &file, rtype t)
Continue the averages of a restart file, or start afresh at time t if it holds none (or with reset); ...
Definition statistics.cpp:168
void copy_device_to_host()
Definition statistics.cpp:162
std::vector< std::string > variables() const
Output variables: MEAN_<field>..., COV__...
Definition statistics.cpp:147
void sample(rtype t, const CellSampler &sampler, uint32_t n_owned)
Add the sample of time t of cells [0, n_owned).
Definition statistics.cpp:123
RestartAttributes attributes() const
Definition statistics.cpp:206
bool enabled() const
Definition statistics.h:75
void register_data(std::vector< Data > &data) const
Definition statistics.cpp:154
const auto & host_covariances() const
Definition statistics.h:100
const auto & host_means() const
Host copies (see copy_device_to_host): (cell, field) means, (cell, product) covariances.
Definition statistics.h:99
void init(const toml::value &input, const std::vector< std::string > &species_names, uint32_t n_cells)
Read [statistics] (if any) and allocate n_cells.
Definition statistics.cpp:64
std::string summary() const
Definition statistics.cpp:213
void start(rtype t)
Start afresh at time t (first sample weighted from max(t, t_start)).
Definition statistics.cpp:114
bool due(uint64_t step, rtype t) const
Definition statistics.h:76
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
Typedefs for common types.
float rtype
Definition common_typedef.h:39
#define N_PRIMITIVE
Definition common_typedef.h:30
Data class declaration.
Data writer class declaration.
std::vector< std::pair< std::string, double > > RestartAttributes
Named scalars of a restart file (version 3), e.g. the statistics' weight.
Definition data_writer.h:47
Mesh class declaration.
Conservative state: the flow block and the species partial densities.
Kokkos::View< rtype *[N_CONSERVATIVE]> StateView
Flow block [rho, rho u, rho E] per cell.
Definition state.h:23
Kokkos::View< rtype **, SpeciesLayout > SpeciesView
Partial densities rho Y_k per (cell, species).
Definition state.h:37
std::vector< int32_t > locate_points(const Mesh &mesh, const std::vector< std::array< double, N_DIM > > &points)
Owned cell of each point on this rank, or -1 where another rank (or none) holds it: the cell containi...
Definition statistics.cpp:221
Cell values that statistics and probes sample, by code: 0 is RHO, 1 + i the primitive PRIMITIVE_NAMES...
Definition statistics.h:37
SpeciesView rhoY
Definition statistics.h:39
KOKKOS_INLINE_FUNCTION rtype operator()(const uint32_t c, const int32_t code) const
Definition statistics.h:47
static int32_t code(const std::string &name, const std::vector< std::string > &species_names, const std::string &key)
Code of a variable name (RHO, a primitive, Y_<species>); throws InputError naming key.
Definition statistics.cpp:25
Kokkos::View< rtype *[N_PRIMITIVE]> P
Definition statistics.h:40
StateView U
Definition statistics.h:38
static constexpr int32_t FIRST_PRIMITIVE
Definition statistics.h:43
static constexpr int32_t RHO
Definition statistics.h:42
static constexpr int32_t FIRST_SPECIES
Definition statistics.h:44
Contents of a restart file.
Definition data_writer.h:67
CellSetup< ExecSpace > c
Definition teno_setup.cpp:1810
TableBatchT< Space > out
Definition teno_setup.cpp:681
Kokkos::View< uint32_t *, Space > cells
Definition teno_setup.cpp:682