FV3 Bundle
FilterBase.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2018 UCAR
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 OOPS_BASE_FILTERBASE_H_
9 #define OOPS_BASE_FILTERBASE_H_
10 
11 #include <map>
12 #include <string>
13 
14 #include <boost/noncopyable.hpp>
15 
16 #include "oops/interface/GeoVaLs.h"
19 #include "oops/util/abor1_cpp.h"
20 #include "oops/util/Printable.h"
21 
22 namespace oops {
23 
24 /// Base class for QC filters applied to observations
25 
26 // -----------------------------------------------------------------------------
27 
28 template <typename MODEL>
29 class FilterBase : public util::Printable,
30  private boost::noncopyable {
34 
35  public:
37  virtual ~FilterBase() {}
38 
39  virtual void priorFilter(const ObsSpace_ &) const = 0;
40  virtual void postFilter(const GeoVaLs_ &, const ObsVector_ &, const ObsSpace_ &) const = 0;
41 
42  private:
43  virtual void print(std::ostream &) const = 0;
44 };
45 
46 // =============================================================================
47 
48 /// ObsFilter Factory
49 template <typename MODEL>
51  public:
52  static FilterBase<MODEL> * create(const eckit::Configuration &);
53  virtual ~FilterFactory() { getMakers().clear(); }
54  protected:
55  explicit FilterFactory(const std::string &);
56  private:
57  virtual FilterBase<MODEL> * make(const eckit::Configuration &) = 0;
58  static std::map < std::string, FilterFactory<MODEL> * > & getMakers() {
59  static std::map < std::string, FilterFactory<MODEL> * > makers_;
60  return makers_;
61  }
62 };
63 
64 // -----------------------------------------------------------------------------
65 
66 template<class MODEL, class T>
67 class FilterMaker : public FilterFactory<MODEL> {
68  virtual FilterBase<MODEL> * make(const eckit::Configuration & conf)
69  { return new T(conf); }
70  public:
71  explicit FilterMaker(const std::string & name) : FilterFactory<MODEL>(name) {}
72 };
73 
74 // =============================================================================
75 
76 template <typename MODEL>
78  if (getMakers().find(name) != getMakers().end()) {
79  Log::error() << name << " already registered in obs filter factory." << std::endl;
80  ABORT("Element already registered in FilterFactory.");
81  }
82  getMakers()[name] = this;
83 }
84 
85 // -----------------------------------------------------------------------------
86 
87 template <typename MODEL>
88 FilterBase<MODEL>* FilterFactory<MODEL>::create(const eckit::Configuration & conf) {
89  Log::trace() << "FilterBase<MODEL>::create starting" << std::endl;
90  Log::debug() << "FilterBase<MODEL>::create conf" << conf << std::endl;
91  const std::string id = conf.getString("Filter");
92  typename std::map<std::string, FilterFactory<MODEL>*>::iterator
93  jloc = getMakers().find(id);
94  if (jloc == getMakers().end()) {
95  Log::error() << id << " does not exist in obs filter factory." << std::endl;
96  ABORT("Element does not exist in FilterFactory.");
97  }
98  FilterBase<MODEL> * ptr = jloc->second->make(conf);
99  Log::trace() << "FilterBase<MODEL>::create done" << std::endl;
100  return ptr;
101 }
102 
103 // -----------------------------------------------------------------------------
104 
105 } // namespace oops
106 
107 #endif // OOPS_BASE_FILTERBASE_H_
Base class for QC filters applied to observations.
Definition: FilterBase.h:29
virtual void priorFilter(const ObsSpace_ &) const =0
virtual FilterBase< MODEL > * make(const eckit::Configuration &)=0
ObsVector< MODEL > ObsVector_
Definition: FilterBase.h:33
virtual FilterBase< MODEL > * make(const eckit::Configuration &conf)
Definition: FilterBase.h:68
virtual ~FilterFactory()
Definition: FilterBase.h:53
ObservationSpace< MODEL > ObsSpace_
Definition: FilterBase.h:32
************************************************************************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
character(len=32) name
The namespace for the main oops code.
virtual void postFilter(const GeoVaLs_ &, const ObsVector_ &, const ObsSpace_ &) const =0
logical debug
Definition: mpp.F90:1297
FilterMaker(const std::string &name)
Definition: FilterBase.h:71
************************************************************************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
integer error
Definition: mpp.F90:1310
ObsFilter Factory.
Definition: FilterBase.h:50
static FilterBase< MODEL > * create(const eckit::Configuration &)
Definition: FilterBase.h:88
virtual ~FilterBase()
Definition: FilterBase.h:37
static std::map< std::string, FilterFactory< MODEL > *> & getMakers()
Definition: FilterBase.h:58
GeoVaLs< MODEL > GeoVaLs_
Definition: FilterBase.h:31
virtual void print(std::ostream &) const =0
FilterFactory(const std::string &)
Definition: FilterBase.h:77