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

'Save nothing' subclass of Solution History, this is the default. More...

#include <no_solution_history.h>

Inheritance diagram for libMesh::NoSolutionHistory:
[legend]

Public Member Functions

 NoSolutionHistory ()
 Constructor. More...
 
virtual ~NoSolutionHistory ()
 Destructor. More...
 
virtual void store (bool is_adjoint_solve, Real time) override
 Virtual function store which we will be overriding. More...
 
virtual void retrieve (bool is_adjoint_solve, Real time) override
 Virtual function retrieve which we will be overriding. More...
 
virtual std::unique_ptr< SolutionHistoryclone () const override
 Definition of the clone function needed for the setter function. More...
 
void erase (Real time)
 Erase stored_data entry at time. 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 Types

typedef std::map< Real, std::unique_ptr< HistoryData > > map_type
 
typedef map_type::iterator stored_data_iterator
 

Protected Member Functions

void find_stored_entry (Real time, bool storing=false)
 

Protected Attributes

bool overwrite_previously_stored
 
map_type stored_data
 
stored_data_iterator stored_datum
 

Detailed Description

'Save nothing' subclass of Solution History, this is the default.

Author
Vikram Garg
Date
2012 For storing and retrieving timestep data.

Definition at line 37 of file no_solution_history.h.

Member Typedef Documentation

◆ map_type

typedef std::map<Real, std::unique_ptr<HistoryData> > libMesh::SolutionHistory::map_type
protectedinherited

Definition at line 93 of file solution_history.h.

◆ stored_data_iterator

typedef map_type::iterator libMesh::SolutionHistory::stored_data_iterator
protectedinherited

Definition at line 95 of file solution_history.h.

Constructor & Destructor Documentation

◆ NoSolutionHistory()

libMesh::NoSolutionHistory::NoSolutionHistory ( )
inline

Constructor.

Definition at line 44 of file no_solution_history.h.

44 : SolutionHistory() {}
SolutionHistory()
Constructor.

◆ ~NoSolutionHistory()

virtual libMesh::NoSolutionHistory::~NoSolutionHistory ( )
inlinevirtual

Destructor.

Definition at line 49 of file no_solution_history.h.

49 {}

Member Function Documentation

◆ clone()

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

Definition of the clone function needed for the setter function.

Implements libMesh::SolutionHistory.

Definition at line 64 of file no_solution_history.h.

65  {
66  return std::make_unique<NoSolutionHistory>();
67  }

◆ erase()

void libMesh::SolutionHistory::erase ( Real  time)
inherited

Erase stored_data entry at time.

Definition at line 95 of file solution_history.C.

References libMesh::SolutionHistory::find_stored_entry(), libMesh::libmesh_assert(), libMesh::SolutionHistory::stored_data, and libMesh::SolutionHistory::stored_datum.

96  {
97  // We cant erase the stored_datum iterator which is used in other places
98  // So save its current value for the future
99  stored_data_iterator stored_datum_last = stored_datum;
100  //std::map<Real, unsigned int>::iterator timeTotimestamp_iterator_last = timeTotimestamp_iterator;
101 
102  // This will map the stored_datum iterator to the current time
103  this->find_stored_entry(time, false);
104 
105  // map::erase behaviour is undefined if the iterator is pointing
106  // to a non-existent element.
108 
109  // We want to keep using the stored_datum iterator, so we have to create
110  // a new one to erase the concerned entry
111  stored_data_iterator stored_datum_copy = stored_datum;
112 
113  // If we're asking to erase the entry at stored_datum, then move stored_datum somewhere safer first
114  if(stored_datum == stored_datum_last)
115  stored_datum--;
116 
117  stored_data.erase(stored_datum_copy);
118  }
libmesh_assert(ctx)
map_type::iterator stored_data_iterator
stored_data_iterator stored_datum
void find_stored_entry(Real time, bool storing=false)

◆ find_stored_entry()

void libMesh::SolutionHistory::find_stored_entry ( Real  time,
bool  storing = false 
)
protectedinherited

Definition at line 27 of file solution_history.C.

References std::abs(), libMesh::MeshTools::Subdivision::prev, libMesh::SolutionHistory::stored_data, libMesh::SolutionHistory::stored_datum, and libMesh::TOLERANCE.

Referenced by libMesh::SolutionHistory::erase(), libMesh::MemorySolutionHistory::retrieve(), libMesh::FileSolutionHistory::retrieve(), libMesh::MemorySolutionHistory::store(), and libMesh::FileSolutionHistory::store().

28  {
29  if (stored_data.begin() == stored_data.end())
30  return;
31 
32  // We will use the map::lower_bound operation to find the key which
33  // is the least upper bound among all existing keys for time.
34  // (key before map::lower_bound) < time < map::lower_bound, one of these
35  // should be within TOLERANCE of time (unless we are creating a new map entry)
36  // If the lower bound iterator points to:
37  // begin -> we are looking for the solution at the initial time
38  // end -> we are creating a new entry
39  // anything else, we are looking for an existing entry
40  stored_data_iterator lower_bound_it = stored_data.lower_bound(time);
41 
42  // For the key right before the lower bound
43  stored_data_iterator lower_bound_it_decremented;
44 
45  // If we are at end, we could be creating a new entry (depends on the storing bool), return
46  // Otherwise, get a decremented iterator for the sandwich test
47  if(lower_bound_it == stored_data.end())
48  {
49  // If we are storing and lower_bound_it points to stored_data.end(), we assume
50  // that this is a brand new entry in the map. We leave stored_datum unchanged.
51  if(storing)
52  {
53  return;
54  }
55  else
56  {
57  // We are trying to retrieve and none of the keys was an upper bound.
58  // We could have a situation in which the time is greatest key + FPE.
59  // So we can check the key before the end and see if it matches time, else we have an error.
60  lower_bound_it = std::prev(lower_bound_it);
61  }
62  }
63  else if(lower_bound_it == stored_data.begin()) // At the beginning, so we cant go back any further
64  {
65  stored_datum = stored_data.begin();
66  return;
67  }
68  else // A decremented iterator, to perform the sandwich test for the key closest to time
69  {
70  lower_bound_it_decremented = std::prev(lower_bound_it);
71  }
72 
73  // Set the stored sols iterator as per the key which is within TOLERANCE of time
74  if(std::abs(lower_bound_it->first - time) < TOLERANCE)
75  {
76  stored_datum = lower_bound_it;
77  }
78  else if(std::abs(lower_bound_it_decremented->first - time) < TOLERANCE)
79  {
80  stored_datum = lower_bound_it_decremented;
81  }
82  else // Neither of the two candidate keys matched our time
83  {
84  if(storing) // If we are storing, this is fine, we need to create a new entry, so just return
85  {
86  return;
87  }
88  else // If we are not storing, then we expected to find something but didn't, so we have a problem
89  {
90  libmesh_error_msg("Failed to set stored solutions iterator to a valid value.");
91  }
92  }
93  }
static constexpr Real TOLERANCE
static const unsigned int prev[3]
A lookup table for the decrement modulo 3 operation, for iterating through the three nodes per elemen...
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:57
map_type::iterator stored_data_iterator
stored_data_iterator stored_datum

◆ retrieve()

void libMesh::NoSolutionHistory::retrieve ( bool  is_adjoint_solve,
Real  time 
)
overridevirtual

Virtual function retrieve which we will be overriding.

Implements libMesh::SolutionHistory.

Definition at line 29 of file no_solution_history.C.

30 {
31  // Nothing was stored, so nothing can be retrieved
32  libmesh_not_implemented();
33 }

◆ 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 80 of file solution_history.h.

References libMesh::SolutionHistory::overwrite_previously_stored.

◆ store()

void libMesh::NoSolutionHistory::store ( bool  is_adjoint_solve,
Real  time 
)
overridevirtual

Virtual function store which we will be overriding.

Implements libMesh::SolutionHistory.

Definition at line 24 of file no_solution_history.C.

25 {
26  // Do nothing
27 }

Member Data Documentation

◆ overwrite_previously_stored

bool libMesh::SolutionHistory::overwrite_previously_stored
protectedinherited

◆ stored_data

map_type libMesh::SolutionHistory::stored_data
protectedinherited

◆ stored_datum

stored_data_iterator libMesh::SolutionHistory::stored_datum
protectedinherited

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