FV3 Bundle
MakeObs.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_MAKEOBS_H_
12 #define OOPS_RUNS_MAKEOBS_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"
20 #include "oops/base/Departures.h"
22 #include "oops/base/ObsErrors.h"
23 #include "oops/base/Observations.h"
24 #include "oops/base/Observer.h"
25 #include "oops/base/ObsFilters.h"
26 #include "oops/base/ObsOperators.h"
27 #include "oops/base/ObsSpaces.h"
29 #include "oops/base/StateInfo.h"
32 #include "oops/interface/Model.h"
35 #include "oops/interface/State.h"
36 #include "oops/runs/Application.h"
37 #include "oops/util/DateTime.h"
38 #include "oops/util/Duration.h"
39 #include "oops/util/Logger.h"
40 
41 namespace oops {
42 
43 template <typename MODEL> class MakeObs : public Application {
54 
55  public:
56 // -----------------------------------------------------------------------------
57  MakeObs() {
58  instantiateObsErrorFactory<MODEL>();
59  instantiateFilterFactory<MODEL>();
60  }
61 // -----------------------------------------------------------------------------
62  virtual ~MakeObs() {}
63 // -----------------------------------------------------------------------------
64  int execute(const eckit::Configuration & fullConfig) const {
65 // Setup observation window
66  const eckit::LocalConfiguration windowConf(fullConfig, "Assimilation Window");
67  const util::DateTime bgn(windowConf.getString("Begin"));
68  const util::DateTime end(windowConf.getString("End"));
69  const util::Duration fclen(end - bgn);
70  Log::info() << "Observation window is:" << windowConf << std::endl;
71 
72 // Setup resolution
73  const eckit::LocalConfiguration resolConfig(fullConfig, "Geometry");
74  const Geometry_ resol(resolConfig);
75 
76 // Setup Model
77  const eckit::LocalConfiguration modelConfig(fullConfig, "Model");
78  const Model_ model(resol, modelConfig);
79 
80 // Setup initial "true" state
81  const eckit::LocalConfiguration initialConfig(fullConfig, "Initial Condition");
82  Log::info() << "Initial configuration is:" << initialConfig << std::endl;
83  State_ xx(resol, model.variables(), initialConfig);
84  Log::test() << "Initial state: " << xx << std::endl;
85 
86 // Setup augmented state
87  ModelAux_ moderr(resol, initialConfig);
88 
89 // Setup forecast outputs
91 
92  eckit::LocalConfiguration prtConf;
93  fullConfig.get("prints", prtConf);
94  post.enrollProcessor(new StateInfo<State_>("fc", prtConf));
95 
96 // Setup observations
97  eckit::LocalConfiguration biasConf;
98  fullConfig.get("ObsBias", biasConf);
99  ObsAuxCtrl_ ybias(biasConf);
100 
101 // Setup observations
102  const eckit::LocalConfiguration obsconf(fullConfig, "Observations");
103  Log::info() << "Observation configuration is:" << obsconf << std::endl;
104  ObsSpace_ obspace(obsconf, bgn, end);
105  ObsOperator_ hop(obspace);
106 
107 // Setup QC filters
108  eckit::LocalConfiguration filterConf;
109  obsconf.get("ObsFilters", filterConf);
110  ObsFilters_ filter(obspace, obsconf);
111 
112 // Setup Observer
113  boost::shared_ptr<Observer<MODEL, State_> >
114  pobs(new Observer<MODEL, State_>(obspace, hop, ybias, filter));
115  post.enrollProcessor(pobs);
116 
117 // Run forecast and generate observations
118  model.forecast(xx, moderr, fclen, post);
119  Log::test() << "Final state: " << xx << std::endl;
120  Log::info() << "MakeObs: Finished observation generation." << std::endl;
121 
122  boost::scoped_ptr<Observations_> yobs(pobs->release());
123  Log::info() << "Generated observation: " << *yobs << std::endl;
124 
125 // Perturb observations
126  if (obsconf.has("obspert")) {
127  Departures_ ypert(obspace);
128  ObsErrors<MODEL> matR(obspace);
129  matR.randomize(ypert);
130  double opert = obsconf.getDouble("obspert");
131  ypert *= opert;
132  *yobs += ypert;
133  Log::info() << "Perturbed observation: " << *yobs << std::endl;
134  }
135 
136 // Save observations
137  for (std::size_t jj = 0; jj < yobs->size(); ++jj) {
138  Log::test() << "Generated observation: " << (*yobs)[jj] << std::endl;
139  }
140  yobs->save("ObsVal");
141 
142  return 0;
143  }
144 // -----------------------------------------------------------------------------
145  private:
146  std::string appname() const {
147  return "oops::MakeObs<" + MODEL::name() + ">";
148  }
149 // -----------------------------------------------------------------------------
150 };
151 
152 } // namespace oops
153 #endif // OOPS_RUNS_MAKEOBS_H_
ObsOperators< MODEL > ObsOperator_
Definition: MakeObs.h:52
virtual ~MakeObs()
Definition: MakeObs.h:62
Departures< MODEL > Departures_
Definition: MakeObs.h:44
State< MODEL > State_
Definition: MakeObs.h:53
Difference between two observation vectors.
Definition: Departures.h:36
Observations< MODEL > Observations_
Definition: MakeObs.h:49
************************************************************************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
ModelAuxControl< MODEL > ModelAux_
Definition: MakeObs.h:47
Model< MODEL > Model_
Definition: MakeObs.h:46
std::string appname() const
Definition: MakeObs.h:146
Encapsulates the model state.
Observations Class.
Definition: Observations.h:36
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)
int execute(const eckit::Configuration &fullConfig) const
Definition: MakeObs.h:64
Encapsulates the nonlinear forecast model.
ObsSpaces< MODEL > ObsSpace_
Definition: MakeObs.h:51
void randomize(Departures_ &) const
Generate random perturbation.
Definition: ObsErrors.h:120
Computes observation equivalent during model run.
Definition: Observer.h:43
ObsFilters< MODEL > ObsFilters_
Definition: MakeObs.h:50
Geometry< MODEL > Geometry_
Definition: MakeObs.h:45
Control model post processing.
Definition: PostProcessor.h:31
ObsAuxControl< MODEL > ObsAuxCtrl_
Definition: MakeObs.h:48
void enrollProcessor(PostBase_ *pp)
Definition: PostProcessor.h:39