https://mooseframework.inl.gov
XMLOutput.C
Go to the documentation of this file.
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 
19 {
21  params.addClassDescription("Output for VectorPostprocessor using XML format.");
22  params += AdvancedOutput::enableOutputTypes("vector_postprocessor");
23  return params;
24 }
25 
26 XMLOutput::XMLOutput(const InputParameters & parameters) : AdvancedOutput(parameters)
27 {
28  // Creates section in VPP
29  _xml_doc.append_child("VectorPostprocessors");
30 }
31 
32 std::string
34 {
35  if (processor_id() > 0)
36  {
37  std::ostringstream file_name;
38  int digits = MooseUtils::numDigits(n_processors());
39  file_name << _file_base << ".xml"
40  << "." << std::setw(digits) << std::setfill('0') << processor_id();
41  return file_name.str();
42  }
43  return _file_base + ".xml";
44 }
45 
46 void
48 {
49  // Create pugi node for storing vector data
50  auto vpp_node = _xml_doc.child("VectorPostprocessors");
51  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  vec_node.append_attribute("time") = _problem_ptr->time();
56  vec_node.append_attribute("timestep") = _problem_ptr->timeStep();
58  vec_node.append_attribute("linear_iteration") = _linear_iter;
60  vec_node.append_attribute("nonlinear_iteration") = _nonlinear_iter;
61 
62  // The VPP objects to be output
63  const std::set<std::string> & out = getVectorPostprocessorOutput();
64 
65  // Loop through Reporter values and search for VPP objects that should be output
66  for (const auto & r_name : _reporter_data.getReporterNames())
67  {
68  const std::string & vpp_name = r_name.getObjectName();
69  const std::string & vec_name = r_name.getValueName();
70  const bool vpp_out = out.find(vpp_name) != out.end();
72  {
73  const VectorPostprocessor & vpp_obj =
75  auto distributed = vpp_obj.isDistributed();
76  if (processor_id() == 0 || distributed)
77  {
78  // Create a Vector node and associated operators
79  auto data_node = vec_node.append_child("Vector");
80  data_node.append_attribute("object") = vpp_name.c_str();
81  data_node.append_attribute("name") = vec_name.c_str();
82  data_node.append_attribute("distributed") = distributed;
83  if (distributed)
84  {
85  data_node.append_attribute("processor_id") = processor_id();
86  data_node.append_attribute("n_processors") = n_processors();
87  _distributed = true;
88  }
89 
90  // Write the vector of data
91  const auto & vector = _reporter_data.getReporterValue<VectorPostprocessorValue>(r_name);
92  std::ostringstream oss;
93  std::copy(vector.begin(), vector.end(), infix_ostream_iterator<Real>(oss, " "));
94  data_node.text().set(oss.str().c_str());
95  }
96  }
97  }
98 }
99 
100 void
102 {
104  if (processor_id() == 0 || _distributed)
105  _xml_doc.save_file(filename().c_str());
106 }
virtual Real & time() const
pugi::xml_document _xml_doc
Definition: XMLOutput.h:29
bool _distributed
Definition: XMLOutput.h:31
virtual void outputVectorPostprocessors() override
Performs output of VectorPostprocessors The child class must define this method to output the VectorP...
Definition: XMLOutput.C:47
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
virtual void output()
A single call to this function should output all the necessary data for a single timestep.
bool _on_nonlinear_residual
True if current output call is on the non-linear residual (used by time())
Definition: PetscOutput.h:93
const std::set< std::string > & getVectorPostprocessorOutput()
The list of VectorPostprocessor names that are set for output.
static InputParameters validParams()
Definition: XMLOutput.C:18
processor_id_type n_processors() const
PetscInt _linear_iter
Current linear iteration returned from PETSc.
Definition: PetscOutput.h:87
virtual void output() override
A single call to this function should output all the necessary data for a single timestep.
Definition: XMLOutput.C:101
const T & getReporterValue(const ReporterName &reporter_name, const MooseObject &consumer, const ReporterMode &mode, const std::size_t time_index=0) const
Method for returning read only references to Reporter values.
Definition: ReporterData.h:388
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
Definition: Output.h:185
virtual std::string filename() override
The filename for the output file.
Definition: XMLOutput.C:33
const VectorPostprocessor & getVectorPostprocessorObjectByName(const std::string &object_name, const THREAD_ID tid=0) const
Return the VPP object given the name.
bool isValueSet(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
static InputParameters enableOutputTypes(const std::string &names=std::string())
A method for enabling individual output type control.
const ExecFlagType EXEC_LINEAR
Definition: Moose.C:29
virtual int & timeStep() const
std::set< ReporterName > getReporterNames() const
Return a list of all reporter names.
Definition: ReporterData.C:62
const ExecFlagEnum & _execute_enum
Execute settings for this object.
registerMooseObject("MooseApp", XMLOutput)
const ReporterData & _reporter_data
Storage for Reporter values.
Based class for output objects.
const ExecFlagType EXEC_NONLINEAR
Definition: Moose.C:31
std::vector< Real > VectorPostprocessorValue
Definition: MooseTypes.h:203
int numDigits(const T &num)
Return the number of digits for a number.
Definition: MooseUtils.h:948
OStreamProxy out
XMLOutput(const InputParameters &parameters)
Definition: XMLOutput.C:26
bool isDistributed() const
Return true if the VPP is operating in distributed mode.
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...
bool hasReporterValue(const ReporterName &reporter_name) const
Return True if a Reporter value with the given type and name have been created.
Definition: ReporterData.h:445
static InputParameters validParams()
processor_id_type processor_id() const
Base class for Postprocessors that produce a vector of values.
PetscInt _nonlinear_iter
Current non-linear iteration returned from PETSc.
Definition: PetscOutput.h:84