| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2006 - 2023 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_dof_output_operator_templates_h |
| 16 |
#define dealii_dof_output_operator_templates_h |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/parameter_handler.h> |
| 22 |
|
| 23 |
#include <deal.II/numerics/dof_output_operator.h> |
| 24 |
|
| 25 |
DEAL_II_NAMESPACE_OPEN |
| 26 |
|
| 27 |
namespace Algorithms |
| 28 |
{ |
| 29 |
template <typename VectorType, int dim, int spacedim> |
| 30 |
DoFOutputOperator<VectorType, dim, spacedim>::DoFOutputOperator( |
| 31 |
const std::string &filename_base, |
| 32 |
const unsigned int digits) |
| 33 |
: filename_base(filename_base) |
| 34 |
, digits(digits) |
| 35 |
{ |
| 36 |
out.set_default_format(DataOutBase::gnuplot); |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
template <typename VectorType, int dim, int spacedim> |
| 41 |
void |
| 42 |
DoFOutputOperator<VectorType, dim, spacedim>::parse_parameters( |
| 43 |
ParameterHandler ¶m) |
| 44 |
{ |
| 45 |
out.parse_parameters(param); |
| 46 |
} |
| 47 |
|
| 48 |
template <typename VectorType, int dim, int spacedim> |
| 49 |
OutputOperator<VectorType> & |
| 50 |
DoFOutputOperator<VectorType, dim, spacedim>::operator<<(const AnyData &data) |
| 51 |
{ |
| 52 |
Assert((dof != nullptr), ExcNotInitialized()); |
| 53 |
out.attach_dof_handler(*dof); |
| 54 |
for (unsigned int i = 0; i < data.size(); ++i) |
| 55 |
{ |
| 56 |
const VectorType *p = data.try_read_ptr<VectorType>(i); |
| 57 |
if (p != nullptr) |
| 58 |
{ |
| 59 |
out.add_data_vector(*p, data.name(i)); |
| 60 |
} |
| 61 |
} |
| 62 |
std::ostringstream streamOut; |
| 63 |
streamOut << filename_base << std::setw(digits) << std::setfill('0') |
| 64 |
<< this->step << out.default_suffix(); |
| 65 |
std::ofstream out_filename(streamOut.str()); |
| 66 |
out.build_patches(); |
| 67 |
out.write(out_filename); |
| 68 |
out.clear(); |
| 69 |
return *this; |
| 70 |
} |
| 71 |
} // namespace Algorithms |
| 72 |
|
| 73 |
DEAL_II_NAMESPACE_CLOSE |
| 74 |
|
| 75 |
#endif |