https://mooseframework.inl.gov
SolutionInvalidity.h
Go to the documentation of this file.
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 #pragma once
11 
12 // MOOSE Includes
13 #include "MooseTypes.h"
14 #include "MooseError.h"
16 #include "ConsoleStream.h"
17 #include "ConsoleStreamInterface.h"
18 
19 // System Includes
20 #include <array>
21 #include <atomic>
22 #include <thread>
23 #include <future>
24 #include <mutex>
25 
26 // libMesh Includes
27 #include "libmesh/parallel_object.h"
28 
29 // Forward Declarations
30 template <class... Ts>
31 class VariadicTable;
32 
38 {
39 public:
41 
46 
48  void flagInvalidSolutionInternal(const InvalidSolutionID _invalid_solution_id);
49 
55  bool hasInvalidSolutionWarning() const;
56 
62  bool hasInvalidSolutionError() const;
63 
69  bool hasInvalidSolution() const;
70 
76  bool hasEverHadSolutionIssue() const;
77 
80 
83 
86 
88  void accumulateTimeStepIntoTotalOccurences(const unsigned int timestep_index);
89 
92  {
93  TimestepCounts() : timestep_index(std::numeric_limits<unsigned int>::max()) {}
95  unsigned int timestep_index;
96  unsigned int counts = 0;
97  };
98 
101  {
103  unsigned int current_counts = 0;
105  unsigned int current_timestep_counts = 0;
107  unsigned int total_counts = 0;
109  std::vector<TimestepCounts> timestep_counts;
110  };
111 
113  const std::vector<InvalidCounts> & counts() const { return _counts; }
114 
119  void print(const ConsoleStream & console) const;
120 
125  void printHistory(const ConsoleStream & console, unsigned int & timestep_interval_size) const;
126 
130  void printDebug(InvalidSolutionID _invalid_solution_id) const;
131 
136  void syncIteration();
137 
139  bool hasSynced() const { return _has_synced; }
140 
141  friend void dataStore(std::ostream &, SolutionInvalidity &, void *);
142  friend void dataLoad(std::istream &, SolutionInvalidity &, void *);
143 
144 private:
147  mutable std::mutex _invalid_mutex;
148 
149  typedef VariadicTable<std::string,
150  unsigned long int,
151  unsigned long int,
152  unsigned long int,
153  std::string>
155 
157  FullTable summaryTable() const;
158 
160 
162  TimeTable transientTable(unsigned int & time_interval) const;
163 
166 
168  std::vector<InvalidCounts> _counts;
169 
178 };
179 
180 // datastore and dataload for recover
181 void dataStore(std::ostream & stream,
182  SolutionInvalidity::TimestepCounts & timestep_counts,
183  void * context);
184 void dataLoad(std::istream & stream,
185  SolutionInvalidity::TimestepCounts & timestep_counts,
186  void * context);
187 void dataStore(std::ostream & stream, SolutionInvalidity & solution_invalidity, void * context);
188 void dataLoad(std::istream & stream, SolutionInvalidity & solution_invalidity, void * context);
bool hasInvalidSolutionError() const
Whether or not an invalid solution was encountered that was an error.
std::vector< TimestepCounts > timestep_counts
Keep track of the occurences across all time steps.
bool hasEverHadSolutionIssue() const
Whether or not any warning or invalid solution has ever been encountered during the simulation...
A helper class for re-directing output streams to Console output objects form MooseObjects.
Definition: ConsoleStream.h:30
void accumulateTimeStepIntoTotalOccurences(const unsigned int timestep_index)
Pass the number of solution invalid occurrences from current timestep to cumulative timestep counter ...
bool _has_recorded_issue
Whether or not we have ever had any warning or solution issue during the simulation.
bool hasInvalidSolutionWarning() const
Whether or not an invalid solution was encountered that was a warning.
VariadicTable< std::string, unsigned long int, unsigned long int, unsigned long int, std::string > FullTable
std::mutex _invalid_mutex
Mutex for locking access to the invalid counts TODO: These can be changed to shared_mutexes.
const std::vector< InvalidCounts > & counts() const
Access the private solution invalidity counts.
Struct used in _counts for storing warning and invalid-solution occurrences.
void dataLoad(std::istream &stream, SolutionInvalidity::TimestepCounts &timestep_counts, void *context)
unsigned int InvalidSolutionID
Definition: MooseTypes.h:241
void accumulateIterationIntoTimeStepOccurences()
Pass the number of solution invalid occurrences from current iteration to cumulative counters...
std::vector< InvalidCounts > _counts
Store the solution invalidity counts.
SolutionInvalidity(MooseApp &app)
Create a new SolutionInvalidity.
void dataStore(std::ostream &stream, SolutionInvalidity::TimestepCounts &timestep_counts, void *context)
friend void dataLoad(std::istream &, SolutionInvalidity &, void *)
bool _has_synced
Whether or not we&#39;ve synced (can check counts/existance of warnings or errors)
A class for "pretty printing" a table of data.
Definition: PerfGraph.h:34
void printDebug(InvalidSolutionID _invalid_solution_id) const
Immediately print the section and message for debug purpose.
Base class for MOOSE-based applications.
Definition: MooseApp.h:108
SolutionInvalidityRegistry & _solution_invalidity_registry
Create a registry to keep track of the names and occurrences of the solution invalidity.
friend void dataStore(std::ostream &, SolutionInvalidity &, void *)
auto max(const L &left, const R &right)
void resetIterationOccurences()
Reset the number of solution invalid occurrences back to zero.
TimeTable transientTable(unsigned int &time_interval) const
Build a VariadicTable for solution invalidity history.
unsigned int total_counts
Total counts across the entire simulation.
The place where all sections with solution invalid warnings will be stored.
void syncIteration()
Sync iteration counts to main processor Sum across all processors.
bool _has_solution_warning
Whether or not we have a warning (only after a sync)
An inteface for the _console for outputting to the Console object.
bool hasInvalidSolution() const
Whether or not any invalid solution was encountered (error or warning).
void flagInvalidSolutionInternal(const InvalidSolutionID _invalid_solution_id)
Increments solution invalid occurrences for each solution id.
bool _has_solution_error
Whether or not we have an invalid solution (only after a sync)
The SolutionInvalidity will contain all the information about the occurrence(s) of solution invalidit...
Struct used in InvalidCounts for storing the time history of invalid occurrences. ...
bool hasSynced() const
Whether the solution invalidity has synchronized iteration counts across MPI processes.
unsigned int current_timestep_counts
Counts for the current time step.
TimestepCounts(unsigned int timestep_index)
VariadicTable< std::string, std::string, unsigned long int, unsigned long int > TimeTable
void print(const ConsoleStream &console) const
Print the summary table of Solution Invalid warnings.
unsigned int current_counts
Counts for the current iteration (depends on the count, but usually linear iteration) ...
void resetTimeStepOccurences()
Reset the number of solution invalid occurrences back to zero for the current time step...
void printHistory(const ConsoleStream &console, unsigned int &timestep_interval_size) const
Print the time history table of Solution Invalid warnings.
void ErrorVector unsigned int
FullTable summaryTable() const
Build a VariadicTable for solution invalidity.