11#include <deal.II/base/function_parser.h>
12#include <deal.II/numerics/data_out.h>
13#include <deal.II/numerics/vector_tools.h>
18 using namespace dealii;
21 template <
typename Description,
int dim,
typename Number>
30 const std::string &subsection )
31 : ParameterAcceptor(subsection)
32 , mpi_ensemble_(mpi_ensemble)
33 , offline_data_(&offline_data)
34 , hyperbolic_system_(&hyperbolic_system)
35 , parabolic_system_(¶bolic_system)
36 , postprocessor_(&postprocessor)
37 , initial_precomputed_(initial_precomputed)
41 add_parameter(
"use mpi io",
43 "If enabled write out one vtu file via MPI IO using "
44 "write_vtu_in_parallel() instead of independent output files "
45 "via write_vtu_with_pvtu_record()");
47 add_parameter(
"manifolds",
49 "List of level set functions. The description is used to "
50 "only output cells that intersect the given level set.");
52 std::copy(std::begin(View::component_names),
53 std::end(View::component_names),
54 std::back_inserter(vtu_output_quantities_));
56 std::copy(std::begin(View::initial_precomputed_names),
57 std::end(View::initial_precomputed_names),
58 std::back_inserter(vtu_output_quantities_));
60 add_parameter(
"vtu output quantities",
61 vtu_output_quantities_,
62 "List of conserved, primitive, precomputed, or postprocessed "
63 "quantities that will be written to the vtu files.");
67 template <
typename Description,
int dim,
typename Number>
71 std::cout <<
"VTUOutput<dim, Number>::prepare()" << std::endl;
75 vtu_output_quantities_);
79 template <
typename Description,
int dim,
typename Number>
86 bool output_levelsets)
89 std::cout <<
"VTUOutput<dim, Number>::schedule_output()" << std::endl;
91 const auto &affine_constraints = offline_data_->affine_constraints();
98 auto selected_components =
102 initial_precomputed_,
104 vtu_output_quantities_);
108 auto data_out = std::make_unique<dealii::DataOut<dim>>();
109 data_out->attach_dof_handler(offline_data_->dof_handler());
111 for (
unsigned int d = 0; d < selected_components.size(); ++d) {
112 affine_constraints.distribute(selected_components[d]);
113 selected_components[d].update_ghost_values();
114 data_out->add_data_vector(selected_components[d],
115 vtu_output_quantities_[d],
116 DataOut<dim>::type_dof_data);
119 const auto n_quantities = postprocessor_->n_quantities();
120 for (
unsigned int i = 0; i < n_quantities; ++i)
121 data_out->add_data_vector(postprocessor_->quantities()[i],
122 postprocessor_->component_names()[i],
123 DataOut<dim>::type_dof_data);
125 DataOutBase::VtkFlags flags(t,
128#
if DEAL_II_VERSION_GTE(9, 5, 0)
129 DataOutBase::CompressionLevel::best_speed);
131 DataOutBase::VtkFlags::best_speed);
133 data_out->set_flags(flags);
135 const auto &discretization = offline_data_->discretization();
136 const auto &mapping = discretization.mapping();
137 const auto patch_order =
138 std::max(1u, discretization.finite_element().degree) - 1u;
143 data_out->build_patches(mapping, patch_order);
147 data_out->write_vtu_in_parallel(
148 name +
"_" + Utilities::to_string(cycle, 6) +
".vtu",
149 mpi_ensemble_.ensemble_communicator());
151 data_out->write_vtu_with_pvtu_record(
152 "", name, cycle, mpi_ensemble_.ensemble_communicator(), 6);
156 if (output_levelsets && manifolds_.size() != 0) {
162 std::vector<std::shared_ptr<FunctionParser<dim>>> level_set_functions;
163 for (
const auto &expression : manifolds_)
164 level_set_functions.emplace_back(
165 std::make_shared<FunctionParser<dim>>(expression));
167 data_out->set_cell_selection([level_set_functions](
const auto &cell) {
168 if (!cell->is_active() || cell->is_artificial())
171 for (
const auto &function : level_set_functions) {
173 unsigned int above = 0;
174 unsigned int below = 0;
176 for (
unsigned int v : cell->vertex_indices()) {
177 const auto vertex = cell->vertex(v);
178 constexpr auto eps = std::numeric_limits<Number>::epsilon();
179 if (function->value(vertex) >= 0. - 100. * eps)
181 if (function->value(vertex) <= 0. + 100. * eps)
183 if (above > 0 && below > 0)
190 data_out->build_patches(mapping, patch_order);
194 data_out->write_vtu_in_parallel(
195 name +
"-levelsets_" + Utilities::to_string(cycle, 6) +
".vtu",
196 mpi_ensemble_.ensemble_communicator());
198 data_out->write_vtu_with_pvtu_record(
202 mpi_ensemble_.ensemble_communicator(),
typename View::StateVector StateVector
void schedule_output(const StateVector &state_vector, std::string name, Number t, unsigned int cycle, bool output_full=true, bool output_cutplanes=true)
VTUOutput(const MPIEnsemble &mpi_ensemble, const OfflineData< dim, Number > &offline_data, const HyperbolicSystem &hyperbolic_system, const ParabolicSystem ¶bolic_system, const Postprocessor< Description, dim, Number > &postprocessor, const InitialPrecomputedVector &initial_precomputed, const ScalarVector &alpha, const std::string &subsection="/VTUOutput")
typename Description::HyperbolicSystem HyperbolicSystem
Vectors::ScalarVector< Number > ScalarVector
typename Description::ParabolicSystem ParabolicSystem
typename View::InitialPrecomputedVector InitialPrecomputedVector