FV3 Bundle
JqTermTLAD.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_ASSIMILATION_JQTERMTLAD_H_
12 #define OOPS_ASSIMILATION_JQTERMTLAD_H_
13 
14 #include <vector>
15 
18 #include "oops/base/PostBaseTLAD.h"
20 #include "oops/interface/State.h"
21 #include "oops/util/DateTime.h"
22 #include "oops/util/Duration.h"
23 
24 namespace oops {
25  template<typename MODEL> class Increment4D;
26 
27 // -----------------------------------------------------------------------------
28 
29 template <typename MODEL>
30 class JqTermTLAD : public PostBaseTLAD<MODEL> {
35 
36  public:
37  explicit JqTermTLAD(unsigned nsub);
39 
40  void clear() {xi_.clear();}
43 
44  GeneralizedDepartures * releaseOutputFromTL() override {return 0;}
45  void setupAD(const Increment4D_ & dx);
46 
47  private:
48  void doInitializeTraj(const State_ &, const util::DateTime &,
49  const util::Duration &) override {}
50  void doProcessingTraj(const State_ &) override {}
51  void doFinalizeTraj(const State_ &) override;
52 
53  void doInitializeTL(const Increment_ &, const util::DateTime &,
54  const util::Duration &) override {}
55  void doProcessingTL(const Increment_ &) override {}
56  void doFinalizeTL(const Increment_ &) override;
57 
58  void doFirstAD(Increment_ &, const util::DateTime &, const util::Duration &) override;
59  void doProcessingAD(Increment_ &) override {}
60  void doLastAD(Increment_ &) override {}
61 
63  std::vector<Increment_> mxi_;
64  std::vector<Increment_> xi_;
65  const unsigned nsubwin_;
66  unsigned current_;
67 };
68 
69 // =============================================================================
70 
71 template <typename MODEL>
73  : jq_(nsub), mxi_(), xi_(), nsubwin_(nsub), current_(0)
74 {
75  Log::trace() << "JqTermTLAD::JqTermTLAD" << std::endl;
76 }
77 
78 // -----------------------------------------------------------------------------
79 
80 template <typename MODEL>
82  Log::trace() << "JqTermTLAD::doFinalizeTraj start" << std::endl;
83  jq_.finalize(xx);
84  Log::trace() << "JqTermTLAD::doFinalizeTraj done" << std::endl;
85 }
86 
87 // -----------------------------------------------------------------------------
88 
89 template <typename MODEL>
91  Log::trace() << "JqTermTLAD::computeModelErrorTraj start" << std::endl;
92  jq_.computeModelError(fg, dx);
93  Log::trace() << "JqTermTLAD::computeModelErrorTraj done" << std::endl;
94 }
95 
96 // -----------------------------------------------------------------------------
97 
98 template <typename MODEL>
100  Log::trace() << "JqTermTLAD::doFinalizeTL start" << std::endl;
101  if (mxi_.size() < nsubwin_ - 1) mxi_.push_back(dx);
102  Log::trace() << "JqTermTLAD::doFinalizeTL done" << std::endl;
103 }
104 
105 // -----------------------------------------------------------------------------
106 
107 template <typename MODEL>
109  Log::trace() << "JqTermTLAD::computeModelErrorTL start" << std::endl;
110 // Compute x_i - M(x_{i-1})
111  for (unsigned jsub = 1; jsub < nsubwin_; ++jsub) {
112  dx[jsub] -= mxi_[jsub-1];
113  Log::info() << "JqTermTLAD: x_" << jsub << " - M(x_" << jsub-1 << ")" << dx[jsub] << std::endl;
114  }
115  mxi_.clear();
116  Log::trace() << "JqTermTLAD::computeModelErrorTL done" << std::endl;
117 }
118 
119 // -----------------------------------------------------------------------------
120 
121 template <typename MODEL>
123  Log::trace() << "JqTermTLAD::setupAD start" << std::endl;
124  xi_.clear();
125  for (unsigned jsub = 0; jsub < nsubwin_; ++jsub) {
126  xi_.push_back(dx[jsub]);
127  }
128  current_ = nsubwin_;
129  Log::trace() << "JqTermTLAD::setupAD done" << std::endl;
130 }
131 
132 // -----------------------------------------------------------------------------
133 
134 template <typename MODEL>
135 void JqTermTLAD<MODEL>::doFirstAD(Increment_ & dx, const util::DateTime &,
136  const util::Duration &) {
137  Log::trace() << "JqTermTLAD::doFirstAD start" << std::endl;
138  ASSERT(current_ >= 0);
139  ASSERT(current_ <= nsubwin_);
140  if (current_ < xi_.size()) {
141  dx -= xi_[current_];
142  }
143  current_ -= 1;
144  Log::trace() << "JqTermTLAD::doFirstAD done" << std::endl;
145 }
146 
147 // -----------------------------------------------------------------------------
148 
149 } // namespace oops
150 
151 #endif // OOPS_ASSIMILATION_JQTERMTLAD_H_
Increment4D< MODEL > Increment4D_
Definition: JqTermTLAD.h:32
State< MODEL > State_
Definition: JqTermTLAD.h:33
void doLastAD(Increment_ &) override
Definition: JqTermTLAD.h:60
void doFirstAD(Increment_ &, const util::DateTime &, const util::Duration &) override
Definition: JqTermTLAD.h:135
void doInitializeTL(const Increment_ &, const util::DateTime &, const util::Duration &) override
Definition: JqTermTLAD.h:53
GeneralizedDepartures * releaseOutputFromTL() override
Return TL dual space output.
Definition: JqTermTLAD.h:44
void doFinalizeTraj(const State_ &) override
Definition: JqTermTLAD.h:81
void doProcessingTL(const Increment_ &) override
Definition: JqTermTLAD.h:55
JqTerm< MODEL > jq_
Definition: JqTermTLAD.h:62
void setupAD(const Increment4D_ &dx)
Definition: JqTermTLAD.h:122
unsigned current_
Definition: JqTermTLAD.h:66
Encapsulates the model state.
The namespace for the main oops code.
void computeModelErrorTraj(const State4D_ &, Increment4D_ &)
Definition: JqTermTLAD.h:90
const unsigned nsubwin_
Definition: JqTermTLAD.h:65
void doInitializeTraj(const State_ &, const util::DateTime &, const util::Duration &) override
Definition: JqTermTLAD.h:48
subroutine, public info(self)
Increment< MODEL > Increment_
Definition: JqTermTLAD.h:31
void doProcessingTraj(const State_ &) override
Definition: JqTermTLAD.h:50
State increment.
Definition: CostJbState.h:28
Four dimensional state.
Definition: CostJbState.h:29
void doProcessingAD(Increment_ &) override
Definition: JqTermTLAD.h:59
JqTermTLAD(unsigned nsub)
Definition: JqTermTLAD.h:72
std::vector< Increment_ > mxi_
Definition: JqTermTLAD.h:63
Increment Class: Difference between two states.
std::vector< Increment_ > xi_
Definition: JqTermTLAD.h:64
void doFinalizeTL(const Increment_ &) override
Definition: JqTermTLAD.h:99
Abstract base class for quantities.
State4D< MODEL > State4D_
Definition: JqTermTLAD.h:34
void computeModelErrorTL(Increment4D_ &)
Definition: JqTermTLAD.h:108