FV3 Bundle
ioda/src/ioda/ObsVector.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #ifndef IODA_OBSVECTOR_H_
9 #define IODA_OBSVECTOR_H_
10 
11 #include <ostream>
12 #include <string>
13 #include <vector>
14 
15 #include "Fortran.h"
16 #include "oops/util/ObjectCounter.h"
17 #include "oops/util/Printable.h"
18 
19 namespace ioda {
20  class ObsSpace;
21 
22 //-----------------------------------------------------------------------------
23 /*! \brief ObsVector class to handle vectors in observation space for IODA
24  *
25  * \details This class holds observation vector data. Examples of an obs vector
26  * are the y vector and the H(x) vector. The methods of this class
27  * that implement vector operations (e.g., bitwise add, bitwise subtract,
28  * dot product) are capable of handling missing values in the obs data.
29  */
30 
31 class ObsVector : public util::Printable,
32  private util::ObjectCounter<ObsVector> {
33  public:
34  static const std::string classname() {return "ioda::ObsVector";}
35 
36  explicit ObsVector(const ObsSpace &);
37  ObsVector(const ObsVector &, const bool copy = true);
38  ~ObsVector();
39 
40  ObsVector & operator = (const ObsVector &);
41  ObsVector & operator*= (const double &);
42  ObsVector & operator+= (const ObsVector &);
43  ObsVector & operator-= (const ObsVector &);
44  ObsVector & operator*= (const ObsVector &);
45  ObsVector & operator/= (const ObsVector &);
46 
47  void zero();
48  void axpy(const double &, const ObsVector &);
49  void invert();
50  void random();
51  double dot_product_with(const ObsVector &) const;
52  double rms() const;
53 
54  std::size_t size() const {return values_.size();} // Size of vector in local memory
55  unsigned int nobs() const; // Number of active observations (without missing values)
56 
57  const double & toFortran() const {return values_[0];}
58  double & toFortran() {return values_[0];}
59 
60 // I/O
61  void read(const std::string &);
62  void save(const std::string &) const;
63 
64  private:
65  void print(std::ostream &) const;
66 
67  /*! \brief Associate ObsSpace object */
68  const ObsSpace & obsdb_;
69 
70  /*! \brief Vector data */
71  std::vector<double> values_;
72 };
73 // -----------------------------------------------------------------------------
74 
75 } // namespace ioda
76 
77 #endif // IODA_OBSVECTOR_H_
void axpy(const double &, const ObsVector &)
Definition: ObsVector.cc:110
void read(const std::string &)
Definition: ObsVector.cc:166
std::size_t size() const
unsigned int nobs() const
Definition: ObsVector.cc:174
ObsVector class to handle vectors in observation space for IODA.
std::vector< double > values_
Vector data.
void save(const std::string &) const
Definition: ObsVector.cc:170
subroutine, public copy(self, rhs)
const double & toFortran() const
ObsVector & operator+=(const ObsVector &)
Definition: ObsVector.cc:52
Wrapper around ObsHelpQG, mostly to hide the factory.
ObsVector & operator=(const ObsVector &)
Definition: ObsVector.cc:38
ObsVector & operator*=(const double &)
Definition: ObsVector.cc:43
const ObsSpace & obsdb_
Associate ObsSpace object.
ObsVector & operator-=(const ObsVector &)
Definition: ObsVector.cc:65
ObsVector(const ObsSpace &)
Definition: ObsVector.cc:23
double dot_product_with(const ObsVector &) const
Definition: ObsVector.cc:138
void print(std::ostream &) const
Definition: ObsVector.cc:185
static const std::string classname()
ObsVector & operator/=(const ObsVector &)
Definition: ObsVector.cc:91
double rms() const
Definition: ObsVector.cc:151