OOPS
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 ModelL95Parameters & params)
32  : resol_(resol), f_(params.f),
33  tstep_(params.tstep),
34  dt_(tstep_.toSeconds()/432000.0), vars_({"x"})
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 #ifdef __INTEL_COMPILER
92 #pragma optimize("", off)
93 #endif
94 void ModelL95::tendencies(const FieldL95 & xx, const double & bias,
95  FieldL95 & dx) const {
96  const int nn = resol_.npoints();
97  // intel 19 is doing some agressive optimization of this loop that
98  // is modifying the solution.
99  for (int jj = 0; jj < nn; ++jj) {
100  int jm2 = jj - 2;
101  int jm1 = jj - 1;
102  int jp1 = jj + 1;
103  if (jm2 < 0) jm2 += nn;
104  if (jm1 < 0) jm1 += nn;
105  if (jp1 >= nn) jp1 -= nn;
106  const double dxdt = -xx[jm2] * xx[jm1] + xx[jm1] * xx[jp1] - xx[jj] + f_ - bias;
107  dx[jj] = dt_ * dxdt;
108  }
109 }
110 #ifdef __INTEL_COMPILER
111 #pragma optimize("", on)
112 #endif
113 
114 // -----------------------------------------------------------------------------
115 
116 void ModelL95::print(std::ostream & os) const {
117  os << "ModelL95: resol = " << resol_ << ", f = " << f_ << ", tstep = " << tstep_;
118 }
119 
120 // -----------------------------------------------------------------------------
121 
122 } // namespace lorenz95
lorenz95::ModelBias
Model error for Lorenz 95 model.
Definition: l95/src/lorenz95/ModelBias.h:41
lorenz95::ModelL95::stepRK
void stepRK(FieldL95 &, const ModelBias &, ModelTrajectory &) const
Definition: ModelL95.cc:56
lorenz95::ModelTrajectory
L95 model trajectory.
Definition: ModelTrajectory.h:26
FieldL95.h
lorenz95::Resolution
Handles resolution.
Definition: Resolution.h:42
ModelL95.h
lorenz95::ModelL95::resol_
const Resolution resol_
Definition: ModelL95.h:75
lorenz95::StateL95
L95 model state.
Definition: StateL95.h:53
lorenz95::ModelL95Parameters
Definition: ModelL95.h:38
lorenz95::ModelL95::f_
const double f_
Definition: ModelL95.h:76
oops::ModelMaker
A subclass of ModelFactory able to create instances of T (a concrete subclass of ModelBase<MODEL>).
Definition: ModelBase.h:172
lorenz95::ModelL95::tendencies
void tendencies(const FieldL95 &, const double &, FieldL95 &) const
Definition: ModelL95.cc:94
lorenz95::StateL95::validTime
const util::DateTime & validTime() const
Definition: StateL95.h:79
lorenz95::StateL95::getField
const FieldL95 & getField() const
Definition: StateL95.h:69
lorenz95::ModelL95::finalize
void finalize(StateL95 &) const
Definition: ModelL95.cc:47
lorenz95::ModelTrajectory::set
void set(const FieldL95 &)
Save trajectory.
Definition: ModelTrajectory.cc:23
lorenz95::Resolution::npoints
int npoints() const
Definition: Resolution.h:50
lorenz95::FieldL95::axpy
void axpy(const double &, const FieldL95 &)
Definition: FieldL95.cc:130
lorenz95::ModelL95::~ModelL95
~ModelL95()
Definition: ModelL95.cc:41
lorenz95::ModelL95::step
void step(StateL95 &, const ModelBias &) const
Definition: ModelL95.cc:49
lorenz95::makermodel_
static oops::ModelMaker< L95Traits, ModelL95 > makermodel_("L95")
StateL95.h
lorenz95::ModelL95::initialize
void initialize(StateL95 &) const
Definition: ModelL95.cc:46
lorenz95::ModelL95::dt_
const double dt_
Definition: ModelL95.h:78
lorenz95::ModelBias::bias
const double & bias() const
Definition: l95/src/lorenz95/ModelBias.h:52
ModelBias.h
lorenz95::ModelL95::tstep_
const util::Duration tstep_
Definition: ModelL95.h:77
ModelTrajectory.h
lorenz95::ModelL95::print
void print(std::ostream &) const
Print; used for logging.
Definition: ModelL95.cc:116
lorenz95::FieldL95
Class to represent fields for the L95 model.
Definition: FieldL95.h:34
lorenz95
The namespace for the L95 model.
Definition: l95/src/lorenz95/AnalyticInit.cc:17
Resolution.h
lorenz95::ModelL95::ModelL95
ModelL95(const Resolution &, const ModelL95Parameters &)
Definition: ModelL95.cc:31