FV3 Bundle
TlmFV3JEDI.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017 UCAR
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  */
7 
8 #include <vector>
9 
10 #include "eckit/config/LocalConfiguration.h"
11 
12 #include "oops/util/abor1_cpp.h"
13 #include "oops/util/DateTime.h"
14 #include "oops/util/Logger.h"
15 
16 #include "FV3JEDITraits.h"
17 #include "TlmFV3JEDIFortran.h"
18 #include "GeometryFV3JEDI.h"
19 #include "IncrementFV3JEDI.h"
20 #include "ModelFV3JEDI.h"
21 #include "StateFV3JEDI.h"
22 #include "src/Model/TlmFV3JEDI.h"
23 #include "UtilitiesFV3JEDI.h"
24 
25 namespace fv3jedi {
26 
27 // -----------------------------------------------------------------------------
29  makerFV3JEDITLM_("FV3JEDITLM");
30 // -----------------------------------------------------------------------------
32  const eckit::Configuration & tlConf)
33  : keyConfig_(0), tstep_(), resol_(resol), traj_(),
34  lrmodel_(resol_, eckit::LocalConfiguration(tlConf, "trajectory")),
35  linvars_(std::vector<std::string>{"ua", "va", "t", "ps",
36  "q", "qi", "ql", "o3"})
37 {
38  tstep_ = util::Duration(tlConf.getString("tstep"));
39 
40  const eckit::Configuration * configc = &tlConf;
41  stageFv3Files(tlConf);
42  fv3jedi_tlm_create_f90(&configc, resol_.toFortran(), keyConfig_);
44  oops::Log::trace() << "TlmFV3JEDI created" << std::endl;
45 }
46 // -----------------------------------------------------------------------------
49  for (trajIter jtra = traj_.begin(); jtra != traj_.end(); ++jtra) {
50  fv3jedi_traj_wipe_f90(jtra->second);
51  }
52  oops::Log::trace() << "TlmFV3JEDI destructed" << std::endl;
53 }
54 // -----------------------------------------------------------------------------
56  const ModelBiasFV3JEDI & bias) {
57 // StateFV3JEDI xlr(resol_, xx);
58  xlr.changeResolution(xx);
59  int ftraj = lrmodel_.saveTrajectory(xlr, bias);
60  traj_[xx.validTime()] = ftraj;
61 
62 // should be in print method
63  std::vector<double> zstat(15);
64 // fv3jedi_traj_minmaxrms_f90(ftraj, zstat[0]);
65  oops::Log::debug() << "TlmFV3JEDI trajectory at time "
66  << xx.validTime() << std::endl;
67  for (unsigned int jj = 0; jj < 5; ++jj) {
68  oops::Log::debug() << " Min=" << zstat[3*jj] << ", Max=" << zstat[3*jj+1]
69  << ", RMS=" << zstat[3*jj+2] << std::endl;
70  }
71 // should be in print method
72 }
73 // -----------------------------------------------------------------------------
76  oops::Log::debug() << "TlmFV3JEDI::initializeTL" << std::endl;
77 }
78 // -----------------------------------------------------------------------------
80  const ModelBiasIncrementFV3JEDI &) const {
81  trajICst itra = traj_.find(dx.validTime());
82  if (itra == traj_.end()) {
83  oops::Log::error() << "TlmFV3JEDI: trajectory not available at time "
84  << dx.validTime() << std::endl;
85  ABORT("TlmFV3JEDI: trajectory not available");
86  }
88  dx.toFortran(),
89  itra->second);
90  dx.validTime() += tstep_;
91 }
92 // -----------------------------------------------------------------------------
95  oops::Log::debug() << "TlmFV3JEDI::finalizeTL" << std::endl;
96 }
97 // -----------------------------------------------------------------------------
100  oops::Log::debug() << "TlmFV3JEDI::initializeAD" << std::endl;
101 }
102 // -----------------------------------------------------------------------------
104  const {
105  dx.validTime() -= tstep_;
106  trajICst itra = traj_.find(dx.validTime());
107  if (itra == traj_.end()) {
108  oops::Log::error() << "TlmFV3JEDI: trajectory not available at time "
109  << dx.validTime() << std::endl;
110  ABORT("TlmFV3JEDI: trajectory not available");
111  }
113  dx.toFortran(),
114  itra->second);
115 }
116 // -----------------------------------------------------------------------------
119  oops::Log::debug() << "TlmFV3JEDI::finalizeAD" << std::endl;
120 }
121 // -----------------------------------------------------------------------------
122 void TlmFV3JEDI::print(std::ostream & os) const {
123  os << "FV3JEDI TLM Trajectory, nstep=" << traj_.size() << std::endl;
124  typedef std::map< util::DateTime, int >::const_iterator trajICst;
125  if (traj_.size() > 0) {
126  os << "FV3JEDI TLM Trajectory: times are:";
127  for (trajICst jtra = traj_.begin(); jtra != traj_.end(); ++jtra) {
128  os << " " << jtra->first;
129  }
130  }
131 }
132 // -----------------------------------------------------------------------------
133 } // namespace fv3jedi
void fv3jedi_tlm_delete_f90(F90tlm &)
void stepTL(IncrementFV3JEDI &, const ModelBiasIncrementFV3JEDI &) const override
Definition: TlmFV3JEDI.cc:79
void removeFv3Files()
void stageFv3Files(const eckit::Configuration &conf)
void initializeAD(IncrementFV3JEDI &) const override
Definition: TlmFV3JEDI.cc:98
TlmFV3JEDI(const GeometryFV3JEDI &, const eckit::Configuration &)
Definition: TlmFV3JEDI.cc:31
subroutine std(a, mean, stdv, area)
void print(std::ostream &) const override
Definition: TlmFV3JEDI.cc:122
const ModelFV3JEDI lrmodel_
Definition: TlmFV3JEDI.h:76
std::map< util::DateTime, int >::iterator trajIter
Definition: TlmFV3JEDI.h:68
Model error for the FV3JEDI model.
void fv3jedi_tlm_initialize_tl_f90(const F90geom &, const F90tlm &, const F90inc &)
util::Duration tstep_
Definition: TlmFV3JEDI.h:73
logical debug
Definition: mpp.F90:1297
void changeResolution(const StateFV3JEDI &xx)
Interpolate full state.
void initializeTL(IncrementFV3JEDI &) const override
Run TLM and its adjoint.
Definition: TlmFV3JEDI.cc:74
void fv3jedi_tlm_create_f90(const eckit::Configuration *const *, const F90geom &, F90tlm &)
void fv3jedi_tlm_step_tl_f90(const F90geom &, const F90tlm &, const F90inc &, const F90traj &)
void fv3jedi_tlm_step_ad_f90(const F90geom &, const F90tlm &, const F90inc &, const F90traj &)
static oops::LinearModelMaker< FV3JEDITraits, TlmFV3JEDI > makerFV3JEDITLM_("FV3JEDITLM")
void stepAD(IncrementFV3JEDI &, ModelBiasIncrementFV3JEDI &) const override
Definition: TlmFV3JEDI.cc:103
integer error
Definition: mpp.F90:1310
const util::DateTime & validTime() const
Definition: StateFV3JEDI.h:91
void fv3jedi_tlm_initialize_ad_f90(const F90geom &, const F90tlm &, const F90inc &)
std::map< util::DateTime, F90traj > traj_
Definition: TlmFV3JEDI.h:75
std::map< util::DateTime, int >::const_iterator trajICst
Definition: TlmFV3JEDI.h:69
const GeometryFV3JEDI resol_
Definition: TlmFV3JEDI.h:74
void finalizeAD(IncrementFV3JEDI &) const override
Definition: TlmFV3JEDI.cc:117
int saveTrajectory(StateFV3JEDI &, const ModelBiasFV3JEDI &) const
Definition: ModelFV3JEDI.cc:63
GeometryFV3JEDI handles geometry for FV3JEDI model.
void finalizeTL(IncrementFV3JEDI &) const override
Definition: TlmFV3JEDI.cc:93
void fv3jedi_tlm_finalize_ad_f90(const F90geom &, const F90tlm &, const F90inc &)
void fv3jedi_traj_wipe_f90(F90traj &)
void setTrajectory(const StateFV3JEDI &, StateFV3JEDI &, const ModelBiasFV3JEDI &) override
Model trajectory computation.
Definition: TlmFV3JEDI.cc:55
void fv3jedi_tlm_finalize_tl_f90(const F90geom &, const F90tlm &, const F90inc &)
F90model keyConfig_
Definition: TlmFV3JEDI.h:72
const util::DateTime & validTime() const