libMesh::MemorySolutionHistory Class Reference

Stores past solutions in memory. More...

#include <memory_solution_history.h>

Inheritance diagram for libMesh::MemorySolutionHistory:

Public Types

typedef std::list< std::pair< Real, std::map< std::string, NumericVector< Number > * > > >::iterator stored_solutions_iterator
 

Public Member Functions

 MemorySolutionHistory (System &system_)
 
 ~MemorySolutionHistory ()
 
virtual void store () libmesh_override
 
virtual void retrieve () libmesh_override
 
virtual UniquePtr< SolutionHistoryclone () const libmesh_override
 
void set_overwrite_previously_stored (bool val)
 

Protected Attributes

bool overwrite_previously_stored
 

Private Member Functions

void find_stored_entry ()
 

Private Attributes

std::list< std::pair< Real, std::map< std::string, NumericVector< Number > * > > > stored_solutions
 
stored_solutions_iterator stored_sols
 
System_system
 

Detailed Description

Stores past solutions in memory.

Subclass of Solution History that stores the solutions and other important vectors in memory.

Author
Vikram Garg
Date
2012

Definition at line 41 of file memory_solution_history.h.

Member Typedef Documentation

typedef std::list<std::pair<Real, std::map<std::string, NumericVector<Number> *> > >::iterator libMesh::MemorySolutionHistory::stored_solutions_iterator

Typedef for Stored Solutions iterator, a list of pairs of the current system time, map of strings and saved vectors

Definition at line 71 of file memory_solution_history.h.

Constructor & Destructor Documentation

libMesh::MemorySolutionHistory::MemorySolutionHistory ( System system_)
inline

Constructor, reference to system to be passed by user, set the stored_sols iterator to some initial value

Definition at line 49 of file memory_solution_history.h.

References retrieve(), store(), and ~MemorySolutionHistory().

Referenced by clone().

49  : stored_sols(stored_solutions.end()), _system(system_)
50  { libmesh_experimental(); }
std::list< std::pair< Real, std::map< std::string, NumericVector< Number > * > > > stored_solutions
stored_solutions_iterator stored_sols
libMesh::MemorySolutionHistory::~MemorySolutionHistory ( )

Destructor

Definition at line 26 of file memory_solution_history.C.

References stored_solutions.

Referenced by MemorySolutionHistory().

27 {
28  stored_solutions_iterator stored_sols_it = stored_solutions.begin();
29  const stored_solutions_iterator stored_sols_end = stored_solutions.end();
30 
31  for (; stored_sols_it != stored_sols_end; ++stored_sols_it)
32  {
33  // The saved vectors at this timestep
34  std::map<std::string, NumericVector<Number> *> saved_vectors = stored_sols_it->second;
35 
36  std::map<std::string, NumericVector<Number> *>::iterator vec = saved_vectors.begin();
37  std::map<std::string, NumericVector<Number> *>::iterator vec_end = saved_vectors.end();
38 
39  // Loop over all the saved vectors
40  for (; vec != vec_end; ++vec)
41  {
42  // Delete this saved vector
43  delete vec->second;
44  }
45  }
46 }
std::list< std::pair< Real, std::map< std::string, NumericVector< Number > * > > >::iterator stored_solutions_iterator
std::list< std::pair< Real, std::map< std::string, NumericVector< Number > * > > > stored_solutions

Member Function Documentation

virtual UniquePtr<SolutionHistory > libMesh::MemorySolutionHistory::clone ( ) const
inlinevirtual

Definition of the clone function needed for the setter function

Implements libMesh::SolutionHistory.

Definition at line 76 of file memory_solution_history.h.

References _system, and MemorySolutionHistory().

77  {
78  return UniquePtr<SolutionHistory >(new MemorySolutionHistory(_system));
79  }
void libMesh::MemorySolutionHistory::find_stored_entry ( )
private

Definition at line 50 of file memory_solution_history.C.

References _system, std::abs(), libMesh::libmesh_assert(), stored_sols, stored_solutions, libMesh::System::time, and libMesh::TOLERANCE.

Referenced by retrieve(), and store().

51 {
52  if (stored_solutions.begin() == stored_solutions.end())
53  return;
54 
56 
57  if (std::abs(stored_sols->first - _system.time) < TOLERANCE)
58  return;
59 
60  // If we're not at the front, check the previous entry
61  if (stored_sols != stored_solutions.begin())
62  {
64  if (std::abs((--test_it)->first - _system.time) < TOLERANCE)
65  {
66  --stored_sols;
67  return;
68  }
69  }
70 
71  // If we're not at the end, check the subsequent entry
73  if ((++test_it) != stored_solutions.end())
74  {
75  if (std::abs(test_it->first - _system.time) < TOLERANCE)
76  {
77  ++stored_sols;
78  return;
79  }
80  }
81 }
double abs(double a)
std::list< std::pair< Real, std::map< std::string, NumericVector< Number > * > > >::iterator stored_solutions_iterator
std::list< std::pair< Real, std::map< std::string, NumericVector< Number > * > > > stored_solutions
static const Real TOLERANCE
libmesh_assert(j)
stored_solutions_iterator stored_sols
void libMesh::MemorySolutionHistory::retrieve ( )
virtual

Virtual function retrieve which we will be overriding to retrieve timesteps

Implements libMesh::SolutionHistory.

Definition at line 155 of file memory_solution_history.C.

References _system, std::abs(), find_stored_entry(), libMesh::System::get_vector(), libMesh::Real, libMesh::System::solution, stored_sols, stored_solutions, libMesh::System::time, and libMesh::TOLERANCE.

Referenced by MemorySolutionHistory().

156 {
157  this->find_stored_entry();
158 
159  // Get the time at which we are recovering the solution vectors
160  Real recovery_time = stored_sols->first;
161 
162  // Print out what time we are recovering vectors at
163  // libMesh::out << "Recovering solution vectors at time: " <<
164  // recovery_time << std::endl;
165 
166  // Do we not have a solution for this time? Then
167  // there's nothing to do.
168  if (stored_sols == stored_solutions.end() ||
169  std::abs(recovery_time - _system.time) > TOLERANCE)
170  {
171  //libMesh::out << "No more solutions to recover ! We are at time t = " <<
172  // _system.time << std::endl;
173  return;
174  }
175 
176  // Get the saved vectors at this timestep
177  std::map<std::string, NumericVector<Number> *> & saved_vectors = stored_sols->second;
178 
179  std::map<std::string, NumericVector<Number> *>::iterator vec = saved_vectors.begin();
180  std::map<std::string, NumericVector<Number> *>::iterator vec_end = saved_vectors.end();
181 
182  // Loop over all the saved vectors
183  for (; vec != vec_end; ++vec)
184  {
185  // The name of this vector
186  const std::string & vec_name = vec->first;
187 
188  // Get the vec_name entry in the saved vectors map and set the
189  // current system vec[vec_name] entry to it
190  if (vec_name != "_solution")
191  _system.get_vector(vec_name) = *(vec->second);
192  }
193 
194  // Of course, we will *always* have to get the actual solution
195  std::string _solution("_solution");
196  *(_system.solution) = *(saved_vectors[_solution]);
197 }
double abs(double a)
std::list< std::pair< Real, std::map< std::string, NumericVector< Number > * > > > stored_solutions
static const Real TOLERANCE
stored_solutions_iterator stored_sols
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1521
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:792
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void libMesh::SolutionHistory::set_overwrite_previously_stored ( bool  val)
inlineinherited

Turn on overwrite_previously_stored to overwrite any already-saved data encountered during subsequent store() calls

Definition at line 70 of file solution_history.h.

References libMesh::SolutionHistory::overwrite_previously_stored.

void libMesh::MemorySolutionHistory::store ( )
virtual

Virtual function store which we will be overriding to store timesteps

Implements libMesh::SolutionHistory.

Definition at line 85 of file memory_solution_history.C.

References _system, std::abs(), find_stored_entry(), libMesh::libmesh_assert(), libMesh::SolutionHistory::overwrite_previously_stored, libMesh::System::project_solution_on_reinit(), libMesh::System::solution, stored_sols, stored_solutions, libMesh::System::time, libMesh::TOLERANCE, libMesh::System::vector_preservation(), libMesh::System::vectors_begin(), and libMesh::System::vectors_end().

Referenced by MemorySolutionHistory().

86 {
87  this->find_stored_entry();
88 
89  // In an empty history we create the first entry
90  if (stored_solutions.begin() == stored_solutions.end())
91  {
92  stored_solutions.push_back
93  (std::make_pair(_system.time,
94  std::map<std::string, NumericVector<Number> *>()));
95  stored_sols = stored_solutions.begin();
96  }
97 
98  // If we're past the end we can create a new entry
99  if (_system.time - stored_sols->first > TOLERANCE )
100  {
101 #ifndef NDEBUG
102  ++stored_sols;
104 #endif
105  stored_solutions.push_back
106  (std::make_pair(_system.time,
107  std::map<std::string, NumericVector<Number> *>()));
109  --stored_sols;
110  }
111 
112  // If we're before the beginning we can create a new entry
113  else if (stored_sols->first - _system.time > TOLERANCE)
114  {
116  stored_solutions.push_front
117  (std::make_pair(_system.time,
118  std::map<std::string, NumericVector<Number> *>()));
119  stored_sols = stored_solutions.begin();
120  }
121 
122  // We don't support inserting entries elsewhere
124 
125  // Map of stored vectors for this solution step
126  std::map<std::string, NumericVector<Number> *> & saved_vectors = stored_sols->second;
127 
128  // Loop over all the system vectors
129  for (System::vectors_iterator vec = _system.vectors_begin(); vec != _system.vectors_end(); ++vec)
130  {
131  // The name of this vector
132  const std::string & vec_name = vec->first;
133 
134  // If we haven't seen this vector before or if we have and
135  // want to overwrite it
137  !saved_vectors.count(vec_name)) &&
138  // and if we think it's worth preserving
139  _system.vector_preservation(vec_name))
140  {
141  // Then we save it.
142  saved_vectors[vec_name] = vec->second->clone().release();
143  }
144  }
145 
146  // Of course, we will usually save the actual solution
147  std::string _solution("_solution");
149  !saved_vectors.count(_solution)) &&
150  // and if we think it's worth preserving
152  saved_vectors[_solution] = _system.solution->clone().release();
153 }
vectors_iterator vectors_end()
Definition: system.h:2236
double abs(double a)
std::list< std::pair< Real, std::map< std::string, NumericVector< Number > * > > > stored_solutions
bool vector_preservation(const std::string &vec_name) const
Definition: system.C:893
static const Real TOLERANCE
vectors_iterator vectors_begin()
Definition: system.h:2224
libmesh_assert(j)
stored_solutions_iterator stored_sols
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1521
std::map< std::string, NumericVector< Number > * >::iterator vectors_iterator
Definition: system.h:748
bool & project_solution_on_reinit(void)
Definition: system.h:794

Member Data Documentation

System& libMesh::MemorySolutionHistory::_system
private

Definition at line 94 of file memory_solution_history.h.

Referenced by clone(), find_stored_entry(), retrieve(), and store().

bool libMesh::SolutionHistory::overwrite_previously_stored
protectedinherited
stored_solutions_iterator libMesh::MemorySolutionHistory::stored_sols
private

Definition at line 88 of file memory_solution_history.h.

Referenced by find_stored_entry(), retrieve(), and store().

std::list<std::pair<Real, std::map<std::string, NumericVector<Number> *> > > libMesh::MemorySolutionHistory::stored_solutions
private

The documentation for this class was generated from the following files: