11 #ifndef OOPS_ASSIMILATION_INCREMENT4D_H_ 12 #define OOPS_ASSIMILATION_INCREMENT4D_H_ 20 #include <boost/ptr_container/ptr_map.hpp> 22 #include "eckit/config/LocalConfiguration.h" 27 #include "oops/util/DateTime.h" 28 #include "oops/util/dot_product.h" 29 #include "oops/util/Duration.h" 30 #include "oops/util/Logger.h" 31 #include "oops/util/Printable.h" 42 template<
typename MODEL>
class Increment4D :
public util::Printable {
49 static const std::string
classname() {
return "Increment4D";}
69 void read(
const eckit::Configuration &);
70 void write(
const eckit::Configuration &)
const;
76 Increment_ &
operator[](
const int ii) {
return this->
get(ii);}
88 void print(std::ostream &)
const;
90 typedef typename boost::ptr_map<int, Increment_>::iterator
iter_;
91 typedef typename boost::ptr_map<int, Increment_>::const_iterator
icst_;
99 template<
typename MODEL>
101 : incr4d_(), first_(0), last_(jb.nstates() - 1)
103 for (
int jsub = 0; jsub <=
last_; ++jsub) {
107 Log::trace() <<
"Increment4D:Increment4D created." << std::endl;
110 template<
typename MODEL>
112 : incr4d_(), first_(other.first_), last_(other.last_)
114 for (
icst_ jsub = other.incr4d_.begin(); jsub != other.incr4d_.end(); ++jsub) {
115 int isub = jsub->first;
119 Log::trace() <<
"Increment4D:Increment4D copied." << std::endl;
122 template<
typename MODEL>
124 : incr4d_(), first_(other.first_), last_(other.last_)
126 for (
icst_ jsub = other.incr4d_.begin(); jsub != other.incr4d_.end(); ++jsub) {
127 int isub = jsub->first;
131 Log::trace() <<
"Increment4D:Increment4D copied." << std::endl;
134 template<
typename MODEL>
136 : incr4d_(), first_(other.first_), last_(other.last_)
138 for (
icst_ jsub = other.incr4d_.begin(); jsub != other.incr4d_.end(); ++jsub) {
139 int isub = jsub->first;
143 Log::trace() <<
"Increment4D:Increment4D copied." << std::endl;
146 template<
typename MODEL>
148 iter_ it = incr4d_.find(ii);
149 ASSERT(it != incr4d_.end());
153 template<
typename MODEL>
155 icst_ it = incr4d_.find(ii);
156 ASSERT(it != incr4d_.end());
160 template<
typename MODEL>
163 template<
typename MODEL>
165 for (
iter_ jsub = incr4d_.begin(); jsub != incr4d_.end(); ++jsub) {
166 jsub->second->zero();
170 template<
typename MODEL>
172 for (
iter_ jsub = incr4d_.begin(); jsub != incr4d_.end(); ++jsub) {
173 jsub->second->diff(cv1[jsub->first], cv2[jsub->first]);
177 template<
typename MODEL>
179 incr4d_ = rhs.incr4d_;
183 template<
typename MODEL>
185 for (
int jsub = rhs.first(); jsub <= rhs.last(); ++jsub) {
186 this->
get(jsub) += rhs[jsub];
191 template<
typename MODEL>
193 for (
int jsub = rhs.first(); jsub <= rhs.last(); ++jsub) {
194 this->
get(jsub) -= rhs[jsub];
199 template<
typename MODEL>
201 for (
iter_ jsub = incr4d_.begin(); jsub != incr4d_.end(); ++jsub) {
207 template<
typename MODEL>
209 for (
iter_ jsub = incr4d_.begin(); jsub != incr4d_.end(); ++jsub) {
210 jsub->second->axpy(zz, rhs[jsub->first]);
214 template<
typename MODEL>
216 for (
iter_ jsub = incr4d_.begin(); jsub != incr4d_.end(); ++jsub) {
217 std::stringstream ss;
219 std::string query =
"increment[@indx='" + ss.str() +
"']";
220 eckit::LocalConfiguration fileConfig(config, query);
221 jsub->second->read(fileConfig);
222 Log::info() <<
"Increment4D:read increment" << *jsub->second << std::endl;
226 template<
typename MODEL>
228 for (
icst_ jsub = incr4d_.begin(); jsub != incr4d_.end(); ++jsub) {
229 jsub->second->write(config);
233 template <
typename MODEL>
235 for (
icst_ jsub = incr4d_.begin(); jsub != incr4d_.end(); ++jsub) {
236 outs << *jsub->second << std::endl;
240 template<
typename MODEL>
243 for (
icst_ jsub = incr4d_.begin(); jsub != incr4d_.end(); ++jsub) {
244 zz += dot_product(*jsub->second, x2[jsub->first]);
249 template<
typename MODEL>
251 typedef typename boost::ptr_map<int, Increment_>::reverse_iterator rit;
252 for (rit jsub = incr4d_.rbegin(); jsub != incr4d_.rend(); ++jsub) {
253 const int isub = jsub->first;
254 if (isub > first_) this->
get(isub) = this->
get(isub-1);
256 incr4d_.erase(first_);
257 Log::info() <<
"Increment4D::shift_forward erased " << first_ << std::endl;
261 template<
typename MODEL>
263 for (
iter_ jsub = incr4d_.begin(); jsub != incr4d_.end(); ++jsub) {
264 const int isub = jsub->first;
265 if (isub < last_) this->
get(isub) = this->
get(isub+1);
267 incr4d_.erase(last_);
268 Log::info() <<
"Increment4D::shift_backward erased " << last_ << std::endl;
274 #endif // OOPS_ASSIMILATION_INCREMENT4D_H_ Increment4D(const JbState_ &)
Constructor, destructor.
CostJbState< MODEL > JbState_
State4D< MODEL > State4D_
subroutine, public copy(self, rhs)
Increment4D & operator=(const Increment4D &)
void diff(const State4D_ &, const State4D_ &)
Linear algebra operators.
void print(std::ostream &) const
Geometry< MODEL > Geometry_
The namespace for the main oops code.
Increment4D & operator-=(const Increment4D &)
Increment4D & operator+=(const Increment4D &)
static const std::string classname()
void axpy(const double, const Increment4D &)
Increment_ & operator[](const int ii)
Get model space control variable.
virtual Increment_ * newStateIncrement(const unsigned int) const =0
subroutine, public info(self)
boost::ptr_map< int, Increment_ >::const_iterator icst_
boost::ptr_map< int, Increment_ >::iterator iter_
void read(const eckit::Configuration &)
I/O and diagnostics.
const Increment_ & operator[](const int ii) const
Increment4D & operator*=(const double)
Increment_ & get(const int)
Jb Cost Function Base Class.
boost::ptr_map< int, Increment_ > incr4d_
Increment Class: Difference between two states.
Geometry_ geometry() const
Get geometry.
Increment< MODEL > Increment_
double dot_product_with(const Increment4D &) const
void write(const eckit::Configuration &) const
void shift_forward()
To be removed.