11 #ifndef OOPS_ASSIMILATION_COSTJBTOTAL_H_
12 #define OOPS_ASSIMILATION_COSTJBTOTAL_H_
17 #include "eckit/config/LocalConfiguration.h"
27 #include "oops/util/Logger.h"
30 template<
typename MODEL>
class JqTermTLAD;
102 std::unique_ptr<JbState_>
jb_;
118 mutable std::shared_ptr<JqTermTLAD_>
jqtl_;
119 mutable std::shared_ptr<JqTermTLAD_>
jqad_;
124 template<
typename MODEL,
typename OBS>
126 const eckit::Configuration & conf,
129 jbModBias_(conf.getSubConfiguration(
"model aux error"), resol),
130 jbObsBias_(odb, conf.getSubConfiguration(
"observations")), dxFG_(), resol_(),
131 windowBegin_(conf.getString(
"window begin")),
132 windowEnd_(windowBegin_ +
util::Duration(conf.getString(
"window length"))),
136 Log::trace() <<
"CostJbTotal contructed." << std::endl;
141 template<
typename MODEL,
typename OBS>
143 Log::trace() <<
"CostJbTotal::initialize start" << std::endl;
145 Log::trace() <<
"CostJbTotal::initialize done" << std::endl;
150 template<
typename MODEL,
typename OBS>
152 Log::trace() <<
"CostJbTotal::finalize start" << std::endl;
157 jb_->computeIncrement(xb_.state(), fg_->state(), mx.
state(), dx.
state());
160 dx.
modVar().
diff(fg_->modVar(), xb_.modVar());
161 dx.
obsVar().
diff(fg_->obsVar(), xb_.obsVar());
164 Log::info() <<
"CostJb: FG-BG" << dx << std::endl;
168 if (jbEvaluation_) zjb = this->evaluate(dx);
169 Log::trace() <<
"CostJbTotal::finalize done" << std::endl;
175 template<
typename MODEL,
typename OBS>
177 const eckit::Configuration & inner,
179 Log::trace() <<
"CostJbTotal::initializeTraj start" << std::endl;
183 jb_->linearize(fg.
state(), *resol_);
184 jbModBias_.linearize(fg.
modVar(), *resol_);
185 jbObsBias_.linearize(fg.
obsVar(), inner);
187 jqtraj_.reset(jb_->initializeJqTLAD());
190 Log::trace() <<
"CostJbTotal::initializeTraj done" << std::endl;
195 template<
typename MODEL,
typename OBS>
197 Log::trace() <<
"CostJbTotal::finalizeTraj start" << std::endl;
204 if (jqtraj_) mx = &jqtraj_->getMxi();
205 jb_->computeIncrement(xb_.state(), fg_->state(), *mx, dxFG_->
state());
208 dxFG_->modVar().diff(fg_->modVar(), xb_.modVar());
209 dxFG_->obsVar().diff(fg_->obsVar(), xb_.obsVar());
212 Log::info() <<
"CostJb: FG-BG" << *dxFG_ << std::endl;
214 Log::trace() <<
"CostJbTotal::finalizeTraj done" << std::endl;
219 template<
typename MODEL,
typename OBS>
221 Log::trace() <<
"CostJbTotal::evaluate start" << std::endl;
223 this->multiplyBinv(dx, gg);
226 double zz = 0.5 * dot_product(dx.
state(), gg.
state());
227 Log::info() <<
"CostJb : Nonlinear Jb State = " << zz << std::endl;
230 Log::info() <<
"CostJb : Nonlinear Jb Model Aux = " << zz << std::endl;
233 Log::info() <<
"CostJb : Nonlinear Jb Obs Aux = " << zz << std::endl;
236 Log::info() <<
"CostJb : Nonlinear Jb = " << zjb << std::endl;
240 if (zjb >= 0.0 && zjb <= std::numeric_limits<double>::epsilon()) ztest = 0.0;
241 Log::test() <<
"CostJb : Nonlinear Jb = " << ztest << std::endl;
243 Log::trace() <<
"CostJbTotal::evaluate done" << std::endl;
249 template<
typename MODEL,
typename OBS>
251 Log::trace() <<
"CostJbTotal::addGradientFG 1 start" << std::endl;
253 this->multiplyBinv(*dxFG_, gg);
255 Log::trace() <<
"CostJbTotal::addGradientFG 1 done" << std::endl;
260 template<
typename MODEL,
typename OBS>
262 Log::trace() <<
"CostJbTotal::addGradientFG 2 start" << std::endl;
263 jb_->addGradient(dxFG_->state(), grad.
state(), gradJb.
state());
266 Log::trace() <<
"CostJbTotal::addGradientFG 2 done" << std::endl;
271 template<
typename MODEL,
typename OBS>
273 Log::trace() <<
"CostJbTotal::initializeTL start" << std::endl;
274 jqtl_.reset(jb_->initializeJqTL());
276 Log::trace() <<
"CostJbTotal::initializeTL done" << std::endl;
281 template<
typename MODEL,
typename OBS>
283 Log::trace() <<
"CostJbTotal::finalizeTL start" << std::endl;
285 if (jqtl_) jqtl_->computeModelErrorTL(dx.
state());
287 Log::trace() <<
"CostJbTotal::finalizeTL done" << std::endl;
292 template<
typename MODEL,
typename OBS>
295 Log::trace() <<
"CostJbTotal::initializeAD start" << std::endl;
296 jqad_.reset(jb_->initializeJqAD(dx.
state()));
299 Log::trace() <<
"CostJbTotal::initializeAD done" << std::endl;
304 template<
typename MODEL,
typename OBS>
306 Log::trace() <<
"CostJbTotal::finalizeAD start" << std::endl;
307 if (jqad_) jqad_->clear();
309 Log::trace() <<
"CostJbTotal::finalizeAD done" << std::endl;
314 template<
typename MODEL,
typename OBS>
316 Log::trace() <<
"CostJbTotal::multiplyB start" << std::endl;
320 Log::trace() <<
"CostJbTotal::multiplyB done" << std::endl;
325 template<
typename MODEL,
typename OBS>
327 Log::trace() <<
"CostJbTotal::multiplyBinv start" << std::endl;
329 jbModBias_.inverseMultiply(dxin.
modVar(), dxout.
modVar());
330 jbObsBias_.inverseMultiply(dxin.
obsVar(), dxout.
obsVar());
331 Log::trace() <<
"CostJbTotal::multiplyBinv done" << std::endl;
336 template<
typename MODEL,
typename OBS>
338 Log::trace() <<
"CostJbTotal::randomize start" << std::endl;
339 jb_->randomize(dx.
state());
340 jbModBias_.randomize(dx.
modVar());
341 jbObsBias_.randomize(dx.
obsVar());
342 Log::trace() <<
"CostJbTotal::randomize done" << std::endl;
ObsAuxIncrs_ & obsVar()
Get augmented observation control variable.
Increment_ & state()
Get state control variable.
ModelAuxIncr_ & modVar()
Get augmented model control variable.
ObsAuxCtrls_ & obsVar()
Get augmented observation control variable.
ModelAux_ & modVar()
Get augmented model control variable.
State_ & state()
Get state control variable.
Jb Cost Function Base Class.
Control variable increment.
PostProcessorTLAD< MODEL > PostProcTLAD_
double evaluate(const CtrlInc_ &) const
std::shared_ptr< JqTermTLAD_ > jqad_
void initialize(const CtrlVar_ &) const
Initialize before nonlinear model integration.
const Geometry_ & resolution() const
Jb terms for ControlIncrement constructor.
const util::DateTime & windowBegin() const
void addGradientFG(CtrlInc_ &) const
Add Jb gradient at first guess.
ControlIncrement< MODEL, OBS > CtrlInc_
void finalizeTL(const CtrlInc_ &, CtrlInc_ &) const
const JbState_ & jbState() const
JqTermTLAD< MODEL > JqTermTLAD_
std::unique_ptr< CtrlInc_ > dxFG_
First guess increment or more generally .
const CtrlInc_ & getFirstGuess() const
Return first guess .
const CtrlVar_ & getBackground() const
Return background.
ControlVariable< MODEL, OBS > CtrlVar_
Geometry< MODEL > Geometry_
void initializeAD(CtrlInc_ &, const CtrlInc_ &, PostProcTLAD_ &) const
Initialize before starting the AD run.
ObsAuxCovariances< OBS > ObsAuxCovars_
ModelAuxCovariance< MODEL > ModelAuxCovar_
std::unique_ptr< Geometry_ > resol_
Inner loop resolution.
ModelAuxCovar_ jbModBias_
double finalize(const CtrlVar_ &) const
Finalize computation after nonlinear model integration.
CostJbState< MODEL > JbState_
const ObsAuxCovars_ & jbObsBias() const
const util::DateTime windowBegin_
ObsSpaces< OBS > ObsSpaces_
std::shared_ptr< JqTermTLAD_ > jqtraj_
~CostJbTotal()
Destructor.
std::unique_ptr< JbState_ > jb_
const util::DateTime windowEnd_
void multiplyBinv(const CtrlInc_ &, CtrlInc_ &) const
void initializeTraj(const CtrlVar_ &, const Geometry_ &, const eckit::Configuration &, PostProcTLAD_ &)
void multiplyB(const CtrlInc_ &, CtrlInc_ &) const
Multiply by covariance matrix and its inverse.
std::shared_ptr< JqTermTLAD_ > jqtl_
void initializeTL(PostProcTLAD_ &) const
Initialize before starting the TL run.
void randomize(CtrlInc_ &) const
Randomize.
CostJbTotal(const CtrlVar_ &, JbState_ *, const eckit::Configuration &, const Geometry_ &, const ObsSpaces_ &odb)
Construct .
const ModelAuxCovar_ & jbModBias() const
const util::DateTime & windowEnd() const
Geometry class used in oops; subclass of interface class interface::Geometry.
Auxiliary Error Covariance related to model, not used at the moment.
void diff(const ModelAuxControl_ &, const ModelAuxControl_ &)
Sets this ModelAuxIncrement to the difference between two ModelAuxControl objects.
Holds a vector of ObsAuxCovariance.
void diff(const ObsAuxControls_ &, const ObsAuxControls_ &)
Linear algebra operators.
Control model post processing.
void enrollProcessor(PostBaseTLAD_ *pp)
State class used in oops; subclass of interface class interface::State.
State_ & state()
Accessor.
The namespace for the main oops code.