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 
9  /**
10  * Construct empty time-interpolated data storage.
11  */
12  TimeInterpolatedData() = default;
13 
14  /**
15  * Construct storage associated with a time.
16  *
17  * @param[in] time time associated with the data
18  */
19  TimeInterpolatedData(double time) : m_time(time) {}
20 
21  /**
22  * Destroy owned data and clear internal storage.
23  */
25  clear();
26  }
27 
28  /**
29  * Default move constructor.
30  */
32 
33  /**
34  * Default move-assignment operator.
35  *
36  * @param[in] other source object
37  */
38  TimeInterpolatedData& operator=(TimeInterpolatedData&& other) noexcept = default;
39 
40  /**
41  * Deleted copy constructor.
42  *
43  * @param[in] other source object
44  */
46 
47  /**
48  * Deleted copy-assignment operator.
49  *
50  * @param[in] other source object
51  */
52  TimeInterpolatedData& operator=(const TimeInterpolatedData& other) = delete;
53 
54  /**
55  * Set the time associated with the data.
56  *
57  * @param[in] time time associated with the data
58  */
59  void set_time(double time) {
60  m_time = time;
61  }
62 
63  /**
64  * Return the time associated with the data.
65  */
66  [[nodiscard]] double get_time() const { return m_time; }
67 
68  /**
69  * Add a MultiFab pointer to the managed list.
70  *
71  * @param[in] var_data MultiFab pointer to store
72  * @param[in] own_data whether this object owns and deletes var_data
73  */
74  void add_var(amrex::MultiFab* var_data, int own_data) {
75  m_data.push_back(var_data);
76  m_owns_data.push_back(own_data);
77  }
78 
79  /**
80  * Return one stored MultiFab.
81  *
82  * @param[in] var_idx index of the stored MultiFab
83  */
84  amrex::MultiFab& get_var(int var_idx) {
85  return *m_data[var_idx];
86  }
87 
88  /**
89  * Return the number of stored MultiFabs.
90  */
91  int num_vars() { return m_data.size(); }
92 
93  /**
94  * Clear stored data, deleting entries owned by this object.
95  */
96  void clear() {
97  // clear all data owned by this object
98  for (int i = 0; i < num_vars(); ++i) {
99  if (m_owns_data[i] == 1) {
100  m_data[i]->clear();
101  delete m_data[i];
102  }
103  }
104 
105  // clear internal memory
106  m_data.clear();
107  m_owns_data.clear();
108  m_time = 0.0;
109  }
110 
111 private:
112  amrex::Vector<amrex::MultiFab*> m_data;
113  amrex::Vector<int> m_owns_data;
114  double m_time;
115 };
116 
117 #endif
Definition: ERF_TimeInterpolatedData.H:8
TimeInterpolatedData()=default
void add_var(amrex::MultiFab *var_data, int own_data)
Definition: ERF_TimeInterpolatedData.H:74
TimeInterpolatedData(double time)
Definition: ERF_TimeInterpolatedData.H:19
amrex::MultiFab & get_var(int var_idx)
Definition: ERF_TimeInterpolatedData.H:84
void clear()
Definition: ERF_TimeInterpolatedData.H:96
int num_vars()
Definition: ERF_TimeInterpolatedData.H:91
amrex::Vector< int > m_owns_data
Definition: ERF_TimeInterpolatedData.H:113
amrex::Vector< amrex::MultiFab * > m_data
Definition: ERF_TimeInterpolatedData.H:112
double get_time() const
Definition: ERF_TimeInterpolatedData.H:66
double m_time
Definition: ERF_TimeInterpolatedData.H:114
void set_time(double time)
Definition: ERF_TimeInterpolatedData.H:59
~TimeInterpolatedData()
Definition: ERF_TimeInterpolatedData.H:24
TimeInterpolatedData(TimeInterpolatedData &&) noexcept=default