IODA Bundle
TlmQG.cc
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 #include "model/TlmQG.h"
12 
13 #include <iomanip>
14 #include <vector>
15 
16 #include "eckit/config/LocalConfiguration.h"
17 #include "eckit/exception/Exceptions.h"
18 
19 #include "oops/util/abor1_cpp.h"
20 #include "oops/util/DateTime.h"
21 #include "oops/util/Logger.h"
22 
23 #include "model/GeometryQG.h"
24 #include "model/IncrementQG.h"
26 #include "model/ModelQG.h"
27 #include "model/QgFortran.h"
28 #include "model/QgTraits.h"
29 #include "model/StateQG.h"
30 
31 namespace qg {
32 // -----------------------------------------------------------------------------
34 // -----------------------------------------------------------------------------
35 TlmQG::TlmQG(const GeometryQG & resol, const eckit::Configuration & tlConf)
36  : keyConfig_(0), tstep_(), resol_(resol), traj_(),
37  lrmodel_(resol_,
38  oops::validateAndDeserialize<ModelQgParameters>(
39  eckit::LocalConfiguration(tlConf, "trajectory"))),
40  linvars_({"x"})
41 {
42  if (tlConf.has("tlm variables")) linvars_ = oops::Variables(tlConf, "tlm variables");
43  tstep_ = util::Duration(tlConf.getString("tstep"));
44  qg_model_setup_f90(keyConfig_, tlConf);
45 
46  oops::Log::trace() << "TlmQG created" << std::endl;
47 }
48 // -----------------------------------------------------------------------------
51  for (trajIter jtra = traj_.begin(); jtra != traj_.end(); ++jtra) {
52  qg_fields_delete_f90(jtra->second);
53  }
54  oops::Log::trace() << "TlmQG destructed" << std::endl;
55 }
56 // -----------------------------------------------------------------------------
57 void TlmQG::setTrajectory(const StateQG & xx, StateQG & xlr, const ModelBias & bias) {
58 // StateQG xlr(resol_, xx);
59  xlr.changeResolution(xx);
60  int ftraj = lrmodel_.saveTrajectory(xlr, bias);
61  traj_[xx.validTime()] = ftraj;
62 }
63 // -----------------------------------------------------------------------------
64 void TlmQG::initializeTL(IncrementQG & dx) const {
65  ASSERT(dx.fields().isForModel(false));
66  oops::Log::debug() << "TlmQG::initializeTL" << dx.fields() << std::endl;
67 }
68 // -----------------------------------------------------------------------------
69 void TlmQG::stepTL(IncrementQG & dx, const ModelBiasIncrement &) const {
70  trajICst itra = traj_.find(dx.validTime());
71  if (itra == traj_.end()) {
72  oops::Log::error() << "TlmQG: trajectory not available at time " << dx.validTime() << std::endl;
73  ABORT("TlmQG: trajectory not available");
74  }
75  ASSERT(dx.fields().isForModel(false));
76  oops::Log::debug() << "TlmQG::stepTL fields in" << dx.fields() << std::endl;
78  oops::Log::debug() << "TlmQG::stepTL fields out" << dx.fields() << std::endl;
79  dx.validTime() += tstep_;
80 }
81 // -----------------------------------------------------------------------------
82 void TlmQG::finalizeTL(IncrementQG & dx) const {
83  oops::Log::debug() << "TlmQG::finalizeTL" << dx.fields() << std::endl;
84 }
85 // -----------------------------------------------------------------------------
86 void TlmQG::initializeAD(IncrementQG & dx) const {
87  ASSERT(dx.fields().isForModel(false));
88  oops::Log::debug() << "TlmQG::initializeAD" << dx.fields() << std::endl;
89 }
90 // -----------------------------------------------------------------------------
92  dx.validTime() -= tstep_;
93  trajICst itra = traj_.find(dx.validTime());
94  if (itra == traj_.end()) {
95  oops::Log::error() << "TlmQG: trajectory not available at time " << dx.validTime() << std::endl;
96  ABORT("TlmQG: trajectory not available");
97  }
98  ASSERT(dx.fields().isForModel(false));
99  oops::Log::debug() << "TlmQG::stepAD fields in" << dx.fields() << std::endl;
100  qg_model_propagate_ad_f90(keyConfig_, itra->second, dx.fields().toFortran());
101  oops::Log::debug() << "TlmQG::stepAD fields out" << dx.fields() << std::endl;
102 }
103 // -----------------------------------------------------------------------------
104 void TlmQG::finalizeAD(IncrementQG & dx) const {
105  oops::Log::debug() << "TlmQG::finalizeAD" << dx.fields() << std::endl;
106 }
107 // -----------------------------------------------------------------------------
108 void TlmQG::print(std::ostream & os) const {
109  os << "QG TLM Trajectory, nstep=" << traj_.size() << std::endl;
110  typedef std::map< util::DateTime, int >::const_iterator trajICst;
111  if (traj_.size() > 0) {
112  os << "QG TLM Trajectory: times are:";
113  for (trajICst jtra = traj_.begin(); jtra != traj_.end(); ++jtra) {
114  // Time
115  os << " " << jtra->first;
116  os << " " << jtra->second;
117  }
118  }
119 }
120 // -----------------------------------------------------------------------------
121 } // namespace qg
const int & toFortran() const
Definition: FieldsQG.h:99
bool isForModel(const bool &) const
Definition: FieldsQG.cc:211
GeometryQG handles geometry for QG model.
Definition: GeometryQG.h:58
Increment Class: Difference between two states.
Definition: IncrementQG.h:64
const util::DateTime & validTime() const
Definition: IncrementQG.h:94
FieldsQG & fields()
Access to fields.
Definition: IncrementQG.h:104
Model error for the QG model.
int saveTrajectory(StateQG &, const ModelBias &) const
Definition: ModelQG.cc:61
QG model state.
Definition: StateQG.h:42
void changeResolution(const StateQG &xx)
Interpolate full fields.
Definition: StateQG.cc:99
const util::DateTime & validTime() const
Definition: StateQG.h:64
void print(std::ostream &) const override
Definition: TlmQG.cc:108
void initializeTL(IncrementQG &) const override
Run TLM and its adjoint.
Definition: TlmQG.cc:64
void stepTL(IncrementQG &, const ModelBiasIncrement &) const override
Definition: TlmQG.cc:69
std::map< util::DateTime, int >::iterator trajIter
Definition: TlmQG.h:69
void finalizeTL(IncrementQG &) const override
Definition: TlmQG.cc:82
void setTrajectory(const StateQG &, StateQG &, const ModelBias &) override
Model trajectory computation.
Definition: TlmQG.cc:57
F90model keyConfig_
Definition: TlmQG.h:73
void stepAD(IncrementQG &, ModelBiasIncrement &) const override
Definition: TlmQG.cc:91
std::map< util::DateTime, F90flds > traj_
Definition: TlmQG.h:76
~TlmQG()
Definition: TlmQG.cc:49
TlmQG(const GeometryQG &, const eckit::Configuration &)
Definition: TlmQG.cc:35
void initializeAD(IncrementQG &) const override
Definition: TlmQG.cc:86
std::map< util::DateTime, int >::const_iterator trajICst
Definition: TlmQG.h:70
void finalizeAD(IncrementQG &) const override
Definition: TlmQG.cc:104
const ModelQG lrmodel_
Definition: TlmQG.h:77
util::Duration tstep_
Definition: TlmQG.h:74
The namespace for the main oops code.
The namespace for the qg model.
void qg_model_setup_f90(F90model &, const eckit::Configuration &)
void qg_model_delete_f90(F90model &)
static oops::LinearModelMaker< QgTraits, TlmQG > makerQGTLM_("QgTLM")
void qg_fields_delete_f90(F90flds &)
void qg_model_propagate_ad_f90(const F90model &, const F90flds &, const F90flds &)
void qg_model_propagate_tl_f90(const F90model &, const F90flds &, const F90flds &)