libMesh::MemorySolutionHistory Class Reference

Stores past solutions in memory. More...

#include <memory_solution_history.h>

Inheritance diagram for libMesh::MemorySolutionHistory:

Public Types

typedef std::map< std::string, std::unique_ptr< NumericVector< Number > > > map_type
 
typedef std::list< std::pair< Real, map_type > > list_type
 
typedef list_type::iterator stored_solutions_iterator
 

Public Member Functions

 MemorySolutionHistory (System &system_)
 
 ~MemorySolutionHistory ()
 
virtual void store () libmesh_override
 
virtual void retrieve () libmesh_override
 
virtual std::unique_ptr< 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

list_type 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 42 of file memory_solution_history.h.

Member Typedef Documentation

typedef std::list<std::pair<Real, map_type> > libMesh::MemorySolutionHistory::list_type

Definition at line 73 of file memory_solution_history.h.

typedef std::map<std::string, std::unique_ptr<NumericVector<Number> > > libMesh::MemorySolutionHistory::map_type

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

Definition at line 72 of file memory_solution_history.h.

Definition at line 74 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 50 of file memory_solution_history.h.

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

50  : stored_sols(stored_solutions.end()), _system(system_)
51  { libmesh_experimental(); }
stored_solutions_iterator stored_sols
libMesh::MemorySolutionHistory::~MemorySolutionHistory ( )

Destructor

Definition at line 26 of file memory_solution_history.C.

Referenced by MemorySolutionHistory().

27 {
28 }

Member Function Documentation

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

Definition of the clone function needed for the setter function

Implements libMesh::SolutionHistory.

Definition at line 79 of file memory_solution_history.h.

References _system.

80  {
81  return libmesh_make_unique<MemorySolutionHistory>(_system);
82  }
void libMesh::MemorySolutionHistory::find_stored_entry ( )
private

Definition at line 32 of file memory_solution_history.C.

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

Referenced by retrieve(), and store().

33 {
34  if (stored_solutions.begin() == stored_solutions.end())
35  return;
36 
37  libmesh_assert (stored_sols != stored_solutions.end());
38 
39  if (std::abs(stored_sols->first - _system.time) < TOLERANCE)
40  return;
41 
42  // If we're not at the front, check the previous entry
43  if (stored_sols != stored_solutions.begin())
44  {
46  if (std::abs((--test_it)->first - _system.time) < TOLERANCE)
47  {
48  --stored_sols;
49  return;
50  }
51  }
52 
53  // If we're not at the end, check the subsequent entry
55  if ((++test_it) != stored_solutions.end())
56  {
57  if (std::abs(test_it->first - _system.time) < TOLERANCE)
58  {
59  ++stored_sols;
60  return;
61  }
62  }
63 }
double abs(double a)
static const Real TOLERANCE
stored_solutions_iterator stored_sols
list_type::iterator stored_solutions_iterator
void libMesh::MemorySolutionHistory::retrieve ( )
virtual

Virtual function retrieve which we will be overriding to retrieve timesteps

Implements libMesh::SolutionHistory.

Definition at line 129 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().

130 {
131  this->find_stored_entry();
132 
133  // Get the time at which we are recovering the solution vectors
134  Real recovery_time = stored_sols->first;
135 
136  // Print out what time we are recovering vectors at
137  // libMesh::out << "Recovering solution vectors at time: " <<
138  // recovery_time << std::endl;
139 
140  // Do we not have a solution for this time? Then
141  // there's nothing to do.
142  if (stored_sols == stored_solutions.end() ||
143  std::abs(recovery_time - _system.time) > TOLERANCE)
144  {
145  //libMesh::out << "No more solutions to recover ! We are at time t = " <<
146  // _system.time << std::endl;
147  return;
148  }
149 
150  // Get the saved vectors at this timestep
151  map_type & saved_vectors = stored_sols->second;
152 
153  map_type::iterator vec = saved_vectors.begin();
154  map_type::iterator vec_end = saved_vectors.end();
155 
156  // Loop over all the saved vectors
157  for (; vec != vec_end; ++vec)
158  {
159  // The name of this vector
160  const std::string & vec_name = vec->first;
161 
162  // Get the vec_name entry in the saved vectors map and set the
163  // current system vec[vec_name] entry to it
164  if (vec_name != "_solution")
165  _system.get_vector(vec_name) = *(vec->second);
166  }
167 
168  // Of course, we will *always* have to get the actual solution
169  std::string _solution("_solution");
170  *(_system.solution) = *(saved_vectors[_solution]);
171 }
double abs(double a)
static const Real TOLERANCE
stored_solutions_iterator stored_sols
std::unique_ptr< NumericVector< Number > > solution
Definition: system.h:1509
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:775
std::map< std::string, std::unique_ptr< NumericVector< Number > > > map_type
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 67 of file memory_solution_history.C.

References _system, std::abs(), find_stored_entry(), 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().

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

Member Data Documentation

System& libMesh::MemorySolutionHistory::_system
private

Definition at line 97 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 91 of file memory_solution_history.h.

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

list_type libMesh::MemorySolutionHistory::stored_solutions
private

Definition at line 88 of file memory_solution_history.h.

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


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