11 #ifndef OOPS_ASSIMILATION_COSTFCTWEAK_H_
12 #define OOPS_ASSIMILATION_COSTFCTWEAK_H_
18 #include "eckit/config/LocalConfiguration.h"
37 #include "oops/util/DateTime.h"
38 #include "oops/util/Duration.h"
39 #include "oops/util/Logger.h"
63 CostFctWeak(
const eckit::Configuration &,
const eckit::mpi::Comm &);
68 const bool idModel =
false)
const override;
71 const bool idModel =
false)
const override;
98 std::shared_ptr<LinearModel_>
tlm_;
107 template<
typename MODEL,
typename OBS>
109 const eckit::mpi::Comm & comm)
111 ctlvars_(config,
"analysis variables"), tlm_(), an2model_(), inc2model_(),
112 commSpace_(nullptr), commTime_(nullptr)
114 util::Duration windowLength(config.getString(
"window length"));
115 util::DateTime windowBegin(config.getString(
"window begin"));
116 subWinLength_ = util::Duration(config.getString(
"subwindow"));
121 size_t ntasks = comm.size();
123 size_t myrank = comm.rank();
124 size_t ntaskpslot = ntasks /
nsubwin_;
132 std::string sgeom =
"comm_geom_" + std::to_string(
mysubwin_);
133 char const *geomName = sgeom.c_str();
138 std::string stime =
"comm_time_" + std::to_string(myarea);
139 char const *timeName = stime.c_str();
140 commTime_ = &comm.split(myarea, timeName);
144 resol_.reset(
new Geometry_(eckit::LocalConfiguration(config,
"geometry"),
151 Log::trace() <<
"CostFctWeak constructed" << std::endl;
156 template <
typename MODEL,
typename OBS>
165 template <
typename MODEL,
typename OBS>
168 subWinBegin_, subWinEnd_, *commTime_);
173 template <
typename MODEL,
typename OBS>
176 const eckit::LocalConfiguration jcdfi(jcConf,
"jcdfi");
177 const util::DateTime vt(subWinBegin_ + subWinLength_/2);
183 template <
typename MODEL,
typename OBS>
188 an2model_->changeVar(xx.
state(), xm);
189 model_->forecast(xm, xx.
modVar(), subWinLength_, post);
190 an2model_->changeVarInverse(xm, xx.
state());
197 template<
typename MODEL,
typename OBS>
199 const eckit::Configuration & innerConf,
203 Log::trace() <<
"CostFctWeak::doLinearize start" << std::endl;
204 eckit::LocalConfiguration conf(innerConf,
"linear model");
212 inc2model_->setInputVariables(ctlvars_);
213 Log::trace() <<
"CostFctWeak::doLinearize done" << std::endl;
218 template <
typename MODEL,
typename OBS>
222 const bool idModel)
const {
223 Log::trace() <<
"CostFctWeak: runTLM start" << std::endl;
224 inc2model_->setOutputVariables(tlm_->variables());
229 inc2model_->multiply(dx.
state(), dxmodel);
230 tlm_->forecastTL(dxmodel, dx.
modVar(), subWinLength_, post, cost, idModel);
231 inc2model_->multiplyInverse(dxmodel, dx.
state());
234 Log::trace() <<
"CostFctWeak: runTLM done" << std::endl;
239 template <
typename MODEL,
typename OBS>
243 inc2model_->setOutputVariables(tlm_->variables());
251 inc2model_->multiply(dx.
state(), dxmodel);
252 tlm_->forecastTL(dxmodel, dx.
modVar(), subWinLength_, post, cost);
253 inc2model_->multiplyInverse(dxmodel, dx.
state());
261 template <
typename MODEL,
typename OBS>
270 template <
typename MODEL,
typename OBS>
274 const bool idModel)
const {
275 Log::trace() <<
"CostFctWeak: runADJ start" << std::endl;
276 inc2model_->setOutputVariables(tlm_->variables());
281 inc2model_->multiplyInverseAD(dx.
state(), dxmodel);
282 tlm_->forecastAD(dxmodel, dx.
modVar(), subWinLength_, post, cost, idModel);
283 inc2model_->multiplyAD(dxmodel, dx.
state());
286 Log::trace() <<
"CostFctWeak: runADJ done" << std::endl;
291 template <
typename MODEL,
typename OBS>
295 inc2model_->setOutputVariables(tlm_->variables());
303 inc2model_->multiplyInverseAD(dx.
state(), dxmodel);
304 tlm_->forecastAD(dxmodel, dx.
modVar(), subWinLength_, post, cost);
305 inc2model_->multiplyAD(dxmodel, dx.
state());
313 template<
typename MODEL,
typename OBS>
323 #endif // OOPS_ASSIMILATION_COSTFCTWEAK_H_