FV3 Bundle
test/lorenz95/TLML95.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 #include <fstream>
12 #include <iostream>
13 
14 #include <boost/scoped_ptr.hpp>
15 #include <boost/test/unit_test.hpp>
16 
17 #include "./TestConfig.h"
18 #include "eckit/config/LocalConfiguration.h"
19 #include "lorenz95/ModelBias.h"
22 #include "lorenz95/ModelL95.h"
24 #include "lorenz95/Resolution.h"
25 #include "lorenz95/StateL95.h"
26 #include "lorenz95/TLML95.h"
27 #include "oops/util/DateTime.h"
28 #include "oops/util/Duration.h"
29 #include "test/TestFixture.h"
30 
31 namespace test {
32 
33 // -----------------------------------------------------------------------------
35  public:
37  eckit::LocalConfiguration res(TestConfig::config(), "resolution");
38  resol_.reset(new lorenz95::Resolution(res));
39  eckit::LocalConfiguration mod(TestConfig::config(), "model");
40  model_.reset(new lorenz95::ModelL95(*resol_, mod));
41  tlconf_.reset(new eckit::LocalConfiguration(TestConfig::config(), "linearmodel"));
42  }
44  boost::scoped_ptr<lorenz95::ModelL95> model_;
45  boost::scoped_ptr<lorenz95::Resolution> resol_;
46  boost::scoped_ptr<const eckit::LocalConfiguration> tlconf_;
47 };
48 // -----------------------------------------------------------------------------
49 
50 // -----------------------------------------------------------------------------
51 BOOST_FIXTURE_TEST_SUITE(test_tlmL95, TlmTestFixture)
52 // -----------------------------------------------------------------------------
53  BOOST_AUTO_TEST_CASE(test_tlmL95_constructor) {
54  boost::scoped_ptr<lorenz95::TLML95> tlm(new lorenz95::TLML95(*resol_, *tlconf_));
55  BOOST_CHECK(tlm.get() != NULL);
56  }
57 // -----------------------------------------------------------------------------
58 /*
59  BOOST_AUTO_TEST_CASE(test_tlmL95_set_get_Trajectory) {
60  lorenz95::TLML95 tlm(*resol_, *tlconf_, *model_);
61 
62  // construct a StateL95 object
63  std::string date_string("2014-09-12T09:35:00Z");
64  util::DateTime dt(date_string);
65  oops::Variables vars();
66  boost::scoped_ptr<lorenz95::StateL95> stateL95(new lorenz95::StateL95(*resol_, vars, dt));
67 
68  // construct a ModelBias object
69  boost::shared_ptr<const eckit::LocalConfiguration> biasCfg(new eckit::LocalConfiguration(TestConfig::config(), "ModelBias"));
70  boost::scoped_ptr<lorenz95::ModelBias> modelBias(new lorenz95::ModelBias(*biasCfg, *resol_));
71 
72  tlm.setTrajectory(*stateL95, *modelBias);
73 
74  boost::scoped_ptr<lorenz95::ModelTrajectory> modelTraj(new lorenz95::ModelTrajectory(true));
75  std::cout << "PMC: getTraj result <" << tlm.getTrajectory(dt)->get(1) << ">" << std::endl;
76  modelTraj->set(tlm.getTrajectory(dt)->get(1));
77  //std::cout << "PMC: modelTraj 1st " << modelTraj->get(1)
78  std::cout << "PMC: modelTraj resol <" << modelTraj->get(1).resol() << ">" << std::endl;
79  for(int i = 0; i < modelTraj->get(1).resol(); ++i) {
80  std::cout << "PMC: modelTraj FieldL95 elements " << modelTraj->get(1)[i] << std::endl;
81  }
82  }
83 */
84 // -----------------------------------------------------------------------------
85 /*
86  BOOST_AUTO_TEST_CASE(test_tlmL95_stepTL) {
87  lorenz95::TLML95 tlm(*resol_, *tlconf_, *model_);
88 
89  // construct a FieldL95 object
90  boost::scoped_ptr<lorenz95::FieldL95> fieldL95(new lorenz95::FieldL95(*resol_));
91 
92  // construct a datetime object
93  std::string dateString("2014-10-08T11:25:45Z");
94  util::DateTime dt(dateString);
95 
96  //construct a ModelBiasCorrection object
97  boost::scoped_ptr<const eckit::LocalConfiguration> covarCfg(new eckit::LocalConfiguration(TestConfig::config(), "Covariance"));
98  boost::scoped_ptr<lorenz95::ModelBiasCovariance> modelBiasCovariance(
99  new lorenz95::ModelBiasCovariance(*covarCfg, *resol_));
100  boost::scoped_ptr<lorenz95::ModelBiasCorrection> modelBiasCorrection(
101  new lorenz95::ModelBiasCorrection(*modelBiasCovariance));
102 
103  tlm.stepTL(*fieldL95, dt, *modelBiasCorrection);
104 
105  std::cout << "PMC: original dt was " << dateString << std::endl;
106  std::cout << "PMC: modified dt is " << dt.toString() << std::endl;
107  }
108 // -----------------------------------------------------------------------------
109  BOOST_AUTO_TEST_CASE(test_tlmL95_stepAD) {
110  }
111 */
112 // -----------------------------------------------------------------------------
113  BOOST_AUTO_TEST_CASE(test_tlmL95_get_classname) {
114  lorenz95::TLML95 tlm(*resol_, *tlconf_);
115  BOOST_CHECK_EQUAL(tlm.classname(), "lorenz95::TLML95");
116  }
117 // -----------------------------------------------------------------------------
118  BOOST_AUTO_TEST_CASE(test_tlmL95_get_timestep) {
119  lorenz95::TLML95 tlm(*resol_, *tlconf_);
120  util::Duration dt(tlconf_->getString("tstep"));
121  BOOST_CHECK_EQUAL(tlm.timeResolution().toSeconds(), dt.toSeconds());
122  }
123 // -----------------------------------------------------------------------------
124  BOOST_AUTO_TEST_CASE(test_tlmL95_get_resolution) {
125  eckit::LocalConfiguration rescf(TestConfig::config(), "resolution");
126  lorenz95::Resolution resol(rescf);
127  lorenz95::TLML95 tlm(*resol_, *tlconf_);
128  BOOST_CHECK_EQUAL(tlm.resolution().npoints(), resol.npoints());
129  }
130 // -----------------------------------------------------------------------------
131  BOOST_AUTO_TEST_CASE(test_tlmL95_stream_output) {
132  lorenz95::TLML95 tlm(*resol_, *tlconf_);
133 
134  // use the operator<< method to write the value to a file
135  std::filebuf fb;
136  std::string filename("TLML95Test.txt");
137  fb.open(filename.c_str(), std::ios::out);
138  std::ostream os(&fb);
139  os << tlm;
140  fb.close();
141 
142  // then read the value that was written to the file
143  std::string inputString;
144  std::string inputStartsWith;
145  std::string testString("TLML95: resol = ");
146  int endPos = testString.size();
147  std::ifstream inputFile(filename.c_str());
148  if (inputFile.is_open()) {
149  getline(inputFile, inputString);
150 
151  inputStartsWith = inputString.substr(0, endPos);
152 
153  BOOST_CHECK_EQUAL(inputStartsWith, testString);
154  } else {
155  // if we can't open the file then we can't
156  // verify that the value was correctly written
157  BOOST_ERROR("operator<< functionality cannot be determined");
158  }
159  inputFile.close();
160  }
161 // -----------------------------------------------------------------------------
162 BOOST_AUTO_TEST_SUITE_END()
163 } // namespace test
boost::scoped_ptr< const eckit::LocalConfiguration > tlconf_
boost::scoped_ptr< lorenz95::ModelL95 > model_
*f90 *************************************************************************GNU Lesser General Public License **This file is part of the GFDL Flexible Modeling System(FMS). ! *! *FMS is free software without even the implied warranty of MERCHANTABILITY or *FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License *for more details **You should have received a copy of the GNU Lesser General Public *License along with FMS If see< http:! ***********************************************************************! this routine is used to retrieve scalar boundary data for symmetric domain. subroutine MPP_GET_BOUNDARY_2D_(field, domain, ebuffer, sbuffer, wbuffer, nbuffer, flags, &position, complete, tile_count) type(domain2D), intent(in) ::domain MPP_TYPE_, intent(in) ::field(:,:) MPP_TYPE_, intent(inout), optional ::ebuffer(:), sbuffer(:), wbuffer(:), nbuffer(:) integer, intent(in), optional ::flags, position, tile_count logical, intent(in), optional ::complete MPP_TYPE_ ::field3D(size(field, 1), size(field, 2), 1) MPP_TYPE_, allocatable, dimension(:,:) ::ebuffer2D, sbuffer2D, wbuffer2D, nbuffer2D integer ::xcount, ycount integer ::ntile logical ::need_ebuffer, need_sbuffer, need_wbuffer, need_nbuffer integer(LONG_KIND), dimension(MAX_DOMAIN_FIELDS, MAX_TILES), save ::f_addrs=-9999 integer(LONG_KIND), dimension(4, MAX_DOMAIN_FIELDS, MAX_TILES), save ::b_addrs=-9999 integer, save ::bsize(4)=0, isize=0, jsize=0, ksize=0, pos, list=0, l_size=0, upflags integer ::buffer_size(4) integer ::max_ntile, tile, update_position, ishift, jshift logical ::do_update, is_complete, set_mismatch character(len=3) ::text MPP_TYPE_ ::d_type type(overlapSpec), pointer ::bound=> NULL() ntile
Lorenz 95 linear model definition.
Definition: TLML95.h:44
Lorenz 95 model configuration and computations.
Definition: ModelL95.h:38
Handles resolution.
Definition: Resolution.h:25
boost::scoped_ptr< lorenz95::Resolution > resol_
int npoints() const
Definition: Resolution.h:37
string tlm
Definition: TLM_vs_NLM.py:25
BOOST_AUTO_TEST_CASE(test_GomL95_constructor)
static const eckit::Configuration & config()
Definition: TestConfig.h:30