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 "MaterialPropertyDebugOutput.h" 12 : #include "FEProblem.h" 13 : #include "MooseApp.h" 14 : #include "Material.h" 15 : #include "ConsoleUtils.h" 16 : #include "MooseMesh.h" 17 : #include "MooseObjectName.h" 18 : 19 : #include "libmesh/transient_system.h" 20 : 21 : registerMooseObject("MooseApp", MaterialPropertyDebugOutput); 22 : 23 : InputParameters 24 14717 : MaterialPropertyDebugOutput::validParams() 25 : { 26 14717 : InputParameters params = Output::validParams(); 27 14717 : params.addClassDescription("Debug output object for displaying material property information."); 28 14717 : params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL; 29 14717 : return params; 30 0 : } 31 : 32 226 : MaterialPropertyDebugOutput::MaterialPropertyDebugOutput(const InputParameters & parameters) 33 226 : : Output(parameters) 34 : { 35 226 : printMaterialMap(); 36 226 : } 37 : 38 : void 39 202 : MaterialPropertyDebugOutput::output() 40 : { 41 : // Write out objects that consume properties 42 202 : std::stringstream consumed; 43 2875 : for (const auto & pair : _problem_ptr->getConsumedPropertyMap()) 44 : { 45 2673 : consumed << " Object: " << pair.first << "\n"; 46 2673 : consumed << " Properties: " << MooseUtils::join(pair.second, ", ") << "\n\n"; 47 : } 48 : 49 202 : _console << "\n\nConsumed Material Properties:\n"; 50 202 : _console << std::setw(ConsoleUtils::console_field_width) << consumed.str() << std::endl; 51 202 : } 52 : 53 : void 54 226 : MaterialPropertyDebugOutput::printMaterialMap() const 55 : { 56 : // Build output streams for block materials and block face materials 57 226 : std::stringstream active_block, active_face, active_neighbor, active_boundary; 58 : 59 : // Reference to mesh for getting boundary/block names 60 226 : MooseMesh & mesh = _problem_ptr->mesh(); 61 : 62 : // Reference to the Material warehouse 63 226 : const MaterialWarehouse & warehouse = _problem_ptr->getMaterialWarehouse(); 64 : 65 : // Active materials on block 66 : { 67 226 : const auto & objects = warehouse.getBlockObjects(); 68 524 : for (const auto & it : objects) 69 : { 70 298 : active_block << " Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first 71 298 : << ")\n"; 72 298 : printMaterialProperties(active_block, it.second); 73 : } 74 : } 75 : 76 : // Active face materials on blocks 77 : { 78 226 : const auto & objects = warehouse[Moose::FACE_MATERIAL_DATA].getBlockObjects(); 79 524 : for (const auto & it : objects) 80 : { 81 298 : active_face << " Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first 82 298 : << ")\n"; 83 298 : printMaterialProperties(active_face, it.second); 84 : } 85 : } 86 : 87 : // Active neighbor materials on blocks 88 : { 89 226 : const auto & objects = warehouse[Moose::NEIGHBOR_MATERIAL_DATA].getBlockObjects(); 90 524 : for (const auto & it : objects) 91 : { 92 298 : active_neighbor << " Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first 93 298 : << ")\n"; 94 298 : printMaterialProperties(active_neighbor, it.second); 95 : } 96 : } 97 : 98 : // Active boundary materials 99 : { 100 226 : const auto & objects = warehouse.getBoundaryObjects(); 101 294 : for (const auto & it : objects) 102 : { 103 68 : active_boundary << " Boundary: " << mesh.getBoundaryName(it.first) << " (" << it.first 104 68 : << ")\n"; 105 68 : printMaterialProperties(active_boundary, it.second); 106 : } 107 : } 108 : 109 : // Write the stored strings to the ConsoleUtils output objects 110 226 : _console << "\n\nActive Materials:\n"; 111 226 : _console << std::setw(ConsoleUtils::console_field_width) << active_block.str() << '\n'; 112 : 113 226 : _console << std::setw(ConsoleUtils::console_field_width) << "Active Face Materials:\n"; 114 226 : _console << std::setw(ConsoleUtils::console_field_width) << active_face.str() << '\n'; 115 : 116 226 : _console << std::setw(ConsoleUtils::console_field_width) << "Active Neighboring Materials:\n"; 117 226 : _console << std::setw(ConsoleUtils::console_field_width) << active_neighbor.str() << '\n'; 118 : 119 226 : _console << std::setw(ConsoleUtils::console_field_width) << "Active Boundary Materials:\n"; 120 226 : _console << std::setw(ConsoleUtils::console_field_width) << active_boundary.str() << std::endl; 121 226 : } 122 : 123 : void 124 962 : MaterialPropertyDebugOutput::printMaterialProperties( 125 : std::stringstream & output, const std::vector<std::shared_ptr<MaterialBase>> & materials) const 126 : { 127 : // Loop through all material objects 128 3304 : for (const auto & mat : materials) 129 : { 130 : // Get a list of properties for the current material 131 2342 : const std::set<std::string> & props = mat->getSuppliedItems(); 132 : 133 : // Adds the material name to the output stream 134 2342 : output << std::left << std::setw(ConsoleUtils::console_field_width) 135 2342 : << " Material Name: " << mat->name() << '\n'; 136 : 137 : // Build stream for properties using the ConsoleUtils helper functions to wrap the names if 138 : // there are too many for one line 139 2342 : std::streampos begin_string_pos = output.tellp(); 140 2342 : std::streampos curr_string_pos = begin_string_pos; 141 2342 : output << std::left << std::setw(ConsoleUtils::console_field_width) << " Property Names: "; 142 6982 : for (const auto & prop : props) 143 : { 144 4640 : output << "\"" << prop << "\" "; 145 4640 : curr_string_pos = output.tellp(); 146 4640 : ConsoleUtils::insertNewline(output, begin_string_pos, curr_string_pos); 147 : } 148 2342 : output << '\n'; 149 : } 150 : 151 962 : output << std::flush; 152 962 : }