12 #ifndef OOPS_ASSIMILATION_COSTFCTWEAK_H_
13 #define OOPS_ASSIMILATION_COSTFCTWEAK_H_
19 #include <boost/make_unique.hpp>
21 #include "eckit/config/LocalConfiguration.h"
40 #include "oops/util/DateTime.h"
41 #include "oops/util/Duration.h"
42 #include "oops/util/Logger.h"
66 CostFctWeak(
const eckit::Configuration &,
const eckit::mpi::Comm &);
71 const bool idModel =
false)
const override;
74 const bool idModel =
false)
const override;
101 std::shared_ptr<LinearModel_>
tlm_;
110 template<
typename MODEL,
typename OBS>
112 const eckit::mpi::Comm & comm)
114 ctlvars_(config,
"analysis variables"), tlm_(), an2model_(), inc2model_(),
115 commSpace_(nullptr), commTime_(nullptr)
117 util::Duration windowLength(config.getString(
"window length"));
118 util::DateTime windowBegin(config.getString(
"window begin"));
119 subWinLength_ = util::Duration(config.getString(
"subwindow"));
124 size_t ntasks = comm.size();
126 size_t myrank = comm.rank();
127 size_t ntaskpslot = ntasks /
nsubwin_;
135 std::string sgeom =
"comm_geom_" + std::to_string(
mysubwin_);
136 char const *geomName = sgeom.c_str();
141 std::string stime =
"comm_time_" + std::to_string(myarea);
142 char const *timeName = stime.c_str();
143 commTime_ = &comm.split(myarea, timeName);
147 resol_.reset(
new Geometry_(eckit::LocalConfiguration(config,
"geometry"),
154 Log::trace() <<
"CostFctWeak constructed" << std::endl;
159 template <
typename MODEL,
typename OBS>
168 template <
typename MODEL,
typename OBS>
171 subWinBegin_, subWinEnd_, *commTime_);
176 template <
typename MODEL,
typename OBS>
179 const eckit::LocalConfiguration jcdfi(jcConf,
"jcdfi");
180 const util::DateTime vt(subWinBegin_ + subWinLength_/2);
186 template <
typename MODEL,
typename OBS>
191 an2model_->changeVar(xx.
state(), xm);
192 model_->forecast(xm, xx.
modVar(), subWinLength_, post);
193 an2model_->changeVarInverse(xm, xx.
state());
200 template<
typename MODEL,
typename OBS>
202 const eckit::Configuration & innerConf,
206 Log::trace() <<
"CostFctWeak::doLinearize start" << std::endl;
207 eckit::LocalConfiguration conf(innerConf,
"linear model");
215 inc2model_->setInputVariables(ctlvars_);
216 Log::trace() <<
"CostFctWeak::doLinearize done" << std::endl;
221 template <
typename MODEL,
typename OBS>
225 const bool idModel)
const {
226 Log::trace() <<
"CostFctWeak: runTLM start" << std::endl;
227 inc2model_->setOutputVariables(tlm_->variables());
232 inc2model_->multiply(dx.
state(), dxmodel);
233 tlm_->forecastTL(dxmodel, dx.
modVar(), subWinLength_, post, cost, idModel);
234 inc2model_->multiplyInverse(dxmodel, dx.
state());
237 Log::trace() <<
"CostFctWeak: runTLM done" << std::endl;
242 template <
typename MODEL,
typename OBS>
246 inc2model_->setOutputVariables(tlm_->variables());
254 inc2model_->multiply(dx.
state(), dxmodel);
255 tlm_->forecastTL(dxmodel, dx.
modVar(), subWinLength_, post, cost);
256 inc2model_->multiplyInverse(dxmodel, dx.
state());
264 template <
typename MODEL,
typename OBS>
273 template <
typename MODEL,
typename OBS>
277 const bool idModel)
const {
278 Log::trace() <<
"CostFctWeak: runADJ start" << std::endl;
279 inc2model_->setOutputVariables(tlm_->variables());
284 inc2model_->multiplyInverseAD(dx.
state(), dxmodel);
285 tlm_->forecastAD(dxmodel, dx.
modVar(), subWinLength_, post, cost, idModel);
286 inc2model_->multiplyAD(dxmodel, dx.
state());
289 Log::trace() <<
"CostFctWeak: runADJ done" << std::endl;
294 template <
typename MODEL,
typename OBS>
298 inc2model_->setOutputVariables(tlm_->variables());
306 inc2model_->multiplyInverseAD(dx.
state(), dxmodel);
307 tlm_->forecastAD(dxmodel, dx.
modVar(), subWinLength_, post, cost);
308 inc2model_->multiplyAD(dxmodel, dx.
state());
316 template<
typename MODEL,
typename OBS>
ObsAuxIncrs_ & obsVar()
Get augmented observation control variable.
Increment_ & state()
Get state control variable.
ModelAuxIncr_ & modVar()
Get augmented model control variable.
ModelAux_ & modVar()
Get augmented model control variable.
State_ & state()
Get state control variable.
Weak Constraint 4D-Var Cost Function.
CostTermBase< MODEL, OBS > * newJc(const eckit::Configuration &, const Geometry_ &) const override
VariableChange< MODEL > VarCha_
std::unique_ptr< Geometry_ > resol_
eckit::mpi::Comm * commSpace_
CostJbJq< MODEL > * newJb(const eckit::Configuration &, const Geometry_ &, const CtrlVar_ &) const override
void addIncr(CtrlVar_ &, const CtrlInc_ &, PostProcessor< Increment_ > &) const override
util::DateTime subWinEnd_
ControlVariable< MODEL, OBS > CtrlVar_
util::DateTime subWinBegin_
std::unique_ptr< Model_ > model_
CostFunction< MODEL, OBS > CostFct_
Increment< MODEL > Increment_
void runTLM(CtrlInc_ &, PostProcessorTLAD< MODEL > &, PostProcessor< Increment_ >, const bool idModel=false) const override
CostJo< MODEL, OBS > * newJo(const eckit::Configuration &) const override
ControlIncrement< MODEL, OBS > CtrlInc_
std::unique_ptr< VarCha_ > an2model_
void runNL(CtrlVar_ &, PostProcessor< State_ > &) const override
std::unique_ptr< LinVarCha_ > inc2model_
LinearVariableChangeBase< MODEL > LinVarCha_
util::Duration subWinLength_
eckit::mpi::Comm * commTime_
std::shared_ptr< LinearModel_ > tlm_
void runADJ(CtrlInc_ &, PostProcessorTLAD< MODEL > &, PostProcessor< Increment_ >, const bool idModel=false) const override
void doLinearize(const Geometry_ &, const eckit::Configuration &, const CtrlVar_ &, const CtrlVar_ &, PostProcessor< State_ > &, PostProcessorTLAD< MODEL > &) override
CostFctWeak(const eckit::Configuration &, const eckit::mpi::Comm &)
Geometry< MODEL > Geometry_
const Geometry_ & geometry() const override
void zeroAD(CtrlInc_ &) const override
LinearModel< MODEL > LinearModel_
void setupTerms(const eckit::Configuration &)
Base Class for Cost Function Terms.
Geometry class used in oops; subclass of interface class interface::Geometry.
Increment class used in oops.
Abstract linear forecast model used by high level algorithms and applications.
LinearVariableChange factory.
void zero()
Zero out this ModelAuxIncrement.
Abstract nonlinear forecast model used by high level algorithms and applications.
Control model post processing.
void enrollProcessor(PostBase_ *pp)
Control model post processing.
State class used in oops; subclass of interface class interface::State.
Save trajectory during forecast run.
Encapsulates the nonlinear variable change Note: to see methods that need to be implemented in the im...
void updateTime(const util::Duration &dt)
Updates this Increment's valid time by dt (used in PseudoModel)
Geometry_ geometry() const
Accessor to geometry associated with this Increment.
void zero()
Zero out this Increment.
const util::DateTime validTime() const
Accessor to the time of this Increment.
Geometry_ geometry() const
Accessor to geometry associated with this State.
const util::DateTime validTime() const
Accessor to the time of this State.
The namespace for the main oops code.