OOPS
FieldsQG.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/FieldsQG.h"
12 
13 #include <cmath>
14 #include <iomanip>
15 #include <map>
16 #include <string>
17 #include <vector>
18 
19 #include "atlas/field.h"
20 
21 #include "eckit/config/Configuration.h"
22 #include "eckit/config/LocalConfiguration.h"
23 
24 #include "model/GeometryQG.h"
25 #include "model/GomQG.h"
26 #include "model/LocationsQG.h"
27 #include "model/QgFortran.h"
28 
29 #include "oops/base/Variables.h"
30 #include "oops/util/DateTime.h"
31 #include "oops/util/Logger.h"
32 
33 // -----------------------------------------------------------------------------
34 namespace qg {
35 // -----------------------------------------------------------------------------
36 FieldsQG::FieldsQG(const GeometryQG & geom, const oops::Variables & vars,
37  const bool & lbc, const util::DateTime & time):
38  geom_(new GeometryQG(geom)), vars_(vars), lbc_(lbc), time_(time)
39 {
40  qg_fields_create_f90(keyFlds_, geom_->toFortran(), vars_, lbc_);
41 }
42 // -----------------------------------------------------------------------------
43 FieldsQG::FieldsQG(const FieldsQG & other, const bool copy)
44  : geom_(other.geom_), vars_(other.vars_), lbc_(other.lbc_), time_(other.time_)
45 {
47  if (copy) {
49  }
50 }
51 // -----------------------------------------------------------------------------
53  : geom_(other.geom_), vars_(other.vars_), lbc_(other.lbc_), time_(other.time_)
54 {
57 }
58 // -----------------------------------------------------------------------------
59 FieldsQG::FieldsQG(const FieldsQG & other, const GeometryQG & geom)
60  : geom_(new GeometryQG(geom)), vars_(other.vars_), lbc_(other.lbc_), time_(other.time_)
61 {
62  qg_fields_create_f90(keyFlds_, geom_->toFortran(), vars_, lbc_);
64 }
65 // -----------------------------------------------------------------------------
66 FieldsQG::FieldsQG(const FieldsQG & other, const oops::Variables & vars)
67  : geom_(other.geom_), vars_(vars), lbc_(other.lbc_), time_(other.time_)
68 {
69 // TODO(Benjamin): delete that ?
70  qg_fields_create_f90(keyFlds_, geom_->toFortran(), vars_, lbc_);
72 }
73 // -----------------------------------------------------------------------------
76 }
77 // -----------------------------------------------------------------------------
80  time_ = rhs.time_;
81  return *this;
82 }
83 // -----------------------------------------------------------------------------
86  return *this;
87 }
88 // -----------------------------------------------------------------------------
91  return *this;
92 }
93 // -----------------------------------------------------------------------------
94 FieldsQG & FieldsQG::operator*=(const double & zz) {
96  return *this;
97 }
98 // -----------------------------------------------------------------------------
101 }
102 // -----------------------------------------------------------------------------
103 void FieldsQG::zero(const util::DateTime & time) {
105  time_ = time;
106 }
107 // -----------------------------------------------------------------------------
110 }
111 // -----------------------------------------------------------------------------
112 void FieldsQG::axpy(const double & zz, const FieldsQG & rhs) {
114 }
115 // -----------------------------------------------------------------------------
116 double FieldsQG::dot_product_with(const FieldsQG & fld2) const {
117  double zz;
119  return zz;
120 }
121 // -----------------------------------------------------------------------------
124 }
125 // -----------------------------------------------------------------------------
128 }
129 // -----------------------------------------------------------------------------
130 void FieldsQG::dirac(const eckit::Configuration & config) {
131  qg_fields_dirac_f90(keyFlds_, config);
132 }
133 // -----------------------------------------------------------------------------
136 }
137 // -----------------------------------------------------------------------------
138 void FieldsQG::add(const FieldsQG & rhs) {
139  FieldsQG rhs_myres(rhs, *geom_);
141 }
142 // -----------------------------------------------------------------------------
143 void FieldsQG::diff(const FieldsQG & x1, const FieldsQG & x2) {
144  FieldsQG x1_myres(x1, *geom_);
145  FieldsQG x2_myres(x2, *geom_);
146  qg_fields_diff_incr_f90(keyFlds_, x1_myres.keyFlds_, x2_myres.keyFlds_);
147 }
148 // -----------------------------------------------------------------------------
149 void FieldsQG::setAtlas(atlas::FieldSet * afieldset) const {
150  qg_fields_set_atlas_f90(keyFlds_, vars_, afieldset->get());
151 }
152 // -----------------------------------------------------------------------------
153 void FieldsQG::toAtlas(atlas::FieldSet * afieldset) const {
154  qg_fields_to_atlas_f90(keyFlds_, vars_, afieldset->get());
155 }
156 // -----------------------------------------------------------------------------
157 void FieldsQG::fromAtlas(atlas::FieldSet * afieldset) {
158  qg_fields_from_atlas_f90(keyFlds_, vars_, afieldset->get());
159 }
160 // -----------------------------------------------------------------------------
161 void FieldsQG::read(const eckit::Configuration & config) {
163 }
164 // -----------------------------------------------------------------------------
165 void FieldsQG::analytic_init(const eckit::Configuration & config) {
167 }
168 // -----------------------------------------------------------------------------
169 void FieldsQG::write(const eckit::Configuration & config) const {
171 }
172 // -----------------------------------------------------------------------------
173 double FieldsQG::norm() const {
174  double zz = 0.0;
176  return zz;
177 }
178 // -----------------------------------------------------------------------------
179 void FieldsQG::print(std::ostream & os) const {
180  int nx, ny, nz, nb, lq, lbc;
181  qg_fields_sizes_f90(keyFlds_, nx, ny, nz, nb);
182  qg_fields_vars_f90(keyFlds_, lq, lbc);
183  os << std::endl << " Resolution = " << nx << ", " << ny << ", " << nz;
184  if (lq == 1) {
185  os << std::endl << " Variable = potential vorticity";
186  } else {
187  os << std::endl << " Variable = streamfunction";
188  }
189  if (lbc == 1) {
190  os << std::endl << " Boundary conditions are activated";
191  } else {
192  os << std::endl << " Boundary conditions are not activated";
193  }
194  std::vector<double> zstat(4*(1+nb));
195  qg_fields_gpnorm_f90(keyFlds_, nb, zstat[0]);
196  for (int jj = 0; jj < 1+nb; ++jj) {
197  std::ios_base::fmtflags f(os.flags());
198  os << std::endl << " Scaling=" << std::setprecision(4) << std::setw(7) << zstat[4*jj]
199  << ", Min=" << std::fixed << std::setprecision(4) << std::setw(12) << zstat[4*jj+1]
200  << ", Max=" << std::fixed << std::setprecision(4) << std::setw(12) <<zstat[4*jj+2]
201  << ", RMS=" << std::fixed << std::setprecision(4) << std::setw(12) <<zstat[4*jj+3];
202  os.flags(f);
203  }
204 }
205 // -----------------------------------------------------------------------------
206 bool FieldsQG::isForModel(const bool & nonlinear) const {
207  int nx, ny, nz, nb;
208  qg_fields_sizes_f90(keyFlds_, nx, ny, nz, nb);
209  bool ok = true;
210  if (nonlinear) ok = (nb == 2);
211  return ok;
212 }
213 // -----------------------------------------------------------------------------
215  int nx, ny, nz, nb;
216  qg_fields_sizes_f90(keyFlds_, nx, ny, nz, nb);
217  std::vector<int> varlens(1, nz);
218  std::vector<double> values(nz);
219  qg_fields_getpoint_f90(keyFlds_, iter.toFortran(), nz, values[0]);
220  return oops::LocalIncrement(vars_, values, varlens);
221 }
222 // -----------------------------------------------------------------------------
224  const std::vector<double> vals = x.getVals();
225  qg_fields_setpoint_f90(keyFlds_, iter.toFortran(), vals.size(), vals[0]);
226 }
227 // -----------------------------------------------------------------------------
228 size_t FieldsQG::serialSize() const {
229  size_t nn = 0;
230  int nx, ny, nz, nb;
231  qg_fields_sizes_f90(keyFlds_, nx, ny, nz, nb);
232  nn += nx * ny * nz + nb * (nx + 1) * nz;
233  nn += time_.serialSize();
234  return nn;
235 }
236 // -----------------------------------------------------------------------------
237 void FieldsQG::serialize(std::vector<double> & vect) const {
238  int size_fld = this->serialSize() - 2;
239 
240  // Allocate space for fld, xb and qb
241  std::vector<double> v_fld(size_fld, 0);
242 
243  // Serialize the field
244  qg_fields_serialize_f90(keyFlds_, size_fld, v_fld.data());
245  vect.insert(vect.end(), v_fld.begin(), v_fld.end());
246 
247  // Serialize the date and time
248  time_.serialize(vect);
249 }
250 // -----------------------------------------------------------------------------
251 void FieldsQG::deserialize(const std::vector<double> & vect, size_t & index) {
252  qg_fields_deserialize_f90(keyFlds_, vect.size(), vect.data(), index);
253  time_.deserialize(vect, index);
254 }
255 // -----------------------------------------------------------------------------
256 } // namespace qg
qg::qg_fields_change_resol_f90
void qg_fields_change_resol_f90(const F90flds &, const F90flds &)
qg::qg_fields_create_f90
void qg_fields_create_f90(F90flds &, const F90geom &, const oops::Variables &, const bool &)
qg::qg_fields_zero_f90
void qg_fields_zero_f90(const F90flds &)
qg::FieldsQG::FieldsQG
FieldsQG(const GeometryQG &, const oops::Variables &, const bool &, const util::DateTime &)
Definition: FieldsQG.cc:36
FieldsQG.h
qg
The namespace for the qg model.
Definition: qg/model/AnalyticInit.cc:13
qg::FieldsQG::fromAtlas
void fromAtlas(atlas::FieldSet *)
Definition: FieldsQG.cc:157
qg::qg_fields_self_schur_f90
void qg_fields_self_schur_f90(const F90flds &, const F90flds &)
qg::FieldsQG::dot_product_with
double dot_product_with(const FieldsQG &) const
Definition: FieldsQG.cc:116
QgFortran.h
qg::FieldsQG::vars_
const oops::Variables vars_
Definition: FieldsQG.h:115
qg::qg_fields_set_atlas_f90
void qg_fields_set_atlas_f90(const F90flds &, const oops::Variables &, atlas::field::FieldSetImpl *)
qg::FieldsQG::setAtlas
void setAtlas(atlas::FieldSet *) const
Definition: FieldsQG.cc:149
qg::qg_fields_analytic_init_f90
void qg_fields_analytic_init_f90(const F90flds &, const eckit::Configuration &, util::DateTime &)
qg::qg_fields_delete_f90
void qg_fields_delete_f90(F90flds &)
qg::qg_fields_random_f90
void qg_fields_random_f90(const F90flds &)
qg::FieldsQG::dirac
void dirac(const eckit::Configuration &)
Definition: FieldsQG.cc:130
qg::FieldsQG::serialize
void serialize(std::vector< double > &) const override
Definition: FieldsQG.cc:237
qg::FieldsQG::write
void write(const eckit::Configuration &) const
Definition: FieldsQG.cc:169
qg::qg_fields_serialize_f90
void qg_fields_serialize_f90(const F90flds &, const std::size_t &, double[])
qg::qg_fields_from_atlas_f90
void qg_fields_from_atlas_f90(const F90flds &, const oops::Variables &, atlas::field::FieldSetImpl *)
GeometryQG.h
qg::qg_fields_dirac_f90
void qg_fields_dirac_f90(const F90flds &, const eckit::Configuration &)
qg::FieldsQG::print
void print(std::ostream &) const override
Definition: FieldsQG.cc:179
qg::qg_fields_create_from_other_f90
void qg_fields_create_from_other_f90(F90flds &, const F90flds &)
qg::FieldsQG::isForModel
bool isForModel(const bool &) const
Definition: FieldsQG.cc:206
GomQG.h
qg::FieldsQG::setLocal
void setLocal(const oops::LocalIncrement &, const GeometryQGIterator &)
Definition: FieldsQG.cc:223
qg::qg_fields_read_file_f90
void qg_fields_read_file_f90(const F90flds &, const eckit::Configuration &, util::DateTime &)
qg::qg_fields_add_incr_f90
void qg_fields_add_incr_f90(const F90flds &, const F90flds &)
LocationsQG.h
qg::qg_fields_write_file_f90
void qg_fields_write_file_f90(const F90flds &, const eckit::Configuration &, const util::DateTime &)
qg::qg_fields_to_atlas_f90
void qg_fields_to_atlas_f90(const F90flds &, const oops::Variables &, atlas::field::FieldSetImpl *)
qg::FieldsQG::operator+=
FieldsQG & operator+=(const FieldsQG &)
Definition: FieldsQG.cc:84
qg::FieldsQG::serialSize
size_t serialSize() const override
Serialization.
Definition: FieldsQG.cc:228
qg::FieldsQG::norm
double norm() const
Definition: FieldsQG.cc:173
qg::FieldsQG::lbc_
const bool lbc_
Definition: FieldsQG.h:116
qg::qg_fields_diff_incr_f90
void qg_fields_diff_incr_f90(const F90flds &, const F90flds &, const F90flds &)
qg::FieldsQG::analytic_init
void analytic_init(const eckit::Configuration &)
Definition: FieldsQG.cc:165
qg::qg_fields_ones_f90
void qg_fields_ones_f90(const F90flds &)
qg::GeometryQGIterator::toFortran
const F90iter & toFortran() const
Definition: GeometryQGIterator.h:46
qg::qg_fields_getpoint_f90
void qg_fields_getpoint_f90(const F90flds &, const F90iter &, const int &, double &)
qg::qg_fields_copy_f90
void qg_fields_copy_f90(const F90flds &, const F90flds &)
qg::GeometryQGIterator
Definition: GeometryQGIterator.h:33
qg::FieldsQG::getLocal
oops::LocalIncrement getLocal(const GeometryQGIterator &) const
Definition: FieldsQG.cc:214
qg::qg_fields_setpoint_f90
void qg_fields_setpoint_f90(const F90flds &, const F90iter &, const int &, const double &)
qg::FieldsQG::schur_product_with
void schur_product_with(const FieldsQG &)
Definition: FieldsQG.cc:122
qg::FieldsQG::zero
void zero()
Definition: FieldsQG.cc:99
qg::FieldsQG::add
void add(const FieldsQG &)
Definition: FieldsQG.cc:138
qg::FieldsQG::geom_
std::shared_ptr< const GeometryQG > geom_
Definition: FieldsQG.h:114
qg::qg_fields_self_add_f90
void qg_fields_self_add_f90(const F90flds &, const F90flds &)
qg::FieldsQG::toAtlas
void toAtlas(atlas::FieldSet *) const
Definition: FieldsQG.cc:153
qg::FieldsQG::time_
util::DateTime time_
Definition: FieldsQG.h:117
qg::FieldsQG::changeResolution
void changeResolution(const FieldsQG &)
Definition: FieldsQG.cc:134
qg::FieldsQG::time
const util::DateTime & time() const
Definition: FieldsQG.h:95
qg::qg_fields_self_sub_f90
void qg_fields_self_sub_f90(const F90flds &, const F90flds &)
oops::LocalIncrement
Definition: LocalIncrement.h:19
qg::qg_fields_vars_f90
void qg_fields_vars_f90(const F90flds &, int &, int &)
qg::FieldsQG::deserialize
void deserialize(const std::vector< double > &, size_t &) override
Definition: FieldsQG.cc:251
qg::qg_fields_deserialize_f90
void qg_fields_deserialize_f90(const F90flds &, const std::size_t &, const double[], const std::size_t &)
qg::FieldsQG::random
void random()
Definition: FieldsQG.cc:126
qg::qg_fields_dot_prod_f90
void qg_fields_dot_prod_f90(const F90flds &, const F90flds &, double &)
qg::FieldsQG::~FieldsQG
~FieldsQG()
Definition: FieldsQG.cc:74
qg::FieldsQG::operator-=
FieldsQG & operator-=(const FieldsQG &)
Definition: FieldsQG.cc:89
qg::FieldsQG::axpy
void axpy(const double &, const FieldsQG &)
Definition: FieldsQG.cc:112
qg::FieldsQG::diff
void diff(const FieldsQG &, const FieldsQG &)
Definition: FieldsQG.cc:143
qg::FieldsQG::operator*=
FieldsQG & operator*=(const double &)
Definition: FieldsQG.cc:94
qg::qg_fields_self_mul_f90
void qg_fields_self_mul_f90(const F90flds &, const double &)
qg::qg_fields_gpnorm_f90
void qg_fields_gpnorm_f90(const F90flds &, const int &, double &)
qg::qg_fields_axpy_f90
void qg_fields_axpy_f90(const F90flds &, const double &, const F90flds &)
qg::FieldsQG
Class to represent a Fields for the QG model.
Definition: FieldsQG.h:52
oops::Variables
Definition: oops/base/Variables.h:23
qg::GeometryQG
GeometryQG handles geometry for QG model.
Definition: GeometryQG.h:54
oops::LocalIncrement::getVals
const std::vector< double > & getVals() const
Definition: LocalIncrement.h:27
qg::FieldsQG::operator=
FieldsQG & operator=(const FieldsQG &)
Definition: FieldsQG.cc:78
qg::qg_fields_sizes_f90
void qg_fields_sizes_f90(const F90flds &, int &, int &, int &, int &)
Variables.h
qg::FieldsQG::ones
void ones()
Definition: FieldsQG.cc:108
qg::FieldsQG::read
void read(const eckit::Configuration &)
Definition: FieldsQG.cc:161
qg::FieldsQG::keyFlds_
F90flds keyFlds_
Definition: FieldsQG.h:113
qg::qg_fields_rms_f90
void qg_fields_rms_f90(const F90flds &, double &)