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 14411 : XMLOutput::validParams() 19 : { 20 14411 : InputParameters params = AdvancedOutput::validParams(); 21 14411 : params.addClassDescription("Output for VectorPostprocessor using XML format."); 22 14411 : params += AdvancedOutput::enableOutputTypes("vector_postprocessor"); 23 14411 : return params; 24 0 : } 25 : 26 73 : XMLOutput::XMLOutput(const InputParameters & parameters) : AdvancedOutput(parameters) 27 : { 28 : // Creates section in VPP 29 73 : _xml_doc.append_child("VectorPostprocessors"); 30 73 : } 31 : 32 : std::string 33 233 : XMLOutput::filename() 34 : { 35 233 : if (processor_id() > 0) 36 : { 37 79 : std::ostringstream file_name; 38 79 : int digits = MooseUtils::numDigits(n_processors()); 39 79 : file_name << _file_base << ".xml" 40 79 : << "." << std::setw(digits) << std::setfill('0') << processor_id(); 41 79 : return file_name.str(); 42 79 : } 43 154 : return _file_base + ".xml"; 44 : } 45 : 46 : void 47 232 : XMLOutput::outputVectorPostprocessors() 48 : { 49 : // Create pugi node for storing vector data 50 232 : auto vpp_node = _xml_doc.child("VectorPostprocessors"); 51 232 : 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 232 : vec_node.append_attribute("time") = _problem_ptr->time(); 56 232 : vec_node.append_attribute("timestep") = _problem_ptr->timeStep(); 57 232 : if (_execute_enum.isValueSet(EXEC_LINEAR) && !_on_nonlinear_residual) 58 74 : vec_node.append_attribute("linear_iteration") = _linear_iter; 59 232 : if (_execute_enum.isValueSet(EXEC_NONLINEAR)) 60 124 : vec_node.append_attribute("nonlinear_iteration") = _nonlinear_iter; 61 : 62 : // The VPP objects to be output 63 232 : const std::set<std::string> & out = getVectorPostprocessorOutput(); 64 : 65 : // Loop through Reporter values and search for VPP objects that should be output 66 1068 : for (const auto & r_name : _reporter_data.getReporterNames()) 67 : { 68 836 : const std::string & vpp_name = r_name.getObjectName(); 69 836 : const std::string & vec_name = r_name.getValueName(); 70 836 : const bool vpp_out = out.find(vpp_name) != out.end(); 71 836 : if (vpp_out && (_reporter_data.hasReporterValue<VectorPostprocessorValue>(r_name))) 72 : { 73 : const VectorPostprocessor & vpp_obj = 74 836 : _problem_ptr->getVectorPostprocessorObjectByName(vpp_name); 75 836 : auto distributed = vpp_obj.isDistributed(); 76 836 : if (processor_id() == 0 || distributed) 77 : { 78 : // Create a Vector node and associated operators 79 548 : auto data_node = vec_node.append_child("Vector"); 80 548 : data_node.append_attribute("object") = vpp_name.c_str(); 81 548 : data_node.append_attribute("name") = vec_name.c_str(); 82 548 : data_node.append_attribute("distributed") = distributed; 83 548 : if (distributed) 84 : { 85 54 : data_node.append_attribute("processor_id") = processor_id(); 86 54 : data_node.append_attribute("n_processors") = n_processors(); 87 54 : _distributed = true; 88 : } 89 : 90 : // Write the vector of data 91 548 : const auto & vector = _reporter_data.getReporterValue<VectorPostprocessorValue>(r_name); 92 548 : std::ostringstream oss; 93 548 : std::copy(vector.begin(), vector.end(), infix_ostream_iterator<Real>(oss, " ")); 94 548 : data_node.text().set(oss.str().c_str()); 95 548 : } 96 : } 97 232 : } 98 232 : } 99 : 100 : void 101 232 : XMLOutput::output() 102 : { 103 232 : AdvancedOutput::output(); 104 232 : if (processor_id() == 0 || _distributed) 105 160 : _xml_doc.save_file(filename().c_str()); 106 232 : }