Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2026 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 : #include "libmesh/memory_history_data.h" 19 : 20 : namespace libMesh 21 : { 22 48 : void MemoryHistoryData::store_initial_solution() 23 : { 24 : // The initial data should only be stored once. 25 16 : libmesh_assert(previously_stored == false); 26 : 27 48 : time_stamp = 0; 28 : 29 48 : deltat_at = std::numeric_limits<double>::signaling_NaN(); 30 : 31 48 : store_vectors(); 32 : 33 48 : previously_stored = true; 34 48 : } 35 : 36 684 : void MemoryHistoryData::store_primal_solution(stored_data_iterator stored_datum) 37 : { 38 684 : stored_data_iterator stored_datum_last = stored_datum; 39 228 : stored_datum_last--; 40 : 41 684 : time_stamp = (stored_datum_last->second)->get_time_stamp() + 1; 42 : 43 : // For the current time instant, we dont know yet what timestep the solver might decide, so a placeholder NaN for now. 44 684 : deltat_at = std::numeric_limits<double>::signaling_NaN(); 45 : 46 912 : (stored_datum_last->second)->set_deltat_at(_system.time_solver->TimeSolver::last_completed_timestep_size()); 47 : 48 684 : store_vectors(); 49 : 50 684 : previously_stored = true; 51 684 : } 52 : 53 0 : void MemoryHistoryData::store_adjoint_solution() 54 : { 55 0 : libmesh_error_msg("For MemorySolutionHistory, primal and adjoints are stored in the same container."); 56 : } 57 : 58 732 : void MemoryHistoryData::rewrite_stored_solution() 59 : { 60 : // We are rewriting. 61 244 : libmesh_assert(previously_stored == true); 62 : 63 732 : store_vectors(); 64 732 : } 65 : 66 1992 : void MemoryHistoryData::retrieve_primal_solution() 67 : { 68 1992 : retrieve_vectors(); 69 1992 : } 70 : 71 0 : void MemoryHistoryData::retrieve_adjoint_solution() 72 : { 73 0 : retrieve_vectors(); 74 0 : } 75 : 76 1464 : void MemoryHistoryData::store_vectors() 77 : { 78 : // Now save all the preserved vectors in stored_datum 79 : // Loop over all the system vectors 80 5056 : for (System::vectors_iterator vec = _system.vectors_begin(), 81 15832 : vec_end = _system.vectors_end(); vec != vec_end; ++vec) 82 : { 83 : // The name of this vector 84 10776 : const std::string & vec_name = vec->first; 85 : 86 : // Store the vector if it is to be preserved 87 14368 : if (_system.vector_preservation(vec_name)) 88 : { 89 6800 : stored_vecs[vec_name] = vec->second->clone(); 90 : } 91 : } 92 : 93 : // Of course, we will usually save the actual solution 94 1952 : std::string _solution("_solution"); 95 1464 : if (_system.project_solution_on_reinit()) 96 : { 97 2440 : stored_vecs[_solution] = _system.solution->clone(); 98 : } 99 1464 : } 100 : 101 1992 : void MemoryHistoryData::retrieve_vectors() 102 : { 103 : // We are reading, hopefully something has been written before 104 664 : libmesh_assert(previously_stored == true); 105 : 106 664 : map_type::iterator vec = stored_vecs.begin(); 107 664 : map_type::iterator vec_end = stored_vecs.end(); 108 : 109 : // Loop over all the saved vectors 110 8592 : for (; vec != vec_end; ++vec) 111 : { 112 : // The name of this vector 113 6600 : const std::string & vec_name = vec->first; 114 : 115 : // Get the vec_name entry in the saved vectors map and set the 116 : // current system vec[vec_name] entry to it 117 6600 : if (vec_name != "_solution") 118 6144 : _system.get_vector(vec_name) = *(vec->second); 119 : } 120 : 121 2656 : std::string _solution("_solution"); 122 2656 : *(_system.solution) = *(stored_vecs[_solution]); 123 : 124 1992 : } 125 : }