libMesh
Public Types | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
libMesh::MemorySolutionHistory Class Reference

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

#include <memory_solution_history.h>

Inheritance diagram for libMesh::MemorySolutionHistory:
[legend]

Public Types

typedef std::map< std::string, std::unique_ptr< NumericVector< Number > > > map_type
 Typedef for Stored Solutions iterator, a list of pairs of the current system time, map of strings and saved vectors. More...
 
typedef std::list< std::pair< Real, map_type > > list_type
 
typedef list_type::iterator stored_solutions_iterator
 

Public Member Functions

 MemorySolutionHistory (System &system_)
 Constructor, reference to system to be passed by user, set the stored_sols iterator to some initial value. More...
 
 ~MemorySolutionHistory ()
 Destructor. More...
 
virtual void store () override
 Virtual function store which we will be overriding to store timesteps. More...
 
virtual void retrieve () override
 Virtual function retrieve which we will be overriding to retrieve timesteps. More...
 
virtual std::unique_ptr< SolutionHistoryclone () const override
 Definition of the clone function needed for the setter function. More...
 
void set_overwrite_previously_stored (bool val)
 Turn on overwrite_previously_stored to overwrite any already-saved data encountered during subsequent store() calls. More...
 

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

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

Author
Vikram Garg
Date
2012

Stores past solutions in memory.

Definition at line 42 of file memory_solution_history.h.

Member Typedef Documentation

◆ list_type

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

Definition at line 73 of file memory_solution_history.h.

◆ map_type

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.

◆ stored_solutions_iterator

Definition at line 74 of file memory_solution_history.h.

Constructor & Destructor Documentation

◆ MemorySolutionHistory()

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.

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

◆ ~MemorySolutionHistory()

libMesh::MemorySolutionHistory::~MemorySolutionHistory ( )

Destructor.

Definition at line 26 of file memory_solution_history.C.

27 {
28 }

Member Function Documentation

◆ clone()

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

Definition of the clone function needed for the setter function.

Implements libMesh::SolutionHistory.

Definition at line 79 of file memory_solution_history.h.

80  {
81  return libmesh_make_unique<MemorySolutionHistory>(_system);
82  }

References _system.

◆ find_stored_entry()

void libMesh::MemorySolutionHistory::find_stored_entry ( )
private

Definition at line 32 of file memory_solution_history.C.

33 {
34  if (stored_solutions.begin() == stored_solutions.end())
35  return;
36 
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 }

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

Referenced by retrieve(), and store().

◆ retrieve()

void libMesh::MemorySolutionHistory::retrieve ( )
overridevirtual

Virtual function retrieve which we will be overriding to retrieve timesteps.

Implements libMesh::SolutionHistory.

Definition at line 131 of file memory_solution_history.C.

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

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.

◆ set_overwrite_previously_stored()

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.

◆ store()

void libMesh::MemorySolutionHistory::store ( )
overridevirtual

Virtual function store which we will be overriding to store timesteps.

Implements libMesh::SolutionHistory.

Definition at line 67 of file memory_solution_history.C.

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;
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  {
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
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
106  vec_end = _system.vectors_end();
107  vec != vec_end; ++vec)
108  {
109  // The name of this vector
110  const std::string & vec_name = vec->first;
111 
112  // If we haven't seen this vector before or if we have and
113  // want to overwrite it
114  if ((overwrite_previously_stored || !saved_vectors.count(vec_name)) &&
115  // and if we think it's worth preserving
116  _system.vector_preservation(vec_name))
117  {
118  // Then we save it.
119  saved_vectors[vec_name] = vec->second->clone();
120  }
121  }
122 
123  // Of course, we will usually save the actual solution
124  std::string _solution("_solution");
125  if ((overwrite_previously_stored || !saved_vectors.count(_solution)) &&
126  // and if we think it's worth preserving
128  saved_vectors[_solution] = _system.solution->clone();
129 }

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().

Member Data Documentation

◆ _system

System& libMesh::MemorySolutionHistory::_system
private

Definition at line 97 of file memory_solution_history.h.

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

◆ overwrite_previously_stored

bool libMesh::SolutionHistory::overwrite_previously_stored
protectedinherited

◆ stored_sols

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().

◆ stored_solutions

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:
libMesh::System::vectors_iterator
std::map< std::string, NumericVector< Number > * >::iterator vectors_iterator
Vector iterator typedefs.
Definition: system.h:756
libMesh::MemorySolutionHistory::_system
System & _system
Definition: memory_solution_history.h:97
libMesh::SolutionHistory::overwrite_previously_stored
bool overwrite_previously_stored
Definition: solution_history.h:77
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::MemorySolutionHistory::stored_solutions_iterator
list_type::iterator stored_solutions_iterator
Definition: memory_solution_history.h:74
libMesh::MemorySolutionHistory::stored_solutions
list_type stored_solutions
Definition: memory_solution_history.h:88
libMesh::System::project_solution_on_reinit
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:802
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::MemorySolutionHistory::find_stored_entry
void find_stored_entry()
Definition: memory_solution_history.C:32
libMesh::MemorySolutionHistory::stored_sols
stored_solutions_iterator stored_sols
Definition: memory_solution_history.h:91
std::abs
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::System::vectors_end
vectors_iterator vectors_end()
End of vectors container.
Definition: system.h:2307
libMesh::System::vectors_begin
vectors_iterator vectors_begin()
Beginning of vectors container.
Definition: system.h:2295
libMesh::MemorySolutionHistory::map_type
std::map< std::string, std::unique_ptr< NumericVector< Number > > > map_type
Typedef for Stored Solutions iterator, a list of pairs of the current system time,...
Definition: memory_solution_history.h:72
libMesh::System::time
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
Definition: system.h:1561
libMesh::System::solution
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1539
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::System::vector_preservation
bool vector_preservation(const std::string &vec_name) const
Definition: system.C:863
libMesh::System::get_vector
const NumericVector< Number > & get_vector(const std::string &vec_name) const
Definition: system.C:774