www.mooseframework.org
MaterialPropertyDebugOutput.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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
12 #include "FEProblem.h"
13 #include "MooseApp.h"
14 #include "Material.h"
15 #include "ConsoleUtils.h"
16 #include "MooseMesh.h"
17 
18 #include "libmesh/transient_system.h"
19 
21 
22 template <>
25 {
27  params.addClassDescription("Debug output object for displaying material property information.");
28 
29  // This object only outputs data once, in the constructor, so disable fine control
30  params.suppressParameter<ExecFlagEnum>("execute_on");
31 
32  return params;
33 }
34 
36  : Output(parameters)
37 {
39 }
40 
41 void
43 {
44 }
45 
46 void
48 {
49  // Build output streams for block materials and block face materials
50  std::stringstream active_block, active_face, active_neighbor, active_boundary;
51 
52  // Reference to mesh for getting boundary/block names
53  MooseMesh & mesh = _problem_ptr->mesh();
54 
55  // Reference to the Material warehouse
57 
58  // Active materials on block
59  {
60  const auto & objects = warehouse.getBlockObjects();
61  for (const auto & it : objects)
62  {
63  active_block << " Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first
64  << ")\n";
65  printMaterialProperties(active_block, it.second);
66  }
67  }
68 
69  // Active face materials on blocks
70  {
71  const auto & objects = warehouse[Moose::FACE_MATERIAL_DATA].getBlockObjects();
72  for (const auto & it : objects)
73  {
74  active_block << " Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first
75  << ")\n";
76  printMaterialProperties(active_face, it.second);
77  }
78  }
79 
80  // Active neighbor materials on blocks
81  {
82  const auto & objects = warehouse[Moose::NEIGHBOR_MATERIAL_DATA].getBlockObjects();
83  for (const auto & it : objects)
84  {
85  active_block << " Subdomain: " << mesh.getSubdomainName(it.first) << " (" << it.first
86  << ")\n";
87  printMaterialProperties(active_neighbor, it.second);
88  }
89  }
90 
91  // Active boundary materials
92  {
93  const auto & objects = warehouse.getBoundaryObjects();
94  for (const auto & it : objects)
95  {
96  active_boundary << " Boundary: " << mesh.getBoundaryName(it.first) << " (" << it.first
97  << ")\n";
98  printMaterialProperties(active_boundary, it.second);
99  }
100  }
101 
102  // Write the stored strings to the ConsoleUtils output objects
103  _console << "\n\nActive Materials:\n";
104  _console << std::setw(ConsoleUtils::console_field_width) << active_block.str() << '\n';
105 
106  _console << std::setw(ConsoleUtils::console_field_width) << "Active Face Materials:\n";
107  _console << std::setw(ConsoleUtils::console_field_width) << active_face.str() << '\n';
108 
109  _console << std::setw(ConsoleUtils::console_field_width) << "Active Neighboring Materials:\n";
110  _console << std::setw(ConsoleUtils::console_field_width) << active_neighbor.str() << '\n';
111 
112  _console << std::setw(ConsoleUtils::console_field_width) << "Active Boundary Materials:\n";
113  _console << std::setw(ConsoleUtils::console_field_width) << active_boundary.str() << '\n';
114 }
115 
116 void
118  std::stringstream & output, const std::vector<std::shared_ptr<Material>> & materials) const
119 {
120  // Loop through all material objects
121  for (const auto & mat : materials)
122  {
123  // Get a list of properties for the current material
124  const std::set<std::string> & props = mat->getSuppliedItems();
125 
126  // Adds the material name to the output stream
127  output << std::left << std::setw(ConsoleUtils::console_field_width)
128  << " Material Name: " << mat->name() << '\n';
129 
130  // Build stream for properties using the ConsoleUtils helper functions to wrap the names if
131  // there are too many for one line
132  std::streampos begin_string_pos = output.tellp();
133  std::streampos curr_string_pos = begin_string_pos;
134  output << std::left << std::setw(ConsoleUtils::console_field_width) << " Property Names: ";
135  for (const auto & prop : props)
136  {
137  output << "\"" << prop << "\" ";
138  curr_string_pos = output.tellp();
139  ConsoleUtils::insertNewline(output, begin_string_pos, curr_string_pos);
140  }
141  output << '\n';
142  }
143 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:24
const std::string & getBoundaryName(BoundaryID boundary_id)
Return the name of the boundary given the id.
Definition: MooseMesh.C:1146
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Material objects are special in that they have additional objects created automatically (see FEProble...
const MaterialWarehouse & getMaterialWarehouse() const
static const unsigned int console_field_width
Width used for printing simulation information.
Definition: ConsoleUtils.h:29
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn&#39;t required or valid in the derived class...
Based class for output objects.
Definition: Output.h:41
MaterialPropertyDebugOutput(const InputParameters &parameters)
Class constructor.
void insertNewline(std::stringstream &oss, std::streampos &begin, std::streampos &curr)
Helper function function for stringstream formatting.
Definition: ConsoleUtils.C:310
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
Definition: Output.h:167
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getBlockObjects(THREAD_ID tid=0) const
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getBoundaryObjects(THREAD_ID tid=0) const
InputParameters validParams< Output >()
Definition: Output.C:29
void printMaterialMap() const
Prints material property information in a format similar to Moose system information.
virtual void output(const ExecFlagType &type) override
Perform the debugging output For this object this is empty; the output is preformed in the constructo...
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
virtual MooseMesh & mesh() override
registerMooseObject("MooseApp", MaterialPropertyDebugOutput)
A class for producing various debug related outputs.
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...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
InputParameters validParams< MaterialPropertyDebugOutput >()
void printMaterialProperties(std::stringstream &output, const std::vector< std::shared_ptr< Material >> &materials) const
Builds a output streams for the properties in each material object.
const std::string & getSubdomainName(SubdomainID subdomain_id)
Return the name of a block given an id.
Definition: MooseMesh.C:1124