OOPS
IncrementQG.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  * (C) Copyright 2017-2019 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  * In applying this licence, ECMWF does not waive the privileges and immunities
8  * granted to it by virtue of its status as an intergovernmental organisation nor
9  * does it submit to any jurisdiction.
10  */
11 
12 #include "model/IncrementQG.h"
13 
14 #include <algorithm>
15 #include <string>
16 #include <utility>
17 #include <vector>
18 
19 #include "atlas/field.h"
20 
21 #include "eckit/config/LocalConfiguration.h"
22 #include "eckit/exception/Exceptions.h"
23 
24 #include "oops/base/Variables.h"
25 #include "oops/util/DateTime.h"
26 #include "oops/util/Duration.h"
27 #include "oops/util/Logger.h"
28 
30 #include "model/FieldsQG.h"
31 #include "model/GeometryQG.h"
32 #include "model/GomQG.h"
33 #include "model/LocationsQG.h"
35 #include "model/StateQG.h"
36 
37 namespace qg {
38 
39 // -----------------------------------------------------------------------------
40 /// Constructor, destructor
41 // -----------------------------------------------------------------------------
43  const util::DateTime & vt)
44  : fields_(new FieldsQG(resol, vars, lbc_, vt))
45 {
46  fields_->zero();
47  oops::Log::trace() << "IncrementQG constructed." << std::endl;
48 }
49 // -----------------------------------------------------------------------------
50 IncrementQG::IncrementQG(const GeometryQG & resol, const IncrementQG & other)
51  : fields_(new FieldsQG(*other.fields_, resol))
52 {
53  oops::Log::trace() << "IncrementQG constructed from other." << std::endl;
54 }
55 // -----------------------------------------------------------------------------
56 IncrementQG::IncrementQG(const IncrementQG & other, const bool copy)
57  : fields_(new FieldsQG(*other.fields_, copy))
58 {
59  oops::Log::trace() << "IncrementQG copy-created." << std::endl;
60 }
61 // -----------------------------------------------------------------------------
63  : fields_(new FieldsQG(*other.fields_))
64 {
65  oops::Log::trace() << "IncrementQG copy-created." << std::endl;
66 }
67 // -----------------------------------------------------------------------------
69  oops::Log::trace() << "IncrementQG destructed" << std::endl;
70 }
71 // -----------------------------------------------------------------------------
72 /// Basic operators
73 // -----------------------------------------------------------------------------
74 void IncrementQG::diff(const StateQG & x1, const StateQG & x2) {
75  ASSERT(this->validTime() == x1.validTime());
76  ASSERT(this->validTime() == x2.validTime());
77  fields_->diff(x1.fields(), x2.fields());
78 }
79 // -----------------------------------------------------------------------------
81  *fields_ = *rhs.fields_;
82  return *this;
83 }
84 // -----------------------------------------------------------------------------
86  ASSERT(this->validTime() == dx.validTime());
87  *fields_ += *dx.fields_;
88  return *this;
89 }
90 // -----------------------------------------------------------------------------
92  ASSERT(this->validTime() == dx.validTime());
93  *fields_ -= *dx.fields_;
94  return *this;
95 }
96 // -----------------------------------------------------------------------------
97 IncrementQG & IncrementQG::operator*=(const double & zz) {
98  *fields_ *= zz;
99  return *this;
100 }
101 // -----------------------------------------------------------------------------
103  fields_->zero();
104 }
105 // -----------------------------------------------------------------------------
106 void IncrementQG::zero(const util::DateTime & vt) {
107  fields_->zero(vt);
108 }
109 // -----------------------------------------------------------------------------
111  fields_->ones();
112 }
113 // -----------------------------------------------------------------------------
114 void IncrementQG::axpy(const double & zz, const IncrementQG & dx,
115  const bool check) {
116  ASSERT(!check || this->validTime() == dx.validTime());
117  fields_->axpy(zz, *dx.fields_);
118 }
119 // -----------------------------------------------------------------------------
120 void IncrementQG::accumul(const double & zz, const StateQG & xx) {
121  fields_->axpy(zz, xx.fields());
122 }
123 // -----------------------------------------------------------------------------
125  fields_->schur_product_with(*dx.fields_);
126 }
127 // -----------------------------------------------------------------------------
128 double IncrementQG::dot_product_with(const IncrementQG & other) const {
129  return dot_product(*fields_, *other.fields_);
130 }
131 // -----------------------------------------------------------------------------
133  fields_->random();
134 }
135 // -----------------------------------------------------------------------------
136 void IncrementQG::dirac(const eckit::Configuration & config) {
137  fields_->zero();
138  util::DateTime dd(config.getString("date"));
139  if (this->validTime() == dd) fields_->dirac(config);
140 }
141 // -----------------------------------------------------------------------------
142 /// ATLAS FieldSet
143 // -----------------------------------------------------------------------------
144 void IncrementQG::setAtlas(atlas::FieldSet * afieldset) const {
145  fields_->setAtlas(afieldset);
146 }
147 // -----------------------------------------------------------------------------
148 void IncrementQG::toAtlas(atlas::FieldSet * afieldset) const {
149  fields_->toAtlas(afieldset);
150 }
151 // -----------------------------------------------------------------------------
152 void IncrementQG::fromAtlas(atlas::FieldSet * afieldset) {
153  fields_->fromAtlas(afieldset);
154 }
155 // -----------------------------------------------------------------------------
156 /// I/O and diagnostics
157 // -----------------------------------------------------------------------------
158 void IncrementQG::read(const eckit::Configuration & files) {
159  fields_->read(files);
160 }
161 // -----------------------------------------------------------------------------
162 void IncrementQG::write(const eckit::Configuration & files) const {
163  fields_->write(files);
164 }
165 // -----------------------------------------------------------------------------
166 /// Serialization
167 // -----------------------------------------------------------------------------
168 size_t IncrementQG::serialSize() const {
169  size_t nn = fields_->serialSize();
170  return nn;
171 }
172 // -----------------------------------------------------------------------------
173 void IncrementQG::serialize(std::vector<double> & vect) const {
174  fields_->serialize(vect);
175 }
176 // -----------------------------------------------------------------------------
177 void IncrementQG::deserialize(const std::vector<double> & vect, size_t & index) {
178  fields_->deserialize(vect, index);
179 }
180 // -----------------------------------------------------------------------------
181 void IncrementQG::print(std::ostream & os) const {
182  os << std::endl << " Valid time: " << validTime();
183  os << *fields_;
184 }
185 // -----------------------------------------------------------------------------
187  return fields_->getLocal(iter);
188 }
189 // -----------------------------------------------------------------------------
191  fields_->setLocal(values, iter);
192 }
193 // -----------------------------------------------------------------------------
194 
195 } // namespace qg
Class to represent a Fields for the QG model.
Definition: FieldsQG.h:52
GeometryQG handles geometry for QG model.
Definition: GeometryQG.h:58
Increment Class: Difference between two states.
Definition: IncrementQG.h:64
double dot_product_with(const IncrementQG &) const
Definition: IncrementQG.cc:128
virtual ~IncrementQG()
Definition: IncrementQG.cc:68
void setAtlas(atlas::FieldSet *) const
ATLAS FieldSet.
Definition: IncrementQG.cc:144
void axpy(const double &, const IncrementQG &, const bool check=true)
Definition: IncrementQG.cc:114
void setLocal(const oops::LocalIncrement &, const GeometryQGIterator &)
Definition: IncrementQG.cc:190
void print(std::ostream &) const override
Data.
Definition: IncrementQG.cc:181
void read(const eckit::Configuration &)
I/O and diagnostics.
Definition: IncrementQG.cc:158
const util::DateTime & validTime() const
Definition: IncrementQG.h:94
void toAtlas(atlas::FieldSet *) const
Definition: IncrementQG.cc:148
void dirac(const eckit::Configuration &)
Definition: IncrementQG.cc:136
void write(const eckit::Configuration &) const
Definition: IncrementQG.cc:162
IncrementQG & operator+=(const IncrementQG &)
Definition: IncrementQG.cc:85
IncrementQG & operator=(const IncrementQG &)
Definition: IncrementQG.cc:80
void schur_product_with(const IncrementQG &)
Definition: IncrementQG.cc:124
void serialize(std::vector< double > &) const override
Definition: IncrementQG.cc:173
IncrementQG & operator-=(const IncrementQG &)
Definition: IncrementQG.cc:91
void diff(const StateQG &, const StateQG &)
Basic operators.
Definition: IncrementQG.cc:74
void deserialize(const std::vector< double > &, size_t &) override
Definition: IncrementQG.cc:177
size_t serialSize() const override
Serialization.
Definition: IncrementQG.cc:168
void fromAtlas(atlas::FieldSet *)
Definition: IncrementQG.cc:152
oops::LocalIncrement getLocal(const GeometryQGIterator &) const
Definition: IncrementQG.cc:186
IncrementQG(const GeometryQG &, const oops::Variables &, const util::DateTime &)
Constructor, destructor.
Definition: IncrementQG.cc:42
std::unique_ptr< FieldsQG > fields_
Definition: IncrementQG.h:125
IncrementQG & operator*=(const double &)
Definition: IncrementQG.cc:97
void accumul(const double &, const StateQG &)
Other.
Definition: IncrementQG.cc:120
QG model state.
Definition: StateQG.h:42
FieldsQG & fields()
Access to fields.
Definition: StateQG.h:69
const util::DateTime & validTime() const
Definition: StateQG.h:64
The namespace for the qg model.