ReFRACtor
output_hdf_iteration.cc
Go to the documentation of this file.
1 #include "output_hdf_iteration.h"
2 
3 using namespace FullPhysics;
4 using namespace blitz;
5 
6 // Helper class for OutputHdfIteration
7 // Don't have Doxygen document this class
9 namespace FullPhysics {
10 template<class T, int D> class OutputHdfIterationHelper:
11  public OutputHdfIterationHelperBase {
12 public:
13  OutputHdfIterationHelper(const boost::shared_ptr<HdfFileGenerating> H,
14  const std::string& Data_name)
15  : h(H), d(Data_name) {}
16  // This tacks dt to the end of data.
17  void add_iteration(const Array<T, D-1>& dt)
18  {
19  TinyVector<int, D+1> sz;
20  bool incoming_smaller = false;
21  if(data.cols() == 0) {
22  for(int i = 0; i < D - 1; ++i)
23  sz[i + 2] = dt.shape()[i];
24  sz[0] = 1;
25  sz[1] = 1;
26  } else {
27  for(int i = 0; i < D - 1; ++i) {
28  // Grow data array if incoming data is bigger in
29  // a dimension
30  if(dt.shape()[i] > data.shape()[i + 2]) {
31  sz[i+2] = dt.shape()[i];
32  } else if(dt.shape()[i] < data.shape()[i + 2]) {
33  incoming_smaller = true;
34  sz[i+2] = data.shape()[i+2];
35  } else {
36  sz[i+2] = data.shape()[i+2];
37  }
38  }
39  sz[0] = 1;
40  sz[1] = data.cols() + 1;
41  }
42  data.resizeAndPreserve(sz);
43 
44  if (incoming_smaller) {
45  // Match data portion that is only as
46  // big as incoming data
47  TinyVector<int, D-1> lower(0);
48  RectDomain<D-1> dt_subdomain(lower, dt.shape());
49 
50  // This subdomain use WILL die for string types
51  // but hopefully unlikely they chagne size during execution lifetime
52  subset(data) = 0; // set all entries to 0
53  subset(data)(dt_subdomain) = dt;
54  } else {
55  subset(data) = dt;
56  }
57  }
58  virtual void write() { h->hdf_file().write_field(d, data); }
59 private:
60  Array<T, 1> subset(const Array<T, 3>& V)
61  {return V(0, V.cols() - 1, Range::all());}
62  Array<T, 2> subset(const Array<T, 4>& V)
63  {return V(0, V.cols() - 1, Range::all(), Range::all());}
64  Array<T, 3> subset(const Array<T, 5>& V)
65  {return V(0, V.cols() - 1, Range::all(), Range::all(), Range::all());}
67  std::string d;
68  Array<T, D+1> data;
69 };
70 
71 template<class T> class OutputHdfIterationHelper<T, 1> :
72  public OutputHdfIterationHelperBase {
73 public:
74  OutputHdfIterationHelper(const boost::shared_ptr<HdfFileGenerating> H,
75  const std::string& Data_name)
76  : h(H), d(Data_name) {}
77  void add_iteration(const T& dt)
78  {
79  data.resizeAndPreserve(1, data.cols() + 1);
80  data(0, data.cols() - 1) = dt;
81  }
82  virtual void write() { h->hdf_file().write_field(d, data); }
83 private:
85  std::string d;
86  Array<T, 2> data;
87 };
88 }
90 
92 {
93  typedef std::map<std::string,
95  vt;
96  BOOST_FOREACH(vt& p, data)
97  p.second->write();
98  h.reset();
99 }
100 
101 template<class T> void OutputHdfIteration::write_data_t
102 (const std::string& Dataset_name,
103  T Val)
104 {
105  if(data.count(Dataset_name) == 0)
107  (new OutputHdfIterationHelper<T, 1>
108  (h, iteration_group + "/" + Dataset_name));
110  hlp = boost::dynamic_pointer_cast<OutputHdfIterationHelper<T, 1> >
111  (data[Dataset_name]);
112  hlp->add_iteration(Val);
113 }
114 
115 template<class T, int D> void OutputHdfIteration::write_data_t
116 (const std::string& Dataset_name,
117  const blitz::Array<T, D>& Val)
118 {
119  if(data.count(Dataset_name) == 0)
121  (new OutputHdfIterationHelper<T, D + 1>
122  (h, iteration_group + "/" + Dataset_name));
124  hlp = boost::dynamic_pointer_cast<OutputHdfIterationHelper<T, D + 1> >
125  (data[Dataset_name]);
126  hlp->add_iteration(Val);
127 }
128 
129 // Instantiation of the templates for the various types.
130 
131 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
132  int Val);
133 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
134  int64_t Val);
135 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
136  double Val);
137 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
138  std::string Val);
139 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
140  const char* Val);
141 
142 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
143  const blitz::Array<int, 1>& Val);
144 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
145  const blitz::Array<std::string, 1>& Val);
146 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
147  const blitz::Array<const char*, 1>& Val);
148 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
149  const blitz::Array<double, 1>& Val);
150 
151 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
152  const blitz::Array<int, 2>& Val);
153 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
154  const blitz::Array<std::string, 2>& Val);
155 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
156  const blitz::Array<const char*, 2>& Val);
157 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
158  const blitz::Array<double, 2>& Val);
159 
160 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
161  const blitz::Array<int, 3>& Val);
162 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
163  const blitz::Array<std::string, 3>& Val);
164 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
165  const blitz::Array<const char*, 3>& Val);
166 template void OutputHdfIteration::write_data_t(const std::string& Dataset_name,
167  const blitz::Array<double, 3>& Val);
168 
void write_data_t(const std::string &Dataset_name, T Val)
Apply value function to a blitz array.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:10