OOPS
LocalizationMatrixL95.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  * (C) Copyright 2020-2020 UCAR
4  *
5  * This software is licensed under the terms of the Apache Licence Version 2.0
6  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
7  * In applying this licence, ECMWF does not waive the privileges and immunities
8  * granted to it by virtue of its status as an intergovernmental organisation nor
9  * does it submit to any jurisdiction.
10  */
11 
13 
14 #include <unsupported/Eigen/FFT>
15 #include <algorithm>
16 #include <cmath>
17 
18 #include "eckit/config/Configuration.h"
19 #include "eckit/exception/Exceptions.h"
20 
21 #include "lorenz95/IncrementL95.h"
22 #include "lorenz95/Resolution.h"
23 
24 // -----------------------------------------------------------------------------
25 namespace lorenz95 {
26 // -----------------------------------------------------------------------------
27 
29  const eckit::Configuration & config)
30  : resol_(resol.npoints()),
31  rscale_(1.0/config.getDouble("length_scale"))
32 {
33 // Gaussian structure function
34  unsigned int size = resol_/2+1;
35  std::vector<double> locfct(resol_);
36  for (unsigned int jj = 0; jj < resol_; ++jj) {
37  double zz = rscale_ * std::min(jj, resol_-jj);
38  locfct[jj] = std::exp(-0.5*zz*zz);
39  }
40 // Go to Fourier space
41  Eigen::FFT<double> fft;
42  std::vector<std::complex<double> > four(size);
43  fft.fwd(four, locfct);
44 // Save Fourier coefficients
45  coefs_.resize(size);
46  for (unsigned int jj = 0; jj < size; ++jj) {
47  coefs_[jj] = std::real(four[jj]);
48  }
49 }
50 
51 // -----------------------------------------------------------------------------
52 
54  unsigned int size = resol_/2+1;
55  Eigen::FFT<double> fft;
56  std::vector<std::complex<double> > four(size);
57  fft.fwd(four, dx.asVector());
58  for (unsigned int jj = 0; jj < size; ++jj) {
59  four[jj] *= coefs_[jj];
60  }
61  fft.inv(dx.asVector(), four);
62 }
63 
64 // -----------------------------------------------------------------------------
65 
66 void LocalizationMatrixL95::print(std::ostream & os) const {
67  os << "LocalizationMatrixL95::print not implemented";
68 }
69 
70 // -----------------------------------------------------------------------------
71 
72 } // namespace lorenz95
lorenz95::LocalizationMatrixL95::coefs_
std::vector< double > coefs_
Definition: LocalizationMatrixL95.h:46
lorenz95::IncrementL95::asVector
std::vector< double > & asVector()
Definition: IncrementL95.h:108
lorenz95::Resolution
Handles resolution.
Definition: Resolution.h:42
LocalizationMatrixL95.h
lorenz95::LocalizationMatrixL95::resol_
const unsigned int resol_
Definition: LocalizationMatrixL95.h:44
lorenz95::IncrementL95
Increment Class: Difference between two states.
Definition: IncrementL95.h:60
IncrementL95.h
lorenz95::LocalizationMatrixL95::rscale_
const double rscale_
Definition: LocalizationMatrixL95.h:45
lorenz95::LocalizationMatrixL95::print
void print(std::ostream &) const override
Definition: LocalizationMatrixL95.cc:66
lorenz95
The namespace for the L95 model.
Definition: l95/src/lorenz95/AnalyticInit.cc:17
Resolution.h
lorenz95::LocalizationMatrixL95::multiply
void multiply(IncrementL95 &) const
Definition: LocalizationMatrixL95.cc:53
lorenz95::LocalizationMatrixL95::LocalizationMatrixL95
LocalizationMatrixL95(const Resolution &, const eckit::Configuration &)
Definition: LocalizationMatrixL95.cc:28