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 
73 
76 
79 
81  void solutionInvalidAccumulationTimeStep(const unsigned int timestep_index);
82 
84  void computeTotalCounts();
85 
88  {
89  TimestepCounts() : timestep_index(std::numeric_limits<unsigned int>::max()) {}
91  unsigned int timestep_index;
92  unsigned int counts = 0;
93  };
94 
97  {
98  unsigned int current_counts = 0;
99  unsigned int current_timestep_counts = 0;
100  unsigned int total_counts = 0;
101  std::vector<TimestepCounts> timestep_counts;
102  };
103 
105  const std::vector<InvalidCounts> & counts() const { return _counts; }
106 
111  void print(const ConsoleStream & console) const;
112 
117  void printHistory(const ConsoleStream & console, unsigned int & timestep_interval_size) const;
118 
122  void printDebug(InvalidSolutionID _invalid_solution_id) const;
123 
127  void syncIteration();
128 
129  friend void dataStore(std::ostream &, SolutionInvalidity &, void *);
130  friend void dataLoad(std::istream &, SolutionInvalidity &, void *);
131 
132 private:
135  mutable std::mutex _invalid_mutex;
136 
137  typedef VariadicTable<std::string,
138  unsigned long int,
139  unsigned long int,
140  unsigned long int,
141  std::string>
143 
145  FullTable summaryTable() const;
146 
148 
150  TimeTable transientTable(unsigned int & time_interval) const;
151 
154 
156  std::vector<InvalidCounts> _counts;
157 
164 };
165 
166 // datastore and dataload for recover
167 void dataStore(std::ostream & stream,
168  SolutionInvalidity::TimestepCounts & timestep_counts,
169  void * context);
170 void dataLoad(std::istream & stream,
171  SolutionInvalidity::TimestepCounts & timestep_counts,
172  void * context);
173 void dataStore(std::ostream & stream, SolutionInvalidity & solution_invalidity, void * context);
174 void dataLoad(std::istream & stream, SolutionInvalidity & solution_invalidity, void * context);
void computeTotalCounts()
Compute the total number of solution invalid occurrences.
bool hasInvalidSolutionError() const
Whether or not an invalid solution was encountered that was an error.
std::vector< TimestepCounts > timestep_counts
A helper class for re-directing output streams to Console output objects form MooseObjects.
Definition: ConsoleStream.h:30
void solutionInvalidAccumulationTimeStep(const unsigned int timestep_index)
Pass the number of solution invalid occurrences from current iteration to cumulative time iteration c...
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 invalid occurrences.
void dataLoad(std::istream &stream, SolutionInvalidity::TimestepCounts &timestep_counts, void *context)
unsigned int InvalidSolutionID
Definition: MooseTypes.h:213
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 resetSolutionInvalidTimeStep()
Reset the number of solution invalid occurrences back to zero for the current time step...
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:85
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)
TimeTable transientTable(unsigned int &time_interval) const
Build a VariadicTable for solution invalidity history.
void solutionInvalidAccumulation()
Pass the number of solution invalid occurrences from current iteration to cumulative counters...
The place where all sections with solution invalid warnings will be stored.
void syncIteration()
Sync iteration counts to main processor.
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. ...
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.
void resetSolutionInvalidCurrentIteration()
Reset the number of solution invalid occurrences back to zero.
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.