www.mooseframework.org
ConsoleUtils.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
11 #include "ConsoleUtils.h"
12 
13 #include "AuxiliarySystem.h"
14 #include "Conversion.h"
15 #include "Executioner.h"
16 #include "MoosePreconditioner.h"
17 #include "FEProblem.h"
18 #include "MooseApp.h"
19 #include "MooseMesh.h"
20 #include "NonlinearSystem.h"
21 #include "OutputWarehouse.h"
22 #include "SystemInfo.h"
23 
24 #include "libmesh/string_to_enum.h"
25 
26 namespace ConsoleUtils
27 {
28 
29 std::string
30 indent(unsigned int spaces)
31 {
32  return std::string(spaces, ' ');
33 }
34 
35 std::string
37 {
38  std::stringstream oss;
39  oss << std::left;
40 
41  if (app.getSystemInfo() != NULL)
42  oss << app.getSystemInfo()->getInfo();
43 
44  oss << std::left << "Parallelism:\n"
45  << std::setw(console_field_width)
46  << " Num Processors: " << static_cast<std::size_t>(app.n_processors()) << '\n'
47  << std::setw(console_field_width)
48  << " Num Threads: " << static_cast<std::size_t>(libMesh::n_threads()) << '\n'
49  << '\n';
50 
51  return oss.str();
52 }
53 
54 std::string
55 outputMeshInformation(FEProblemBase & problem, bool verbose)
56 {
57  std::stringstream oss;
58  oss << std::left;
59 
60  MooseMesh & moose_mesh = problem.mesh();
61  MeshBase & mesh = moose_mesh.getMesh();
62 
63  if (verbose)
64  {
65  bool forced = moose_mesh.isParallelTypeForced();
66  bool pre_split = problem.getMooseApp().isUseSplit();
67 
68  // clang-format off
69  oss << "Mesh: " << '\n'
70  << std::setw(console_field_width)
71  << " Parallel Type: " << (moose_mesh.isDistributedMesh() ? "distributed" : "replicated")
72  << (forced || pre_split ? " (" : "")
73  << (forced ? "forced" : "")
74  << (forced && pre_split ? ", " : "")
75  << (pre_split ? "pre-split" : "")
76  << (forced || pre_split ? ")" : "")
77  << '\n'
78  << std::setw(console_field_width) << " Mesh Dimension: " << mesh.mesh_dimension() << '\n'
79  << std::setw(console_field_width) << " Spatial Dimension: " << mesh.spatial_dimension()
80  << '\n';
81  // clang-format on
82  }
83 
84  oss << std::setw(console_field_width) << " Nodes:" << '\n'
85  << std::setw(console_field_width) << " Total:" << mesh.n_nodes() << '\n'
86  << std::setw(console_field_width) << " Local:" << mesh.n_local_nodes() << '\n'
87  << std::setw(console_field_width) << " Elems:" << '\n'
88  << std::setw(console_field_width) << " Total:" << mesh.n_active_elem() << '\n'
89  << std::setw(console_field_width) << " Local:" << mesh.n_active_local_elem() << '\n';
90 
91  if (verbose)
92  {
93 
94  oss << std::setw(console_field_width)
95  << " Num Subdomains: " << static_cast<std::size_t>(mesh.n_subdomains()) << '\n'
96  << std::setw(console_field_width)
97  << " Num Partitions: " << static_cast<std::size_t>(mesh.n_partitions()) << '\n';
98  if (problem.n_processors() > 1)
99  oss << std::setw(console_field_width) << " Partitioner: " << moose_mesh.partitionerName()
100  << (moose_mesh.isPartitionerForced() ? " (forced) " : "") << '\n';
101  }
102 
103  oss << '\n';
104 
105  return oss.str();
106 }
107 
108 std::string
110 {
112 }
113 
114 std::string
116 {
118 }
119 
120 std::string
122 {
123  std::stringstream oss;
124  oss << std::left;
125 
126  if (system.n_dofs())
127  {
128  oss << std::setw(console_field_width) << " Num DOFs: " << system.n_dofs() << '\n'
129  << std::setw(console_field_width) << " Num Local DOFs: " << system.n_local_dofs() << '\n';
130 
131  std::streampos begin_string_pos = oss.tellp();
132  std::streampos curr_string_pos = begin_string_pos;
133  oss << std::setw(console_field_width) << " Variables: ";
134  for (unsigned int vg = 0; vg < system.n_variable_groups(); vg++)
135  {
136  const VariableGroup & vg_description(system.variable_group(vg));
137 
138  if (vg_description.n_variables() > 1)
139  oss << "{ ";
140  for (unsigned int vn = 0; vn < vg_description.n_variables(); vn++)
141  {
142  oss << "\"" << vg_description.name(vn) << "\" ";
143  curr_string_pos = oss.tellp();
144  insertNewline(oss, begin_string_pos, curr_string_pos);
145  }
146 
147  if (vg_description.n_variables() > 1)
148  oss << "} ";
149  }
150  oss << '\n';
151 
152  begin_string_pos = oss.tellp();
153  curr_string_pos = begin_string_pos;
154  oss << std::setw(console_field_width) << " Finite Element Types: ";
155 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
156  for (unsigned int vg = 0; vg < system.n_variable_groups(); vg++)
157  {
158  oss << "\""
159  << libMesh::Utility::enum_to_string<FEFamily>(
160  system.get_dof_map().variable_group(vg).type().family)
161  << "\" ";
162  curr_string_pos = oss.tellp();
163  insertNewline(oss, begin_string_pos, curr_string_pos);
164  }
165  oss << '\n';
166 #else
167  for (unsigned int vg = 0; vg < system.n_variable_groups(); vg++)
168  {
169  oss << "\""
170  << libMesh::Utility::enum_to_string<FEFamily>(
171  system.get_dof_map().variable_group(vg).type().family)
172  << "\", \""
173  << libMesh::Utility::enum_to_string<FEFamily>(
174  system.get_dof_map().variable_group(vg).type().radial_family)
175  << "\" ";
176  curr_string_pos = oss.tellp();
177  insertNewline(oss, begin_string_pos, curr_string_pos);
178  }
179  oss << '\n';
180 
181  begin_string_pos = oss.tellp();
182  curr_string_pos = begin_string_pos;
183  oss << std::setw(console_field_width) << " Infinite Element Mapping: ";
184  for (unsigned int vg = 0; vg < system.n_variable_groups(); vg++)
185  {
186  oss << "\""
187  << libMesh::Utility::enum_to_string<InfMapType>(
188  system.get_dof_map().variable_group(vg).type().inf_map)
189  << "\" ";
190  curr_string_pos = oss.tellp();
191  insertNewline(oss, begin_string_pos, curr_string_pos);
192  }
193  oss << '\n';
194 #endif
195 
196  begin_string_pos = oss.tellp();
197  curr_string_pos = begin_string_pos;
198  oss << std::setw(console_field_width) << " Approximation Orders: ";
199  for (unsigned int vg = 0; vg < system.n_variable_groups(); vg++)
200  {
201 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
202  oss << "\""
203  << Utility::enum_to_string<Order>(system.get_dof_map().variable_group(vg).type().order)
204  << "\" ";
205 #else
206  oss << "\""
207  << Utility::enum_to_string<Order>(system.get_dof_map().variable_group(vg).type().order)
208  << "\", \""
209  << Utility::enum_to_string<Order>(
210  system.get_dof_map().variable_group(vg).type().radial_order)
211  << "\" ";
212 #endif
213  curr_string_pos = oss.tellp();
214  insertNewline(oss, begin_string_pos, curr_string_pos);
215  }
216  oss << "\n\n";
217  }
218 
219  return oss.str();
220 }
221 
222 std::string
224 {
225  std::stringstream oss;
226  oss << std::left;
227 
228  auto info_strings = app.getRelationshipManagerInfo();
229  if (info_strings.size())
230  {
231  for (const auto & info_pair : info_strings)
232  oss << std::setw(console_field_width)
233  << " " + MooseUtils::underscoreToCamelCase(MooseUtils::toLower(info_pair.first), true) +
234  ":"
235  << info_pair.second << '\n';
236  oss << '\n';
237  }
238 
239  return oss.str();
240 }
241 
242 std::string
244 {
245 
246  std::stringstream oss;
247  oss << std::left;
248 
249  Executioner * exec = app.getExecutioner();
250 
251  oss << "Execution Information:\n"
252  << std::setw(console_field_width) << " Executioner: " << demangle(typeid(*exec).name())
253  << '\n';
254 
255  std::string time_stepper = exec->getTimeStepperName();
256  if (time_stepper != "")
257  oss << std::setw(console_field_width) << " TimeStepper: " << time_stepper << '\n';
258 
259  oss << std::setw(console_field_width)
260  << " Solver Mode: " << Moose::stringify(problem.solverParams()._type) << '\n';
261 
262  const std::string & pc_desc = problem.getPetscOptions().pc_description;
263  if (!pc_desc.empty())
264  oss << std::setw(console_field_width) << " PETSc Preconditioner: " << pc_desc << '\n';
265 
267  if (mpc)
268  {
269  oss << std::setw(console_field_width)
270  << " MOOSE Preconditioner: " << mpc->getParam<std::string>("_type");
271  if (mpc->name() == "_moose_auto")
272  oss << " (auto)";
273  oss << '\n';
274  }
275  oss << '\n';
276 
277  return oss.str();
278 }
279 
280 std::string
282 {
283  std::stringstream oss;
284  oss << std::left;
285 
286  const std::vector<Output *> outputs = app.getOutputWarehouse().getOutputs<Output>();
287  oss << "Outputs:\n";
288  for (const auto & out : outputs)
289  {
290  // Display the "execute_on" settings
291  const MultiMooseEnum & execute_on = out->executeOn();
292  oss << " " << std::setw(console_field_width - 2) << out->name() << "\"" << execute_on
293  << "\"\n";
294 
295  // Display the advanced "execute_on" settings, only if they are different from "execute_on"
296  if (out->isAdvanced())
297  {
298  const OutputOnWarehouse & adv_on = out->advancedExecuteOn();
299  for (const auto & adv_it : adv_on)
300  if (execute_on != adv_it.second)
301  oss << " " << std::setw(console_field_width - 4) << adv_it.first + ":"
302  << "\"" << adv_it.second << "\"\n";
303  }
304  }
305 
306  return oss.str();
307 }
308 
309 void
310 insertNewline(std::stringstream & oss, std::streampos & begin, std::streampos & curr)
311 {
312  if (curr - begin > console_line_length)
313  {
314  oss << "\n";
315  begin = oss.tellp();
316  oss << std::setw(console_field_width + 2) << ""; // "{ "
317  }
318 }
319 
320 } // ConsoleUtils namespace
std::string outputNonlinearSystemInformation(FEProblemBase &problem)
Output the Nonlinear system information.
Definition: ConsoleUtils.C:115
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:30
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition: MooseApp.h:255
Moose::PetscSupport::PetscOptions & getPetscOptions()
Retrieve a writable reference the PETSc options (used by PetscSupport)
MoosePreconditioner const * getPreconditioner() const
std::string toLower(const std::string &name)
Convert supplied string to lower case.
Definition: MooseUtils.C:659
SolverParams & solverParams()
Get the solver parameters.
NonlinearSystemBase & getNonlinearSystemBase()
std::vector< std::pair< std::string, std::string > > getRelationshipManagerInfo() const
Returns the Relationship managers info suitable for printing.
Definition: MooseApp.C:1793
std::string outputExecutionInformation(const MooseApp &app, FEProblemBase &problem)
Output execution information.
Definition: ConsoleUtils.C:243
std::string outputAuxiliarySystemInformation(FEProblemBase &problem)
Output the Auxiliary system information.
Definition: ConsoleUtils.C:109
bool isDistributedMesh() const
Returns the final Mesh distribution type.
Definition: MooseMesh.h:784
Base class for MOOSE-based applications.
Definition: MooseApp.h:59
std::vector< T * > getOutputs(const std::vector< OutputName > &names)
Return a vector of objects by names.
std::string outputOutputInformation(MooseApp &app)
Output the output information.
Definition: ConsoleUtils.C:281
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:191
static const unsigned int console_field_width
Width used for printing simulation information.
Definition: ConsoleUtils.h:29
std::string outputSystemInformationHelper(System &system)
Output system information.
Definition: ConsoleUtils.C:121
Base class for MOOSE preconditioners.
std::string outputMeshInformation(FEProblemBase &problem, bool verbose=true)
Output the mesh information.
Definition: ConsoleUtils.C:55
Based class for output objects.
Definition: Output.h:41
static const unsigned int console_line_length
Line length for printing simulation information.
Definition: ConsoleUtils.h:32
nl system()
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
const SystemInfo * getSystemInfo() const
Get SystemInfo object.
Definition: MooseApp.h:423
void insertNewline(std::stringstream &oss, std::streampos &begin, std::streampos &curr)
Helper function function for stringstream formatting.
Definition: ConsoleUtils.C:310
bool isPartitionerForced() const
Tell the user if the partitioner was overriden for any reason.
Definition: MooseMesh.h:799
std::string getInfo() const
Definition: SystemInfo.C:26
bool isUseSplit() const
Whether or not we are running with pre-split (distributed mesh)
Definition: MooseApp.C:877
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
std::string underscoreToCamelCase(const std::string &underscore_name, bool leading_upper_case)
Function for converting an underscore name to a camel case name.
Definition: MooseUtils.C:331
A helper warehouse class for storing the "execute_on" settings for the various output types...
Moose::SolveType _type
Definition: SolverParams.h:19
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:32
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:60
std::string outputFrameworkInformation(const MooseApp &app)
Outputs framework information.
Definition: ConsoleUtils.C:36
AuxiliarySystem & getAuxiliarySystem()
virtual System & system() override
Get the reference to the libMesh system.
virtual System & system() override
Get the reference to the libMesh system.
virtual MooseMesh & mesh() override
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
bool isParallelTypeForced() const
Tell the user if the distribution was overriden for any reason.
Definition: MooseMesh.h:789
MooseApp & getMooseApp() const
Get the MooseApp this object is associated with.
Definition: MooseObject.h:94
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
virtual std::string getTimeStepperName()
The name of the TimeStepper This is an empty string for non-Transient executioners.
Definition: Executioner.h:94
const MooseEnum & partitionerName() const
Definition: MooseMesh.h:794
std::string pc_description
Preconditioner description.
Definition: PetscSupport.h:54
std::string outputRelationshipManagerInformation(const MooseApp &app)
Output action RelationshipManager information.
Definition: ConsoleUtils.C:223
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:1055