Flow123d  release_2.1.0-87-gfbc1563
element_data_cache.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file element_data_cache.hh
15  * @brief
16  */
17 
18 #ifndef ELEMENT_DATA_CACHE_HH_
19 #define ELEMENT_DATA_CACHE_HH_
20 
21 #include <vector>
22 #include <string>
23 #include <memory>
24 
25 
27 public:
28  /// Constructor.
30  : time_(-std::numeric_limits<double>::infinity()),
31  quantity_name_("") {}
32 
33  /// Getter for time of cache
34  double get_time()
35  { return time_; }
36 
37  /// Getter for quantity name of cache
38  std::string get_quantity_name()
39  { return quantity_name_; }
40 
41  /// Check if cache stored actual data
42  bool is_actual(double time, std::string quantity_name) {
43  return (time_ == time) && (quantity_name_ == quantity_name);
44  }
45 
46 protected:
47  /// time step stored in cache
48  double time_;
49  /// name of quantity stored in cache
50  std::string quantity_name_;
51 };
52 
53 
54 template <typename T>
56 public:
57  typedef std::shared_ptr< std::vector<T> > ComponentDataPtr;
59 
60  /// Constructor.
61  ElementDataCache(double time, std::string quantity_name, CacheData data)
62  : data_(data) {
63  this->time_ = time;
64  this->quantity_name_ = quantity_name;
65  }
66 
67  /// Return vector of element data for get component.
68  ComponentDataPtr get_component_data(unsigned int component_idx) {
69  OLD_ASSERT(component_idx < data_.size(), "Index of component is out of range.\n");
70  return data_[component_idx];
71  }
72 
73 protected:
74  /**
75  * Table of element data.
76  *
77  * For every components contains vector of element data.
78  */
79  CacheData data_;
80 
81 };
82 
83 #endif /* ELEMENT_DATA_CACHE_HH_ */
double time_
time step stored in cache
std::shared_ptr< std::vector< T > > ComponentDataPtr
ComponentDataPtr get_component_data(unsigned int component_idx)
Return vector of element data for get component.
std::vector< ComponentDataPtr > CacheData
double get_time()
Getter for time of cache.
ElementDataCache(double time, std::string quantity_name, CacheData data)
Constructor.
std::string quantity_name_
name of quantity stored in cache
#define OLD_ASSERT(...)
Definition: global_defs.h:131
bool is_actual(double time, std::string quantity_name)
Check if cache stored actual data.
ElementDataCacheBase()
Constructor.
std::string get_quantity_name()
Getter for quantity name of cache.