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 : // Local includes 19 : #include "libmesh/file_history_data.h" 20 : 21 : #include "libmesh/enum_xdr_mode.h" 22 : #include "libmesh/equation_systems.h" 23 : 24 : namespace libMesh 25 : { 26 280 : void FileHistoryData::store_initial_solution() 27 : { 28 : // The initial data should only be stored once. 29 8 : libmesh_assert(previously_stored == false); 30 : 31 280 : time_stamp = 0; 32 : 33 280 : primal_filename = "primal.out.xda."; 34 : 35 280 : primal_filename += std::to_string(time_stamp); 36 : 37 288 : _system.get_equation_systems().write (primal_filename, WRITE, EquationSystems::WRITE_DATA | EquationSystems::WRITE_ADDITIONAL_DATA); 38 : 39 : // We wont know the deltat taken at this timestep until the solve is completed, which is done after the store operation. 40 280 : deltat_at = std::numeric_limits<double>::signaling_NaN(); 41 : 42 280 : previously_stored = true; 43 280 : } 44 : 45 3780 : void FileHistoryData::store_primal_solution(stored_data_iterator stored_datum) 46 : { 47 : // An iterator to the datum being stored has been passed. This is taken to imply 48 : // that we are in a sequential time stepping sequence. 49 : 50 3780 : stored_data_iterator stored_datum_last = stored_datum; 51 108 : stored_datum_last--; 52 : 53 3780 : time_stamp = (stored_datum_last->second)->get_time_stamp() + 1; 54 : 55 3780 : primal_filename = "primal.out.xda."; 56 : 57 3780 : primal_filename += std::to_string(time_stamp); 58 : 59 3888 : _system.get_equation_systems().write (primal_filename, WRITE, EquationSystems::WRITE_DATA | EquationSystems::WRITE_ADDITIONAL_DATA); 60 : 61 : // We dont know the deltat that will be taken at the current timestep. 62 3780 : deltat_at = std::numeric_limits<double>::signaling_NaN(); 63 : 64 : // But we know what deltat got us to the current time. 65 3888 : (stored_datum_last->second)->set_deltat_at(_system.time_solver->TimeSolver::last_completed_timestep_size()); 66 : 67 3780 : previously_stored = true; 68 3780 : } 69 : 70 4060 : void FileHistoryData::store_adjoint_solution() 71 : { 72 4060 : adjoint_filename = "adjoint.out.xda."; 73 : 74 4060 : adjoint_filename += std::to_string(time_stamp); 75 : 76 4176 : _system.get_equation_systems().write(adjoint_filename, WRITE, EquationSystems::WRITE_DATA | EquationSystems::WRITE_ADDITIONAL_DATA); 77 4060 : } 78 : 79 0 : void FileHistoryData::rewrite_stored_solution() 80 : { 81 : // We are rewriting. 82 0 : libmesh_assert(previously_stored == true); 83 : 84 0 : _system.get_equation_systems().write(primal_filename, WRITE, EquationSystems::WRITE_DATA | EquationSystems::WRITE_ADDITIONAL_DATA); 85 0 : } 86 : 87 6020 : void FileHistoryData::retrieve_primal_solution() 88 : { 89 : // Read in the primal solution stored at the current recovery time from the disk 90 6192 : _system.get_equation_systems().read(primal_filename, READ, EquationSystems::READ_DATA | EquationSystems::READ_ADDITIONAL_DATA); 91 6020 : } 92 : 93 4060 : void FileHistoryData::retrieve_adjoint_solution() 94 : { 95 : // Read in the adjoint solution stored at the current recovery time from the disk 96 4176 : _system.get_equation_systems().read(adjoint_filename, READ, EquationSystems::READ_DATA | EquationSystems::READ_ADDITIONAL_DATA); 97 4060 : } 98 : }