FV3 Bundle
ObsBiasIncrement.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/ObsBiasIncrement.h"
12 
13 #include <cmath>
14 #include <iostream>
15 #include <sstream>
16 #include <string>
17 
18 #include "eckit/config/Configuration.h"
19 #include "model/ObsBias.h"
21 #include "oops/util/Logger.h"
22 
23 // -----------------------------------------------------------------------------
24 namespace qg {
25 // -----------------------------------------------------------------------------
26 ObsBiasIncrement::ObsBiasIncrement(const eckit::Configuration & conf)
27  : bias_(ObsBias::ntypes, 0.0), active_(ObsBias::ntypes, false)
28 {
29  active_[0] = conf.has("stream");
30  active_[1] = conf.has("uwind");
31  active_[2] = conf.has("vwind");
32  active_[3] = conf.has("wspeed");
33  bool on = false;
34  std::string strn = "";
35  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
36  if (jj > 0) strn += ", ";
37  if (active_[jj]) {
38  strn += "on";
39  on = true;
40  } else {
41  strn += "off";
42  }
43  }
44  if (on) {oops::Log::trace() << "ObsBiasIncrement created : " << strn << std::endl;}
45 }
46 // -----------------------------------------------------------------------------
48  const bool copy)
49  : bias_(ObsBias::ntypes, 0.0), active_(other.active_)
50 {
51  if (copy) {
52  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) bias_[jj] = other.bias_[jj];
53  }
54  this->makePassive();
55 }
56 // -----------------------------------------------------------------------------
58  const eckit::Configuration &)
59  : bias_(ObsBias::ntypes, 0.0), active_(other.active_)
60 {
61  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) bias_[jj] = other.bias_[jj];
62  this->makePassive();
63 }
64 // -----------------------------------------------------------------------------
66  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
67  if (!active_[jj]) bias_[jj] = 0.0;
68  }
69 }
70 // -----------------------------------------------------------------------------
71 void ObsBiasIncrement::diff(const ObsBias & b1, const ObsBias & b2) {
72  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
73  bias_[jj] = b1[jj] - b2[jj];
74  }
75  this->makePassive();
76 }
77 // -----------------------------------------------------------------------------
79  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) bias_[jj] = 0.0;
80 }
81 // -----------------------------------------------------------------------------
83  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) bias_[jj] = rhs.bias_[jj];
84  this->makePassive();
85  return *this;
86 }
87 // -----------------------------------------------------------------------------
89  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) bias_[jj] += rhs.bias_[jj];
90  this->makePassive();
91  return *this;
92 }
93 // -----------------------------------------------------------------------------
95  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) bias_[jj] -= rhs.bias_[jj];
96  this->makePassive();
97  return *this;
98 }
99 // -----------------------------------------------------------------------------
101  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) bias_[jj] *= fact;
102  this->makePassive();
103  return *this;
104 }
105 // -----------------------------------------------------------------------------
106 void ObsBiasIncrement::axpy(const double fact, const ObsBiasIncrement & rhs) {
107  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) bias_[jj] += fact * rhs.bias_[jj];
108  this->makePassive();
109 }
110 // -----------------------------------------------------------------------------
112  double zz = 0.0;
113  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
114  if (active_[jj]) zz += bias_[jj] * rhs.bias_[jj];
115  }
116  return zz;
117 }
118 // -----------------------------------------------------------------------------
119 double ObsBiasIncrement::norm() const {
120  double zz = 0.0;
121  int ii = 0;
122  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
123  if (active_[jj]) {
124  zz += bias_[jj] * bias_[jj];
125  ++ii;
126  }
127  }
128  if (ii > 0) zz = std::sqrt(zz/ii);
129  return zz;
130 }
131 // -----------------------------------------------------------------------------
132 void ObsBiasIncrement::print(std::ostream & os) const {
133  bool on = false;
134  std::string strn = "";
135  for (unsigned int jj = 0; jj < ObsBias::ntypes; ++jj) {
136  if (jj > 0) strn += ", ";
137  if (active_[jj]) {
138  on = true;
139  std::ostringstream strs;
140  strs << bias_[jj];
141  strn += strs.str();
142  } else {
143  strn += "0.0";
144  }
145  }
146  if (on) os << std::endl << "ObsBiasIncrement = " << strn;
147 }
148 // -----------------------------------------------------------------------------
149 } // namespace qg
ObsBiasIncrement & operator=(const ObsBiasIncrement &)
void diff(const ObsBias &, const ObsBias &)
Linear algebra operators.
real, parameter b1
subroutine, public copy(self, rhs)
void axpy(const double, const ObsBiasIncrement &)
Definition: conf.py:1
void print(std::ostream &) const
ObsBiasIncrement & operator+=(const ObsBiasIncrement &)
integer(long), parameter false
ObsBiasIncrement & operator*=(const double)
Class to handle observation bias parameters.
double dot_product_with(const ObsBiasIncrement &) const
static const unsigned int ntypes
ObsBiasIncrement()
Constructor, destructor.
ObsBiasIncrement & operator-=(const ObsBiasIncrement &)
real, parameter b2
The namespace for the qg model.