<commit_before>// Function definitions for MemorySolutionHistory

// Local includes
#include "libmesh/memory_solution_history.h"

#include <cmath>

namespace libMesh
{
  // The Destructor
  MemorySolutionHistory::~MemorySolutionHistory ()
  {
    stored_solutions_iterator stored_sols_it = stored_solutions.begin();
    const stored_solutions_iterator stored_sols_end = stored_solutions.end();

    for(; stored_sols_it != stored_sols_end; ++stored_sols_it)
      {
	// The saved vectors at this timestep
	std::map<std::string, NumericVector<Number> *> saved_vectors = stored_sols_it->second;

	std::map<std::string, NumericVector<Number> *>::iterator vec = saved_vectors.begin();
	std::map<std::string, NumericVector<Number> *>::iterator vec_end = saved_vectors.end();

	// Loop over all the saved vectors
	for (; vec != vec_end; ++vec)
	  {		    	
	    // Delete this saved vector
	    delete vec->second;	    
	  }
      }
  }

  // This function finds, if it can, the entry where we're supposed to
  // be storing data
  void MemorySolutionHistory::find_stored_entry()
  {
    if (stored_solutions.begin() == stored_solutions.end())
      return;

    libmesh_assert (stored_sols != stored_solutions.end());

    if (std::abs(stored_sols->first - _system.time) < TOLERANCE)
      return;

    // If we're not at the front, check the previous entry
    if (stored_sols != stored_solutions.begin())
      {
        stored_solutions_iterator test_it = stored_sols;
        if (std::abs((--test_it)->first - _system.time) < TOLERANCE)
          {
            --stored_sols;
            return;
          }
      }

    // If we're not at the end, check the subsequent entry
    stored_solutions_iterator test_it = stored_sols;
    if ((++test_it) != stored_solutions.end())
      {
        if (std::abs(test_it->first - _system.time) < TOLERANCE)
          {
            ++stored_sols;
            return;
          }
      }
  }

  // This functions saves all the 'projection-worthy' system vectors for
  // future use
  void MemorySolutionHistory::store()
  {    
    this->find_stored_entry();

    // In an empty history we create the first entry
    if (stored_solutions.begin() == stored_solutions.end())
      {
        stored_solutions.push_back
          (std::make_pair(_system.time,
             std::map<std::string, NumericVector<Number> *>()));
        stored_sols = stored_solutions.begin();
      }

    // If we're past the end we can create a new entry
    if (_system.time - stored_sols->first > TOLERANCE )
      {
#ifndef NDEBUG
        stored_sols++;
        libmesh_assert (stored_sols == stored_solutions.end());
#endif
        stored_solutions.push_back
          (std::make_pair(_system.time,
             std::map<std::string, NumericVector<Number> *>()));
        stored_sols = stored_solutions.end();
        --stored_sols;
      }

    // If we're before the beginning we can create a new entry
    else if (stored_sols->first > _system.time)
      {
        libmesh_assert (stored_sols == stored_solutions.begin());
        stored_solutions.push_front
          (std::make_pair(_system.time,
             std::map<std::string, NumericVector<Number> *>()));
        stored_sols = stored_solutions.begin();
      }

    // We don't support inserting entries elsewhere
    libmesh_assert(std::abs(stored_sols->first - _system.time) < TOLERANCE);

    // Map of stored vectors for this solution step
    std::map<std::string, NumericVector<Number> *>& saved_vectors = stored_sols->second;
    
    // Loop over all the system vectors
    for (System::vectors_iterator vec = _system.vectors_begin(); vec != _system.vectors_end(); ++vec)
      {	
	// The name of this vector
	const std::string& vec_name = vec->first;
<commit_msg>Another fix for floating point error<commit_after>// Function definitions for MemorySolutionHistory

// Local includes
#include "libmesh/memory_solution_history.h"

#include <cmath>

namespace libMesh
{
  // The Destructor
  MemorySolutionHistory::~MemorySolutionHistory ()
  {
    stored_solutions_iterator stored_sols_it = stored_solutions.begin();
    const stored_solutions_iterator stored_sols_end = stored_solutions.end();

    for(; stored_sols_it != stored_sols_end; ++stored_sols_it)
      {
	// The saved vectors at this timestep
	std::map<std::string, NumericVector<Number> *> saved_vectors = stored_sols_it->second;

	std::map<std::string, NumericVector<Number> *>::iterator vec = saved_vectors.begin();
	std::map<std::string, NumericVector<Number> *>::iterator vec_end = saved_vectors.end();

	// Loop over all the saved vectors
	for (; vec != vec_end; ++vec)
	  {		    	
	    // Delete this saved vector
	    delete vec->second;	    
	  }
      }
  }

  // This function finds, if it can, the entry where we're supposed to
  // be storing data
  void MemorySolutionHistory::find_stored_entry()
  {
    if (stored_solutions.begin() == stored_solutions.end())
      return;

    libmesh_assert (stored_sols != stored_solutions.end());

    if (std::abs(stored_sols->first - _system.time) < TOLERANCE)
      return;

    // If we're not at the front, check the previous entry
    if (stored_sols != stored_solutions.begin())
      {
        stored_solutions_iterator test_it = stored_sols;
        if (std::abs((--test_it)->first - _system.time) < TOLERANCE)
          {
            --stored_sols;
            return;
          }
      }

    // If we're not at the end, check the subsequent entry
    stored_solutions_iterator test_it = stored_sols;
    if ((++test_it) != stored_solutions.end())
      {
        if (std::abs(test_it->first - _system.time) < TOLERANCE)
          {
            ++stored_sols;
            return;
          }
      }
  }

  // This functions saves all the 'projection-worthy' system vectors for
  // future use
  void MemorySolutionHistory::store()
  {    
    this->find_stored_entry();

    // In an empty history we create the first entry
    if (stored_solutions.begin() == stored_solutions.end())
      {
        stored_solutions.push_back
          (std::make_pair(_system.time,
             std::map<std::string, NumericVector<Number> *>()));
        stored_sols = stored_solutions.begin();
      }

    // If we're past the end we can create a new entry
    if (_system.time - stored_sols->first > TOLERANCE )
      {
#ifndef NDEBUG
        stored_sols++;
        libmesh_assert (stored_sols == stored_solutions.end());
#endif
        stored_solutions.push_back
          (std::make_pair(_system.time,
             std::map<std::string, NumericVector<Number> *>()));
        stored_sols = stored_solutions.end();
        --stored_sols;
      }

    // If we're before the beginning we can create a new entry
    else if (stored_sols->first - _system.time > TOLERANCE)
      {
        libmesh_assert (stored_sols == stored_solutions.begin());
        stored_solutions.push_front
          (std::make_pair(_system.time,
             std::map<std::string, NumericVector<Number> *>()));
        stored_sols = stored_solutions.begin();
      }

    // We don't support inserting entries elsewhere
    libmesh_assert(std::abs(stored_sols->first - _system.time) < TOLERANCE);

    // Map of stored vectors for this solution step
    std::map<std::string, NumericVector<Number> *>& saved_vectors = stored_sols->second;
    
    // Loop over all the system vectors
    for (System::vectors_iterator vec = _system.vectors_begin(); vec != _system.vectors_end(); ++vec)
      {	
	// The name of this vector
	const std::string& vec_name = vec->first;

{'fraction_non_alphanumeric': 0.11888667992047713, 'fraction_numerical': 0.0, 'mean_word_length': 2.840203562340967, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4213033', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2352, 'n_words': 534}