OOPS
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 <memory>
15 #include <vector>
16 
17 #include "oops/base/PostBaseTLAD.h"
19 #include "oops/interface/State.h"
20 #include "oops/mpi/mpi.h"
21 #include "oops/util/DateTime.h"
22 #include "oops/util/Duration.h"
23 
24 namespace oops {
25 
26 // -----------------------------------------------------------------------------
27 
28 template <typename MODEL>
29 class JqTermTLAD : public PostBaseTLAD<MODEL> {
32 
33  public:
34  explicit JqTermTLAD(const eckit::mpi::Comm &);
36 
37  void clear() {xi_.reset();}
38 // void computeModelErrorTraj(const State_ &, Increment_ &); // not used
39  State_ & getMxi() const;
41 
42  std::unique_ptr<GeneralizedDepartures> releaseOutputFromTL() override {return nullptr;}
43  void setupAD(const Increment_ & dx);
44 
45  private:
46  void doInitializeTraj(const State_ &, const util::DateTime &,
47  const util::Duration &) override {}
48  void doProcessingTraj(const State_ &) override {}
49  void doFinalizeTraj(const State_ &) override;
50 
51  void doInitializeTL(const Increment_ &, const util::DateTime &,
52  const util::Duration &) override {}
53  void doProcessingTL(const Increment_ &) override {}
54  void doFinalizeTL(const Increment_ &) override;
55 
56  void doFirstAD(Increment_ &, const util::DateTime &, const util::Duration &) override;
57  void doProcessingAD(Increment_ &) override {}
58  void doLastAD(Increment_ &) override {}
59 
60  const eckit::mpi::Comm & commTime_;
61  std::unique_ptr<State_> xtraj_;
62  std::unique_ptr<Increment_> mxi_;
63  std::unique_ptr<Increment_> xi_;
64 };
65 
66 // =============================================================================
67 
68 template <typename MODEL>
69 JqTermTLAD<MODEL>::JqTermTLAD(const eckit::mpi::Comm & comm)
70  : commTime_(comm), xtraj_(), mxi_(), xi_()
71 {
72  Log::trace() << "JqTermTLAD::JqTermTLAD" << std::endl;
73 }
74 
75 // -----------------------------------------------------------------------------
76 
77 template <typename MODEL>
79  Log::trace() << "JqTermTLAD::doFinalizeTraj start" << std::endl;
80  xtraj_.reset(new State_(xx));
81  Log::trace() << "JqTermTLAD::doFinalizeTraj done" << std::endl;
82 }
83 
84 // -----------------------------------------------------------------------------
85 
86 /*
87 template <typename MODEL>
88 void JqTermTLAD<MODEL>::computeModelErrorTraj(const State_ & fg, Increment_ & dx) {
89  Log::trace() << "JqTermTLAD::computeModelErrorTraj start" << std::endl;
90 
91  static int tag = 83655;
92  size_t mytime = commTime_.rank();
93 // Send values of M(x_i) at end of my subwindow to next subwindow
94  if (mytime + 1 < commTime_.size()) {
95  Log::debug() << "JqTermTLAD::computeModelErrorTraj: sending to " << mytime+1
96  << " " << tag << std::endl;
97  oops::mpi::send(commTime_, fg, mytime+1, tag);
98  Log::debug() << "JqTermTLAD::computeModelErrorTraj: sent to " << mytime+1
99  << " " << tag << std::endl;
100  }
101 
102 // Receive values at beginning of my subwindow from previous subwindow
103  if (mytime > 0) {
104  State_ mxi(fg);
105  Log::debug() << "JqTermTLAD::computeModelErrorTraj: receiving from " << mytime-1
106  << " " << tag << std::endl;
107  oops::mpi::receive(commTime_, mxi, mytime-1, tag);
108  Log::debug() << "JqTermTLAD::computeModelErrorTraj: received from " << mytime-1
109  << " " << tag << std::endl;
110 
111 // Compute x_i - M(x_{i-1})
112  dx.diff(fg, mxi);
113  }
114  ++tag;
115  Log::trace() << "JqTermTLAD::computeModelErrorTraj done" << std::endl;
116 }
117 */
118 
119 // -----------------------------------------------------------------------------
120 
121 template <typename MODEL>
123  Log::trace() << "JqTermTLAD::getMxi" << std::endl;
124 // Retrieve M(x-i)
125  return *xtraj_;
126 }
127 
128 // -----------------------------------------------------------------------------
129 
130 template <typename MODEL>
132  Log::trace() << "JqTermTLAD::doFinalizeTL start" << std::endl;
133  int mytime = commTime_.rank();
134  if (mytime + 1 < commTime_.size()) oops::mpi::send(commTime_, dx, mytime+1, 2468);
135  Log::trace() << "JqTermTLAD::doFinalizeTL done" << std::endl;
136 }
137 
138 // -----------------------------------------------------------------------------
139 
140 template <typename MODEL>
142  Log::trace() << "JqTermTLAD::computeModelErrorTL start" << std::endl;
143 // Compute x_i - M(x_{i-1})
144  int mytime = commTime_.rank();
145  if (mytime > 0) {
146  Increment_ mxim1(dx, false);
147  oops::mpi::receive(commTime_, mxim1, mytime-1, 2468);
148  dx -= mxim1;
149  }
150  Log::info() << "JqTermTLAD: x_i - M(x_i)" << dx << std::endl;
151  Log::trace() << "JqTermTLAD::computeModelErrorTL done" << std::endl;
152 }
153 
154 // -----------------------------------------------------------------------------
155 
156 template <typename MODEL>
158  Log::trace() << "JqTermTLAD::setupAD start" << std::endl;
159  int mytime = commTime_.rank();
160  if (mytime > 0) oops::mpi::send(commTime_, dx, mytime-1, 8642);
161  Log::trace() << "JqTermTLAD::setupAD done" << std::endl;
162 }
163 
164 // -----------------------------------------------------------------------------
165 
166 template <typename MODEL>
167 void JqTermTLAD<MODEL>::doFirstAD(Increment_ & dx, const util::DateTime &,
168  const util::Duration &) {
169  Log::trace() << "JqTermTLAD::doFirstAD start" << std::endl;
170  int mytime = commTime_.rank();
171  if (mytime + 1 < commTime_.size()) {
172  Increment_ xip1(dx, false);
173  oops::mpi::receive(commTime_, xip1, mytime+1, 8642);
174  dx -= xip1;
175  }
176  Log::trace() << "JqTermTLAD::doFirstAD done" << std::endl;
177 }
178 
179 // -----------------------------------------------------------------------------
180 
181 } // namespace oops
182 
183 #endif // OOPS_ASSIMILATION_JQTERMTLAD_H_
oops::JqTermTLAD::doLastAD
void doLastAD(Increment_ &) override
Definition: JqTermTLAD.h:58
oops::JqTermTLAD::doProcessingAD
void doProcessingAD(Increment_ &) override
Definition: JqTermTLAD.h:57
oops
The namespace for the main oops code.
Definition: ErrorCovarianceL95.cc:22
oops::JqTermTLAD::releaseOutputFromTL
std::unique_ptr< GeneralizedDepartures > releaseOutputFromTL() override
Definition: JqTermTLAD.h:42
oops::JqTermTLAD::~JqTermTLAD
~JqTermTLAD()
Definition: JqTermTLAD.h:35
PostBaseTLAD.h
oops::JqTermTLAD::doProcessingTraj
void doProcessingTraj(const State_ &) override
Definition: JqTermTLAD.h:48
mpi.h
oops::JqTermTLAD::computeModelErrorTL
void computeModelErrorTL(Increment_ &)
Definition: JqTermTLAD.h:141
oops::JqTermTLAD::JqTermTLAD
JqTermTLAD(const eckit::mpi::Comm &)
Definition: JqTermTLAD.h:69
oops::JqTermTLAD::getMxi
State_ & getMxi() const
Definition: JqTermTLAD.h:122
oops::JqTermTLAD::xi_
std::unique_ptr< Increment_ > xi_
Definition: JqTermTLAD.h:63
oops::JqTermTLAD::commTime_
const eckit::mpi::Comm & commTime_
Definition: JqTermTLAD.h:60
oops::mpi::send
void send(const eckit::mpi::Comm &comm, const SERIALIZABLE &sendobj, const int dest, const int tag)
Extend eckit Comm for Serializable oops objects.
Definition: oops/mpi/mpi.h:36
oops::JqTermTLAD::State_
State< MODEL > State_
Definition: JqTermTLAD.h:31
oops::JqTermTLAD::clear
void clear()
Definition: JqTermTLAD.h:37
oops::JqTermTLAD::xtraj_
std::unique_ptr< State_ > xtraj_
Definition: JqTermTLAD.h:61
oops::JqTermTLAD::setupAD
void setupAD(const Increment_ &dx)
Definition: JqTermTLAD.h:157
oops::JqTermTLAD::mxi_
std::unique_ptr< Increment_ > mxi_
Definition: JqTermTLAD.h:62
oops::State
Encapsulates the model state.
Definition: CostJbState.h:28
oops::JqTermTLAD::doProcessingTL
void doProcessingTL(const Increment_ &) override
Definition: JqTermTLAD.h:53
oops::JqTermTLAD::Increment_
Increment< MODEL > Increment_
Definition: JqTermTLAD.h:30
State.h
oops::JqTermTLAD::doInitializeTL
void doInitializeTL(const Increment_ &, const util::DateTime &, const util::Duration &) override
Definition: JqTermTLAD.h:51
oops::Increment
Increment Class: Difference between two states.
Definition: CostJbState.h:27
oops::JqTermTLAD::doFinalizeTL
void doFinalizeTL(const Increment_ &) override
Definition: JqTermTLAD.h:131
oops::JqTermTLAD::doInitializeTraj
void doInitializeTraj(const State_ &, const util::DateTime &, const util::Duration &) override
Definition: JqTermTLAD.h:46
oops::JqTermTLAD::doFinalizeTraj
void doFinalizeTraj(const State_ &) override
Definition: JqTermTLAD.h:78
oops::mpi::receive
void receive(const eckit::mpi::Comm &comm, SERIALIZABLE &recvobj, const int source, const int tag)
Definition: oops/mpi/mpi.h:46
Increment.h
oops::JqTermTLAD::doFirstAD
void doFirstAD(Increment_ &, const util::DateTime &, const util::Duration &) override
Definition: JqTermTLAD.h:167