FV3 Bundle
src/lorenz95/ModelL95.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 
12 #include "eckit/config/Configuration.h"
13 
14 #include "lorenz95/FieldL95.h"
15 #include "lorenz95/ModelBias.h"
16 #include "lorenz95/ModelL95.h"
18 #include "lorenz95/Resolution.h"
19 #include "lorenz95/StateL95.h"
20 
21 #include "oops/util/Duration.h"
22 #include "oops/util/Logger.h"
23 
24 namespace lorenz95 {
25 
26 // -----------------------------------------------------------------------------
28 
29 // -----------------------------------------------------------------------------
30 
31 ModelL95::ModelL95(const Resolution & resol, const eckit::Configuration & config)
32  : resol_(resol), f_(config.getDouble("f")),
33  tstep_(util::Duration(config.getString("tstep"))),
34  dt_(tstep_.toSeconds()/432000.0), vars_(config)
35 {
36  oops::Log::info() << *this << std::endl;
37  oops::Log::trace() << "ModelL95::ModelL95 created" << std::endl;
38 }
39 
40 // -----------------------------------------------------------------------------
42 {
43  oops::Log::trace() << "ModelL95::~ModelL95 destructed" << std::endl;
44 }
45 // -----------------------------------------------------------------------------
47 void ModelL95::finalize(StateL95 &) const {}
48 // -----------------------------------------------------------------------------
49 void ModelL95::step(StateL95 & xx, const ModelBias & bias) const {
50  ModelTrajectory traj(false);
51  this->stepRK(xx.getField(), bias, traj);
52  xx.validTime() += tstep_;
53 }
54 // -----------------------------------------------------------------------------
55 
56 void ModelL95::stepRK(FieldL95 & xx, const ModelBias & bias,
57  ModelTrajectory & traj) const {
58  FieldL95 dx(xx, false);
59  FieldL95 zz(xx, false);
60  FieldL95 dz(xx, false);
61 
62  zz = xx;
63  traj.set(zz);
64  this->tendencies(zz, bias.bias(), dz);
65  dx = dz;
66 
67  zz = xx;
68  zz.axpy(0.5, dz);
69  traj.set(zz);
70  this->tendencies(zz, bias.bias(), dz);
71  dx.axpy(2.0, dz);
72 
73  zz = xx;
74  zz.axpy(0.5, dz);
75  traj.set(zz);
76  this->tendencies(zz, bias.bias(), dz);
77  dx.axpy(2.0, dz);
78 
79  zz = xx;
80  zz += dz;
81  traj.set(zz);
82  this->tendencies(zz, bias.bias(), dz);
83  dx += dz;
84 
85  const double zt = 1.0/6.0;
86  xx.axpy(zt, dx);
87 }
88 
89 // -----------------------------------------------------------------------------
90 
91 void ModelL95::tendencies(const FieldL95 & xx, const double & bias,
92  FieldL95 & dx) const {
93  const int nn = resol_.npoints();
94  for (int jj = 0; jj < nn; ++jj) {
95  int jm2 = jj - 2;
96  int jm1 = jj - 1;
97  int jp1 = jj + 1;
98  if (jm2 < 0) jm2 += nn;
99  if (jm1 < 0) jm1 += nn;
100  if (jp1 >= nn) jp1 -= nn;
101  const double dxdt = -xx[jm2] * xx[jm1] + xx[jm1] * xx[jp1] - xx[jj] + f_ - bias;
102  dx[jj] = dt_ * dxdt;
103  }
104 }
105 
106 // -----------------------------------------------------------------------------
107 
108 void ModelL95::print(std::ostream & os) const {
109  os << "ModelL95: resol = " << resol_ << ", f = " << f_ << ", tstep = " << tstep_;
110 }
111 
112 // -----------------------------------------------------------------------------
113 
114 } // namespace lorenz95
void stepRK(FieldL95 &, const ModelBias &, ModelTrajectory &) const
static oops::ModelMaker< L95Traits, ModelL95 > makermodel_("L95")
const util::Duration tstep_
Definition: ModelL95.h:63
const util::DateTime & validTime() const
Definition: StateL95.h:81
ModelL95(const Resolution &, const eckit::Configuration &)
const FieldL95 & getField() const
Definition: StateL95.h:71
const double dt_
Definition: ModelL95.h:64
const double f_
Definition: ModelL95.h:62
void finalize(StateL95 &) const
void step(StateL95 &, const ModelBias &) const
Handles resolution.
Definition: Resolution.h:25
void print(std::ostream &) const
const Resolution resol_
Definition: ModelL95.h:61
int npoints() const
Definition: Resolution.h:37
subroutine, public info(self)
void tendencies(const FieldL95 &, const double &, FieldL95 &) const
The namespace for the L95 model.
const double & bias() const
Model error for Lorenz 95 model.
L95 model trajectory.
L95 model state.
Definition: StateL95.h:50
void set(const FieldL95 &)
Save trajectory.
void initialize(StateL95 &) const
void axpy(const double &, const FieldL95 &)
Definition: FieldL95.cc:125
Class to represent fields for the L95 model.
Definition: FieldL95.h:36