libMesh
memory_history_data.C
Go to the documentation of this file.
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 #include "libmesh/memory_history_data.h"
19 
20 namespace libMesh
21 {
23  {
24  // The initial data should only be stored once.
26 
27  time_stamp = 0;
28 
29  deltat_at = std::numeric_limits<double>::signaling_NaN();
30 
31  store_vectors();
32 
33  previously_stored = true;
34  }
35 
37  {
38  stored_data_iterator stored_datum_last = stored_datum;
39  stored_datum_last--;
40 
41  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  deltat_at = std::numeric_limits<double>::signaling_NaN();
45 
46  (stored_datum_last->second)->set_deltat_at(_system.time_solver->TimeSolver::last_completed_timestep_size());
47 
48  store_vectors();
49 
50  previously_stored = true;
51  }
52 
54  {
55  libmesh_error_msg("For MemorySolutionHistory, primal and adjoints are stored in the same container.");
56  }
57 
59  {
60  // We are rewriting.
62 
63  store_vectors();
64  }
65 
67  {
69  }
70 
72  {
74  }
75 
77  {
78  // Now save all the preserved vectors in stored_datum
79  // Loop over all the system vectors
81  vec_end = _system.vectors_end(); vec != vec_end; ++vec)
82  {
83  // The name of this vector
84  const std::string & vec_name = vec->first;
85 
86  // Store the vector if it is to be preserved
87  if (_system.vector_preservation(vec_name))
88  {
89  stored_vecs[vec_name] = vec->second->clone();
90  }
91  }
92 
93  // Of course, we will usually save the actual solution
94  std::string _solution("_solution");
96  {
97  stored_vecs[_solution] = _system.solution->clone();
98  }
99  }
100 
102  {
103  // We are reading, hopefully something has been written before
105 
106  map_type::iterator vec = stored_vecs.begin();
107  map_type::iterator vec_end = stored_vecs.end();
108 
109  // Loop over all the saved vectors
110  for (; vec != vec_end; ++vec)
111  {
112  // The name of this vector
113  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  if (vec_name != "_solution")
118  _system.get_vector(vec_name) = *(vec->second);
119  }
120 
121  std::string _solution("_solution");
122  *(_system.solution) = *(stored_vecs[_solution]);
123 
124  }
125 }
std::map< std::string, std::unique_ptr< NumericVector< Number > >, std::less<> >::iterator vectors_iterator
Vector iterator typedefs.
Definition: system.h:757
vectors_iterator vectors_end()
End of vectors container.
Definition: system.h:2576
virtual void store_adjoint_solution() override
virtual void retrieve_adjoint_solution() override
unsigned int time_stamp
Definition: history_data.h:73
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:253
virtual void retrieve_primal_solution() override
The libMesh namespace provides an interface to certain functionality in the library.
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2564
unsigned int get_time_stamp()
Definition: history_data.h:33
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1593
libmesh_assert(ctx)
DifferentiableSystem & _system
bool & project_solution_on_reinit(void)
Tells the System whether or not to project the solution vector onto new grids when the system is rein...
Definition: system.h:838
void set_deltat_at(Real deltat_at_val)
Definition: history_data.h:46
virtual void rewrite_stored_solution() override
map_type::iterator stored_data_iterator
Definition: history_data.h:55
bool vector_preservation(std::string_view vec_name) const
Definition: system.C:1148
virtual void store_primal_solution(stored_data_iterator stored_datum) override
const NumericVector< Number > & get_vector(std::string_view vec_name) const
Definition: system.C:943
virtual void store_initial_solution() override