8 #ifndef OOPS_RUNS_HOFX4DHACK_H_
9 #define OOPS_RUNS_HOFX4DHACK_H_
16 #include "eckit/config/LocalConfiguration.h"
17 #include "eckit/exception/Exceptions.h"
33 #include "oops/util/ConfigFunctions.h"
34 #include "oops/util/DateTime.h"
35 #include "oops/util/Duration.h"
36 #include "oops/util/Logger.h"
66 instantiateObsFilterFactory<OBS>();
67 instantiateVariableChangeFactory<MODEL>();
72 int execute(
const eckit::Configuration & fullConfig)
const {
74 const util::Duration winlen(fullConfig.getString(
"window length"));
75 const util::DateTime winbgn(fullConfig.getString(
"window begin"));
76 const util::DateTime winend(winbgn + winlen);
77 Log::info() <<
"Observation window from " << winbgn <<
" to " << winend << std::endl;
80 std::vector<eckit::LocalConfiguration> statesConf;
81 if (fullConfig.has(
"states")) {
82 statesConf = fullConfig.getSubConfigurations(
"states");
84 if (fullConfig.has(
"state")) {
85 statesConf[0] = eckit::LocalConfiguration(fullConfig,
"state");
87 eckit::BadParameter(
"Error in background state(s) configuration");
90 size_t nsubwin = statesConf.size();
92 size_t ntasks = this->
getComm().size();
93 size_t myrank = this->
getComm().rank();
94 ASSERT(ntasks % nsubwin == 0);
95 size_t ntaskpslot = ntasks / nsubwin;
96 size_t mysubwin = myrank / ntaskpslot;
97 Log::debug() <<
"ntasks = " << ntasks <<
" nsubwin = " << nsubwin << std::endl;
100 util::Duration subWinLength = winlen;
101 if (nsubwin > 1) subWinLength = winlen / (nsubwin - 1);
102 Log::debug() <<
"Task " << mysubwin <<
" subWinLength " << subWinLength << std::endl;
103 util::DateTime subWinTime = winbgn + mysubwin * subWinLength;
104 util::DateTime subWinBegin = subWinTime - subWinLength/2;
105 util::DateTime subWinEnd = subWinTime + subWinLength/2;
106 if (mysubwin == 0) subWinBegin = subWinTime;
107 if (mysubwin == nsubwin - 1) subWinEnd = subWinTime;
108 ASSERT(subWinBegin >= winbgn);
109 ASSERT(subWinEnd <= winend);
110 Log::debug() <<
"Task " << mysubwin <<
" Obs times " << subWinTime
111 <<
", " << subWinBegin <<
", " << subWinEnd << std::endl;
113 std::string sgeom =
"comm_geom_" + std::to_string(mysubwin);
114 char const *geomName = sgeom.c_str();
115 eckit::mpi::Comm * commSpace = &this->
getComm().split(mysubwin, geomName);
117 size_t myarea = commSpace->rank();
118 std::string stime =
"comm_time_" + std::to_string(myarea);
119 char const *timeName = stime.c_str();
120 eckit::mpi::Comm * commTime = &this->
getComm().split(myarea, timeName);
121 ASSERT(commTime->size() == nsubwin);
124 const eckit::LocalConfiguration geometryConfig(fullConfig,
"geometry");
125 const Geometry_ geometry(geometryConfig, *commSpace);
128 Log::info() <<
"State configuration is:" << statesConf[mysubwin] << std::endl;
129 State_ xx(geometry, statesConf[mysubwin]);
130 Log::test() <<
"State: " << xx << std::endl;
131 Log::debug() <<
"Task " << mysubwin <<
" State time " << xx.
validTime() << std::endl;
135 const eckit::LocalConfiguration obsConfig(fullConfig,
"observations");
136 ObsSpaces_ obspaces(obsConfig, *commSpace, subWinBegin, subWinEnd, *commTime);
137 ObsAux_ obsaux(obspaces, obsConfig);
145 Log::debug() <<
"HofX4Dhack: Required hofx size = " << hofx.
requiredVars().size() << std::endl;
148 Log::debug() <<
"HofX4Dhack: Required vars size = " << vars.
size() << std::endl;
149 for (
size_t jj = 0; jj < vars.size(); ++jj) {
150 Log::debug() <<
"HofX4Dhack: Required vars:" << vars[jj] << std::endl;
153 Log::debug() <<
"HofX4Dhack: Required variables:" << geovars << std::endl;
154 eckit::LocalConfiguration chvarconf;
160 std::vector<eckit::LocalConfiguration> getValuesConfig =
161 util::vectoriseAndFilter(obsConfig,
"get values");
164 for (
size_t jj = 0; jj < obspaces.
size(); ++jj) {
165 GetValues_ getvals(geometry, *locations[jj], getValuesConfig[jj]);
166 geovals.emplace_back(
new GeoVaLs_(*locations[jj], vars[jj],
168 getvals.
fillGeoVaLs(zz, subWinBegin, subWinEnd, *geovals[jj]);
177 Log::test() <<
"H(x): " << std::endl << yobs <<
"End H(x)" << std::endl;
178 Log::info() <<
"H(x): " << std::endl << yobs <<
"End H(x)" << std::endl;
187 return "oops::HofX4Dhack<" + MODEL::name() +
", " + OBS::name() +
">";
const eckit::mpi::Comm & getComm() const
Computes observation operator (from GeoVaLs), applies bias correction and runs QC filters.
void saveObsErrors(const std::string &) const
save obs error variances (modified in QC) to ObsSpaces
void initialize(const ObsAuxCtrls_ &, const int iteration=0)
Initializes variables, obs bias, obs filters (could be different for different iterations.
const LocationsVec_ & locations() const
accessor to the locations
Observations_ compute(const GeoVaLsVec_ &)
Computes H(x) from the filled in GeoVaLs.
void saveQcFlags(const std::string &) const
save QC flags to ObsSpaces
const VariablesVec_ & requiredVars() const
accessor to variables required from the model
Encapsulates the nonlinear variable change There should not be a factory for ChangeVariable,...
void changeVar(const State_ &xin, State_ &xout) const
change variable from state xin to xout
Geometry class used in oops; subclass of interface class interface::Geometry.
Gets values from model State to observation locations (fills GeoVaLs)
void fillGeoVaLs(const State_ &, const util::DateTime &, const util::DateTime &, GeoVaLs_ &) const
Get state values at observation locations.
Geometry< MODEL > Geometry_
Locations< OBS > Locations_
HofX4Dhack(const eckit::mpi::Comm &comm=oops::mpi::world())
ObsAuxControls< OBS > ObsAux_
Observations< OBS > Observations_
ObsSpaces< OBS > ObsSpaces_
std::vector< Variables > VariablesVec_
GetValues< MODEL, OBS > GetValues_
ChangeVariables< MODEL > ChangeVariables_
std::vector< std::unique_ptr< GeoVaLs_ > > GeoVaLsVec_
std::string appname() const
std::vector< std::unique_ptr< Locations_ > > LocationsVec_
CalcHofX< OBS > CalcHofX_
int execute(const eckit::Configuration &fullConfig) const
Locations of observations for observation operator.
Holds a vector of ObsAuxControl.
void save() const
Save files.
std::size_t size() const
Access.
void save(const std::string &) const
Save/read observations values.
State class used in oops; subclass of interface class interface::State.
std::vector< size_t > variableSizes(const Variables &) const
const util::DateTime validTime() const
Accessor to the time of this State.
const Variables & variables() const
Accessor to variables associated with this State.
const eckit::mpi::Comm & world()
Default communicator with all MPI tasks (ie MPI_COMM_WORLD)
The namespace for the main oops code.