ExaDG
Loading...
Searching...
No Matches
pointwise_output_generator_base.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef EXADG_POSTPROCESSOR_POINTWISE_OUTPUT_GENERATOR_BASE_H_
23#define EXADG_POSTPROCESSOR_POINTWISE_OUTPUT_GENERATOR_BASE_H_
24
25// deal.II
26#include <deal.II/base/conditional_ostream.h>
27#include <deal.II/base/mpi_remote_point_evaluation.h>
28#include <deal.II/base/point.h>
29
30#ifdef DEAL_II_WITH_HDF5
31# include <deal.II/base/hdf5.h>
32#endif
33
34#include <deal.II/distributed/tria.h>
35
36#include <deal.II/fe/mapping.h>
37
38#include <deal.II/numerics/vector_tools.h>
39
40// ExaDG
41#include <exadg/postprocessor/time_control.h>
42#include <exadg/utilities/tensor_utilities.h>
43
44namespace ExaDG
45{
46template<int dim>
47struct PointwiseOutputDataBase
48{
49 using point_value_type = typename dealii::Point<dim>::value_type;
50
51 PointwiseOutputDataBase();
52
53 TimeControlData time_control_data;
54
55 std::string directory;
56 std::string filename;
57
58 bool update_points_before_evaluation;
59
60 std::vector<dealii::Point<dim>> evaluation_points;
61
62 void
63 print(dealii::ConditionalOStream & pcout) const;
64};
65
66template<int dim, typename Number>
67class PointwiseOutputGeneratorBase
68{
69public:
70 using point_value_type = typename PointwiseOutputDataBase<dim>::point_value_type;
71
72 TimeControl time_control;
73
74protected:
75 void
76 do_evaluate(std::function<void()> const & write_solution, double const time, bool const unsteady);
77
78 PointwiseOutputGeneratorBase(MPI_Comm const & comm);
79
80 virtual ~PointwiseOutputGeneratorBase() = default;
81
82 void
83 setup_base(dealii::Triangulation<dim> const & triangulation_in,
84 dealii::Mapping<dim> const & mapping_in,
85 PointwiseOutputDataBase<dim> const & pointwise_output_data_in);
86
87 void
88 add_quantity(std::string const & name, unsigned int const n_components);
89
90 template<int n_components>
91 void
92 write_quantity(std::string const & name,
93 std::vector<dealii::Tensor<1, n_components, Number>> const & values,
94 unsigned int const first_component)
95 {
96 unsigned int const components = name_to_components.at(name);
97 for(unsigned int comp = 0; comp < components; ++comp)
98 {
99 extract_component_from_tensors(componentwise_result, values, first_component + comp);
100 write_component((components == 1) ? name : name + std::to_string(comp), componentwise_result);
101 }
102 }
103
104 void
105 write_quantity(std::string const & name, std::vector<Number> const & values)
106 {
107 write_component(name, values);
108 }
109
110 template<int n_components>
111 [[nodiscard]] std::vector<
112 typename dealii::FEPointEvaluation<n_components, dim, dim, Number>::value_type>
113 compute_point_values(dealii::LinearAlgebra::distributed::Vector<Number> const & solution,
114 dealii::DoFHandler<dim> const & dof_handler) const
115 {
116 return dealii::VectorTools::point_values<n_components>(*remote_evaluator,
117 dof_handler,
118 solution);
119 }
120
121private:
122 void
123 setup_remote_evaluator();
124
125 void
126 reinit_remote_evaluator();
127
128 void
129 create_hdf5_file();
130
131 void
132 write_evaluation_points(std::string const & name);
133
134#ifdef DEAL_II_WITH_HDF5
135 void
136 add_evaluation_points_dataset(dealii::HDF5::Group & group, std::string const & name);
137
138 void
139 add_time_dataset(dealii::HDF5::Group & group, std::string const & name);
140#endif
141
142 void
143 write_time(double time);
144
145 template<typename ComponentwiseContainerType>
146 void
147 write_component(std::string const & name, ComponentwiseContainerType const & componentwise_result)
148 {
149#ifdef DEAL_II_WITH_HDF5
150 auto dataset = hdf5_file->open_dataset("PhysicalInformation/" + name);
151
152 std::vector<hsize_t> hyperslab_offset = {0, time_control.get_counter()};
153 std::vector<hsize_t> hyperslab_dim = {pointwise_output_data.evaluation_points.size(), 1};
154
155 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
156 dataset.write_hyperslab(componentwise_result, hyperslab_offset, hyperslab_dim);
157 else
158 dataset.template write_none<Number>();
159#else
160 (void)name;
161 (void)componentwise_result;
162 AssertThrow(false, dealii::ExcMessage("deal.II is not compiled with HDF5!"));
163#endif
164 }
165
166 MPI_Comm const mpi_comm;
167
168 dealii::ObserverPointer<dealii::Triangulation<dim> const> triangulation;
169 dealii::ObserverPointer<dealii::Mapping<dim> const> mapping;
170 PointwiseOutputDataBase<dim> pointwise_output_data;
171 dealii::Vector<Number> componentwise_result;
172 unsigned int n_out_samples;
173 std::shared_ptr<dealii::Utilities::MPI::RemotePointEvaluation<dim>> remote_evaluator;
174 bool first_evaluation;
175
176 std::map<std::string, unsigned int> name_to_components;
177
178#ifdef DEAL_II_WITH_HDF5
179 std::unique_ptr<dealii::HDF5::File> hdf5_file;
180#endif
181};
182
183} // namespace ExaDG
184
185#endif /* EXADG_POSTPROCESSOR_POINTWISE_OUTPUT_GENERATOR_BASE_H_ */
Definition time_control.h:64
Definition driver.cpp:33
void extract_component_from_tensors(dealii::Vector< Number > &dst, std::vector< dealii::Tensor< n_components1, n_components2, Number > > const &values, unsigned int const comp1, unsigned int const comp2)
Definition tensor_utilities.h:39
Definition pointwise_output_generator_base.h:48
Definition time_control.h:40