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 
17 template <>
20 {
22  params.addClassDescription("Output data using the Visualization Toolkit (VTK).");
23 
24  // Set default padding to 3
25  params.set<unsigned int>("padding") = 3;
26 
27  // Add binary toggle
28  params.addParam<bool>("binary", false, "Set VTK files to output in binary format");
29  params.addParamNamesToGroup("binary", "Advanced");
30 
31  return params;
32 }
33 
35  : OversampleOutput(parameters), _binary(getParam<bool>("binary"))
36 {
37 #ifndef LIBMESH_HAVE_VTK
38  mooseError("VTK output was requested, but libMesh was not configured with VTK. To fix this, you "
39  "must reconfigure libMesh to use VTK.");
40 #endif
41 }
42 
43 void
45 {
46 #ifdef LIBMESH_HAVE_VTK
47  VTKIO vtk(_es_ptr->get_mesh());
49 
50  // Set the comppression
51  vtk.set_compression(_binary);
52 
53  // Write the data
54  vtk.write_equation_systems(filename(), *_es_ptr);
55  _file_num++;
56 #endif
57 }
58 
59 std::string
61 {
62  // Append the .e extension on the base file name
63  std::ostringstream output;
64  output << _file_base;
65 
66  // In serial, add the _00x.vtk extension.
67  // In parallel, add the _00x.pvtu extension.
68  std::string ext = (n_processors() == 1) ? ".vtk" : ".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.
InputParameters validParams< VTKOutput >()
Definition: VTKOutput.C:19
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:81
InputParameters validParams< OversampleOutput >()
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
bool _binary
Flag for using binary compression.
Definition: VTKOutput.h:46
unsigned int _padding
Number of digits to pad the extensions.
Definition: FileOutput.h:87
virtual std::string filename() override
Return the file name with the *.vtk extension.
Definition: VTKOutput.C:60
EquationSystems * _es_ptr
Reference the the libMesh::EquationSystems object that contains the data.
Definition: Output.h:176
registerMooseObjectAliased("MooseApp", VTKOutput, "VTK")
virtual void output(const ExecFlagType &type) override
Perform the output of VTKOutput.
Definition: VTKOutput.C:44
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
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:84
VTKOutput(const InputParameters &parameters)
Class constructor.
Definition: VTKOutput.C:34
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...