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 230 : 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 390 : const std::set<Real> getUniqueTimes() const 30 : { 31 390 : 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 348 : bool isDynamicTimeSequence() const { return _dynamic_time_sequence; }; 53 : 54 : protected: 55 : /// In charge of computing / loading the times, unless all that could be done there is done 56 : /// in the constructor 57 : virtual void initialize() override = 0; 58 : 59 : /// By default, we wont execute often but "executing" will mean loading the times 60 776 : virtual void execute() override { initialize(); } 61 : 62 : /// In charge of reduction across all ranks 63 : virtual void finalize() override; 64 : 65 : /// By default, Times will not be modified very regularly 66 756 : virtual void timestepSetup() override {} 67 0 : virtual void residualSetup() override {} 68 0 : virtual void jacobianSetup() override {} 69 : 70 : /// Clear the times vector 71 : void clearTimes(); 72 : 73 : /// The vector holding the times 74 : std::vector<Real> & _times; 75 : 76 : /// Whether generation of times is distributed or not (and therefore needs a broadcast) 77 : const bool _need_broadcast; 78 : /// Whether times should be sorted, because they come from different sources for example 79 : const bool _need_sort; 80 : /// Whether duplicate times should be removed 81 : const bool _need_unique; 82 : /// Absolute tolerance for performing duplication checks to make the times vector unique 83 : const Real _unique_tol; 84 : 85 : /// whether the time sequence is set dynamically 86 : const bool _dynamic_time_sequence; 87 : };