/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/discretization/data/fe_output.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/discretization/data/fe_output.hh Source File
DiFfRG
fe_output.hh
Go to the documentation of this file.
1#pragma once
2
3// DiFfRG
6
7// external libraries
8#include <deal.II/dofs/dof_handler.h>
9#include <deal.II/lac/vector_memory.h>
10#include <deal.II/numerics/data_out.h>
11
12#include <hdf5lib/hdf5.hh>
13
14// standard library
15#include <exception>
16#include <list>
17#include <mutex>
18#include <thread>
19
20namespace DiFfRG
21{
22 using namespace dealii;
23
30 template <uint dim, typename VectorType> class FEOutput
31 {
32 public:
42 FEOutput(std::string top_folder, std::string output_name, std::string output_folder, const JSONValue &json);
43
46
48
56 void attach(const DoFHandler<dim> &dof_handler, const VectorType &solution, const std::string &name);
57
65 void attach(const DoFHandler<dim> &dof_handler, const VectorType &solution, const std::vector<std::string> &names);
66
72 void flush(double time);
73
74 private:
75 const std::string top_folder;
76 const std::string output_name;
77 const std::string output_folder;
78 const std::string filename_pvd;
80
82 std::vector<std::pair<double, std::string>> time_series;
83
84 constexpr static uint safe_dim = dim == 0 ? 1 : dim;
85 std::vector<DataOut<safe_dim>> data_outs;
86 std::list<std::thread> output_threads;
87 // series number each worker thread is responsible for, kept in lockstep with output_threads so
88 // the main thread can clear() the corresponding DataOut once the worker has been joined. Clearing
89 // a DataOut frees its Kokkos-backed vectors, which (with deal.II's Kokkos host backend) must not
90 // happen on a worker thread concurrently with the main thread's own Kokkos work.
91 std::list<uint> output_thread_series;
92 std::list<std::list<typename VectorMemory<VectorType>::Pointer>> attached_solutions;
93
94 // serializes worker-thread access to time_series and the shared .pvd file
95 std::mutex output_mutex;
96 // captures any exception thrown inside a worker thread so it can be re-raised on the
97 // main thread at the next flush() (or at destruction, if no other throw is unwinding)
98 std::mutex exception_mutex;
99 std::exception_ptr stored_exception;
100
101 GrowingVectorMemory<VectorType> mem;
102
104
106
108 };
109
110 template <typename VectorType> class FEOutput<0, VectorType>
111 {
112 public:
122 FEOutput(std::string top_folder, std::string output_name, std::string output_folder, const JSONValue &json);
123 };
124
125} // namespace DiFfRG
FEOutput(std::string top_folder, std::string output_name, std::string output_folder, const JSONValue &json)
Construct a new FEOutput object.
A class to output finite element data to disk as .vtu files and .pvd time series.
Definition fe_output.hh:31
std::vector< DataOut< safe_dim > > data_outs
Definition fe_output.hh:85
HDF5Output * hdf5_output
Definition fe_output.hh:105
void attach(const DoFHandler< dim > &dof_handler, const VectorType &solution, const std::vector< std::string > &names)
Attach a solution to the output.
std::list< std::thread > output_threads
Definition fe_output.hh:86
uint series_number
Definition fe_output.hh:81
const std::string output_name
Definition fe_output.hh:76
const std::string output_folder
Definition fe_output.hh:77
std::mutex output_mutex
Definition fe_output.hh:95
uint subdivisions
Definition fe_output.hh:81
const uint buffer_size
Definition fe_output.hh:79
const std::string top_folder
Definition fe_output.hh:75
const std::string filename_pvd
Definition fe_output.hh:78
void flush(double time)
Flush all attached solutions to disk.
FEOutput(std::string top_folder, std::string output_name, std::string output_folder, const JSONValue &json)
Construct a new FEOutput object.
std::vector< std::pair< double, std::string > > time_series
Definition fe_output.hh:82
bool save_vtk
Definition fe_output.hh:107
std::list< std::list< typename VectorMemory< VectorType >::Pointer > > attached_solutions
Definition fe_output.hh:92
GrowingVectorMemory< VectorType > mem
Definition fe_output.hh:101
void attach(const DoFHandler< dim > &dof_handler, const VectorType &solution, const std::string &name)
Attach a solution to the output.
std::list< uint > output_thread_series
Definition fe_output.hh:91
static constexpr uint safe_dim
Definition fe_output.hh:84
std::mutex exception_mutex
Definition fe_output.hh:98
std::exception_ptr stored_exception
Definition fe_output.hh:99
void set_hdf5_output(HDF5Output *output)
A class to output data to a CSV file.
Definition hdf5_output.hh:22
A wrapper around the boost json value class.
Definition json.hh:19
Definition complex_math.hh:10
unsigned int uint
Definition utils.hh:24