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 11 of file memory_solution_history.C.

References stored_solutions.

Referenced by MemorySolutionHistory().

12 {
13  stored_solutions_iterator stored_sols_it = stored_solutions.begin();
14  const stored_solutions_iterator stored_sols_end = stored_solutions.end();
15 
16  for(; stored_sols_it != stored_sols_end; ++stored_sols_it)
17  {
18  // The saved vectors at this timestep
19  std::map<std::string, NumericVector<Number> *> saved_vectors = stored_sols_it->second;
20 
21  std::map<std::string, NumericVector<Number> *>::iterator vec = saved_vectors.begin();
22  std::map<std::string, NumericVector<Number> *>::iterator vec_end = saved_vectors.end();
23 
24  // Loop over all the saved vectors
25  for (; vec != vec_end; ++vec)
26  {
27  // Delete this saved vector
28  delete vec->second;
29  }
30  }
31 }
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 35 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().

36 {
37  if (stored_solutions.begin() == stored_solutions.end())
38  return;
39 
41 
42  if (std::abs(stored_sols->first - _system.time) < TOLERANCE)
43  return;
44 
45  // If we're not at the front, check the previous entry
46  if (stored_sols != stored_solutions.begin())
47  {
49  if (std::abs((--test_it)->first - _system.time) < TOLERANCE)
50  {
51  --stored_sols;
52  return;
53  }
54  }
55 
56  // If we're not at the end, check the subsequent entry
58  if ((++test_it) != stored_solutions.end())
59  {
60  if (std::abs(test_it->first - _system.time) < TOLERANCE)
61  {
62  ++stored_sols;
63  return;
64  }
65  }
66 }
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 140 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().

141 {
142  this->find_stored_entry();
143 
144  // Get the time at which we are recovering the solution vectors
145  Real recovery_time = stored_sols->first;
146 
147  // Print out what time we are recovering vectors at
148  // libMesh::out << "Recovering solution vectors at time: " <<
149  // recovery_time << std::endl;
150 
151  // Do we not have a solution for this time? Then
152  // there's nothing to do.
153  if(stored_sols == stored_solutions.end() ||
154  std::abs(recovery_time - _system.time) > TOLERANCE)
155  {
156  //libMesh::out << "No more solutions to recover ! We are at time t = " <<
157  // _system.time << std::endl;
158  return;
159  }
160 
161  // Get the saved vectors at this timestep
162  std::map<std::string, NumericVector<Number> *> & saved_vectors = stored_sols->second;
163 
164  std::map<std::string, NumericVector<Number> *>::iterator vec = saved_vectors.begin();
165  std::map<std::string, NumericVector<Number> *>::iterator vec_end = saved_vectors.end();
166 
167  // Loop over all the saved vectors
168  for (; vec != vec_end; ++vec)
169  {
170  // The name of this vector
171  const std::string & vec_name = vec->first;
172 
173  // Get the vec_name entry in the saved vectors map and set the
174  // current system vec[vec_name] entry to it
175  if (vec_name != "_solution")
176  _system.get_vector(vec_name) = *(vec->second);
177  }
178 
179  // Of course, we will *always* have to get the actual solution
180  std::string _solution("_solution");
181  *(_system.solution) = *(saved_vectors[_solution]);
182 }
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:1512
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:788
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 70 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().

71 {
72  this->find_stored_entry();
73 
74  // In an empty history we create the first entry
75  if (stored_solutions.begin() == stored_solutions.end())
76  {
77  stored_solutions.push_back
78  (std::make_pair(_system.time,
79  std::map<std::string, NumericVector<Number> *>()));
80  stored_sols = stored_solutions.begin();
81  }
82 
83  // If we're past the end we can create a new entry
84  if (_system.time - stored_sols->first > TOLERANCE )
85  {
86 #ifndef NDEBUG
87  ++stored_sols;
89 #endif
90  stored_solutions.push_back
91  (std::make_pair(_system.time,
92  std::map<std::string, NumericVector<Number> *>()));
94  --stored_sols;
95  }
96 
97  // If we're before the beginning we can create a new entry
98  else if (stored_sols->first - _system.time > TOLERANCE)
99  {
101  stored_solutions.push_front
102  (std::make_pair(_system.time,
103  std::map<std::string, NumericVector<Number> *>()));
104  stored_sols = stored_solutions.begin();
105  }
106 
107  // We don't support inserting entries elsewhere
109 
110  // Map of stored vectors for this solution step
111  std::map<std::string, NumericVector<Number> *> & saved_vectors = stored_sols->second;
112 
113  // Loop over all the system vectors
114  for (System::vectors_iterator vec = _system.vectors_begin(); vec != _system.vectors_end(); ++vec)
115  {
116  // The name of this vector
117  const std::string & vec_name = vec->first;
118 
119  // If we haven't seen this vector before or if we have and
120  // want to overwrite it
122  !saved_vectors.count(vec_name)) &&
123  // and if we think it's worth preserving
124  _system.vector_preservation(vec_name))
125  {
126  // Then we save it.
127  saved_vectors[vec_name] = vec->second->clone().release();
128  }
129  }
130 
131  // Of course, we will usually save the actual solution
132  std::string _solution("_solution");
134  !saved_vectors.count(_solution)) &&
135  // and if we think it's worth preserving
137  saved_vectors[_solution] = _system.solution->clone().release();
138 }
vectors_iterator vectors_end()
Definition: system.h:2227
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:889
static const Real TOLERANCE
vectors_iterator vectors_begin()
Definition: system.h:2215
libmesh_assert(j)
stored_solutions_iterator stored_sols
UniquePtr< NumericVector< Number > > solution
Definition: system.h:1512
std::map< std::string, NumericVector< Number > * >::iterator vectors_iterator
Definition: system.h:747
bool & project_solution_on_reinit(void)
Definition: system.h:793

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: