FV3 Bundle
oops/interface/Model.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  * (C) Copyright 2018 UCAR.
4  *
5  * This software is licensed under the terms of the Apache Licence Version 2.0
6  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
7  */
8 
9 #ifndef OOPS_INTERFACE_MODEL_H_
10 #define OOPS_INTERFACE_MODEL_H_
11 
12 #include <string>
13 
14 #include <boost/noncopyable.hpp>
15 
16 #include "oops/base/ModelBase.h"
19 #include "oops/interface/State.h"
20 #include "oops/util/Duration.h"
21 #include "oops/util/Logger.h"
22 #include "oops/util/Printable.h"
23 #include "oops/util/Timer.h"
24 
25 namespace eckit {
26  class Configuration;
27 }
28 
29 namespace oops {
30 
31 /// Encapsulates the nonlinear forecast model
32 
33 // -----------------------------------------------------------------------------
34 
35 template <typename MODEL>
36 class Model : public util::Printable,
37  private boost::noncopyable,
38  private util::ObjectCounter<Model<MODEL> > {
43 
44  public:
45  static const std::string classname() {return "oops::Model";}
46 
47  Model(const Geometry_ &, const eckit::Configuration &);
48  virtual ~Model();
49 
50 // Run the forecast
51  void forecast(State_ &, const ModelAux_ &,
52  const util::Duration &, PostProcessor<State_> &) const;
53 
54 // Information and diagnostics
55  const util::Duration & timeResolution() const {return model_->timeResolution();}
56  const oops::Variables & variables() const {return model_->variables();}
57 
58  private:
59  void initialize(State_ &) const;
60  void step(State_ &, const ModelAux_ &) const;
61  void finalize(State_ &) const;
62  void print(std::ostream &) const;
63 
64  boost::scoped_ptr<ModelBase_> model_;
65 };
66 
67 // =============================================================================
68 
69 template<typename MODEL>
70 Model<MODEL>::Model(const Geometry_ & resol, const eckit::Configuration & conf)
71  : model_()
72 {
73  Log::trace() << "Model<MODEL>::Model starting" << std::endl;
74  util::Timer timer(classname(), "Model");
75  Log::debug() << "Model config is:" << conf << std::endl;
77  Log::trace() << "Model<MODEL>::Model done" << std::endl;
78 }
79 
80 // -----------------------------------------------------------------------------
81 
82 template<typename MODEL>
84  Log::trace() << "Model<MODEL>::~Model starting" << std::endl;
85  util::Timer timer(classname(), "~Model");
86  model_.reset();
87  Log::trace() << "Model<MODEL>::~Model done" << std::endl;
88 }
89 
90 // -----------------------------------------------------------------------------
91 // ****** NOTE: The forecast method below is not from MODEL::Model ******
92 // -----------------------------------------------------------------------------
93 
94 template<typename MODEL>
95 void Model<MODEL>::forecast(State_ & xx, const ModelAux_ & maux,
96  const util::Duration & len,
97  PostProcessor<State_> & post) const {
98  Log::trace() << "Model<MODEL>::forecast starting" << std::endl;
99  util::Timer timer(classname(), "forecast");
100 
101  const util::DateTime end(xx.validTime() + len);
102  Log::info() << "Model:forecast: forecast starting: " << xx << std::endl;
103  this->initialize(xx);
104  post.initialize(xx, end, model_->timeResolution());
105  post.process(xx);
106  while (xx.validTime() < end) {
107  this->step(xx, maux);
108  post.process(xx);
109  }
110  post.finalize(xx);
111  this->finalize(xx);
112  Log::info() << "Model:forecast: forecast finished: " << xx << std::endl;
113  ASSERT(xx.validTime() == end);
114 
115  Log::trace() << "Model<MODEL>::forecast done" << std::endl;
116 }
117 
118 // -----------------------------------------------------------------------------
119 // ****** NOTE: The forecast method above is not from MODEL::Model ******
120 // -----------------------------------------------------------------------------
121 
122 template<typename MODEL>
124  Log::trace() << "Model<MODEL>::initialize starting" << std::endl;
125  util::Timer timer(classname(), "initialize");
126  model_->initialize(xx);
127  Log::trace() << "Model<MODEL>::initialize done" << std::endl;
128 }
129 
130 // -----------------------------------------------------------------------------
131 
132 template<typename MODEL>
133 void Model<MODEL>::step(State_ & xx, const ModelAux_ & maux) const {
134  Log::trace() << "Model<MODEL>::step starting" << std::endl;
135  util::Timer timer(classname(), "step");
136  model_->step(xx, maux);
137  Log::trace() << "Model<MODEL>::step done" << std::endl;
138 }
139 
140 // -----------------------------------------------------------------------------
141 
142 template<typename MODEL>
143 void Model<MODEL>::finalize(State_ & xx) const {
144  Log::trace() << "Model<MODEL>::finalize starting" << std::endl;
145  util::Timer timer(classname(), "finalize");
146  model_->finalize(xx);
147  Log::trace() << "Model<MODEL>::finalize done" << std::endl;
148 }
149 
150 // -----------------------------------------------------------------------------
151 
152 template<typename MODEL>
153 void Model<MODEL>::print(std::ostream & os) const {
154  Log::trace() << "Model<MODEL>::print starting" << std::endl;
155  util::Timer timer(classname(), "print");
156  os << *model_;
157  Log::trace() << "Model<MODEL>::print done" << std::endl;
158 }
159 
160 // -----------------------------------------------------------------------------
161 
162 } // namespace oops
163 
164 #endif // OOPS_INTERFACE_MODEL_H_
subroutine finalize(self)
Definition: ncutils.F90:61
void forecast(State_ &, const ModelAux_ &, const util::Duration &, PostProcessor< State_ > &) const
static const std::string classname()
ModelFactory Factory.
Definition: ModelBase.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
Definition: conf.py:1
ModelBase< MODEL > ModelBase_
Model(const Geometry_ &, const eckit::Configuration &)
Encapsulates the model state.
void initialize(State_ &) const
The namespace for the main oops code.
Geometry< MODEL > Geometry_
logical debug
Definition: mpp.F90:1297
subroutine, private initialize
subroutine, public info(self)
void finalize(const FLDS &xx)
Definition: PostProcessor.h:60
void process(const FLDS &xx)
Definition: PostProcessor.h:56
Encapsulates the nonlinear forecast model.
const util::Duration & timeResolution() const
subroutine, public step(x, g)
boost::scoped_ptr< ModelBase_ > model_
ModelAuxControl< MODEL > ModelAux_
Control model post processing.
Definition: PostProcessor.h:31
void finalize(State_ &) const
Base class for encapsulation of the forecast model.
Definition: ModelBase.h:40
const oops::Variables & variables() const
void print(std::ostream &) const
void initialize(const FLDS &xx, const util::DateTime &end, const util::Duration &step)
Definition: PostProcessor.h:50
State< MODEL > State_
void step(State_ &, const ModelAux_ &) const
const util::DateTime validTime() const
Time.