Line data Source code
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 "GeneralReporter.h" 14 : 15 : /** 16 : * Times objects are under the hood Reporters, but limited to a vector of Real 17 : */ 18 : class Times : public GeneralReporter 19 : { 20 : public: 21 : static InputParameters validParams(); 22 : Times(const InputParameters & parameters); 23 188 : virtual ~Times() = default; 24 : 25 : /// Getter for the full times vector 26 : const std::vector<Real> & getTimes() const; 27 : 28 : /// Getter for a set of the full times 29 359 : const std::set<Real> getUniqueTimes() const 30 : { 31 359 : return std::set<Real>(_times.begin(), _times.end()); 32 : }; 33 : 34 : /// Get the current time 35 1 : Real getCurrentTime() const { return _fe_problem.time(); } 36 : 37 : /// Getter for a single time at a known index 38 : Real getTimeAtIndex(unsigned int index) const; 39 : 40 : /// Find the previous time in the times vector for a given time 41 : /// If current_time is also in the times vector within numerical precision, will return the previous value 42 : /// If the times are not sorted or unique, this will return the time right before the first time found above the current_time 43 : Real getPreviousTime(const Real current_time) const; 44 : 45 : /// Find the next time in the times vector for a given time 46 : /// If current_time is also in the times vector within numerical precision, will return the next value 47 : /// @param current_time the time we want the next time for 48 : /// @param error_if_no_next whether to error if the current time is beyond all existing times in the vector 49 : /// or return instead the largest Real number (from std::numeric_limits) 50 : Real getNextTime(const Real current_time, const bool error_if_no_next) const; 51 : 52 : protected: 53 : /// In charge of computing / loading the times, unless all that could be done there is done 54 : /// in the constructor 55 : virtual void initialize() override = 0; 56 : 57 : /// By default, we wont execute often but "executing" will mean loading the times 58 579 : virtual void execute() override { initialize(); } 59 : 60 : /// In charge of reduction across all ranks 61 : virtual void finalize() override; 62 : 63 : /// By default, Times will not be modified very regularly 64 583 : virtual void timestepSetup() override {} 65 0 : virtual void residualSetup() override {} 66 0 : virtual void jacobianSetup() override {} 67 : 68 : /// Clear the times vector 69 : void clearTimes(); 70 : 71 : /// The vector holding the times 72 : std::vector<Real> & _times; 73 : 74 : /// Whether generation of times is distributed or not (and therefore needs a broadcast) 75 : const bool _need_broadcast; 76 : /// Whether times should be sorted, because they come from different sources for example 77 : const bool _need_sort; 78 : /// Whether duplicate times should be removed 79 : const bool _need_unique; 80 : /// Absolute tolerance for performing duplication checks to make the times vector unique 81 : const Real _unique_tol; 82 : };