ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_TimeInterpolatedData.H
Go to the documentation of this file.
1 #ifndef ERF_TIME_INTERP_DATA_H_
2 #define ERF_TIME_INTERP_DATA_H_
3 
4 #include <AMReX_MultiFab.H>
5 #include <AMReX_Vector.H>
6 #include <AMReX_REAL.H>
7 
8 #include <utility>
9 
11  /**
12  * Construct empty time-interpolated data storage.
13  */
14  TimeInterpolatedData () = default;
15 
16  /**
17  * Construct storage associated with a time.
18  *
19  * @param[in] time time associated with the data
20  */
21  TimeInterpolatedData (double time) : m_time(time) {}
22 
23  /**
24  * Destroy owned data and clear internal storage.
25  */
27  clear();
28  }
29 
30  /**
31  * Move constructor: takes over the source's data and ownership, leaving it empty.
32  *
33  * @param[in] other source object
34  */
36  : m_data(std::move(other.m_data)),
37  m_owns_data(std::move(other.m_owns_data)),
38  m_time(other.m_time)
39  {
40  other.m_data.clear();
41  other.m_owns_data.clear();
42  }
43 
44  /**
45  * Move-assignment operator: frees the data this object owns, then takes over the
46  * source's data and ownership, leaving it empty.
47  *
48  * @param[in] other source object
49  */
51  if (this != &other) {
52  clear();
53  m_data = std::move(other.m_data);
54  m_owns_data = std::move(other.m_owns_data);
55  m_time = other.m_time;
56  other.m_data.clear();
57  other.m_owns_data.clear();
58  }
59  return *this;
60  }
61 
62  /**
63  * Deleted copy constructor.
64  *
65  * @param[in] other source object
66  */
67  TimeInterpolatedData (const TimeInterpolatedData& other) = delete;
68 
69  /**
70  * Deleted copy-assignment operator.
71  *
72  * @param[in] other source object
73  */
75 
76  /**
77  * Set the time associated with the data.
78  *
79  * @param[in] time time associated with the data
80  */
81  void set_time (double time) {
82  m_time = time;
83  }
84 
85  /**
86  * Return the time associated with the data.
87  */
88  [[nodiscard]] double get_time () const { return m_time; }
89 
90  /**
91  * Add a MultiFab pointer to the managed list.
92  *
93  * @param[in] var_data MultiFab pointer to store
94  * @param[in] own_data whether this object owns and deletes var_data
95  */
96  void add_var (amrex::MultiFab* var_data, int own_data) {
97  m_data.push_back(var_data);
98  m_owns_data.push_back(own_data);
99  }
100 
101  /**
102  * Return one stored MultiFab.
103  *
104  * @param[in] var_idx index of the stored MultiFab
105  */
106  amrex::MultiFab& get_var (int var_idx) {
107  return *m_data[var_idx];
108  }
109 
110  /**
111  * Return the number of stored MultiFabs.
112  */
113  int num_vars () { return m_data.size(); }
114 
115  /**
116  * Clear stored data, deleting entries owned by this object.
117  */
118  void clear () {
119  // clear all data owned by this object
120  for (int i = 0; i < num_vars(); ++i) {
121  if (m_owns_data[i] == 1) {
122  m_data[i]->clear();
123  delete m_data[i];
124  }
125  }
126 
127  // clear internal memory
128  m_data.clear();
129  m_owns_data.clear();
130  m_time = 0.0;
131  }
132 
133 private:
134  amrex::Vector<amrex::MultiFab*> m_data;
135  amrex::Vector<int> m_owns_data;
136  double m_time = 0.0;
137 };
138 
139 #endif
Definition: ERF_TimeInterpolatedData.H:10
TimeInterpolatedData()=default
void add_var(amrex::MultiFab *var_data, int own_data)
Definition: ERF_TimeInterpolatedData.H:96
TimeInterpolatedData(double time)
Definition: ERF_TimeInterpolatedData.H:21
TimeInterpolatedData(TimeInterpolatedData &&other) noexcept
Definition: ERF_TimeInterpolatedData.H:35
amrex::MultiFab & get_var(int var_idx)
Definition: ERF_TimeInterpolatedData.H:106
void clear()
Definition: ERF_TimeInterpolatedData.H:118
int num_vars()
Definition: ERF_TimeInterpolatedData.H:113
amrex::Vector< int > m_owns_data
Definition: ERF_TimeInterpolatedData.H:135
amrex::Vector< amrex::MultiFab * > m_data
Definition: ERF_TimeInterpolatedData.H:134
double get_time() const
Definition: ERF_TimeInterpolatedData.H:88
TimeInterpolatedData(const TimeInterpolatedData &other)=delete
double m_time
Definition: ERF_TimeInterpolatedData.H:136
void set_time(double time)
Definition: ERF_TimeInterpolatedData.H:81
~TimeInterpolatedData()
Definition: ERF_TimeInterpolatedData.H:26
TimeInterpolatedData & operator=(TimeInterpolatedData &&other) noexcept
Definition: ERF_TimeInterpolatedData.H:50