Loading [MathJax]/extensions/tex2jax.js
MPAS-JEDI
All Classes Namespaces Files Functions Variables Typedefs Macros Pages
StateMPAS.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017 UCAR
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  */
7 
8 #include <algorithm>
9 #include <iomanip>
10 #include <iostream>
11 #include <vector>
12 
13 #include "eckit/config/LocalConfiguration.h"
14 #include "eckit/exception/Exceptions.h"
15 
16 #include "oops/util/Duration.h"
17 #include "oops/util/Logger.h"
18 
19 #include "mpasjedi/GeometryMPAS.h"
20 #include "mpasjedi/IncrementMPAS.h"
21 #include "mpasjedi/StateMPAS.h"
22 
23 
24 namespace mpas {
25 
26 
27 // -----------------------------------------------------------------------------
28 /// Constructor, destructor
29 // -----------------------------------------------------------------------------
31  const oops::Variables & incvars,
32  const util::DateTime & time)
33  : geom_(new GeometryMPAS(geom)), vars_(incvars), time_(time)
34 {
35  oops::Log::trace() << "StateMPAS::StateMPAS create." << std::endl;
37  oops::Log::trace() << "StateMPAS::StateMPAS created." << std::endl;
38 }
39 // -----------------------------------------------------------------------------
41  const eckit::Configuration & config)
42  : geom_(new GeometryMPAS(resol)), vars_(config, "state variables"),
43  time_(util::DateTime())
44 {
45  oops::Log::trace() << "StateMPAS::StateMPAS create and read." << std::endl;
46 
48 
49  if (config.has("analytic_init")) {
51  } else {
53  }
54 
55  oops::Log::trace() << "StateMPAS::StateMPAS created and read in."
56  << std::endl;
57 }
58 // -----------------------------------------------------------------------------
60  const StateMPAS & other)
61  : geom_(new GeometryMPAS(resol)), vars_(other.vars_), time_(other.time_)
62 {
63  oops::Log::trace() << "StateMPAS::StateMPAS create by interpolation."
64  << std::endl;
65 
68  oops::Log::trace() << "StateMPAS::StateMPAS created by interpolation."
69  << std::endl;
70 }
71 // -----------------------------------------------------------------------------
73  : geom_(other.geom_), vars_(other.vars_), time_(other.time_)
74 {
75  oops::Log::trace() << "StateMPAS::StateMPAS before copied." << std::endl;
76 
79  oops::Log::trace() << "StateMPAS::StateMPAS copied." << std::endl;
80 }
81 // -----------------------------------------------------------------------------
84  oops::Log::trace() << "StateMPAS::StateMPAS destructed." << std::endl;
85 }
86 // -----------------------------------------------------------------------------
87 /// Basic operators
88 // -----------------------------------------------------------------------------
91  time_ = rhs.time_;
92  return *this;
93 }
94 // -----------------------------------------------------------------------------
95 /// Interpolate full state
96 // -----------------------------------------------------------------------------
99  oops::Log::trace() << "StateMPAS changed resolution" << std::endl;
100 }
101 // -----------------------------------------------------------------------------
102 /// Interactions with Increments
103 // -----------------------------------------------------------------------------
105  oops::Log::trace() << "StateMPAS add increment starting" << std::endl;
106  ASSERT(this->validTime() == dx.validTime());
107  // Interpolate increment to state resolution
108  IncrementMPAS dx_sr(*geom_, dx);
110  oops::Log::trace() << "StateMPAS add increment done" << std::endl;
111  return *this;
112 }
113 // -----------------------------------------------------------------------------
114 /// Serialization
115 // -----------------------------------------------------------------------------
116 size_t StateMPAS::serialSize() const {
117  // Field
118  size_t nn;
120 
121  // Magic factor
122  nn += 1;
123 
124  // Date and time
125  nn += time_.serialSize();
126  return nn;
127 }
128 
129 // -----------------------------------------------------------------------------
130 constexpr double SerializeCheckValue = -54321.98765;
131 void StateMPAS::serialize(std::vector<double> & vect) const {
132  // Serialize the field
133  size_t nn;
135  std::vector<double> vect_field(nn, 0);
136  mpas_state_serialize_f90(keyState_, nn, vect_field.data());
137  vect.insert(vect.end(), vect_field.begin(), vect_field.end());
138 
139  // Magic value placed in serialization; used to validate deserialization
140  vect.push_back(SerializeCheckValue);
141 
142  // Serialize the date and time
143  time_.serialize(vect);
144 }
145 // -----------------------------------------------------------------------------
146 void StateMPAS::deserialize(const std::vector<double> & vect, size_t & index) {
147  // Deserialize the field
148  mpas_state_deserialize_f90(keyState_, vect.size(), vect.data(), index);
149 
150  // Use magic value to validate deserialization
151  ASSERT(vect.at(index) == SerializeCheckValue);
152  ++index;
153 
154  // Deserialize the date and time
155  time_.deserialize(vect, index);
156 }
157 // -----------------------------------------------------------------------------
158 /// I/O and diagnostics
159 // -----------------------------------------------------------------------------
160 void StateMPAS::read(const eckit::Configuration & config) {
162 }
163 // -----------------------------------------------------------------------------
164 void StateMPAS::analytic_init(const eckit::Configuration & config,
165  const GeometryMPAS & geom) {
166  oops::Log::trace() << "StateMPAS analytic init starting" << std::endl;
168  oops::Log::trace() << "StateMPAS analytic init done" << std::endl;
169 }
170 // -----------------------------------------------------------------------------
171 void StateMPAS::write(const eckit::Configuration & config) const {
173 }
174 // -----------------------------------------------------------------------------
175 void StateMPAS::print(std::ostream & os) const {
176  // store os fmt state
177  std::ios oldState(nullptr);
178  oldState.copyfmt(os);
179 
180  int nc = 0;
181  int nf = 0;
183 
184  os << std::endl << " Valid time: " << validTime();
185  os << std::endl << " Resolution: nCellsGlobal = " << nc <<
186  ", nFields = " << nf;
187  std::vector<double> zstat(3*nf);
188  mpas_state_gpnorm_f90(keyState_, nf, zstat[0]);
189  os << std::setprecision(9);
190  os << std::scientific;
191  for (int jj = 0; jj < nf; ++jj) {
192  os << std::endl << "Fld=" << jj+1 << " Min=" << zstat[3*jj]
193  << ", Max=" << zstat[3*jj+1] << ", RMS=" << zstat[3*jj+2]
194  << " : " << vars_[jj];
195  }
196 
197  // restore os fmt state
198  os.copyfmt(oldState);
199 }
200 // -----------------------------------------------------------------------------
201 /// For accumulator
202 // -----------------------------------------------------------------------------
205 }
206 // -----------------------------------------------------------------------------
207 void StateMPAS::accumul(const double & zz, const StateMPAS & xx) {
209 }
210 // -----------------------------------------------------------------------------
211 double StateMPAS::norm() const {
212  double zz = 0.0;
214  return zz;
215 }
216 // -----------------------------------------------------------------------------
217 
218 oops::Variables StateMPAS::stateVars()
219 {
220  // ---------------------------------------------------------------------------
221  /// Temporary Auxilliary Variable Definitions
222  // ---------------------------------------------------------------------------
223  //--- TODO: nr and mpas_re_fields are still added in mpas_state_interface_mod
224  // they must be configured in the yaml and stream_list.atmosphere
225  // so that realistic values read from file. Then we can remove this
226  // extra oops::Variables object.
227  oops::Variables statevars(vars_);
228  return statevars;
229 }
230 // -----------------------------------------------------------------------------
231 
232 } // namespace mpas
GeometryMPAS handles geometry for MPAS model.
Definition: GeometryMPAS.h:37
F90geom & toFortran()
Definition: GeometryMPAS.h:45
Increment Class: Difference between two states.
Definition: IncrementMPAS.h:57
const util::DateTime & validTime() const
MPAS model state.
Definition: StateMPAS.h:51
void zero()
For accumulator.
Definition: StateMPAS.cc:203
void write(const eckit::Configuration &) const
Definition: StateMPAS.cc:171
std::shared_ptr< const GeometryMPAS > geom_
Definition: StateMPAS.h:100
void read(const eckit::Configuration &)
I/O and diagnostics.
Definition: StateMPAS.cc:160
F90state keyState_
Definition: StateMPAS.h:99
double norm() const
Definition: StateMPAS.cc:211
void accumul(const double &, const StateMPAS &)
Definition: StateMPAS.cc:207
StateMPAS(const GeometryMPAS &, const oops::Variables &, const util::DateTime &)
Constructor, destructor.
Definition: StateMPAS.cc:30
void analytic_init(const eckit::Configuration &, const GeometryMPAS &)
Definition: StateMPAS.cc:164
void serialize(std::vector< double > &) const override
Definition: StateMPAS.cc:131
void print(std::ostream &) const override
Definition: StateMPAS.cc:175
size_t serialSize() const override
Serialization.
Definition: StateMPAS.cc:116
util::DateTime time_
Definition: StateMPAS.h:102
StateMPAS & operator=(const StateMPAS &)
Basic operators.
Definition: StateMPAS.cc:89
void changeResolution(const StateMPAS &xx)
Interpolate full fields.
Definition: StateMPAS.cc:97
oops::Variables stateVars()
Definition: StateMPAS.cc:218
void deserialize(const std::vector< double > &, size_t &) override
Definition: StateMPAS.cc:146
oops::Variables vars_
Definition: StateMPAS.h:101
const util::DateTime & validTime() const
Definition: StateMPAS.h:89
StateMPAS & operator+=(const IncrementMPAS &)
Interactions with Increment.
Definition: StateMPAS.cc:104
Definition: config.py:1
void mpas_state_read_file_f90(const F90state &, const eckit::Configuration &, util::DateTime &)
void mpas_state_zero_f90(const F90state &)
void mpas_state_deserialize_f90(const F90state &, const std::size_t &, const double[], const std::size_t &)
void mpas_state_gpnorm_f90(const F90state &, const int &, double &)
void mpas_state_write_file_f90(const F90state &, const eckit::Configuration &, const util::DateTime &)
void mpas_state_change_resol_f90(const F90state &, const F90state &)
void mpas_state_sizes_f90(const F90state &, int &, int &)
void mpas_state_axpy_f90(const F90state &, const double &, const F90state &)
void mpas_state_serial_size_f90(const F90state &, std::size_t &)
void mpas_state_rms_f90(const F90state &, double &)
void mpas_state_serialize_f90(const F90state &, const std::size_t &, double[])
void mpas_state_copy_f90(const F90state &, const F90state &)
void mpas_state_create_f90(F90state &, const F90geom &, const oops::Variables &, const oops::Variables &)
constexpr double SerializeCheckValue
void mpas_state_analytic_init_f90(const F90state &, const F90geom &, const eckit::Configuration &, util::DateTime &)
void mpas_state_add_incr_f90(const F90state &, const F90inc &)
void mpas_state_delete_f90(F90state &)
Definition: Fortran.h:24