OOPS
test/assimilation/SpectralLMP.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 Met Office UK
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 #ifndef TEST_ASSIMILATION_SPECTRALLMP_H_
9 #define TEST_ASSIMILATION_SPECTRALLMP_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #include <boost/ptr_container/ptr_vector.hpp>
15 
16 #define ECKIT_TESTING_SELF_REGISTER_CASES 0
17 
18 #include "eckit/config/LocalConfiguration.h"
19 #include "eckit/testing/Test.h"
20 
23 #include "oops/runs/Test.h"
24 #include "oops/util/Expect.h"
25 #include "oops/util/FloatCompare.h"
26 
28 
29 namespace test {
30 
31  void test_SpectralLMP(const eckit::LocalConfiguration &conf)
32  {
33  oops::SpectralLMP<Vector3D> spectralLMP(conf);
34 
35  // assign vectors following DRPLanczosMinimizer.h
36  boost::ptr_vector<Vector3D> hvecs;
37  boost::ptr_vector<Vector3D> vvecs;
38  boost::ptr_vector<Vector3D> zvecs;
39  std::vector<double> alphas;
40  std::vector<double> betas;
41 
42  // Simple case
43  hvecs.push_back(new Vector3D(1, 1, 1));
44  hvecs.push_back(new Vector3D(1, 1, 1));
45  hvecs.push_back(new Vector3D(1, 1, 1));
46  vvecs.push_back(new Vector3D(1, 1, 1));
47  vvecs.push_back(new Vector3D(1, 1, 1));
48  vvecs.push_back(new Vector3D(1, 1, 1));
49  zvecs.push_back(new Vector3D(1, 1, 1));
50  zvecs.push_back(new Vector3D(1, 1, 1));
51  zvecs.push_back(new Vector3D(1, 1, 1));
52 
53  alphas.push_back(1.0);
54  alphas.push_back(1.0);
55  betas.push_back(1.0);
56  betas.push_back(1.0);
57 
58  spectralLMP.update(vvecs, hvecs, zvecs, alphas, betas);
59 
60  Vector3D pr(1, 1, 1);
61  Vector3D zz(1, 1, 1);
62 
63  spectralLMP.multiply(pr, zz);
64 
65  // More complicated case
66  hvecs.clear();
67  vvecs.clear();
68  zvecs.clear();
69  alphas.clear();
70  betas.clear();
71  hvecs.push_back(new Vector3D(10, 1, -10));
72  hvecs.push_back(new Vector3D(1, 10, 100));
73  hvecs.push_back(new Vector3D(-5, 5, 20));
74  vvecs.push_back(new Vector3D(1, 3, 11));
75  vvecs.push_back(new Vector3D(-1, 2, 100));
76  vvecs.push_back(new Vector3D(6, 77, 7));
77  zvecs.push_back(new Vector3D(1, 10, 1));
78  zvecs.push_back(new Vector3D(1, 21, 21));
79  zvecs.push_back(new Vector3D(100, 3, 70));
80 
81  alphas.push_back(1000.0);
82  alphas.push_back(33.0);
83  betas.push_back(93.0);
84  betas.push_back(2.0);
85 
86  spectralLMP.update(vvecs, hvecs, zvecs, alphas, betas);
87 
88  Vector3D pr2(1, 3, 1);
89  Vector3D zz2(50, 1, 1);
90 
91  spectralLMP.multiply(pr2, zz2);
92  }
93 
94  class SpectralLMP : public oops::Test {
95  private:
96  std::string testid() const override {return "test::SpectralLMP";}
97 
98  void register_tests() const override {
99  std::vector<eckit::testing::Test>& ts = eckit::testing::specification();
100 
101  const eckit::LocalConfiguration conf(::test::TestEnvironment::config());
102  for (const std::string & testCaseName : conf.keys())
103  {
104  const eckit::LocalConfiguration testCaseConf(::test::TestEnvironment::config(),
105  testCaseName);
106  ts.emplace_back(CASE("SpectralLMP/" + testCaseName, testCaseConf)
107  {
108  test_SpectralLMP(testCaseConf);
109  });
110  }
111  }
112 
113  void clear() const override {}
114  };
115 
116 } // namespace test
117 
118 #endif // TEST_ASSIMILATION_SPECTRALLMP_H_
test::SpectralLMP::register_tests
void register_tests() const override
Definition: test/assimilation/SpectralLMP.h:98
test::SpectralLMP
Definition: test/assimilation/SpectralLMP.h:94
test::SpectralLMP::testid
std::string testid() const override
Definition: test/assimilation/SpectralLMP.h:96
SpectralLMP.h
test::CASE
CASE("test_linearmodelparameterswrapper_valid_name")
Definition: LinearModelFactory.cc:22
test::test_SpectralLMP
void test_SpectralLMP(const eckit::LocalConfiguration &conf)
Definition: test/assimilation/SpectralLMP.h:31
test::Vector3D
Definition: Vector3D.h:15
test
Definition: LinearModelFactory.cc:20
Test.h
test::SpectralLMP::clear
void clear() const override
Definition: test/assimilation/SpectralLMP.h:113
test::TestEnvironment::config
static const eckit::Configuration & config()
Definition: TestEnvironment.h:40
TestEnvironment.h
Vector3D.h
oops::Test
Definition: Test.h:39
oops::SpectralLMP::multiply
void multiply(const VECTOR &, VECTOR &) const
Definition: oops/assimilation/SpectralLMP.h:271
oops::SpectralLMP
The solvers represent matrices as objects that implement a "multiply" method.
Definition: oops/assimilation/SpectralLMP.h:50
oops::SpectralLMP::update
void update(boost::ptr_vector< VECTOR > &, boost::ptr_vector< VECTOR > &, boost::ptr_vector< VECTOR > &, std::vector< double > &, std::vector< double > &)
Definition: oops/assimilation/SpectralLMP.h:113