FV3 Bundle
StateQG.cc
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 #include "model/StateQG.h"
12 
13 #include <algorithm>
14 #include <string>
15 #include <utility>
16 #include <vector>
17 
18 #include "eckit/config/LocalConfiguration.h"
19 #include "model/FieldsQG.h"
20 #include "model/GeometryQG.h"
21 #include "model/GomQG.h"
22 #include "model/IncrementQG.h"
23 #include "model/LocationsQG.h"
24 #include "model/ModelBias.h"
25 #include "model/ModelQG.h"
26 #include "model/Nothing.h"
27 #include "oops/base/Variables.h"
28 #include "oops/util/DateTime.h"
29 #include "oops/util/Duration.h"
30 #include "oops/util/Logger.h"
31 
32 namespace qg {
33 
34 // -----------------------------------------------------------------------------
35 /// Constructor, destructor
36 // -----------------------------------------------------------------------------
38  const util::DateTime & vt)
39  : fields_(new FieldsQG(resol, vars, vt)), stash_()
40 {
41  oops::Log::trace() << "StateQG::StateQG created." << std::endl;
42 }
43 // -----------------------------------------------------------------------------
45  const eckit::Configuration & file)
46  : fields_(new FieldsQG(resol, vars, util::DateTime())), stash_()
47 {
48  if (file.has("analytic_init")) {
49  fields_->analytic_init(file, resol);
50  } else if (file.has("read_from_file")) {
51  // read_from_file included for backwards compatability
52  (file.getInt("read_from_file") == 1) ?
53  fields_->read(file) : fields_->analytic_init(file, resol);
54  } else {
55  fields_->read(file);
56  }
57 
58  ASSERT(fields_);
59  oops::Log::trace() << "StateQG::StateQG created and read in." << std::endl;
60 }
61 // -----------------------------------------------------------------------------
62 StateQG::StateQG(const GeometryQG & resol, const StateQG & other)
63  : fields_(new FieldsQG(*other.fields_, resol)), stash_()
64 {
65  ASSERT(fields_);
66  oops::Log::trace() << "StateQG::StateQG created by interpolation." << std::endl;
67 }
68 // -----------------------------------------------------------------------------
69 StateQG::StateQG(const StateQG & other)
70  : fields_(new FieldsQG(*other.fields_)), stash_()
71 {
72  ASSERT(fields_);
73  oops::Log::trace() << "StateQG::StateQG copied." << std::endl;
74 }
75 // -----------------------------------------------------------------------------
77  oops::Log::trace() << "StateQG::StateQG destructed." << std::endl;
78 }
79 // -----------------------------------------------------------------------------
80 /// Basic operators
81 // -----------------------------------------------------------------------------
83  ASSERT(fields_);
84  *fields_ = *rhs.fields_;
85  return *this;
86 }
87 // -----------------------------------------------------------------------------
88 /// Get state values at observation locations
89 // -----------------------------------------------------------------------------
91  GomQG & cols) const {
92  fields_->getValues(locs, vars, cols);
93 }
94 // -----------------------------------------------------------------------------
96  GomQG & cols, Nothing &) const {
97  fields_->getValues(locs, vars, cols);
98 }
99 // -----------------------------------------------------------------------------
100 /// Interpolate full fields
101 // -----------------------------------------------------------------------------
102 void StateQG::changeResolution(const StateQG & other) {
103  fields_->changeResolution(*other.fields_);
104  oops::Log::trace() << "StateQG interpolated" << std::endl;
105 }
106 // -----------------------------------------------------------------------------
107 /// Interactions with Increments
108 // -----------------------------------------------------------------------------
110  ASSERT(this->validTime() == dx.validTime());
111  ASSERT(fields_);
112  fields_->add(dx.fields());
113  return *this;
114 }
115 // -----------------------------------------------------------------------------
116 /// I/O and diagnostics
117 // -----------------------------------------------------------------------------
118 void StateQG::read(const eckit::Configuration & files) {
119  fields_->read(files);
120 }
121 // -----------------------------------------------------------------------------
122 void StateQG::write(const eckit::Configuration & files) const {
123  fields_->write(files);
124 }
125 // -----------------------------------------------------------------------------
126 void StateQG::print(std::ostream & os) const {
127  os << std::endl << " Valid time: " << validTime();
128  os << *fields_;
129 }
130 // -----------------------------------------------------------------------------
131 /// For accumulator
132 // -----------------------------------------------------------------------------
134  fields_->zero();
135 }
136 // -----------------------------------------------------------------------------
137 void StateQG::accumul(const double & zz, const StateQG & xx) {
138  fields_->axpy(zz, *xx.fields_);
139 }
140 // -----------------------------------------------------------------------------
142  return fields_->getPoint(iter);
143 }
144 
145 } // namespace qg
GomQG class to handle local model values for QG model.
Definition: GomQG.h:31
FieldsQG & fields()
Access to fields.
Definition: IncrementQG.h:102
void getValues(const LocationsQG &, const oops::Variables &, GomQG &) const
Get state values at observation locations.
Definition: StateQG.cc:90
Class to represent a FieldSet for the QG model.
Definition: FieldsQG.h:46
StateQG & operator=(const StateQG &)
Basic operators.
Definition: StateQG.cc:82
void accumul(const double &, const StateQG &)
Definition: StateQG.cc:137
virtual ~StateQG()
Definition: StateQG.cc:76
boost::scoped_ptr< FieldsQG > fields_
Definition: StateQG.h:96
void zero()
Other.
Definition: StateQG.cc:133
StateQG & operator+=(const IncrementQG &)
Interactions with Increment.
Definition: StateQG.cc:109
void print(std::ostream &) const
Definition: StateQG.cc:126
const util::DateTime & validTime() const
Definition: StateQG.h:77
type(file_type), dimension(:), allocatable, save files
Definition: diag_data.F90:780
real, dimension(:,:,:), allocatable vt
const util::DateTime & validTime() const
Definition: IncrementQG.h:92
StateQG(const GeometryQG &, const oops::Variables &, const util::DateTime &)
Constructor, destructor.
Definition: StateQG.cc:37
void write(const eckit::Configuration &) const
Definition: StateQG.cc:122
QG model state.
Definition: StateQG.h:50
GeometryQG handles geometry for QG model.
Definition: GeometryQG.h:33
LocationsQG class to handle locations for QG model.
Definition: LocationsQG.h:26
void changeResolution(const StateQG &xx)
Interpolate full fields.
Definition: StateQG.cc:102
void read(const eckit::Configuration &)
I/O and diagnostics.
Definition: StateQG.cc:118
oops::GridPoint getPoint(const GeometryQGIterator &) const
Definition: StateQG.cc:141
The namespace for the qg model.
Increment Class: Difference between two states.
Definition: IncrementQG.h:55