FV3 Bundle
PostBaseTLAD.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_POSTBASETLAD_H_
12 #define OOPS_BASE_POSTBASETLAD_H_
13 
14 #include <boost/noncopyable.hpp>
15 
16 #include "eckit/config/Configuration.h"
18 #include "oops/base/PostTimer.h"
20 #include "oops/interface/State.h"
21 #include "oops/util/DateTime.h"
22 #include "oops/util/Duration.h"
23 
24 namespace oops {
25 
26 // -----------------------------------------------------------------------------
27 
28 /// Handles post-processing of model fields related to cost function.
29 /*!
30  * PostBaseTLAD is the base class for all cost function linearized processors,
31  * it is mostly used so that PostProcessorTL can hold a vector of such
32  * processors.
33  * By default processing is performed on every call.
34  * An important difference with PostBase is that the adjoint can modify the
35  * increment.
36  */
37 
38 template <typename MODEL>
39 class PostBaseTLAD : private boost::noncopyable {
42 
43  public:
45  PostBaseTLAD(const util::DateTime & start, const util::DateTime & finish,
46  const util::Duration & freq = util::Duration(0))
47  : timer_(start, finish, freq) {}
48  virtual ~PostBaseTLAD() {}
49 
50 /// Set linearization state
51  void initializeTraj(const State_ & xx, const util::DateTime & end,
52  const util::Duration & step) {
54  this->doInitializeTraj(xx, end, step);
55  }
56 
57  void processTraj(const State_ & xx) {
58  if (timer_.itIsTime(xx.validTime())) this->doProcessingTraj(xx);
59  }
60 
61  void finalizeTraj(const State_ & xx) {
62  this->doFinalizeTraj(xx);
63  }
64 
65 /// Tangent linear methods
66  void initializeTL(const Increment_ & dx, const util::DateTime & end,
67  const util::Duration & step) {
69  this->doInitializeTL(dx, end, step);
70  }
71 
72  void processTL(const Increment_ & dx) {
73  if (timer_.itIsTime(dx.validTime())) this->doProcessingTL(dx);
74  }
75 
76  void finalizeTL(const Increment_ & dx) {
77  this->doFinalizeTL(dx);
78  }
79 
80 /// Return TL dual space output
82 
83 /// Adjoint methods
84  void initializeAD(Increment_ & dx, const util::DateTime & bgn,
85  const util::Duration & step) {
86  timer_.initialize(bgn, dx.validTime(), step);
87  this->doFirstAD(dx, bgn, step);
88  }
89 
90  void processAD(Increment_ & dx) {
91  if (timer_.itIsTime(dx.validTime())) this->doProcessingAD(dx);
92  }
93 
94  void finalizeAD(Increment_ & dx) {
95  this->doLastAD(dx);
96  }
97 
98  private:
100  virtual void doInitializeTraj(const State_ &,
101  const util::DateTime &, const util::Duration &) = 0;
102  virtual void doProcessingTraj(const State_ &) = 0;
103  virtual void doFinalizeTraj(const State_ &) = 0;
104 
105  virtual void doInitializeTL(const Increment_ &,
106  const util::DateTime &, const util::Duration &) = 0;
107  virtual void doProcessingTL(const Increment_ &) = 0;
108  virtual void doFinalizeTL(const Increment_ &) = 0;
109 
110  virtual void doFirstAD(Increment_ &, const util::DateTime &, const util::Duration &) = 0;
111  virtual void doProcessingAD(Increment_ &) = 0;
112  virtual void doLastAD(Increment_ &) = 0;
113 };
114 
115 // -----------------------------------------------------------------------------
116 
117 } // namespace oops
118 
119 #endif // OOPS_BASE_POSTBASETLAD_H_
virtual void doProcessingTL(const Increment_ &)=0
PostBaseTLAD(const util::DateTime &start, const util::DateTime &finish, const util::Duration &freq=util::Duration(0))
Definition: PostBaseTLAD.h:45
virtual ~PostBaseTLAD()
Definition: PostBaseTLAD.h:48
virtual void doLastAD(Increment_ &)=0
PostTimer timer_
Definition: PostBaseTLAD.h:99
void finalizeAD(Increment_ &dx)
Definition: PostBaseTLAD.h:94
virtual void doFinalizeTraj(const State_ &)=0
************************************************************************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
const util::DateTime validTime() const
Time.
Handles post-processing of model fields related to cost function.
Definition: PostBaseTLAD.h:39
void initializeTL(const Increment_ &dx, const util::DateTime &end, const util::Duration &step)
Tangent linear methods.
Definition: PostBaseTLAD.h:66
Encapsulates the model state.
virtual void doFinalizeTL(const Increment_ &)=0
virtual void doProcessingAD(Increment_ &)=0
The namespace for the main oops code.
void processTL(const Increment_ &dx)
Definition: PostBaseTLAD.h:72
Handles timing of post-processing and similar actions.
Definition: PostTimer.h:32
virtual void doInitializeTraj(const State_ &, const util::DateTime &, const util::Duration &)=0
State< MODEL > State_
Definition: PostBaseTLAD.h:41
void initializeAD(Increment_ &dx, const util::DateTime &bgn, const util::Duration &step)
Adjoint methods.
Definition: PostBaseTLAD.h:84
************************************************************************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:! ***********************************************************************subroutine READ_RECORD_CORE_(unit, field, nwords, data, start, axsiz) integer, intent(in) ::unit type(fieldtype), intent(in) ::field integer, intent(in) ::nwords MPP_TYPE_, intent(inout) ::data(nwords) integer, intent(in) ::start(:), axsiz(:) integer(SHORT_KIND) ::i2vals(nwords)!rab used in conjunction with transfer intrinsic to determine size of a variable integer(KIND=1) ::one_byte(8) integer ::word_sz!#ifdef __sgi integer(INT_KIND) ::ivals(nwords) real(FLOAT_KIND) ::rvals(nwords)!#else! integer ::ivals(nwords)! real ::rvals(nwords)!#endif real(DOUBLE_KIND) ::r8vals(nwords) pointer(ptr1, i2vals) pointer(ptr2, ivals) pointer(ptr3, rvals) pointer(ptr4, r8vals) if(mpp_io_stack_size< nwords) call mpp_io_set_stack_size(nwords) call mpp_error(FATAL, 'MPP_READ currently requires use_netCDF option') end subroutine READ_RECORD_CORE_ subroutine READ_RECORD_(unit, field, nwords, data, time_level, domain, position, tile_count, start_in, axsiz_in)!routine that is finally called by all mpp_read routines to perform the read!a non-netCDF record contains:! field ID! a set of 4 coordinates(is:ie, js:je) giving the data subdomain! a timelevel and a timestamp(=NULLTIME if field is static)! 3D real data(stored as 1D)!if you are using direct access I/O, the RECL argument to OPEN must be large enough for the above!in a global direct access file, record position on PE is given by %record.!Treatment of timestamp:! We assume that static fields have been passed without a timestamp.! Here that is converted into a timestamp of NULLTIME.! For non-netCDF fields, field is treated no differently, but is written! with a timestamp of NULLTIME. There is no check in the code to prevent! the user from repeatedly writing a static field. integer, intent(in) ::unit, nwords type(fieldtype), intent(in) ::field MPP_TYPE_, intent(inout) ::data(nwords) integer, intent(in), optional ::time_level type(domain2D), intent(in), optional ::domain integer, intent(in), optional ::position, tile_count integer, intent(in), optional ::start_in(:), axsiz_in(:) integer, dimension(size(field%axes(:))) ::start, axsiz integer ::tlevel !, subdomain(4) integer ::i, error, is, ie, js, je, isg, ieg, jsg, jeg type(domain2d), pointer ::io_domain=> tlevel if(PRESENT(start_in) .AND. PRESENT(axsiz_in)) then if(size(start(! the data domain and compute domain must refer to the subdomain being passed ! In this ! since that attempts to gather all data on PE start
void processAD(Increment_ &dx)
Definition: PostBaseTLAD.h:90
void finalizeTL(const Increment_ &dx)
Definition: PostBaseTLAD.h:76
subroutine, public step(x, g)
virtual GeneralizedDepartures * releaseOutputFromTL()=0
Return TL dual space output.
Increment< MODEL > Increment_
Definition: PostBaseTLAD.h:40
Increment Class: Difference between two states.
virtual void doFirstAD(Increment_ &, const util::DateTime &, const util::Duration &)=0
bool itIsTime(const util::DateTime &)
Definition: PostTimer.cc:79
PostBaseTLAD()
Definition: PostBaseTLAD.h:44
void processTraj(const State_ &xx)
Definition: PostBaseTLAD.h:57
Abstract base class for quantities.
void initializeTraj(const State_ &xx, const util::DateTime &end, const util::Duration &step)
Set linearization state.
Definition: PostBaseTLAD.h:51
virtual void doInitializeTL(const Increment_ &, const util::DateTime &, const util::Duration &)=0
void finalizeTraj(const State_ &xx)
Definition: PostBaseTLAD.h:61
virtual void doProcessingTraj(const State_ &)=0
void initialize(const util::DateTime &, const util::DateTime &, const util::Duration &)
Definition: PostTimer.cc:45
const util::DateTime validTime() const
Time.