11 #ifndef OOPS_INTERFACE_OBSVECTOR_H_
12 #define OOPS_INTERFACE_OBSVECTOR_H_
14 #include <Eigen/Dense>
23 #include "oops/util/gatherPrint.h"
24 #include "oops/util/Logger.h"
25 #include "oops/util/ObjectCounter.h"
26 #include "oops/util/Printable.h"
27 #include "oops/util/Timer.h"
45 template <
typename OBS>
47 private util::ObjectCounter<ObsVector<OBS> > {
51 static const std::string
classname() {
return "oops::ObsVector";}
109 void save(
const std::string &)
const;
111 void read(
const std::string &);
114 unsigned int nobs()
const;
117 void print(std::ostream &)
const;
122 template <
typename OBS>
125 Log::trace() <<
"ObsVector<OBS>::ObsVector starting " << name << std::endl;
126 util::Timer timer(
classname(),
"ObsVector");
128 this->setObjectSize(
data_->size() *
sizeof(
double));
129 Log::trace() <<
"ObsVector<OBS>::ObsVector done" << std::endl;
132 template <
typename OBS>
134 : data_(std::move(obsvector)) {
135 Log::trace() <<
"ObsVector<OBS>::ObsVector starting " << std::endl;
136 util::Timer timer(
classname(),
"ObsVector");
137 this->setObjectSize(
data_->size() *
sizeof(
double));
138 Log::trace() <<
"ObsVector<OBS>::ObsVector done" << std::endl;
141 template <
typename OBS>
143 Log::trace() <<
"ObsVector<OBS>::ObsVector starting" << std::endl;
144 util::Timer timer(
classname(),
"ObsVector");
146 this->setObjectSize(
data_->size() *
sizeof(
double));
147 Log::trace() <<
"ObsVector<OBS>::ObsVector done" << std::endl;
150 template <
typename OBS>
152 Log::trace() <<
"ObsVector<OBS>::~ObsVector starting" << std::endl;
153 util::Timer timer(classname(),
"~ObsVector");
155 Log::trace() <<
"ObsVector<OBS>::~ObsVector done" << std::endl;
158 template <
typename OBS>
160 Log::trace() <<
"ObsVector<OBS>::operator= starting" << std::endl;
161 util::Timer timer(classname(),
"operator=");
165 Log::trace() <<
"ObsVector<OBS>::operator= done" << std::endl;
169 template <
typename OBS>
171 Log::trace() <<
"ObsVector<OBS>::operator*= starting" << std::endl;
172 util::Timer timer(classname(),
"operator*=");
176 Log::trace() <<
"ObsVector<OBS>::operator*= done" << std::endl;
180 template <
typename OBS>
182 Log::trace() <<
"ObsVector<OBS>::operator+= starting" << std::endl;
183 util::Timer timer(classname(),
"operator+=");
185 *data_ += *rhs.
data_;
187 Log::trace() <<
"ObsVector<OBS>::operator+= done" << std::endl;
191 template <
typename OBS>
193 Log::trace() <<
"ObsVector<OBS>::operator-= starting" << std::endl;
194 util::Timer timer(classname(),
"operator-=");
196 *data_ -= *rhs.
data_;
198 Log::trace() <<
"ObsVector<OBS>::operator-= done" << std::endl;
202 template <
typename OBS>
204 Log::trace() <<
"ObsVector<OBS>::operator*= starting" << std::endl;
205 util::Timer timer(classname(),
"operator*=");
207 *data_ *= *rhs.
data_;
209 Log::trace() <<
"ObsVector<OBS>::operator*= done" << std::endl;
213 template <
typename OBS>
215 Log::trace() <<
"ObsVector<OBS>::operator/= starting" << std::endl;
216 util::Timer timer(classname(),
"operator/=");
218 *data_ /= *rhs.
data_;
220 Log::trace() <<
"ObsVector<OBS>::operator/= done" << std::endl;
224 template <
typename OBS>
226 Log::trace() <<
"ObsVector<OBS>::zero starting" << std::endl;
227 util::Timer timer(classname(),
"zero");
231 Log::trace() <<
"ObsVector<OBS>::zero done" << std::endl;
234 template <
typename OBS>
236 Log::trace() <<
"ObsVector<OBS>::ones starting" << std::endl;
237 util::Timer timer(classname(),
"ones");
241 Log::trace() <<
"ObsVector<OBS>::ones done" << std::endl;
244 template <
typename OBS>
246 Log::trace() <<
"ObsVector<OBS>::axpy starting" << std::endl;
247 util::Timer timer(classname(),
"axpy");
249 data_->axpy(zz, *rhs.
data_);
251 Log::trace() <<
"ObsVector<OBS>::axpy done" << std::endl;
254 template <
typename OBS>
256 Log::trace() <<
"ObsVector<OBS>::invert starting" << std::endl;
257 util::Timer timer(classname(),
"invert");
261 Log::trace() <<
"ObsVector<OBS>::invert done" << std::endl;
264 template <
typename OBS>
266 Log::trace() <<
"ObsVector<OBS>::random starting" << std::endl;
267 util::Timer timer(classname(),
"random");
271 Log::trace() <<
"ObsVector<OBS>::random done" << std::endl;
274 template <
typename OBS>
276 Log::trace() <<
"ObsVector<OBS>::dot_product starting" << std::endl;
277 util::Timer timer(classname(),
"dot_product");
279 double zz = data_->dot_product_with(*other.
data_);
281 Log::trace() <<
"ObsVector<OBS>::dot_product done" << std::endl;
285 template <
typename OBS>
287 Log::trace() <<
"ObsVector<OBS>::mask starting" << std::endl;
288 util::Timer timer(classname(),
"mask");
290 Log::trace() <<
"ObsVector<OBS>::mask done" << std::endl;
293 template <
typename OBS>
295 Log::trace() <<
"ObsVector<OBS>::mask(ObsVector) starting" << std::endl;
296 util::Timer timer(classname(),
"mask(ObsVector)");
298 Log::trace() <<
"ObsVector<OBS>::mask(ObsVector) done" << std::endl;
301 template <
typename OBS>
303 Log::trace() <<
"ObsVector<OBS>::operator= starting" << std::endl;
304 util::Timer timer(classname(),
"operator=");
306 Log::trace() <<
"ObsVector<OBS>::operator= done" << std::endl;
310 template <
typename OBS>
312 Log::trace() <<
"ObsVector<OBS>::rms starting" << std::endl;
313 util::Timer timer(classname(),
"rms");
315 double zz = data_->rms();
317 Log::trace() <<
"ObsVector<OBS>::rms done" << std::endl;
321 template <
typename OBS>
323 int nobs = data_->nobs();
327 template <
typename OBS>
329 Log::trace() <<
"ObsVector<OBS>::print starting" << std::endl;
330 util::Timer timer(classname(),
"print");
332 Log::trace() <<
"ObsVector<OBS>::print done" << std::endl;
335 template <
typename OBS>
337 Log::trace() <<
"ObsVector<OBS>::save starting " << name << std::endl;
338 util::Timer timer(classname(),
"save");
342 Log::trace() <<
"ObsVector<OBS>::save done" << std::endl;
345 template <
typename OBS>
347 Log::trace() <<
"ObsVector<OBS>::packEigen starting " << std::endl;
348 util::Timer timer(classname(),
"packEigen");
350 Eigen::VectorXd vec = data_->packEigen(mask.
obsvector());
352 Log::trace() <<
"ObsVector<OBS>::packEigen done" << std::endl;
356 template <
typename OBS>
358 Log::trace() <<
"ObsVector<OBS>::packEigenSize starting " << std::endl;
359 util::Timer timer(classname(),
"packEigenSize");
361 size_t len = data_->packEigenSize(mask.
obsvector());
363 Log::trace() <<
"ObsVector<OBS>::packEigen done" << std::endl;
367 template <
typename OBS>
369 Log::trace() <<
"ObsVector<OBS>::read starting " << name << std::endl;
370 util::Timer timer(classname(),
"read");
374 Log::trace() <<
"ObsVector<OBS>::read done" << std::endl;
ObsDataVector is a vector templated on data type, in the observation space.
ObsDataVec_ & obsdatavector()
Accessor to the data.
ObsSpace_ & obsspace() const
Interfacing.
Holds observation vector (e.g. vector of observation values, or of computed H(x))
void ones()
Set this ObsVector to ones (used in tests)
void print(std::ostream &) const
double rms() const
Return this ObsVector rms.
OBS::ObsVector ObsVector_
Eigen::VectorXd packEigen(const ObsVector &mask) const
const ObsVector_ & obsvector() const
Const accessor.
ObsVector & operator-=(const ObsVector &)
void mask(const ObsDataVector< OBS, int > &mask)
Mask out elements of the vector where mask is > 0.
ObsVector & operator+=(const ObsVector &)
unsigned int nobs() const
Number of non-masked out observations (across all MPI tasks)
ObsVector & operator*=(const double &)
static const std::string classname()
std::unique_ptr< ObsVector_ > data_
ObsVector_ & obsvector()
Accessor.
double dot_product_with(const ObsVector &other) const
Return the dot product between this ObsVector and another one other.
ObsVector & operator/=(const ObsVector &)
void random()
Set each value in this ObsVector to a random value.
size_t packEigenSize(const ObsVector &mask) const
~ObsVector()
Destructor (defined explicitly for timing and tracing)
void save(const std::string &) const
Save this ObsVector as group name in the ObsSpace.
ObsVector & operator=(const ObsVector &)
Linear algebra operators.
void read(const std::string &)
Fill ObsVector with data with group name from the associated ObsSpace.
void axpy(const double &zz, const ObsVector &rhs)
Add zz * rhs to the ObsVector.
void invert()
Set each value in this ObsVector to its inverse.
void zero()
Zero out this ObsVector.
ObsVector(const ObsSpace< OBS > &obsspace, const std::string name="")
The namespace for the main oops code.