deal.II version GIT relicensing-6839-g338455934c 2026-10-02 12:10:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
dof_output_operator.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2010 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14#ifndef dealii_dof_output_operator_h
15#define dealii_dof_output_operator_h
16
17#include <deal.II/base/config.h>
18
21
22#include <deal.II/base/event.h>
25
27
29
30#include <fstream>
31#include <iomanip>
32#include <sstream>
33#include <string>
34
36
37namespace Algorithms
38{
45 template <typename VectorType, int dim, int spacedim = dim>
47 "The caller should set up and manage a DataOut object instead.")
48 DoFOutputOperator : public OutputOperator<VectorType>
49 {
50 public:
51 /*
52 * Constructor. The <tt>filename</tt> is the common base name of
53 * all files and the argument <tt>digits</tt> should be the number
54 * of digits of the highest number in the sequence. File names by
55 * default have the form "outputNNN" with NNN the number set by the
56 * last step command. Numbers with less digits are filled with
57 * zeros from the left.
58 */
59 DoFOutputOperator(const std::string &filename_base = "output",
60 const unsigned int digits = 3);
61
62 void
63 parse_parameters(ParameterHandler &param);
64 void
65 initialize(const DoFHandler<dim, spacedim> &dof_handler);
66
68 operator<<(const AnyData &vectors) override;
69
70 private:
74
75 const std::string filename_base;
76 const unsigned int digits;
77
79 };
80
81 /*-------------------- Functions: DoFOutputOperator ------------------------*/
82
83
84 template <typename VectorType, int dim, int spacedim>
85 inline void
87 const DoFHandler<dim, spacedim> &dof_handler)
88 {
89 dof = &dof_handler;
90 }
91
92
93
94 template <typename VectorType, int dim, int spacedim>
96 const std::string &filename_base,
97 const unsigned int digits)
98 : filename_base(filename_base)
99 , digits(digits)
100 {
101 out.set_default_format(DataOutBase::gnuplot);
102 }
103
104
105
106 template <typename VectorType, int dim, int spacedim>
107 inline void
109 ParameterHandler &param)
110 {
111 out.parse_parameters(param);
112 }
113
114
115
116 template <typename VectorType, int dim, int spacedim>
119 {
120 Assert((dof != nullptr), ExcNotInitialized());
121 out.attach_dof_handler(*dof);
122 for (unsigned int i = 0; i < data.size(); ++i)
123 {
124 const VectorType *p = data.try_read_ptr<VectorType>(i);
125 if (p != nullptr)
126 {
127 out.add_data_vector(*p, data.name(i));
128 }
129 }
130 std::ostringstream streamOut;
131 streamOut << filename_base << std::setw(digits) << std::setfill('0')
132 << this->step << out.default_suffix();
133 std::ofstream out_filename(streamOut.str());
134 out.build_patches();
135 out.write(out_filename);
136 out.clear();
137 return *this;
138 }
139} // namespace Algorithms
140
141
143
144#endif
DoFOutputOperator(const std::string &filename_base="output", const unsigned int digits=3)
void parse_parameters(ParameterHandler &param)
ObserverPointer< const DoFHandler< dim, spacedim >, DoFOutputOperator< VectorType, dim, spacedim > > dof
void initialize(const DoFHandler< dim, spacedim > &dof_handler)
virtual OutputOperator< VectorType > & operator<<(const AnyData &vectors) override
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_DEPRECATED_WITH_COMMENT(comment)
Definition config.h:295
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
std::ostream & operator<<(std::ostream &out, const DerivativeForm< order, dim, spacedim, Number > &df)
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotInitialized()
std::vector< index_type > data
Definition mpi.cc:734