IODA Bundle
ObserverTLAD.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
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  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #ifndef OOPS_BASE_OBSERVERTLAD_H_
12 #define OOPS_BASE_OBSERVERTLAD_H_
13 
14 #include <memory>
15 #include <vector>
16 
17 #include "eckit/config/Configuration.h"
18 #include "oops/base/Geometry.h"
19 #include "oops/base/GetValueTLAD.h"
20 #include "oops/interface/GeoVaLs.h"
28 #include "oops/util/DateTime.h"
29 
30 namespace oops {
31 
32 /// Computes observation equivalent TL and AD to/from increments.
33 
34 template <typename MODEL, typename OBS>
35 class ObserverTLAD {
46 
47  public:
48  ObserverTLAD(const ObsSpace_ &, const eckit::Configuration &);
50 
51  std::shared_ptr<GetValTLAD_> initializeTraj(const Geometry_ &, const ObsAuxCtrl_ &);
52  void finalizeTraj();
53 
54  std::shared_ptr<GetValTLAD_> initializeTL();
55  void finalizeTL(const ObsAuxIncr_ &, ObsVector_ &);
56 
57  std::shared_ptr<GetValTLAD_> initializeAD(const ObsVector_ &, ObsAuxIncr_ &);
58  void finalizeAD();
59 
60  private:
61  eckit::LocalConfiguration obsconfig_;
62  const ObsSpace_ & obspace_; // ObsSpace used in H(x)
63  LinearObsOperator_ hoptlad_; // Linear obs operator
64  std::shared_ptr<GetValTLAD_> getvals_; // Postproc passed to the model during integration
65  std::vector<size_t> linvars_sizes_; // Sizes of variables requested from model for
66  // TL/AD (e.g. number of vertical levels)
67  std::unique_ptr<Locations_> locations_; // locations
68  util::DateTime winbgn_; // Begining of assimilation window
69  util::DateTime winend_; // End of assimilation window
71  bool init_;
72 };
73 
74 // -----------------------------------------------------------------------------
75 template <typename MODEL, typename OBS>
76 ObserverTLAD<MODEL, OBS>::ObserverTLAD(const ObsSpace_ & obsdb, const eckit::Configuration & conf)
77  : obsconfig_(conf), obspace_(obsdb),
78  hoptlad_(obspace_, conf.has("linear obs operator") ?
79  eckit::LocalConfiguration(conf, "linear obs operator") :
80  eckit::LocalConfiguration(conf, "obs operator")),
81  getvals_(), locations_(), winbgn_(obsdb.windowStart()), winend_(obsdb.windowEnd()),
82  ybias_(nullptr), init_(false)
83 {
84  Log::trace() << "ObserverTLAD::ObserverTLAD" << std::endl;
85 }
86 // -----------------------------------------------------------------------------
87 template <typename MODEL, typename OBS>
88 std::shared_ptr<GetValueTLAD<MODEL, OBS>>
90  Log::trace() << "ObserverTLAD::initializeTraj start" << std::endl;
91  ybias_ = &ybias;
92 
93 // hop is only needed to get locations and requiredVars
94  ObsOperator_ hop(obspace_, eckit::LocalConfiguration(obsconfig_, "obs operator"));
95  locations_.reset(new Locations_(hop.locations()));
96  linvars_sizes_ = geom.variableSizes(hoptlad_.requiredVars());
97  eckit::LocalConfiguration gvconf(obsconfig_.has("linear get values") ?
98  eckit::LocalConfiguration(obsconfig_, "linear get values") :
99  (obsconfig_.has("get values") ?
100  eckit::LocalConfiguration(obsconfig_, "get values") :
101  eckit::LocalConfiguration(obsconfig_, "")));
102 
103 // Set up variables that will be requested from the model
104  Variables geovars;
105  geovars += hop.requiredVars();
106  geovars += ybias_->requiredVars();
107 
108  getvals_.reset(new GetValTLAD_(gvconf, geom, winbgn_, winend_,
109  *locations_, geovars, hoptlad_.requiredVars()));
110 
111  init_ = true;
112  Log::trace() << "ObserverTLAD::initializeTraj done" << std::endl;
113  return getvals_;
114 }
115 // -----------------------------------------------------------------------------
116 template <typename MODEL, typename OBS>
118  Log::trace() << "ObserverTLAD::finalizeTraj start" << std::endl;
119  ASSERT(init_);
120 
121  // GetValues releases GeoVaLs, Observer takes ownership
122  std::unique_ptr<GeoVaLs_> geovals = getvals_->finalize();
123 
124  /// Set linearization trajectory for H(x)
125  hoptlad_.setTrajectory(*geovals, *ybias_);
126 
127  init_ = false;
128  Log::trace() << "ObserverTLAD::finalizeTraj done" << std::endl;
129 }
130 // -----------------------------------------------------------------------------
131 template <typename MODEL, typename OBS>
132 std::shared_ptr<GetValueTLAD<MODEL, OBS>> ObserverTLAD<MODEL, OBS>::initializeTL() {
133  Log::trace() << "ObserverTLAD::initializeTL" << std::endl;
134  return getvals_;
135 }
136 // -----------------------------------------------------------------------------
137 template <typename MODEL, typename OBS>
139  Log::trace() << "ObserverTLAD::finalizeTL start" << std::endl;
140 
141  // GetValues releases GeoVaLs, Observer takes ownership
142  std::unique_ptr<GeoVaLs_> geovals = getvals_->finalize();
143 
144  // Compute linear H(x)
145  hoptlad_.simulateObsTL(*geovals, ydeptl, ybiastl);
146 
147  Log::trace() << "ObserverTLAD::finalizeTL done" << std::endl;
148 }
149 // -----------------------------------------------------------------------------
150 template <typename MODEL, typename OBS>
151 std::shared_ptr<GetValueTLAD<MODEL, OBS>>
153  Log::trace() << "ObserverTLAD::initializeAD start" << std::endl;
154 
155  // Compute adjoint of H(x)
156  std::unique_ptr<GeoVaLs_> geovals(new GeoVaLs_(*locations_, hoptlad_.requiredVars(),
157  linvars_sizes_));
158  hoptlad_.simulateObsAD(*geovals, ydepad, ybiasad);
159 
160  // GetValues get GeoVaLs and takes ownership
161  getvals_->setAD(geovals);
162 
163  Log::trace() << "ObserverTLAD::initializeAD done" << std::endl;
164  return getvals_;
165 }
166 // -----------------------------------------------------------------------------
167 template <typename MODEL, typename OBS>
169  getvals_->finalizeAD();
170  Log::trace() << "ObserverTLAD::finalizeAD done" << std::endl;
171 }
172 // -----------------------------------------------------------------------------
173 
174 } // namespace oops
175 
176 #endif // OOPS_BASE_OBSERVERTLAD_H_
Geometry class used in oops; subclass of interface class interface::Geometry.
TLAD of filling GeoVaLs with requested variables at requested locations during model run.
Definition: GetValueTLAD.h:41
Locations of observations for observation operator.
const Variables & requiredVars() const
Other.
Locations_ locations() const
Computes observation equivalent TL and AD to/from increments.
Definition: ObserverTLAD.h:35
GeoVaLs< OBS > GeoVaLs_
Definition: ObserverTLAD.h:37
std::shared_ptr< GetValTLAD_ > initializeTraj(const Geometry_ &, const ObsAuxCtrl_ &)
Definition: ObserverTLAD.h:89
util::DateTime winend_
Definition: ObserverTLAD.h:69
ObsSpace< OBS > ObsSpace_
Definition: ObserverTLAD.h:44
ObsAuxIncrement< OBS > ObsAuxIncr_
Definition: ObserverTLAD.h:42
void finalizeTL(const ObsAuxIncr_ &, ObsVector_ &)
Definition: ObserverTLAD.h:138
std::shared_ptr< GetValTLAD_ > initializeAD(const ObsVector_ &, ObsAuxIncr_ &)
Definition: ObserverTLAD.h:152
ObsOperator< OBS > ObsOperator_
Definition: ObserverTLAD.h:43
GetValueTLAD< MODEL, OBS > GetValTLAD_
Definition: ObserverTLAD.h:38
ObsVector< OBS > ObsVector_
Definition: ObserverTLAD.h:45
Locations< OBS > Locations_
Definition: ObserverTLAD.h:40
std::vector< size_t > linvars_sizes_
Definition: ObserverTLAD.h:65
std::unique_ptr< Locations_ > locations_
Definition: ObserverTLAD.h:67
ObsAuxControl< OBS > ObsAuxCtrl_
Definition: ObserverTLAD.h:41
std::shared_ptr< GetValTLAD_ > initializeTL()
Definition: ObserverTLAD.h:132
const ObsSpace_ & obspace_
Definition: ObserverTLAD.h:62
std::shared_ptr< GetValTLAD_ > getvals_
Definition: ObserverTLAD.h:64
const ObsAuxCtrl_ * ybias_
Definition: ObserverTLAD.h:70
Geometry< MODEL > Geometry_
Definition: ObserverTLAD.h:36
ObserverTLAD(const ObsSpace_ &, const eckit::Configuration &)
Definition: ObserverTLAD.h:76
eckit::LocalConfiguration obsconfig_
Definition: ObserverTLAD.h:61
util::DateTime winbgn_
Definition: ObserverTLAD.h:68
LinearObsOperator< OBS > LinearObsOperator_
Definition: ObserverTLAD.h:39
LinearObsOperator_ hoptlad_
Definition: ObserverTLAD.h:63
std::vector< size_t > variableSizes(const Variables &) const
logical function has(this, var)
The namespace for the main oops code.