LCOV - code coverage report
Current view: top level - src/outputs - XMLOutput.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 55 56 98.2 %
Date: 2025-07-17 01:28:37 Functions: 5 5 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             : // Moose includes
      11             : #include "XMLOutput.h"
      12             : #include "FEProblem.h"
      13             : #include "MooseApp.h"
      14             : 
      15             : registerMooseObject("MooseApp", XMLOutput);
      16             : 
      17             : InputParameters
      18       14397 : XMLOutput::validParams()
      19             : {
      20       14397 :   InputParameters params = AdvancedOutput::validParams();
      21       14397 :   params.addClassDescription("Output for VectorPostprocessor using XML format.");
      22       14397 :   params += AdvancedOutput::enableOutputTypes("vector_postprocessor");
      23       14397 :   return params;
      24           0 : }
      25             : 
      26          66 : XMLOutput::XMLOutput(const InputParameters & parameters) : AdvancedOutput(parameters)
      27             : {
      28             :   // Creates section in VPP
      29          66 :   _xml_doc.append_child("VectorPostprocessors");
      30          66 : }
      31             : 
      32             : std::string
      33         206 : XMLOutput::filename()
      34             : {
      35         206 :   if (processor_id() > 0)
      36             :   {
      37          71 :     std::ostringstream file_name;
      38          71 :     int digits = MooseUtils::numDigits(n_processors());
      39          71 :     file_name << _file_base << ".xml"
      40          71 :               << "." << std::setw(digits) << std::setfill('0') << processor_id();
      41          71 :     return file_name.str();
      42          71 :   }
      43         135 :   return _file_base + ".xml";
      44             : }
      45             : 
      46             : void
      47         208 : XMLOutput::outputVectorPostprocessors()
      48             : {
      49             :   // Create pugi node for storing vector data
      50         208 :   auto vpp_node = _xml_doc.child("VectorPostprocessors");
      51         208 :   auto vec_node = vpp_node.append_child("Vectors");
      52             : 
      53             :   // Populate output information from FEProblem, do not use AdvancedOutput because the psuedo time
      54             :   // is not required.
      55         208 :   vec_node.append_attribute("time") = _problem_ptr->time();
      56         208 :   vec_node.append_attribute("timestep") = _problem_ptr->timeStep();
      57         208 :   if (_execute_enum.isValueSet(EXEC_LINEAR) && !_on_nonlinear_residual)
      58          68 :     vec_node.append_attribute("linear_iteration") = _linear_iter;
      59         208 :   if (_execute_enum.isValueSet(EXEC_NONLINEAR))
      60         112 :     vec_node.append_attribute("nonlinear_iteration") = _nonlinear_iter;
      61             : 
      62             :   // The VPP objects to be output
      63         208 :   const std::set<std::string> & out = getVectorPostprocessorOutput();
      64             : 
      65             :   // Loop through Reporter values and search for VPP objects that should be output
      66         960 :   for (const auto & r_name : _reporter_data.getReporterNames())
      67             :   {
      68         752 :     const std::string & vpp_name = r_name.getObjectName();
      69         752 :     const std::string & vec_name = r_name.getValueName();
      70         752 :     const bool vpp_out = out.find(vpp_name) != out.end();
      71         752 :     if (vpp_out && (_reporter_data.hasReporterValue<VectorPostprocessorValue>(r_name)))
      72             :     {
      73             :       const VectorPostprocessor & vpp_obj =
      74         752 :           _problem_ptr->getVectorPostprocessorObjectByName(vpp_name);
      75         752 :       auto distributed = vpp_obj.isDistributed();
      76         752 :       if (processor_id() == 0 || distributed)
      77             :       {
      78             :         // Create a Vector node and associated operators
      79         476 :         auto data_node = vec_node.append_child("Vector");
      80         476 :         data_node.append_attribute("object") = vpp_name.c_str();
      81         476 :         data_node.append_attribute("name") = vec_name.c_str();
      82         476 :         data_node.append_attribute("distributed") = distributed;
      83         476 :         if (distributed)
      84             :         {
      85          48 :           data_node.append_attribute("processor_id") = processor_id();
      86          48 :           data_node.append_attribute("n_processors") = n_processors();
      87          48 :           _distributed = true;
      88             :         }
      89             : 
      90             :         // Write the vector of data
      91         476 :         const auto & vector = _reporter_data.getReporterValue<VectorPostprocessorValue>(r_name);
      92         476 :         std::ostringstream oss;
      93         476 :         std::copy(vector.begin(), vector.end(), infix_ostream_iterator<Real>(oss, " "));
      94         476 :         data_node.text().set(oss.str().c_str());
      95         476 :       }
      96             :     }
      97         208 :   }
      98         208 : }
      99             : 
     100             : void
     101         208 : XMLOutput::output()
     102             : {
     103         208 :   AdvancedOutput::output();
     104         208 :   if (processor_id() == 0 || _distributed)
     105         140 :     _xml_doc.save_file(filename().c_str());
     106         208 : }

Generated by: LCOV version 1.14