UFO
ObsIdentityTLAD.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2021 UK Met Office
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 
9 
10 #include <ostream>
11 #include <vector>
12 
13 #include "ioda/ObsSpace.h"
14 #include "ioda/ObsVector.h"
15 
16 #include "oops/base/Variables.h"
17 #include "oops/util/Logger.h"
18 #include "oops/util/missingValues.h"
19 
20 #include "ufo/GeoVaLs.h"
21 #include "ufo/utils/OperatorUtils.h" // for getOperatorVariables
22 
23 namespace ufo {
24 
25 // -----------------------------------------------------------------------------
27 // -----------------------------------------------------------------------------
28 
29 ObsIdentityTLAD::ObsIdentityTLAD(const ioda::ObsSpace & odb,
30  const eckit::Configuration & config)
32 {
33  oops::Log::trace() << "ObsIdentityTLAD constructor starting" << std::endl;
34 
35  getOperatorVariables(config, odb.obsvariables(), operatorVars_, operatorVarIndices_);
37 
38  oops::Log::trace() << "ObsIdentityTLAD constructor finished" << std::endl;
39 }
40 
41 // -----------------------------------------------------------------------------
42 
44  oops::Log::trace() << "ObsIdentityTLAD destructed" << std::endl;
45 }
46 
47 // -----------------------------------------------------------------------------
48 
50  // The trajectory is not needed because the observation operator is linear.
51  oops::Log::trace() << "ObsIdentityTLAD: trajectory set" << std::endl;
52 }
53 
54 // -----------------------------------------------------------------------------
55 
56 void ObsIdentityTLAD::simulateObsTL(const GeoVaLs & dx, ioda::ObsVector & dy) const {
57  oops::Log::trace() << "ObsIdentityTLAD: TL observation operator starting" << std::endl;
58 
59  std::vector<double> vec(dy.nlocs());
60  for (int jvar : operatorVarIndices_) {
61  const std::string& varname = dy.varnames().variables()[jvar];
62  // Fill dy with dx at the lowest level.
63  dx.getAtLevel(vec, varname, 0);
64  for (size_t jloc = 0; jloc < dy.nlocs(); ++jloc) {
65  const size_t idx = jloc * dy.nvars() + jvar;
66  dy[idx] = vec[jloc];
67  }
68  }
69 
70  oops::Log::trace() << "ObsIdentityTLAD: TL observation operator finished" << std::endl;
71 }
72 
73 // -----------------------------------------------------------------------------
74 
75 void ObsIdentityTLAD::simulateObsAD(GeoVaLs & dx, const ioda::ObsVector & dy) const {
76  oops::Log::trace() << "ObsIdentityTLAD: adjoint observation operator starting" << std::endl;
77 
78  const double missing = util::missingValue(missing);
79 
80  std::vector<double> vec(dy.nlocs());
81  for (int jvar : operatorVarIndices_) {
82  const std::string& varname = dy.varnames().variables()[jvar];
83  // Get current value of dx at the lowest level.
84  dx.getAtLevel(vec, varname, 0);
85  // Increment dx with non-missing values of dy.
86  for (size_t jloc = 0; jloc < dy.nlocs(); ++jloc) {
87  const size_t idx = jloc * dy.nvars() + jvar;
88  if (dy[idx] != missing)
89  vec[jloc] += dy[idx];
90  }
91  // Store new value of dx.
92  dx.putAtLevel(vec, varname, 0);
93  }
94 
95  oops::Log::trace() << "ObsIdentityTLAD: adjoint observation operator finished" << std::endl;
96 }
97 
98 // -----------------------------------------------------------------------------
99 
100 void ObsIdentityTLAD::print(std::ostream & os) const {
101  os << "ObsIdentityTLAD operator" << std::endl;
102 }
103 
104 // -----------------------------------------------------------------------------
105 
106 } // namespace ufo
GeoVaLs: geophysical values at locations.
void getAtLevel(std::vector< double > &, const std::string &, const int) const
Get GeoVaLs at a specified level.
Definition: GeoVaLs.cc:330
void putAtLevel(const std::vector< double > &vals, const std::string &var, const int lev) const
Put GeoVaLs for double variable var at level lev.
Definition: GeoVaLs.cc:414
ObsIdentityTLAD(const ioda::ObsSpace &, const eckit::Configuration &)
oops::Variables requiredVars_
Required variables.
std::vector< int > operatorVarIndices_
Indices of operator variables.
void print(std::ostream &) const override
void setTrajectory(const GeoVaLs &, ObsDiagnostics &) override
Obs Operator.
void simulateObsAD(GeoVaLs &, const ioda::ObsVector &) const override
oops::Variables operatorVars_
Operator variables.
void simulateObsTL(const GeoVaLs &, ioda::ObsVector &) const override
constexpr int missing
Definition: QCflags.h:20
Definition: RunCRTM.h:27
static LinearObsOperatorMaker< ObsIdentityTLAD > makerIdentityTL_("Identity")
void getOperatorVariables(const eckit::Configuration &conf, const oops::Variables &simulatedVariables, oops::Variables &operatorVariables, std::vector< int > &operatorVariableIndices)