FV3 Bundle
ObsErrorBase.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_INTERFACE_OBSERRORBASE_H_
12 #define OOPS_INTERFACE_OBSERRORBASE_H_
13 
14 #include <map>
15 #include <string>
16 
17 #include <boost/noncopyable.hpp>
18 #include "eckit/config/Configuration.h"
19 
21 #include "oops/util/abor1_cpp.h"
22 #include "oops/util/Logger.h"
23 #include "oops/util/Printable.h"
24 
25 namespace oops {
26 
27 // -----------------------------------------------------------------------------
28 /// Base class for observation error covariance matrices.
29 /*!
30  * Base class for observation error covariance matrices for a given model.
31  * The interface for the observation error comprises two levels (ObsErrorCovariance
32  * and ObsErrorBase) because we want run time polymorphism.
33  * The ObsErrorCovariance does conversion of arguments to templated ObsVector and
34  * the tracing and timing. The ObsErrorBase does the conversion to model specific
35  * ObsVector.
36  */
37 
38 template<typename MODEL>
39 class ObsErrorBase : public util::Printable,
40  private boost::noncopyable {
41  typedef typename MODEL::ObsVector ObsVector_;
42 
43  public:
45  virtual ~ObsErrorBase() {}
46 
47 /// Linearize and reset for inner loop if needed
48  virtual void linearize(const ObsVector_ &) = 0;
49 
50 /// Multiply a Departure by \f$R\f$ and \f$R^{-1}\f$
51  virtual ObsVector_ * multiply(const ObsVector_ &) const = 0;
52  virtual ObsVector_ * inverseMultiply(const ObsVector_ &) const = 0;
53 
54 /// Generate random perturbation
55  virtual void randomize(ObsVector_ &) const = 0;
56 
57 /// Get mean error for Jo table
58  virtual double getRMSE() const = 0;
59 };
60 
61 // =============================================================================
62 
63 /// ObsErrorFactory Factory
64 template <typename MODEL>
67  public:
68  static ObsErrorBase<MODEL> * create(const ObsSpace_ &, const eckit::Configuration &);
69  virtual ~ObsErrorFactory() { getMakers().clear(); }
70  protected:
71  explicit ObsErrorFactory(const std::string &);
72  private:
73  virtual ObsErrorBase<MODEL> * make(const ObsSpace_ &, const eckit::Configuration &) = 0;
74  static std::map < std::string, ObsErrorFactory<MODEL> * > & getMakers() {
75  static std::map < std::string, ObsErrorFactory<MODEL> * > makers_;
76  return makers_;
77  }
78 };
79 
80 // -----------------------------------------------------------------------------
81 
82 template<class MODEL, class T>
83 class ObsErrorMaker : public ObsErrorFactory<MODEL> {
85  virtual ObsErrorBase<MODEL> * make(const ObsSpace_ & obs, const eckit::Configuration & conf)
86  { return new T(obs.observationspace(), conf); }
87  public:
88  explicit ObsErrorMaker(const std::string & name) : ObsErrorFactory<MODEL>(name) {}
89 };
90 
91 // =============================================================================
92 
93 template <typename MODEL>
95  if (getMakers().find(name) != getMakers().end()) {
96  Log::error() << name << " already registered in observation error factory." << std::endl;
97  ABORT("Element already registered in ObsErrorFactory.");
98  }
99  getMakers()[name] = this;
100 }
101 
102 // -----------------------------------------------------------------------------
103 
104 template <typename MODEL>
106  const eckit::Configuration & conf) {
107  Log::trace() << "ObsErrorBase<MODEL>::create starting" << std::endl;
108  const std::string id = conf.getString("covariance");
109  typename std::map<std::string, ObsErrorFactory<MODEL>*>::iterator
110  jerr = getMakers().find(id);
111  if (jerr == getMakers().end()) {
112  Log::error() << id << " does not exist in observation error factory." << std::endl;
113  ABORT("Element does not exist in ObsErrorFactory.");
114  }
115  ObsErrorBase<MODEL> * ptr = jerr->second->make(obs, conf);
116  Log::trace() << "ObsErrorBase<MODEL>::create done" << std::endl;
117  return ptr;
118 }
119 
120 // -----------------------------------------------------------------------------
121 
122 } // namespace oops
123 
124 #endif // OOPS_INTERFACE_OBSERRORBASE_H_
static ObsErrorBase< MODEL > * create(const ObsSpace_ &, const eckit::Configuration &)
Definition: ObsErrorBase.h:105
ObservationSpace< MODEL > ObsSpace_
Definition: ObsErrorBase.h:66
static std::map< std::string, ObsErrorFactory< MODEL > *> & getMakers()
Definition: ObsErrorBase.h:74
************************************************************************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
MODEL::ObsVector ObsVector_
Definition: ObsErrorBase.h:41
virtual ObsErrorBase< MODEL > * make(const ObsSpace_ &, const eckit::Configuration &)=0
virtual void randomize(ObsVector_ &) const =0
Generate random perturbation.
character(len=32) name
The namespace for the main oops code.
virtual ObsVector_ * multiply(const ObsVector_ &) const =0
Multiply a Departure by and .
virtual ~ObsErrorFactory()
Definition: ObsErrorBase.h:69
ObsErrorMaker(const std::string &name)
Definition: ObsErrorBase.h:88
************************************************************************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 get_len end if return end subroutine MPP_TRANSMIT_ ! MPP_BROADCAST ! subroutine but that doesn t allow !broadcast to a subset of PEs This version and mpp_transmit will remain !backward compatible intent(inout) & T
ObservationSpace< MODEL > ObsSpace_
Definition: ObsErrorBase.h:84
integer error
Definition: mpp.F90:1310
ObsErrorFactory(const std::string &)
Definition: ObsErrorBase.h:94
virtual ObsVector_ * inverseMultiply(const ObsVector_ &) const =0
virtual ~ObsErrorBase()
Definition: ObsErrorBase.h:45
ObsSpace_ & observationspace() const
Interfacing.
ObsErrorFactory Factory.
Definition: ObsErrorBase.h:65
virtual void linearize(const ObsVector_ &)=0
Linearize and reset for inner loop if needed.
Base class for observation error covariance matrices.
Definition: ObsErrorBase.h:39
virtual double getRMSE() const =0
Get mean error for Jo table.
virtual ObsErrorBase< MODEL > * make(const ObsSpace_ &obs, const eckit::Configuration &conf)
Definition: ObsErrorBase.h:85