OOPS
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  os << " " << jtra->first;
115  int nx, ny, nz, nb, lq, lbc;
116  qg_fields_sizes_f90(jtra->second, nx, ny, nz, nb);
117  qg_fields_vars_f90(jtra->second, lq, lbc);
118  os << std::endl << " Resolution = " << nx << ", " << ny << ", " << nz;
119  if (lq == 1) {
120  os << std::endl << " Variable = potential vorticity";
121  } else {
122  os << std::endl << " Variable = streamfunction";
123  }
124  if (lbc == 1) {
125  os << std::endl << " Boundary conditions are activated";
126  } else {
127  os << std::endl << " Boundary conditions are not activated";
128  }
129  std::vector<double> zstat(4*(1+nb));
130  qg_fields_gpnorm_f90(jtra->second, nb, zstat[0]);
131  for (int jj = 0; jj < 1+nb; ++jj) {
132  std::ios_base::fmtflags f(os.flags());
133  os << std::endl << " Scaling=" << std::setprecision(4) << std::setw(7) << zstat[4*jj]
134  << ", Min=" << std::fixed << std::setprecision(4) << std::setw(12) << zstat[4*jj+1]
135  << ", Max=" << std::fixed << std::setprecision(4) << std::setw(12) <<zstat[4*jj+2]
136  << ", RMS=" << std::fixed << std::setprecision(4) << std::setw(12) <<zstat[4*jj+3];
137  os.flags(f);
138  }
139  }
140  }
141 }
142 // -----------------------------------------------------------------------------
143 } // namespace qg
qg::TlmQG::TlmQG
TlmQG(const GeometryQG &, const eckit::Configuration &)
Definition: TlmQG.cc:35
oops
The namespace for the main oops code.
Definition: ErrorCovarianceL95.cc:22
qg::TlmQG::stepTL
void stepTL(IncrementQG &, const ModelBiasIncrement &) const override
Definition: TlmQG.cc:69
qg::IncrementQG::validTime
const util::DateTime & validTime() const
Definition: IncrementQG.h:96
QgTraits.h
qg
The namespace for the qg model.
Definition: qg/model/AnalyticInit.cc:13
qg::StateQG
QG model state.
Definition: StateQG.h:42
QgFortran.h
qg::ModelBias
Model error for the QG model.
Definition: qg/model/ModelBias.h:43
qg::qg_model_setup_f90
void qg_model_setup_f90(F90model &, const eckit::Configuration &)
qg::TlmQG::trajICst
std::map< util::DateTime, int >::const_iterator trajICst
Definition: TlmQG.h:70
qg::qg_fields_delete_f90
void qg_fields_delete_f90(F90flds &)
qg::TlmQG::finalizeAD
void finalizeAD(IncrementQG &) const override
Definition: TlmQG.cc:104
qg::TlmQG::keyConfig_
F90model keyConfig_
Definition: TlmQG.h:73
qg::StateQG::changeResolution
void changeResolution(const StateQG &xx)
Interpolate full fields.
Definition: StateQG.cc:99
GeometryQG.h
qg::TlmQG::initializeTL
void initializeTL(IncrementQG &) const override
Run TLM and its adjoint.
Definition: TlmQG.cc:64
qg::FieldsQG::isForModel
bool isForModel(const bool &) const
Definition: FieldsQG.cc:206
qg::TlmQG::lrmodel_
const ModelQG lrmodel_
Definition: TlmQG.h:77
qg::TlmQG::setTrajectory
void setTrajectory(const StateQG &, StateQG &, const ModelBias &) override
Model trajectory computation.
Definition: TlmQG.cc:57
qg::qg_model_delete_f90
void qg_model_delete_f90(F90model &)
eckit
Definition: FieldL95.h:22
qg::qg_model_propagate_tl_f90
void qg_model_propagate_tl_f90(const F90model &, const F90flds &, const F90flds &)
qg::TlmQG::initializeAD
void initializeAD(IncrementQG &) const override
Definition: TlmQG.cc:86
qg::FieldsQG::toFortran
const int & toFortran() const
Definition: FieldsQG.h:99
qg::TlmQG::trajIter
std::map< util::DateTime, int >::iterator trajIter
Definition: TlmQG.h:69
qg::IncrementQG
Increment Class: Difference between two states.
Definition: IncrementQG.h:66
IncrementQG.h
qg::makerQGTLM_
static oops::LinearModelMaker< QgTraits, TlmQG > makerQGTLM_("QgTLM")
qg::ModelQG::saveTrajectory
int saveTrajectory(StateQG &, const ModelBias &) const
Definition: ModelQG.cc:61
qg::TlmQG::traj_
std::map< util::DateTime, F90flds > traj_
Definition: TlmQG.h:76
qg::TlmQG::finalizeTL
void finalizeTL(IncrementQG &) const override
Definition: TlmQG.cc:82
ModelQG.h
oops::LinearModelMaker
Definition: LinearModelBase.h:204
qg::qg_fields_vars_f90
void qg_fields_vars_f90(const F90flds &, int &, int &)
ModelBiasIncrement.h
StateQG.h
qg::IncrementQG::fields
FieldsQG & fields()
Access to fields.
Definition: IncrementQG.h:106
qg::qg_fields_gpnorm_f90
void qg_fields_gpnorm_f90(const F90flds &, const int &, double &)
qg::TlmQG::~TlmQG
~TlmQG()
Definition: TlmQG.cc:49
oops::Variables
Definition: oops/base/Variables.h:23
compare.error
int error
Definition: compare.py:168
qg::TlmQG::print
void print(std::ostream &) const override
Definition: TlmQG.cc:108
qg::qg_model_propagate_ad_f90
void qg_model_propagate_ad_f90(const F90model &, const F90flds &, const F90flds &)
qg::GeometryQG
GeometryQG handles geometry for QG model.
Definition: GeometryQG.h:54
qg::ModelBiasIncrement
Definition: ModelBiasIncrement.h:32
TlmQG.h
qg::StateQG::validTime
const util::DateTime & validTime() const
Definition: StateQG.h:64
qg::TlmQG::tstep_
util::Duration tstep_
Definition: TlmQG.h:74
qg::qg_fields_sizes_f90
void qg_fields_sizes_f90(const F90flds &, int &, int &, int &, int &)
qg::TlmQG::stepAD
void stepAD(IncrementQG &, ModelBiasIncrement &) const override
Definition: TlmQG.cc:91
qg::ModelQgParameters
Definition: ModelQG.h:40