FV3 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 <vector>
14 
15 #include "eckit/config/LocalConfiguration.h"
16 #include "model/GeometryQG.h"
17 #include "model/IncrementQG.h"
19 #include "model/ModelQG.h"
20 #include "model/QgFortran.h"
21 #include "model/QgTraits.h"
22 #include "model/StateQG.h"
23 #include "oops/util/abor1_cpp.h"
24 #include "oops/util/DateTime.h"
25 #include "oops/util/Logger.h"
26 
27 namespace qg {
28 // -----------------------------------------------------------------------------
30 // -----------------------------------------------------------------------------
31 TlmQG::TlmQG(const GeometryQG & resol, const eckit::Configuration & tlConf)
32  : keyConfig_(0), tstep_(), resol_(resol), traj_(),
33  lrmodel_(resol_, eckit::LocalConfiguration(tlConf, "trajectory")),
34  linvars_(std::vector<std::string>{"x", "q", "u", "v"})
35 {
36  tstep_ = util::Duration(tlConf.getString("tstep"));
37 
38  const eckit::Configuration * configc = &tlConf;
39  qg_setup_f90(&configc, resol_.toFortran(), keyConfig_);
40 
41  oops::Log::trace() << "TlmQG created" << std::endl;
42 }
43 // -----------------------------------------------------------------------------
46  for (trajIter jtra = traj_.begin(); jtra != traj_.end(); ++jtra) {
47  qg_wipe_traj_f90(jtra->second);
48  }
49  oops::Log::trace() << "TlmQG destructed" << std::endl;
50 }
51 // -----------------------------------------------------------------------------
52 void TlmQG::setTrajectory(const StateQG & xx, StateQG & xlr, const ModelBias & bias) {
53 // StateQG xlr(resol_, xx);
54  xlr.changeResolution(xx);
55  int ftraj = lrmodel_.saveTrajectory(xlr, bias);
56  traj_[xx.validTime()] = ftraj;
57 
58 // should be in print method
59  std::vector<double> zstat(15);
60  qg_traj_minmaxrms_f90(ftraj, zstat[0]);
61  oops::Log::debug() << "TlmQG trajectory at time " << xx.validTime() << std::endl;
62  for (unsigned int jj = 0; jj < 5; ++jj) {
63  oops::Log::debug() << " Min=" << zstat[3*jj] << ", Max=" << zstat[3*jj+1]
64  << ", RMS=" << zstat[3*jj+2] << std::endl;
65  }
66 // should be in print method
67 }
68 // -----------------------------------------------------------------------------
69 void TlmQG::initializeTL(IncrementQG & dx) const {
70  ASSERT(dx.fields().isForModel(false));
72  oops::Log::debug() << "TlmQG::initializeTL" << dx.fields() << std::endl;
73 }
74 // -----------------------------------------------------------------------------
75 void TlmQG::stepTL(IncrementQG & dx, const ModelBiasIncrement &) const {
76  trajICst itra = traj_.find(dx.validTime());
77  if (itra == traj_.end()) {
78  oops::Log::error() << "TlmQG: trajectory not available at time " << dx.validTime() << std::endl;
79  ABORT("TlmQG: trajectory not available");
80  }
81  ASSERT(dx.fields().isForModel(false));
82  oops::Log::debug() << "TlmQG::stepTL fields in" << dx.fields() << std::endl;
83  qg_propagate_tl_f90(keyConfig_, dx.fields().toFortran(), itra->second);
84  oops::Log::debug() << "TlmQG::stepTL fields out" << dx.fields() << std::endl;
85  dx.validTime() += tstep_;
86 }
87 // -----------------------------------------------------------------------------
88 void TlmQG::finalizeTL(IncrementQG & dx) const {
89  oops::Log::debug() << "TlmQG::finalizeTL" << dx.fields() << std::endl;
90 }
91 // -----------------------------------------------------------------------------
92 void TlmQG::initializeAD(IncrementQG & dx) const {
93  ASSERT(dx.fields().isForModel(false));
94  oops::Log::debug() << "TlmQG::initializeAD" << dx.fields() << std::endl;
95 }
96 // -----------------------------------------------------------------------------
98  dx.validTime() -= tstep_;
99  trajICst itra = traj_.find(dx.validTime());
100  if (itra == traj_.end()) {
101  oops::Log::error() << "TlmQG: trajectory not available at time " << dx.validTime() << std::endl;
102  ABORT("TlmQG: trajectory not available");
103  }
104  ASSERT(dx.fields().isForModel(false));
105  oops::Log::debug() << "TlmQG::stepAD fields in" << dx.fields() << std::endl;
106  qg_propagate_ad_f90(keyConfig_, dx.fields().toFortran(), itra->second);
107  oops::Log::debug() << "TlmQG::stepAD fields out" << dx.fields() << std::endl;
108 }
109 // -----------------------------------------------------------------------------
110 void TlmQG::finalizeAD(IncrementQG & dx) const {
112  oops::Log::debug() << "TlmQG::finalizeAD" << dx.fields() << std::endl;
113 }
114 // -----------------------------------------------------------------------------
115 void TlmQG::print(std::ostream & os) const {
116  os << "QG TLM Trajectory, nstep=" << traj_.size() << std::endl;
117  typedef std::map< util::DateTime, int >::const_iterator trajICst;
118  if (traj_.size() > 0) {
119  os << "QG TLM Trajectory: times are:";
120  for (trajICst jtra = traj_.begin(); jtra != traj_.end(); ++jtra) {
121  os << " " << jtra->first;
122  }
123  }
124 }
125 // -----------------------------------------------------------------------------
126 } // namespace qg
void stepTL(IncrementQG &, const ModelBiasIncrement &) const override
Definition: TlmQG.cc:75
int & toFortran()
Definition: FieldsQG.h:96
Model error for the QG model.
void qg_prepare_integration_ad_f90(const F90model &, const F90flds &)
FieldsQG & fields()
Access to fields.
Definition: IncrementQG.h:102
int saveTrajectory(StateQG &, const ModelBias &) const
Definition: ModelQG.cc:65
void print(std::ostream &) const override
Definition: TlmQG.cc:115
void qg_propagate_ad_f90(const F90model &, const F90flds &, const F90traj &)
subroutine std(a, mean, stdv, area)
const ModelQG lrmodel_
Definition: TlmQG.h:78
~TlmQG()
Definition: TlmQG.cc:44
std::map< util::DateTime, int >::iterator trajIter
Definition: TlmQG.h:70
bool isForModel(const bool &) const
Definition: FieldsQG.cc:213
const util::DateTime & validTime() const
Definition: StateQG.h:77
void initializeAD(IncrementQG &) const override
Definition: TlmQG.cc:92
logical debug
Definition: mpp.F90:1297
F90model keyConfig_
Definition: TlmQG.h:74
void initializeTL(IncrementQG &) const override
Run TLM and its adjoint.
Definition: TlmQG.cc:69
static oops::LinearModelMaker< QgTraits, TlmQG > makerQGTLM_("QgTLM")
void qg_setup_f90(const eckit::Configuration *const *, const F90geom &, F90model &)
void qg_prepare_integration_tl_f90(const F90model &, const F90flds &)
const util::DateTime & validTime() const
Definition: IncrementQG.h:92
integer error
Definition: mpp.F90:1310
void qg_traj_minmaxrms_f90(const F90traj &, double &)
void stepAD(IncrementQG &, ModelBiasIncrement &) const override
Definition: TlmQG.cc:97
void finalizeTL(IncrementQG &) const override
Definition: TlmQG.cc:88
QG model state.
Definition: StateQG.h:50
void qg_propagate_tl_f90(const F90model &, const F90flds &, const F90traj &)
void qg_wipe_traj_f90(F90traj &)
void setTrajectory(const StateQG &, StateQG &, const ModelBias &) override
Model trajectory computation.
Definition: TlmQG.cc:52
GeometryQG handles geometry for QG model.
Definition: GeometryQG.h:33
void qg_delete_f90(F90model &)
TlmQG(const GeometryQG &, const eckit::Configuration &)
Definition: TlmQG.cc:31
util::Duration tstep_
Definition: TlmQG.h:75
std::map< util::DateTime, int >::const_iterator trajICst
Definition: TlmQG.h:71
void changeResolution(const StateQG &xx)
Interpolate full fields.
Definition: StateQG.cc:102
std::map< util::DateTime, F90traj > traj_
Definition: TlmQG.h:77
The namespace for the qg model.
void finalizeAD(IncrementQG &) const override
Definition: TlmQG.cc:110
Increment Class: Difference between two states.
Definition: IncrementQG.h:55