Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 : 4 : // This library is free software; you can redistribute it and/or 5 : // modify it under the terms of the GNU Lesser General Public 6 : // License as published by the Free Software Foundation; either 7 : // version 2.1 of the License, or (at your option) any later version. 8 : 9 : // This library is distributed in the hope that it will be useful, 10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : // Lesser General Public License for more details. 13 : 14 : // You should have received a copy of the GNU Lesser General Public 15 : // License along with this library; if not, write to the Free Software 16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 : 18 : #ifndef LIBMESH_SOLUTION_HISTORY_H 19 : #define LIBMESH_SOLUTION_HISTORY_H 20 : 21 : // Local Includes 22 : #include "libmesh/system.h" 23 : #include "libmesh/history_data.h" 24 : 25 : namespace libMesh 26 : { 27 : 28 : /** 29 : * A SolutionHistory class that enables the storage and retrieval of 30 : * timesteps and (in the future) adaptive steps. 31 : * SolutionHistory interfaces between the time solver and HistoryData. 32 : * SolutionHistory organizes and manages the overall history record as a map, 33 : * while HistoryData manages individual I/O, memory or preprocessing operations 34 : * for the history data at a particular time. 35 : * 36 : * \author Vikram Garg 37 : * \date 2012 38 : * \brief For storing and retrieving timestep data. 39 : */ 40 : class SolutionHistory 41 : { 42 : public: 43 : 44 : /** 45 : * Constructor 46 : */ 47 8148 : SolutionHistory() : overwrite_previously_stored(false), 48 8390 : stored_datum(stored_data.end()) {} 49 : 50 : /** 51 : * Destructor 52 : */ 53 8824 : virtual ~SolutionHistory () {} 54 : 55 : /** 56 : * Function to store a solution, pure virtual 57 : */ 58 : virtual void store(bool is_adjoint_solve, Real time) = 0; 59 : 60 : /** 61 : * Function to retrieve a solution, pure virtual 62 : */ 63 : virtual void retrieve(bool is_adjoint_solve, Real time) = 0; 64 : 65 : /** 66 : * Erase stored_data entry at time 67 : */ 68 : void erase(Real time); 69 : 70 : /** 71 : * Cloning function for a std::unique_ptr, pure virtual, used in the 72 : * setter function in time_solver.C 73 : */ 74 : virtual std::unique_ptr<SolutionHistory > clone() const = 0; 75 : 76 : /** 77 : * Turn on overwrite_previously_stored to overwrite any 78 : * already-saved data encountered during subsequent store() calls 79 : */ 80 : void set_overwrite_previously_stored (bool val) 81 : { overwrite_previously_stored = val; } 82 : 83 : protected: 84 : 85 : // Flag to specify whether we want to overwrite previously stored 86 : // vectors at a given time or not 87 : bool overwrite_previously_stored; 88 : 89 : // The abstract data structure that indexes and stores history data 90 : // Any type of history, solution, mesh or any future type will use 91 : // a realization of this map to store history information. This way, 92 : // we avoid multiple histories scatterred across the code. 93 : typedef std::map<Real, std::unique_ptr<HistoryData>> map_type; 94 : map_type stored_data; 95 : typedef map_type::iterator stored_data_iterator; 96 : stored_data_iterator stored_datum; 97 : 98 : // Function to locate entries at a given time 99 : // Behaviour depends on whether we are calling this function 100 : // while storing or retrieving/erasing entries. 101 : // While storing, if no entry in our map matches our time key, 102 : // we will create a new entry in the map. If we are not storing, 103 : // not matching a given time key implies an error. 104 : void find_stored_entry(Real time, bool storing = false); 105 : 106 : }; 107 : 108 : } // end namespace libMesh 109 : 110 : #endif // LIBMESH_SOLUTION_HISTORY_H