FV3 Bundle
test/lorenz95/ObsVec1D.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 <boost/scoped_ptr.hpp>
12 #include <boost/test/unit_test.hpp>
13 
14 #include "./TestConfig.h"
15 #include "eckit/config/LocalConfiguration.h"
16 #include "lorenz95/ObsTable.h"
17 #include "lorenz95/ObsVec1D.h"
18 #include "test/TestFixture.h"
19 
20 namespace test {
21 
22 // -----------------------------------------------------------------------------
24  public:
26  const eckit::LocalConfiguration conf(TestConfig::config(), "Observations");
27  const util::DateTime bgn(conf.getString("window_begin"));
28  const util::DateTime end(conf.getString("window_end"));
29  const eckit::LocalConfiguration otconf(conf, "Observation");
30  obstable_.reset(new lorenz95::ObsTable(otconf, bgn, end));
31  }
33  boost::scoped_ptr<lorenz95::ObsTable> obstable_;
34 };
35 // -----------------------------------------------------------------------------
36 
37 // -----------------------------------------------------------------------------
38 BOOST_FIXTURE_TEST_SUITE(test_ObsVec1D, ObsVecTestFixture)
39 // -----------------------------------------------------------------------------
40  BOOST_AUTO_TEST_CASE(test_ObsVec1D_constructor) {
41  boost::scoped_ptr<lorenz95::ObsVec1D> ov(new lorenz95::ObsVec1D(*obstable_));
42  BOOST_CHECK(ov.get() != NULL);
43  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
44  BOOST_CHECK_EQUAL((*ov)(ii), 0.0);
45  }
46  }
47 // -----------------------------------------------------------------------------
48  BOOST_AUTO_TEST_CASE(test_ObsVec1D_nobs) {
49  boost::scoped_ptr<lorenz95::ObsVec1D> ov(new lorenz95::ObsVec1D(*obstable_));
50  BOOST_CHECK_EQUAL(ov->size(), obstable_->nobs());
51  }
52 // -----------------------------------------------------------------------------
53  BOOST_AUTO_TEST_CASE(test_ObsVec1D_read) {
54  boost::scoped_ptr<lorenz95::ObsVec1D> ov(new lorenz95::ObsVec1D(*obstable_));
55  ov->read("ObsVal");
56  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
57  BOOST_CHECK((*ov)(ii) != 0.0);
58  }
59  }
60 // -----------------------------------------------------------------------------
61  BOOST_AUTO_TEST_CASE(test_ObsVec1D_copy_constructor_copy) {
62  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
63  ov1->read("ObsVal");
64  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*ov1, true));
65 
66  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
67  BOOST_CHECK_EQUAL((*ov2)(ii), (*ov1)(ii));
68  }
69  }
70 // -----------------------------------------------------------------------------
71  BOOST_AUTO_TEST_CASE(test_ObsVec1D_copy_constructor_no_copy) {
72  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
73  ov1->read("ObsVal");
74  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*ov1, false));
75 
76  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
77  BOOST_CHECK_EQUAL((*ov2)(ii), 0.0);
78  }
79  }
80 // -----------------------------------------------------------------------------
81  BOOST_AUTO_TEST_CASE(test_ObsVec1D_classname) {
82  boost::scoped_ptr<lorenz95::ObsVec1D> ov(new lorenz95::ObsVec1D(*obstable_));
83  BOOST_CHECK_EQUAL(ov->classname(), "lorenz95::ObsVec1D");
84  }
85 // -----------------------------------------------------------------------------
86  BOOST_AUTO_TEST_CASE(test_ObsVec1D_assignment) {
87  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
88  ov1->read("ObsVal");
89  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*obstable_));
90 
91  // use the assignment operator to populate the second ObsVec1D object
92  *ov2 = *ov1;
93 
94  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
95  BOOST_CHECK_EQUAL((*ov2)(ii), (*ov1)(ii));
96  }
97  }
98 // -----------------------------------------------------------------------------
99  BOOST_AUTO_TEST_CASE(test_ObsVec1D_compound_assignment_multiply_double) {
100  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
101  ov1->read("ObsVal");
102  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*ov1, true));
103 
104  // create a random double value
105  double mult = 7.92;
106  *ov2 *= mult;
107 
108  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
109  BOOST_CHECK_EQUAL((*ov2)(ii), (*ov1)(ii) * mult);
110  }
111  }
112 // -----------------------------------------------------------------------------
113  BOOST_AUTO_TEST_CASE(test_ObsVec1D_compound_assignment_add) {
114  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
115  ov1->read("ObsVal");
116  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*ov1, true));
117 
118  *ov1 += *ov2;
119 
120  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
121  BOOST_CHECK_EQUAL((*ov1)(ii), (*ov2)(ii) + (*ov2)(ii));
122  }
123  }
124 // -----------------------------------------------------------------------------
125  BOOST_AUTO_TEST_CASE(test_ObsVec1D_compound_assignment_subtract) {
126  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
127  ov1->read("ObsVal");
128  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*ov1, true));
129 
130  *ov1 -= *ov2;
131 
132  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
133  BOOST_CHECK_EQUAL((*ov1)(ii), 0.0);
134  }
135  }
136 // -----------------------------------------------------------------------------
137  BOOST_AUTO_TEST_CASE(test_ObsVec1D_compound_assignment_multiply) {
138  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
139  ov1->read("ObsVal");
140  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*ov1, true));
141 
142  *ov1 *= *ov2;
143 
144  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
145  BOOST_CHECK_EQUAL((*ov1)(ii), (*ov2)(ii) * (*ov2)(ii));
146  }
147  }
148 // -----------------------------------------------------------------------------
149  BOOST_AUTO_TEST_CASE(test_ObsVec1D_compound_assignment_divide) {
150  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
151  ov1->read("ObsVal");
152  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*ov1, true));
153 
154  *ov1 /= *ov2;
155 
156  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
157  BOOST_CHECK_EQUAL((*ov1)(ii), 1.0);
158  }
159  }
160 // -----------------------------------------------------------------------------
161  BOOST_AUTO_TEST_CASE(test_ObsVec1D_zero) {
162  boost::scoped_ptr<lorenz95::ObsVec1D> ov(new lorenz95::ObsVec1D(*obstable_));
163  ov->read("ObsVal");
164 
165  ov->zero();
166 
167  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
168  BOOST_CHECK_EQUAL((*ov)(ii), 0.0);
169  }
170  }
171 // -----------------------------------------------------------------------------
172  BOOST_AUTO_TEST_CASE(test_ObsVec1D_axpy) {
173  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
174  ov1->read("ObsVal");
175  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*ov1, true));
176 
177  double mult = 2.00;
178 
179  ov1->axpy(mult, *ov2);
180 
181  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
182  BOOST_CHECK_EQUAL((*ov1)(ii), (*ov2)(ii) + mult * (*ov2)(ii));
183  }
184  }
185 // -----------------------------------------------------------------------------
186  BOOST_AUTO_TEST_CASE(test_ObsVec1D_invert) {
187  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
188  ov1->read("ObsVal");
189  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*ov1, true));
190 
191  ov1->invert();
192 
193  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
194  BOOST_CHECK_EQUAL((*ov1)(ii), 1.0 / (*ov2)(ii));
195  }
196  }
197 // -----------------------------------------------------------------------------
198  BOOST_AUTO_TEST_CASE(test_ObsVec1D_random) {
199  boost::scoped_ptr<lorenz95::ObsVec1D> ov(new lorenz95::ObsVec1D(*obstable_));
200 
201  ov->random();
202 
203  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
204  BOOST_CHECK((*ov)(ii) != 0);
205  }
206  }
207 // -----------------------------------------------------------------------------
208  BOOST_AUTO_TEST_CASE(test_ObsVec1D_dot_product_with) {
209  boost::scoped_ptr<lorenz95::ObsVec1D> ov1(new lorenz95::ObsVec1D(*obstable_));
210  ov1->read("ObsVal");
211  boost::scoped_ptr<lorenz95::ObsVec1D> ov2(new lorenz95::ObsVec1D(*ov1, true));
212 
213  double result = ov1->dot_product_with(*ov2);
214 
215  double check = 0.0;
216  for (unsigned int ii = 0; ii < obstable_->nobs(); ++ii) {
217  check += (*ov2)(ii) * (*ov2)(ii);
218  }
219 
220  BOOST_CHECK_CLOSE(result, check, 1.0e-8);
221  }
222 // -----------------------------------------------------------------------------
223 BOOST_AUTO_TEST_SUITE_END()
224 // -----------------------------------------------------------------------------
225 
226 } // namespace test
************************************************************************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:! ***********************************************************************!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! MPP_TRANSMIT !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine MPP_TRANSMIT_(put_data, put_len, to_pe, get_data, get_len, from_pe, block, tag, recv_request, send_request)!a message-passing routine intended to be reminiscent equally of both MPI and SHMEM!put_data and get_data are contiguous MPP_TYPE_ arrays!at each call, your put_data array is put to to_pe 's get_data! your get_data array is got from from_pe 's put_data!i.e we assume that typically(e.g updating halo regions) each PE performs a put _and_ a get!special PE designations:! NULL_PE:to disable a put or a get(e.g at boundaries)! ANY_PE:if remote PE for the put or get is to be unspecific! ALL_PES:broadcast and collect operations(collect not yet implemented)!ideally we would not pass length, but this f77-style call performs better(arrays passed by address, not descriptor)!further, this permits< length > contiguous words from an array of any rank to be passed(avoiding f90 rank conformance check)!caller is responsible for completion checks(mpp_sync_self) before and after integer, intent(in) ::put_len, to_pe, get_len, from_pe MPP_TYPE_, intent(in) ::put_data(*) MPP_TYPE_, intent(out) ::get_data(*) logical, intent(in), optional ::block integer, intent(in), optional ::tag integer, intent(out), optional ::recv_request, send_request logical ::block_comm integer ::i MPP_TYPE_, allocatable, save ::local_data(:) !local copy used by non-parallel code(no SHMEM or MPI) integer ::comm_tag integer ::rsize if(.NOT.module_is_initialized) call mpp_error(FATAL, 'MPP_TRANSMIT:You must first call mpp_init.') if(to_pe.EQ.NULL_PE .AND. from_pe.EQ.NULL_PE) return block_comm=.true. if(PRESENT(block)) block_comm=block if(debug) then call SYSTEM_CLOCK(tick) write(stdout_unit,'(a, i18, a, i6, a, 2i6, 2i8)')&'T=', tick, ' PE=', pe, ' MPP_TRANSMIT begin:to_pe, from_pe, put_len, get_len=', to_pe, from_pe, put_len, get_len end if comm_tag=DEFAULT_TAG if(present(tag)) comm_tag=tag!do put first and then get if(to_pe.GE.0 .AND. to_pe.LT.npes) then!use non-blocking sends if(debug .and.(current_clock.NE.0)) call SYSTEM_CLOCK(start_tick)!z1l:truly non-blocking send.! if(request(to_pe).NE.MPI_REQUEST_NULL) then !only one message from pe-> to_pe in queue *PE waiting for to_pe ! call error else get_len so only do gets but you cannot have a pure get with MPI call a get means do a wait to ensure put on remote PE is complete error call increase mpp_nml request_multiply call MPP_TRANSMIT end
Definition: conf.py:1
*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
Vector in observation space.
Definition: ObsVec1D.h:32
real(fp), parameter, public e
boost::scoped_ptr< lorenz95::ObsTable > obstable_
A Simple Observation Data Handler.
Definition: ObsTable.h:39
BOOST_AUTO_TEST_CASE(test_GomL95_constructor)
static const eckit::Configuration & config()
Definition: TestConfig.h:30
void mult(long double m[], long double v[], long double out_v[])
Definition: mosaic_util.c:768