LCOV - code coverage report
Current view: top level - src/outputs - VTKOutput.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 23 24 95.8 %
Date: 2025-07-17 01:28:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       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             : InputParameters
      18       14449 : VTKOutput::validParams()
      19             : {
      20       14449 :   InputParameters params = SampledOutput::validParams();
      21       14449 :   params.addClassDescription("Output data using the Visualization Toolkit (VTK).");
      22             : 
      23             :   // Set default padding to 3
      24       14449 :   params.set<unsigned int>("padding") = 3;
      25             : 
      26             :   // Add binary toggle
      27       14449 :   params.addParam<bool>("binary", false, "Set VTK files to output in binary format");
      28       14449 :   params.addParamNamesToGroup("binary", "Advanced");
      29             : 
      30       14449 :   return params;
      31           0 : }
      32             : 
      33          92 : VTKOutput::VTKOutput(const InputParameters & parameters)
      34          92 :   : SampledOutput(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          92 : }
      41             : 
      42             : void
      43         387 : VTKOutput::output()
      44             : {
      45             : #ifdef LIBMESH_HAVE_VTK
      46             :   /// Create VTKIO object
      47         387 :   libMesh::VTKIO vtk(_es_ptr->get_mesh());
      48             : 
      49             :   // Set the comppression
      50         387 :   vtk.set_compression(_binary);
      51             : 
      52             :   // Write the data
      53         387 :   vtk.write_equation_systems(filename(), *_es_ptr);
      54         387 :   _file_num++;
      55             : #endif
      56         387 : }
      57             : 
      58             : std::string
      59         479 : VTKOutput::filename()
      60             : {
      61             :   // Append the .e extension on the base file name
      62         479 :   std::ostringstream output;
      63         479 :   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         479 :   const std::string ext = ".pvtu";
      69         479 :   output << "_" << std::setw(_padding) << std::setfill('0') << std::right << _file_num << ext;
      70             : 
      71             :   // Return the filename
      72         958 :   return output.str();
      73         479 : }

Generated by: LCOV version 1.14