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  TimeInterpolatedData() = default;
10 
11  TimeInterpolatedData(amrex::Real time) : m_time(time) {}
12 
14  clear();
15  }
16 
17  // Declare a default move constructor so we ensure the destructor is
18  // not called when we return an object of this class by value
20 
21  // Declare a default move assignment operator
22  TimeInterpolatedData& operator=(TimeInterpolatedData&& other) noexcept = default;
23 
24  // Delete the copy constructor and copy assignment operators because
25  // the integrator allocates internal memory that is best initialized
26  // from scratch when needed instead of making a copy.
27 
28  // Delete the copy constructor
30  //
31  // Delete the copy assignment operator
32  TimeInterpolatedData& operator=(const TimeInterpolatedData& other) = delete;
33 
34  void set_time(amrex::Real time) {
35  m_time = time;
36  }
37 
38  [[nodiscard]] amrex::Real get_time() const { return m_time; }
39 
40  void add_var(amrex::MultiFab* var_data, int own_data) {
41  m_data.push_back(var_data);
42  m_owns_data.push_back(own_data);
43  }
44 
45  amrex::MultiFab& get_var(int var_idx) {
46  return *m_data[var_idx];
47  }
48 
49  int num_vars() { return m_data.size(); }
50 
51  void clear() {
52  // clear all data owned by this object
53  for (int i = 0; i < num_vars(); ++i) {
54  if (m_owns_data[i] == 1) {
55  m_data[i]->clear();
56  delete m_data[i];
57  }
58  }
59 
60  // clear internal memory
61  m_data.clear();
62  m_owns_data.clear();
63  m_time = 0.;
64  }
65 
66 private:
67  amrex::Vector<amrex::MultiFab*> m_data;
68  amrex::Vector<int> m_owns_data;
69  amrex::Real m_time;
70 };
71 
72 #endif
Definition: ERF_ConsoleIO.cpp:12
Definition: ERF_TimeInterpolatedData.H:8
void set_time(amrex::Real time)
Definition: ERF_TimeInterpolatedData.H:34
TimeInterpolatedData()=default
void add_var(amrex::MultiFab *var_data, int own_data)
Definition: ERF_TimeInterpolatedData.H:40
amrex::Real get_time() const
Definition: ERF_TimeInterpolatedData.H:38
amrex::MultiFab & get_var(int var_idx)
Definition: ERF_TimeInterpolatedData.H:45
void clear()
Definition: ERF_TimeInterpolatedData.H:51
int num_vars()
Definition: ERF_TimeInterpolatedData.H:49
amrex::Vector< int > m_owns_data
Definition: ERF_TimeInterpolatedData.H:68
amrex::Vector< amrex::MultiFab * > m_data
Definition: ERF_TimeInterpolatedData.H:67
amrex::Real m_time
Definition: ERF_TimeInterpolatedData.H:69
TimeInterpolatedData(amrex::Real time)
Definition: ERF_TimeInterpolatedData.H:11
~TimeInterpolatedData()
Definition: ERF_TimeInterpolatedData.H:13
TimeInterpolatedData(TimeInterpolatedData &&) noexcept=default