FV3 Bundle
Observer.h
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 #ifndef OOPS_BASE_OBSERVER_H_
12 #define OOPS_BASE_OBSERVER_H_
13 
14 #include <memory>
15 #include <vector>
16 
17 #include <boost/shared_ptr.hpp>
18 
20 #include "oops/base/Observations.h"
21 #include "oops/base/ObsFilters.h"
22 #include "oops/base/ObsOperators.h"
23 #include "oops/base/ObsSpaces.h"
24 #include "oops/base/PostBase.h"
25 #include "oops/interface/GeoVaLs.h"
28 #include "oops/util/DateTime.h"
29 #include "oops/util/Duration.h"
30 #include "oops/util/Logger.h"
31 #include "oops/util/Printable.h"
32 
33 namespace oops {
34 
35 /// Computes observation equivalent during model run.
36 
37 // Sub-windows knowledge could be removed if vector of obs was used in
38 // weak constraint 4D-Var. YT
39 
40 // -----------------------------------------------------------------------------
41 
42 template <typename MODEL, typename STATE>
43 class Observer : public util::Printable, public PostBase<STATE> {
52 
53  public:
54  Observer(const ObsSpace_ &, const ObsOperator_ &, const ObsAuxCtrl_ &, const ObsFilters_ &,
55  const util::Duration & tslot = util::Duration(0), const bool subwin = false);
56  ~Observer() {}
57 
58  Observations_ * release() {return yobs_.release();}
59 
60  void processTraj(const STATE &, std::vector<boost::shared_ptr<InterpolatorTraj_> > &) const;
61  void finalizeTraj(const STATE &, LinearObsOperator_ &);
62 
63  private:
64 // Methods
65  void doInitialize(const STATE &, const util::DateTime &, const util::Duration &) override;
66  void doProcessing(const STATE &) override;
67  void doFinalize(const STATE &) override;
68  void print(std::ostream &) const;
69 
70 // Obs operator
72  const ObsOperator_ & hop_;
73 
74 // Data
75  std::auto_ptr<Observations_> yobs_;
77 
78  util::DateTime winbgn_; //!< Begining of assimilation window
79  util::DateTime winend_; //!< End of assimilation window
80  util::DateTime bgn_; //!< Begining of currently active observations
81  util::DateTime end_; //!< End of currently active observations
82  util::Duration hslot_; //!< Half time slot
83  const bool subwindows_;
84 
85  std::vector<boost::shared_ptr<GeoVaLs_> > gvals_;
87 
88  typedef std::vector<boost::shared_ptr<InterpolatorTraj_> > vspit;
89 };
90 
91 // -----------------------------------------------------------------------------
92 
93 template <typename MODEL, typename STATE>
95  const ObsOperator_ & hop,
96  const ObsAuxCtrl_ & ybias,
97  const ObsFilters_ & filters,
98  const util::Duration & tslot, const bool swin)
99  : PostBase<STATE>(), obspace_(obsdb), hop_(hop),
100  yobs_(new Observations_(obsdb)), ybias_(ybias),
101  winbgn_(obsdb.windowStart()), winend_(obsdb.windowEnd()),
102  bgn_(winbgn_), end_(winend_), hslot_(tslot/2), subwindows_(swin),
103  gvals_(0), filters_(filters)
104 {
105  Log::trace() << "Observer::Observer" << std::endl;
106  Log::debug() << "Observer filter is " << filters_ << std::endl;
107 }
108 // -----------------------------------------------------------------------------
109 template <typename MODEL, typename STATE>
111  const util::DateTime & end,
112  const util::Duration & tstep) {
113  Log::trace() << "Observer::doInitialize start" << std::endl;
114  const util::DateTime bgn(xx.validTime());
115  if (hslot_ == util::Duration(0)) hslot_ = tstep/2;
116  if (subwindows_) {
117  if (bgn == end) {
118  bgn_ = bgn - hslot_;
119  end_ = end + hslot_;
120  } else {
121  bgn_ = bgn;
122  end_ = end;
123  }
124  }
125  if (bgn_ < winbgn_) bgn_ = winbgn_;
126  if (end_ > winend_) end_ = winend_;
127 
128  for (size_t jj = 0; jj < obspace_.size(); ++jj) {
129  boost::shared_ptr<GeoVaLs_> tmp(new GeoVaLs_(obspace_[jj].locations(bgn_, end_),
130  hop_.variables(jj)));
131  gvals_.push_back(tmp);
132  }
133  Log::trace() << "Observer::doInitialize done" << std::endl;
134 }
135 // -----------------------------------------------------------------------------
136 template <typename MODEL, typename STATE>
137 void Observer<MODEL, STATE>::doProcessing(const STATE & xx) {
138  Log::trace() << "Observer::doProcessing start" << std::endl;
139  util::DateTime t1(xx.validTime()-hslot_);
140  util::DateTime t2(xx.validTime()+hslot_);
141  if (t1 < bgn_) t1 = bgn_;
142  if (t2 > end_) t2 = end_;
143 
144 // Get state variables at obs locations
145  for (size_t jj = 0; jj < obspace_.size(); ++jj) {
146  xx.getValues(obspace_[jj].locations(t1, t2), hop_.variables(jj), *gvals_.at(jj));
147  }
148  Log::trace() << "Observer::doProcessing done" << std::endl;
149 }
150 // -----------------------------------------------------------------------------
151 template <typename MODEL, typename STATE>
152 void Observer<MODEL, STATE>::processTraj(const STATE & xx, vspit & traj) const {
153  Log::trace() << "Observer::processTraj start" << std::endl;
154  util::DateTime t1(xx.validTime()-hslot_);
155  util::DateTime t2(xx.validTime()+hslot_);
156  if (t1 < bgn_) t1 = bgn_;
157  if (t2 > end_) t2 = end_;
158 
159 // Get state variables at obs locations and trajectory
160  for (size_t jj = 0; jj < obspace_.size(); ++jj) {
161  xx.getValues(obspace_[jj].locations(t1, t2), hop_.variables(jj), *gvals_.at(jj),
162  *traj.at(jj));
163  }
164  Log::trace() << "Observer::processTraj done" << std::endl;
165 }
166 // -----------------------------------------------------------------------------
167 template <typename MODEL, typename STATE>
169  Log::trace() << "Observer::finalizeTraj start" << std::endl;
170  for (size_t jj = 0; jj < obspace_.size(); ++jj) {
171  htlad[jj].setTrajectory(*gvals_.at(jj), ybias_);
172  }
173  this->doFinalize(xx);
174  Log::trace() << "Observer::finalizeTraj done" << std::endl;
175 }
176 // -----------------------------------------------------------------------------
177 template <typename MODEL, typename STATE>
179  Log::trace() << "Observer::doFinalize start" << std::endl;
180  for (size_t jj = 0; jj < obspace_.size(); ++jj) {
181  hop_[jj].simulateObs(*gvals_.at(jj), (*yobs_)[jj], ybias_);
182  filters_[jj].postFilter(*gvals_.at(jj), (*yobs_)[jj], obspace_[jj]);
183  }
184  gvals_.clear();
185  Log::trace() << "Observer::doFinalize done" << std::endl;
186 }
187 // -----------------------------------------------------------------------------
188 template <typename MODEL, typename STATE>
189 void Observer<MODEL, STATE>::print(std::ostream &) const {}
190 // -----------------------------------------------------------------------------
191 
192 } // namespace oops
193 
194 #endif // OOPS_BASE_OBSERVER_H_
util::DateTime end_
End of currently active observations.
Definition: Observer.h:81
ObsSpaces< MODEL > ObsSpace_
Definition: Observer.h:51
InterpolatorTraj< MODEL > InterpolatorTraj_
Definition: Observer.h:45
const ObsAuxCtrl_ & ybias_
Definition: Observer.h:76
************************************************************************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
std::auto_ptr< Observations_ > yobs_
Definition: Observer.h:75
util::DateTime winend_
End of assimilation window.
Definition: Observer.h:79
real, parameter t2
Observations Class.
Definition: Observations.h:36
Handles post-processing of model fields.
Definition: PostBase.h:33
The namespace for the main oops code.
void doFinalize(const STATE &) override
Definition: Observer.h:178
const bool subwindows_
Definition: Observer.h:83
Observations_ * release()
Definition: Observer.h:58
const ObsSpace_ & obspace_
Definition: Observer.h:71
logical debug
Definition: mpp.F90:1297
std::vector< boost::shared_ptr< InterpolatorTraj_ > > vspit
Definition: Observer.h:88
ObsOperators< MODEL > ObsOperator_
Definition: Observer.h:50
ObsFilters< MODEL > ObsFilters_
Definition: Observer.h:48
util::DateTime winbgn_
Begining of assimilation window.
Definition: Observer.h:78
ObsAuxControl< MODEL > ObsAuxCtrl_
Definition: Observer.h:47
void finalizeTraj(const STATE &, LinearObsOperator_ &)
Definition: Observer.h:168
const ObsOperator_ & hop_
Definition: Observer.h:72
real, parameter t1
std::vector< boost::shared_ptr< GeoVaLs_ > > gvals_
Definition: Observer.h:85
Observations< MODEL > Observations_
Definition: Observer.h:49
util::Duration hslot_
Half time slot.
Definition: Observer.h:82
const ObsFilters_ filters_
Definition: Observer.h:86
Computes observation equivalent during model run.
Definition: Observer.h:43
LinearObsOperators< MODEL > LinearObsOperator_
Definition: Observer.h:46
GeoVaLs< MODEL > GeoVaLs_
Definition: Observer.h:44
void doProcessing(const STATE &) override
Actual processing.
Definition: Observer.h:137
void print(std::ostream &) const
Definition: Observer.h:189
util::DateTime bgn_
Begining of currently active observations.
Definition: Observer.h:80
void doInitialize(const STATE &, const util::DateTime &, const util::Duration &) override
Definition: Observer.h:110
Observer(const ObsSpace_ &, const ObsOperator_ &, const ObsAuxCtrl_ &, const ObsFilters_ &, const util::Duration &tslot=util::Duration(0), const bool subwin=false)
Definition: Observer.h:94
void processTraj(const STATE &, std::vector< boost::shared_ptr< InterpolatorTraj_ > > &) const
Definition: Observer.h:152