www.mooseframework.org
ConsoleUtils.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
16 #include "ConsoleUtils.h"
17 
18 #include "AuxiliarySystem.h"
19 #include "Conversion.h"
20 #include "Executioner.h"
21 #include "FEProblem.h"
22 #include "MooseApp.h"
23 #include "MooseMesh.h"
24 #include "NonlinearSystem.h"
25 #include "OutputWarehouse.h"
26 #include "SystemInfo.h"
27 
28 #include "libmesh/string_to_enum.h"
29 
30 namespace ConsoleUtils
31 {
32 
33 std::string
34 indent(unsigned int spaces)
35 {
36  return std::string(spaces, ' ');
37 }
38 
39 std::string
41 {
42  std::stringstream oss;
43  oss << std::left;
44 
45  if (app.getSystemInfo() != NULL)
46  oss << app.getSystemInfo()->getInfo();
47 
48  oss << std::left << "Parallelism:\n"
49  << std::setw(console_field_width)
50  << " Num Processors: " << static_cast<std::size_t>(app.n_processors()) << '\n'
51  << std::setw(console_field_width)
52  << " Num Threads: " << static_cast<std::size_t>(libMesh::n_threads()) << '\n'
53  << '\n';
54 
55  return oss.str();
56 }
57 
58 std::string
59 outputMeshInformation(FEProblemBase & problem, bool verbose)
60 {
61  std::stringstream oss;
62  oss << std::left;
63 
64  MooseMesh & moose_mesh = problem.mesh();
65  MeshBase & mesh = moose_mesh.getMesh();
66 
67  if (verbose)
68  {
69  oss << "Mesh: " << '\n'
70  << std::setw(console_field_width)
71  << " Parallel Type: " << (moose_mesh.isDistributedMesh() ? "distributed" : "replicated")
72  << (moose_mesh.isParallelTypeForced() ? " (forced) " : "") << '\n'
73  << std::setw(console_field_width) << " Mesh Dimension: " << mesh.mesh_dimension() << '\n'
74  << std::setw(console_field_width) << " Spatial Dimension: " << mesh.spatial_dimension()
75  << '\n';
76  }
77 
78  oss << std::setw(console_field_width) << " Nodes:" << '\n'
79  << std::setw(console_field_width) << " Total:" << mesh.n_nodes() << '\n'
80  << std::setw(console_field_width) << " Local:" << mesh.n_local_nodes() << '\n'
81  << std::setw(console_field_width) << " Elems:" << '\n'
82  << std::setw(console_field_width) << " Total:" << mesh.n_active_elem() << '\n'
83  << std::setw(console_field_width) << " Local:" << mesh.n_active_local_elem() << '\n';
84 
85  if (verbose)
86  {
87 
88  oss << std::setw(console_field_width)
89  << " Num Subdomains: " << static_cast<std::size_t>(mesh.n_subdomains()) << '\n'
90  << std::setw(console_field_width)
91  << " Num Partitions: " << static_cast<std::size_t>(mesh.n_partitions()) << '\n';
92  if (problem.n_processors() > 1)
93  oss << std::setw(console_field_width) << " Partitioner: " << moose_mesh.partitionerName()
94  << (moose_mesh.isPartitionerForced() ? " (forced) " : "") << '\n';
95  }
96 
97  oss << '\n';
98 
99  return oss.str();
100 }
101 
102 std::string
104 {
106 }
107 
108 std::string
110 {
112 }
113 
114 std::string
116 {
117  std::stringstream oss;
118  oss << std::left;
119 
120  if (system.n_dofs())
121  {
122  oss << std::setw(console_field_width) << " Num DOFs: " << system.n_dofs() << '\n'
123  << std::setw(console_field_width) << " Num Local DOFs: " << system.n_local_dofs() << '\n';
124 
125  std::streampos begin_string_pos = oss.tellp();
126  std::streampos curr_string_pos = begin_string_pos;
127  oss << std::setw(console_field_width) << " Variables: ";
128  for (unsigned int vg = 0; vg < system.n_variable_groups(); vg++)
129  {
130  const VariableGroup & vg_description(system.variable_group(vg));
131 
132  if (vg_description.n_variables() > 1)
133  oss << "{ ";
134  for (unsigned int vn = 0; vn < vg_description.n_variables(); vn++)
135  {
136  oss << "\"" << vg_description.name(vn) << "\" ";
137  curr_string_pos = oss.tellp();
138  insertNewline(oss, begin_string_pos, curr_string_pos);
139  }
140 
141  if (vg_description.n_variables() > 1)
142  oss << "} ";
143  }
144  oss << '\n';
145 
146  begin_string_pos = oss.tellp();
147  curr_string_pos = begin_string_pos;
148  oss << std::setw(console_field_width) << " Finite Element Types: ";
149 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
150  for (unsigned int vg = 0; vg < system.n_variable_groups(); vg++)
151  {
152  oss << "\"" << libMesh::Utility::enum_to_string<FEFamily>(
153  system.get_dof_map().variable_group(vg).type().family)
154  << "\" ";
155  curr_string_pos = oss.tellp();
156  insertNewline(oss, begin_string_pos, curr_string_pos);
157  }
158  oss << '\n';
159 #else
160  for (unsigned int vg = 0; vg < system.n_variable_groups(); vg++)
161  {
162  oss << "\"" << libMesh::Utility::enum_to_string<FEFamily>(
163  system.get_dof_map().variable_group(vg).type().family)
164  << "\", \"" << libMesh::Utility::enum_to_string<FEFamily>(
165  system.get_dof_map().variable_group(vg).type().radial_family)
166  << "\" ";
167  curr_string_pos = oss.tellp();
168  insertNewline(oss, begin_string_pos, curr_string_pos);
169  }
170  oss << '\n';
171 
172  begin_string_pos = oss.tellp();
173  curr_string_pos = begin_string_pos;
174  oss << std::setw(console_field_width) << " Infinite Element Mapping: ";
175  for (unsigned int vg = 0; vg < system.n_variable_groups(); vg++)
176  {
177  oss << "\"" << libMesh::Utility::enum_to_string<InfMapType>(
178  system.get_dof_map().variable_group(vg).type().inf_map)
179  << "\" ";
180  curr_string_pos = oss.tellp();
181  insertNewline(oss, begin_string_pos, curr_string_pos);
182  }
183  oss << '\n';
184 #endif
185 
186  begin_string_pos = oss.tellp();
187  curr_string_pos = begin_string_pos;
188  oss << std::setw(console_field_width) << " Approximation Orders: ";
189  for (unsigned int vg = 0; vg < system.n_variable_groups(); vg++)
190  {
191 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
192  oss << "\""
193  << Utility::enum_to_string<Order>(system.get_dof_map().variable_group(vg).type().order)
194  << "\" ";
195 #else
196  oss << "\""
197  << Utility::enum_to_string<Order>(system.get_dof_map().variable_group(vg).type().order)
198  << "\", \"" << Utility::enum_to_string<Order>(
199  system.get_dof_map().variable_group(vg).type().radial_order)
200  << "\" ";
201 #endif
202  curr_string_pos = oss.tellp();
203  insertNewline(oss, begin_string_pos, curr_string_pos);
204  }
205  oss << "\n\n";
206  }
207 
208  return oss.str();
209 }
210 
211 std::string
213 {
214 
215  std::stringstream oss;
216  oss << std::left;
217 
218  Executioner * exec = app.getExecutioner();
219 
220  oss << "Execution Information:\n"
221  << std::setw(console_field_width) << " Executioner: " << demangle(typeid(*exec).name())
222  << '\n';
223 
224  std::string time_stepper = exec->getTimeStepperName();
225  if (time_stepper != "")
226  oss << std::setw(console_field_width) << " TimeStepper: " << time_stepper << '\n';
227 
228  oss << std::setw(console_field_width)
229  << " Solver Mode: " << Moose::stringify(problem.solverParams()._type) << '\n';
230 
231  const std::string & pc_desc = problem.getPetscOptions().pc_description;
232  if (!pc_desc.empty())
233  oss << std::setw(console_field_width) << " Preconditioner: " << pc_desc << '\n';
234  oss << '\n';
235 
236  return oss.str();
237 }
238 
239 std::string
241 {
242  std::stringstream oss;
243  oss << std::left;
244 
245  const std::vector<Output *> outputs = app.getOutputWarehouse().getOutputs<Output>();
246  oss << "Outputs:\n";
247  for (const auto & out : outputs)
248  {
249  // Display the "execute_on" settings
250  const MultiMooseEnum & execute_on = out->executeOn();
251  oss << " " << std::setw(console_field_width - 2) << out->name() << "\"" << execute_on
252  << "\"\n";
253 
254  // Display the advanced "execute_on" settings, only if they are different from "execute_on"
255  if (out->isAdvanced())
256  {
257  const OutputOnWarehouse & adv_on = out->advancedExecuteOn();
258  for (const auto & adv_it : adv_on)
259  if (execute_on != adv_it.second)
260  oss << " " << std::setw(console_field_width - 4) << adv_it.first + ":"
261  << "\"" << adv_it.second << "\"\n";
262  }
263  }
264 
265  return oss.str();
266 }
267 
268 void
269 insertNewline(std::stringstream & oss, std::streampos & begin, std::streampos & curr)
270 {
271  if (curr - begin > console_line_length)
272  {
273  oss << "\n";
274  begin = oss.tellp();
275  oss << std::setw(console_field_width + 2) << ""; // "{ "
276  }
277 }
278 
279 } // ConsoleUtils namespace
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
std::string outputNonlinearSystemInformation(FEProblemBase &problem)
Output the Nonlinear system information.
Definition: ConsoleUtils.C:109
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:34
bool isParallelTypeForced() const
Tell the user if the distribution was overriden for any reason.
Definition: MooseMesh.h:742
Moose::PetscSupport::PetscOptions & getPetscOptions()
Retrieve a writable reference the PETSc options (used by PetscSupport)
virtual std::string getTimeStepperName()
The name of the TimeStepper This is an empty string for non-Transient executioners.
Definition: Executioner.C:168
SolverParams & solverParams()
Get the solver parameters.
NonlinearSystemBase & getNonlinearSystemBase()
std::string outputAuxiliarySystemInformation(FEProblemBase &problem)
Output the Auxiliary system information.
Definition: ConsoleUtils.C:103
const SystemInfo * getSystemInfo() const
Get SystemInfo object.
Definition: MooseApp.h:377
std::string outputSystemInformationHelper(const System &system)
Output system information.
Definition: ConsoleUtils.C:115
Base class for MOOSE-based applications.
Definition: MooseApp.h:58
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:240
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
static const unsigned int console_field_width
Width used for printing simulation information.
Definition: ConsoleUtils.h:35
std::string outputMeshInformation(FEProblemBase &problem, bool verbose=true)
Output the mesh information.
Definition: ConsoleUtils.C:59
Based class for output objects.
Definition: Output.h:45
static const unsigned int console_line_length
Line length for printing simulation information.
Definition: ConsoleUtils.h:38
nl system()
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
void insertNewline(std::stringstream &oss, std::streampos &begin, std::streampos &curr)
Helper function function for stringstream formatting.
Definition: ConsoleUtils.C:269
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
A helper warehouse class for storing the "execute_on" settings for the various output types...
Moose::SolveType _type
Definition: SolverParams.h:25
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:41
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:66
AuxiliarySystem & getAuxiliarySystem()
const MooseEnum & partitionerName() const
Definition: MooseMesh.h:747
std::string getInfo() const
Definition: SystemInfo.C:32
std::string outputExecutionInformation(MooseApp &app, FEProblemBase &problem)
Output execution information.
Definition: ConsoleUtils.C:212
std::string outputFrameworkInformation(MooseApp &app)
Outputs framework information.
Definition: ConsoleUtils.C:40
virtual System & system() override
Get the reference to the libMesh system.
virtual System & system() override
Get the reference to the libMesh system.
bool isPartitionerForced() const
Tell the user if the partitioner was overriden for any reason.
Definition: MooseMesh.h:752
virtual MooseMesh & mesh() override
Executioner * getExecutioner()
Retrieve the Executioner for this App.
Definition: MooseApp.h:233
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
std::string pc_description
Preconditioner description.
Definition: PetscSupport.h:56
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:841
bool isDistributedMesh() const
Returns the final Mesh distribution type.
Definition: MooseMesh.h:737