FV3 Bundle
ExternalDFI.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_RUNS_EXTERNALDFI_H_
12 #define OOPS_RUNS_EXTERNALDFI_H_
13 
14 #include <string>
15 
16 #include <boost/scoped_ptr.hpp>
17 #include <boost/shared_ptr.hpp>
18 
19 #include "eckit/config/LocalConfiguration.h"
21 #include "oops/base/StateInfo.h"
22 #include "oops/base/StateWriter.h"
23 #include "oops/base/WeightedMean.h"
25 #include "oops/interface/Model.h"
27 #include "oops/interface/State.h"
28 #include "oops/runs/Application.h"
29 #include "oops/util/abor1_cpp.h"
30 #include "oops/util/DateTime.h"
31 #include "oops/util/Duration.h"
32 #include "oops/util/Logger.h"
33 
34 namespace oops {
35 
36 template <typename MODEL> class ExternalDFI : public Application {
41 
42  public:
43 // -----------------------------------------------------------------------------
45 // -----------------------------------------------------------------------------
46  virtual ~ExternalDFI() {}
47 // -----------------------------------------------------------------------------
48  int execute(const eckit::Configuration & fullConfig) const {
49 // Setup resolution
50  const eckit::LocalConfiguration resolConfig(fullConfig, "resolution");
51  const Geometry_ resol(resolConfig);
52 
53 // Setup Model
54  const eckit::LocalConfiguration modelConfig(fullConfig, "model");
55  const Model_ model(resol, modelConfig);
56 
57 // Setup initial state
58  const eckit::LocalConfiguration initialConfig(fullConfig, "initial");
59  State_ xx(resol, model.variables(), initialConfig);
60  Log::test() << "Initial state: " << xx << std::endl;
61 
62 // Setup augmented state
63  const ModelAux_ moderr(resol, initialConfig);
64 
65 // Setup times
66  const util::Duration fclength(fullConfig.getString("forecast_length"));
67  const util::DateTime bgndate(xx.validTime());
68  const util::DateTime enddate(bgndate + fclength);
69  Log::info() << "Running forecast from " << bgndate << " to " << enddate << std::endl;
70 
71 // Setup post-processing
73 
74  eckit::LocalConfiguration prtConf;
75  fullConfig.get("prints", prtConf);
76  post.enrollProcessor(new StateInfo<State_>("fc", prtConf));
77 
78 // Setup DFI
79  PostProcessor<State_> pp(post);
80 
81  const eckit::LocalConfiguration dfiConf(fullConfig, "dfi");
82  const util::Duration dfispan(dfiConf.getString("filter_span"));
83  const util::DateTime dfitime(bgndate+dfispan/2);
84  boost::shared_ptr< WeightedMean<MODEL, State_> >
85  pdfi(new WeightedMean<MODEL, State_>(dfitime, dfispan, resol, dfiConf));
86  pp.enrollProcessor(pdfi);
87 
88 // Run DFI forecast
89  model.forecast(xx, moderr, dfispan, pp);
90 
91 // Retrieve initialized state
92  boost::scoped_ptr<State_> xdfi(pdfi->releaseMean());
93  Log::test() << "Filtered state: " << *xdfi << std::endl;
94 
95 // Setup forecast outputs
96  const eckit::LocalConfiguration outConfig(fullConfig, "output");
97  post.enrollProcessor(new StateWriter<State_>(bgndate, outConfig));
98 
99 // Run forecast from initialized state
100  const util::Duration fclen = fclength - dfispan/2;
101  if (fclength < util::Duration(0)) ABORT("DFI: fliter span longer than forecast");
102  State_ zz(*xdfi);
103  model.forecast(zz, moderr, fclen, post);
104  Log::test() << "Final state: " << zz << std::endl;
105 
106  return 0;
107  }
108 // -----------------------------------------------------------------------------
109  private:
110  std::string appname() const {
111  return "oops::ExternalDFI<" + MODEL::name() + ">";
112  }
113 // -----------------------------------------------------------------------------
114 };
115 
116 } // namespace oops
117 #endif // OOPS_RUNS_EXTERNALDFI_H_
Model< MODEL > Model_
Definition: ExternalDFI.h:38
Handles writing-out of forecast fields.
Definition: StateWriter.h:26
Geometry< MODEL > Geometry_
Definition: ExternalDFI.h:37
State< MODEL > State_
Definition: ExternalDFI.h:40
Encapsulates the model state.
int execute(const eckit::Configuration &fullConfig) const
Definition: ExternalDFI.h:48
program test
character(len=32) name
The namespace for the main oops code.
Handles writing-out of forecast fields.
Definition: StateInfo.h:28
subroutine, public info(self)
Encapsulates the nonlinear forecast model.
ModelAuxControl< MODEL > ModelAux_
Definition: ExternalDFI.h:39
Compute time average of states or increments during model run.
Definition: WeightedMean.h:39
Control model post processing.
Definition: PostProcessor.h:31
virtual ~ExternalDFI()
Definition: ExternalDFI.h:46
std::string appname() const
Definition: ExternalDFI.h:110
void enrollProcessor(PostBase_ *pp)
Definition: PostProcessor.h:39