LCOV - code coverage report
Current view: top level - src/outputs - MaterialPropertyDebugOutput.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 65 66 98.5 %
Date: 2026-05-29 20:35:17 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 "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        3615 : MaterialPropertyDebugOutput::validParams()
      25             : {
      26        3615 :   InputParameters params = Output::validParams();
      27        7230 :   params.addClassDescription("Debug output object for displaying material property information.");
      28        3615 :   params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;
      29        3615 :   return params;
      30           0 : }
      31             : 
      32         277 : MaterialPropertyDebugOutput::MaterialPropertyDebugOutput(const InputParameters & parameters)
      33         277 :   : Output(parameters)
      34             : {
      35         277 :   printMaterialMap();
      36         277 : }
      37             : 
      38             : void
      39         244 : MaterialPropertyDebugOutput::output()
      40             : {
      41             :   // Write out objects that consume properties
      42         244 :   std::stringstream consumed;
      43        3035 :   for (const auto & pair : _problem_ptr->getConsumedPropertyMap())
      44             :   {
      45        2791 :     consumed << "      Object: " << pair.first << "\n";
      46        8373 :     consumed << "  Properties: " << MooseUtils::join(pair.second, ", ") << "\n\n";
      47             :   }
      48             : 
      49         244 :   _console << "\n\nConsumed Material Properties:\n";
      50         244 :   _console << std::setw(ConsoleUtils::console_field_width) << consumed.str() << std::endl;
      51         244 : }
      52             : 
      53             : void
      54         277 : MaterialPropertyDebugOutput::printMaterialMap() const
      55             : {
      56             :   // Build output streams for block materials and block face materials
      57         277 :   std::stringstream active_block, active_face, active_neighbor, active_boundary;
      58             : 
      59             :   // Reference to mesh for getting boundary/block names
      60         277 :   MooseMesh & mesh = _problem_ptr->mesh();
      61             : 
      62             :   // Reference to the Material warehouse
      63         277 :   const MaterialWarehouse & warehouse = _problem_ptr->getMaterialWarehouse();
      64             : 
      65             :   // Active materials on block
      66             :   {
      67         277 :     const auto & objects = warehouse.getBlockObjects();
      68         623 :     for (const auto & it : objects)
      69             :     {
      70         346 :       active_block << "    Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first
      71         346 :                    << ")\n";
      72         346 :       printMaterialProperties(active_block, it.second);
      73             :     }
      74             :   }
      75             : 
      76             :   // Active face materials on blocks
      77             :   {
      78         277 :     const auto & objects = warehouse[Moose::FACE_MATERIAL_DATA].getBlockObjects();
      79         623 :     for (const auto & it : objects)
      80             :     {
      81         346 :       active_face << "    Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first
      82         346 :                   << ")\n";
      83         346 :       printMaterialProperties(active_face, it.second);
      84             :     }
      85             :   }
      86             : 
      87             :   // Active neighbor materials on blocks
      88             :   {
      89         277 :     const auto & objects = warehouse[Moose::NEIGHBOR_MATERIAL_DATA].getBlockObjects();
      90         623 :     for (const auto & it : objects)
      91             :     {
      92         346 :       active_neighbor << "    Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first
      93         346 :                       << ")\n";
      94         346 :       printMaterialProperties(active_neighbor, it.second);
      95             :     }
      96             :   }
      97             : 
      98             :   // Active boundary materials
      99             :   {
     100         277 :     const auto & objects = warehouse.getBoundaryObjects();
     101         343 :     for (const auto & it : objects)
     102             :     {
     103          66 :       active_boundary << "    Boundary: " << mesh.getBoundaryName(it.first) << " (" << it.first
     104          66 :                       << ")\n";
     105          66 :       printMaterialProperties(active_boundary, it.second);
     106             :     }
     107             :   }
     108             : 
     109             :   // Write the stored strings to the ConsoleUtils output objects
     110         277 :   _console << "\n\nActive Materials:\n";
     111         277 :   _console << std::setw(ConsoleUtils::console_field_width) << active_block.str() << '\n';
     112             : 
     113         277 :   _console << std::setw(ConsoleUtils::console_field_width) << "Active Face Materials:\n";
     114         277 :   _console << std::setw(ConsoleUtils::console_field_width) << active_face.str() << '\n';
     115             : 
     116         277 :   _console << std::setw(ConsoleUtils::console_field_width) << "Active Neighboring Materials:\n";
     117         277 :   _console << std::setw(ConsoleUtils::console_field_width) << active_neighbor.str() << '\n';
     118             : 
     119         277 :   _console << std::setw(ConsoleUtils::console_field_width) << "Active Boundary Materials:\n";
     120         277 :   _console << std::setw(ConsoleUtils::console_field_width) << active_boundary.str() << std::endl;
     121         277 : }
     122             : 
     123             : void
     124        1104 : MaterialPropertyDebugOutput::printMaterialProperties(
     125             :     std::stringstream & output, const std::vector<std::shared_ptr<MaterialBase>> & materials) const
     126             : {
     127             :   // Loop through all material objects
     128        3750 :   for (const auto & mat : materials)
     129             :   {
     130             :     // Get a list of properties for the current material
     131        2646 :     const std::set<std::string> & props = mat->getSuppliedItems();
     132             : 
     133             :     // Adds the material name to the output stream
     134        2646 :     output << std::left << std::setw(ConsoleUtils::console_field_width)
     135        2646 :            << "      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        2646 :     std::streampos begin_string_pos = output.tellp();
     140        2646 :     std::streampos curr_string_pos = begin_string_pos;
     141        2646 :     output << std::left << std::setw(ConsoleUtils::console_field_width) << "      Property Names: ";
     142        7467 :     for (const auto & prop : props)
     143             :     {
     144        4821 :       output << "\"" << prop << "\" ";
     145        4821 :       curr_string_pos = output.tellp();
     146        4821 :       ConsoleUtils::insertNewline(output, begin_string_pos, curr_string_pos);
     147             :     }
     148        2646 :     output << '\n';
     149             :   }
     150             : 
     151        1104 :   output << std::flush;
     152        1104 : }

Generated by: LCOV version 1.14