FV3 Bundle
ErrorCovarianceL95.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 
12 
13 #include <algorithm>
14 #include <cmath>
15 
16 #include "eckit/config/Configuration.h"
17 #include "lorenz95/IncrementL95.h"
18 #include "lorenz95/Resolution.h"
19 #include "lorenz95/StateL95.h"
20 #include "oops/util/Logger.h"
21 
22 namespace oops {
23 class Variables;
24 }
25 
26 // -----------------------------------------------------------------------------
27 namespace lorenz95 {
28 // -----------------------------------------------------------------------------
30  const eckit::Configuration & config,
31  const StateL95 &, const StateL95 &) :
32  time_(util::DateTime(config.getString("date"))),
33  sigmab_(config.getDouble("standard_deviation")),
34  rscale_(1.0/config.getDouble("length_scale"))
35 {
36 // Gaussian structure function
37  resol_ = geom.npoints();
38  size_ = resol_/2+1;
39  std::vector<double> structFct(resol_);
40  for (unsigned int jj = 0; jj < resol_; ++jj) {
41  double zz = rscale_ * std::min(jj, resol_-jj);
42  structFct[jj] = std::exp(-0.5*zz*zz);
43  }
44 // Go to Fourier space
45  std::vector<std::complex<double> > coefs(size_);
46  fft_.fwd(coefs, structFct);
47 // Save Fourier coefficients
48  bcoefs_.resize(size_);
49  for (unsigned int jj = 0; jj < size_; ++jj) {
50  bcoefs_[jj] = std::real(coefs[jj]);
51  }
52 }
53 // -----------------------------------------------------------------------------
55 // -----------------------------------------------------------------------------
57  IncrementL95 & dxout) const {
58  std::vector<std::complex<double> > coefs(resol_);
59  fft_.fwd(coefs, dxin.asVector());
60  for (unsigned int jj = 0; jj < size_; ++jj) {
61  coefs[jj] *= bcoefs_[jj];
62  }
63  fft_.inv(dxout.asVector(), coefs);
64  double var = sigmab_ * sigmab_;
65  dxout *= var;
66 }
67 // -----------------------------------------------------------------------------
69  IncrementL95 & dxout) const {
70  std::vector<std::complex<double> > coefs(resol_);
71  fft_.fwd(coefs, dxin.asVector());
72  for (unsigned int jj = 0; jj < size_; ++jj) {
73  coefs[jj] /= bcoefs_[jj];
74  }
75  fft_.inv(dxout.asVector(), coefs);
76  double vari = 1.0 / (sigmab_ * sigmab_);
77  dxout *= vari;
78 }
79 // -----------------------------------------------------------------------------
81  dx.random();
82  std::vector<std::complex<double> > coefs(resol_);
83  fft_.fwd(coefs, dx.asVector());
84  for (unsigned int jj = 0; jj < size_; ++jj) {
85  coefs[jj] *= std::sqrt(bcoefs_[jj]);
86  }
87  fft_.inv(dx.asVector(), coefs);
88  dx *= sigmab_;
89 }
90 // -----------------------------------------------------------------------------
91 void ErrorCovarianceL95::print(std::ostream & os) const {
92  os << "ErrorCovarianceL95: time = " << time_ << ", std dev = " << sigmab_
93  << ", length scale = " << 1.0/rscale_ << std::endl;
94 }
95 // -----------------------------------------------------------------------------
96 
97 } // namespace lorenz95
Increment Class: Difference between two states.
Definition: IncrementL95.h:51
Handles resolution.
Definition: Resolution.h:25
The namespace for the main oops code.
int npoints() const
Definition: Resolution.h:37
void inverseMultiply(const IncrementL95 &, IncrementL95 &) const
The namespace for the L95 model.
std::vector< double > & asVector()
Definition: IncrementL95.h:103
void print(std::ostream &) const
L95 model state.
Definition: StateL95.h:50
void multiply(const IncrementL95 &, IncrementL95 &) const
ErrorCovarianceL95(const Resolution &, const oops::Variables &, const eckit::Configuration &, const StateL95 &, const StateL95 &)
#define min(a, b)
Definition: mosaic_util.h:32
std::vector< double > bcoefs_
void randomize(IncrementL95 &) const