www.mooseframework.org
VTKOutput.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "VTKOutput.h"
11 
12 #include "libmesh/vtk_io.h"
13 #include "libmesh/equation_systems.h"
14 
15 registerMooseObjectAliased("MooseApp", VTKOutput, "VTK");
16 
19 {
21  params.addClassDescription("Output data using the Visualization Toolkit (VTK).");
22 
23  // Set default padding to 3
24  params.set<unsigned int>("padding") = 3;
25 
26  // Add binary toggle
27  params.addParam<bool>("binary", false, "Set VTK files to output in binary format");
28  params.addParamNamesToGroup("binary", "Advanced");
29 
30  return params;
31 }
32 
34  : OversampleOutput(parameters), _binary(getParam<bool>("binary"))
35 {
36 #ifndef LIBMESH_HAVE_VTK
37  mooseError("VTK output was requested, but libMesh was not configured with VTK. To fix this, you "
38  "must reconfigure libMesh to use VTK.");
39 #endif
40 }
41 
42 void
44 {
45 #ifdef LIBMESH_HAVE_VTK
46  VTKIO vtk(_es_ptr->get_mesh());
48 
49  // Set the comppression
50  vtk.set_compression(_binary);
51 
52  // Write the data
53  vtk.write_equation_systems(filename(), *_es_ptr);
54  _file_num++;
55 #endif
56 }
57 
58 std::string
60 {
61  // Append the .e extension on the base file name
62  std::ostringstream output;
63  output << _file_base;
64 
65  // In parallel, add the _00x.pvtu extension.
66  // In serial, add the _00x.pvtu extension anyway - libMesh outputs
67  // PVTU format regardless of what file name we give it.
68  const std::string ext = ".pvtu";
69  output << "_" << std::setw(_padding) << std::setfill('0') << std::right << _file_num << ext;
70 
71  // Return the filename
72  return output.str();
73 }
Based class for providing re-positioning and oversampling support to output objects.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::string _file_base
The base filename from the input paramaters.
Definition: FileOutput.h:89
static InputParameters validParams()
Definition: VTKOutput.C:18
bool _binary
Flag for using binary compression.
Definition: VTKOutput.h:42
unsigned int _padding
Number of digits to pad the extensions.
Definition: FileOutput.h:83
virtual std::string filename() override
Return the file name with the *.vtk extension.
Definition: VTKOutput.C:59
EquationSystems * _es_ptr
Reference the the libMesh::EquationSystems object that contains the data.
Definition: Output.h:188
registerMooseObjectAliased("MooseApp", VTKOutput, "VTK")
virtual void output() override
Perform the output of VTKOutput.
Definition: VTKOutput.C:43
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
unsigned int & _file_num
A file number counter, initialized to 0 (this must be controlled by the child class, see Exodus)
Definition: FileOutput.h:80
VTKOutput(const InputParameters &parameters)
Class constructor.
Definition: VTKOutput.C:33
static InputParameters validParams()
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...