OOPS
PostBaseTLAD.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_POSTBASETLAD_H_
12 #define OOPS_BASE_POSTBASETLAD_H_
13 
14 #include <memory>
15 
16 #include <boost/noncopyable.hpp>
17 
18 #include "eckit/config/Configuration.h"
20 #include "oops/base/Increment.h"
21 #include "oops/base/PostTimer.h"
22 #include "oops/base/State.h"
23 #include "oops/util/DateTime.h"
24 #include "oops/util/Duration.h"
25 
26 namespace oops {
27 
28 // -----------------------------------------------------------------------------
29 
30 /// Handles post-processing of model fields related to cost function.
31 /*!
32  * PostBaseTLAD is the base class for all cost function linearized processors,
33  * it is mostly used so that PostProcessorTL can hold a vector of such
34  * processors.
35  * By default processing is performed on every call.
36  * An important difference with PostBase is that the adjoint can modify the
37  * increment.
38  */
39 
40 template <typename MODEL>
41 class PostBaseTLAD : private boost::noncopyable {
44 
45  public:
47  PostBaseTLAD(const util::DateTime & start, const util::DateTime & finish,
48  const util::Duration & freq = util::Duration(0))
49  : timer_(start, finish, freq) {}
50  virtual ~PostBaseTLAD() {}
51 
52 /// Set linearization state
53  void initializeTraj(const State_ & xx, const util::DateTime & end,
54  const util::Duration & step) {
55  timer_.initialize(xx.validTime(), end);
56  this->doInitializeTraj(xx, end, step);
57  }
58 
59  void processTraj(const State_ & xx) {
60  if (timer_.itIsTime(xx.validTime())) this->doProcessingTraj(xx);
61  }
62 
63  void finalizeTraj(const State_ & xx) {
64  this->doFinalizeTraj(xx);
65  }
66 
67 /// Tangent linear methods
68  void initializeTL(const Increment_ & dx, const util::DateTime & end,
69  const util::Duration & step) {
70  timer_.initialize(dx.validTime(), end);
71  this->doInitializeTL(dx, end, step);
72  }
73 
74  void processTL(const Increment_ & dx) {
75  if (timer_.itIsTime(dx.validTime())) this->doProcessingTL(dx);
76  }
77 
78  void finalizeTL(const Increment_ & dx) {
79  this->doFinalizeTL(dx);
80  }
81 
82 /// Adjoint methods
83  void initializeAD(Increment_ & dx, const util::DateTime & bgn,
84  const util::Duration & step) {
85  timer_.initialize(bgn, dx.validTime());
86  this->doFirstAD(dx, bgn, step);
87  }
88 
89  void processAD(Increment_ & dx) {
90  if (timer_.itIsTime(dx.validTime())) this->doProcessingAD(dx);
91  }
92 
93  void finalizeAD(Increment_ & dx) {
94  this->doLastAD(dx);
95  }
96 
97  private:
99  virtual void doInitializeTraj(const State_ &,
100  const util::DateTime &, const util::Duration &) = 0;
101  virtual void doProcessingTraj(const State_ &) = 0;
102  virtual void doFinalizeTraj(const State_ &) = 0;
103 
104  virtual void doInitializeTL(const Increment_ &,
105  const util::DateTime &, const util::Duration &) = 0;
106  virtual void doProcessingTL(const Increment_ &) = 0;
107  virtual void doFinalizeTL(const Increment_ &) = 0;
108 
109  virtual void doFirstAD(Increment_ &, const util::DateTime &, const util::Duration &) = 0;
110  virtual void doProcessingAD(Increment_ &) = 0;
111  virtual void doLastAD(Increment_ &) = 0;
112 };
113 
114 // -----------------------------------------------------------------------------
115 
116 } // namespace oops
117 
118 #endif // OOPS_BASE_POSTBASETLAD_H_
Increment class used in oops.
Handles post-processing of model fields related to cost function.
Definition: PostBaseTLAD.h:41
void processTL(const Increment_ &dx)
Definition: PostBaseTLAD.h:74
void initializeTL(const Increment_ &dx, const util::DateTime &end, const util::Duration &step)
Tangent linear methods.
Definition: PostBaseTLAD.h:68
void initializeTraj(const State_ &xx, const util::DateTime &end, const util::Duration &step)
Set linearization state.
Definition: PostBaseTLAD.h:53
void processAD(Increment_ &dx)
Definition: PostBaseTLAD.h:89
void finalizeAD(Increment_ &dx)
Definition: PostBaseTLAD.h:93
PostTimer timer_
Definition: PostBaseTLAD.h:98
Increment< MODEL > Increment_
Definition: PostBaseTLAD.h:42
void finalizeTraj(const State_ &xx)
Definition: PostBaseTLAD.h:63
virtual void doProcessingTraj(const State_ &)=0
PostBaseTLAD()
Definition: PostBaseTLAD.h:46
virtual void doInitializeTraj(const State_ &, const util::DateTime &, const util::Duration &)=0
virtual void doLastAD(Increment_ &)=0
virtual ~PostBaseTLAD()
Definition: PostBaseTLAD.h:50
virtual void doProcessingTL(const Increment_ &)=0
void finalizeTL(const Increment_ &dx)
Definition: PostBaseTLAD.h:78
PostBaseTLAD(const util::DateTime &start, const util::DateTime &finish, const util::Duration &freq=util::Duration(0))
Definition: PostBaseTLAD.h:47
void processTraj(const State_ &xx)
Definition: PostBaseTLAD.h:59
void initializeAD(Increment_ &dx, const util::DateTime &bgn, const util::Duration &step)
Adjoint methods.
Definition: PostBaseTLAD.h:83
virtual void doFinalizeTraj(const State_ &)=0
virtual void doInitializeTL(const Increment_ &, const util::DateTime &, const util::Duration &)=0
virtual void doProcessingAD(Increment_ &)=0
State< MODEL > State_
Definition: PostBaseTLAD.h:43
virtual void doFirstAD(Increment_ &, const util::DateTime &, const util::Duration &)=0
virtual void doFinalizeTL(const Increment_ &)=0
Handles timing of post-processing and similar actions.
bool itIsTime(const util::DateTime &)
void initialize(const util::DateTime &, const util::DateTime &)
State class used in oops; subclass of interface class interface::State.
const util::DateTime validTime() const
Accessor to the time of this Increment.
const util::DateTime validTime() const
Accessor to the time of this State.
The namespace for the main oops code.