11 #ifndef OOPS_ASSIMILATION_COSTJO_H_ 12 #define OOPS_ASSIMILATION_COSTJO_H_ 15 #include <boost/noncopyable.hpp> 16 #include <boost/pointer_cast.hpp> 17 #include <boost/scoped_ptr.hpp> 18 #include <boost/shared_ptr.hpp> 20 #include "eckit/config/LocalConfiguration.h" 39 #include "oops/util/DateTime.h" 40 #include "oops/util/Duration.h" 41 #include "oops/util/Logger.h" 55 private boost::noncopyable {
73 CostJo(
const eckit::Configuration &,
const util::DateTime &,
const util::DateTime &,
74 const util::Duration &,
const bool subwindows =
false);
83 const eckit::Configuration &)
override;
85 double finalize(
const eckit::Configuration &)
const override;
89 boost::shared_ptr<PostBaseTLAD_>
setupTL(
const CtrlInc_ &)
const override;
92 boost::shared_ptr<PostBaseTLAD_>
setupAD(
93 boost::shared_ptr<const GeneralizedDepartures>,
CtrlInc_ &)
const override;
121 mutable boost::shared_ptr<Observer<MODEL, State_> >
pobs_;
133 template<
typename MODEL>
135 const util::DateTime & winbgn,
const util::DateTime & winend,
136 const util::Duration & tslot,
const bool subwindows)
137 : obspace_(joConf, winbgn, winend),
138 hop_(obspace_), yobs_(obspace_), R_(obspace_),
139 gradFG_(), pobs_(), tslot_(tslot),
140 pobstlad_(), subwindows_(subwindows)
142 Log::trace() <<
"CostJo::CostJo start" << std::endl;
145 Log::trace() <<
"CostJo::CostJo done" << std::endl;
150 template<
typename MODEL>
151 boost::shared_ptr<PostBase<State<MODEL> > >
153 Log::trace() <<
"CostJo::initialize start" << std::endl;
154 const eckit::LocalConfiguration
conf;
157 tslot_, subwindows_));
158 Log::trace() <<
"CostJo::initialize done" << std::endl;
164 template<
typename MODEL>
166 Log::trace() <<
"CostJo::finalize start" << std::endl;
167 boost::scoped_ptr<Observations_> yeqv(pobs_->release());
168 Log::info() <<
"Jo Observation Equivalent:" << *yeqv << std::endl;
171 Log::info() <<
"Jo Departures:" << ydep << std::endl;
173 boost::scoped_ptr<Departures_> grad(R_.inverseMultiply(ydep));
175 double zjo = this->printJo(ydep, *grad);
177 if (
conf.has(
"departures")) {
178 const std::string depname =
conf.getString(
"departures");
183 Log::trace() <<
"CostJo::finalize done" << std::endl;
189 template<
typename MODEL>
190 boost::shared_ptr<PostBaseTLAD<MODEL> >
192 const eckit::Configuration &
conf) {
193 Log::trace() <<
"CostJo::initializeTraj start" << std::endl;
196 tslot_, subwindows_));
197 Log::trace() <<
"CostJo::initializeTraj done" << std::endl;
203 template<
typename MODEL>
205 Log::trace() <<
"CostJo::finalizeTraj start" << std::endl;
206 boost::scoped_ptr<Observations_> yeqv(pobstlad_->release());
207 Log::info() <<
"Jo Traj Observation Equivalent:" << *yeqv << std::endl;
211 Log::info() <<
"Jo Traj Departures:" << ydep << std::endl;
213 gradFG_.reset(R_.inverseMultiply(ydep));
214 Log::trace() <<
"CostJo::finalizeTraj done" << std::endl;
219 template<
typename MODEL>
221 Log::trace() <<
"CostJo::setupTL start" << std::endl;
223 pobstlad_->setupTL(dx.
obsVar());
224 Log::trace() <<
"CostJo::setupTL done" << std::endl;
230 template<
typename MODEL>
232 boost::shared_ptr<const GeneralizedDepartures>
pv,
234 Log::trace() <<
"CostJo::setupAD start" << std::endl;
236 boost::shared_ptr<const Departures_> dy = boost::dynamic_pointer_cast<
const Departures_>(
pv);
237 pobstlad_->setupAD(dy, dx.
obsVar());
238 Log::trace() <<
"CostJo::setupAD done" << std::endl;
244 template<
typename MODEL>
246 Log::trace() <<
"CostJo::multiplyCovar start" << std::endl;
248 return R_.multiply(y1);
253 template<
typename MODEL>
255 Log::trace() <<
"CostJo::multiplyCoInv start" << std::endl;
257 return R_.inverseMultiply(y1);
262 template<
typename MODEL>
264 Log::trace() <<
"CostJo::newDualVector start" << std::endl;
267 Log::trace() <<
"CostJo::newDualVector done" << std::endl;
273 template<
typename MODEL>
275 Log::trace() <<
"CostJo::resetLinearization start" << std::endl;
277 Log::trace() <<
"CostJo::resetLinearization done" << std::endl;
282 template<
typename MODEL>
284 Log::trace() <<
"CostJo::printJo start" << std::endl;
285 obspace_.printJo(dy, grad);
288 for (std::size_t jj = 0; jj < dy.
size(); ++jj) {
289 const double zz = 0.5 * dot_product(dy[jj], grad[jj]);
290 const unsigned nobs = dy[jj].
size();
292 Log::test() <<
"CostJo : Nonlinear Jo = " << zz
293 <<
", nobs = " <<
nobs <<
", Jo/n = " << zz/
nobs 294 <<
", err = " << R_[jj].getRMSE() << std::endl;
296 Log::test() <<
"CostJo : Nonlinear Jo = " << zz <<
" --- No Observations" << std::endl;
297 Log::warning() <<
"CostJo: No Observations!!!" << std::endl;
302 Log::trace() <<
"CostJo::printJo done" << std::endl;
310 #endif // OOPS_ASSIMILATION_COSTJO_H_ boost::shared_ptr< PostBaseTLAD_ > setupAD(boost::shared_ptr< const GeneralizedDepartures >, CtrlInc_ &) const override
Initialize before starting the AD run.
ControlVariable< MODEL > CtrlVar_
CostJo(const eckit::Configuration &, const util::DateTime &, const util::DateTime &, const util::Duration &, const bool subwindows=false)
Construct from and .
double printJo(const Departures_ &, const Departures_ &) const
Print Jo.
LinearObsOperators< MODEL > LinearObsOperator_
integer, parameter, public warning
void resetLinearization() override
Reset obs operator trajectory.
double finalize(const eckit::Configuration &) const override
Finalize after the integration of the model.
ObserverTLAD< MODEL > ObserverTLAD_
Observations< MODEL > Observations_
ObsAuxIncr_ & obsVar()
Get augmented observation control variable.
Difference between two observation vectors.
Geometry< MODEL > Geometry_
PostBaseTLAD< MODEL > PostBaseTLAD_
Handles post-processing of model fields related to cost function.
virtual ~CostJo()
Destructor.
Encapsulates the model state.
Departures_ * newGradientFG() const override
Return gradient at first guess ie .
The namespace for the main oops code.
void save(const std::string &) const
Save departures values.
boost::shared_ptr< PostBaseTLAD_ > setupTL(const CtrlInc_ &) const override
Initialize before starting the TL run.
boost::shared_ptr< PostBaseTLAD_ > initializeTraj(const CtrlVar_ &, const Geometry_ &, const eckit::Configuration &) override
subroutine, public info(self)
ObsOperators< MODEL > ObsOperator_
Increment< MODEL > Increment_
ObsSpaces< MODEL > ObsSpace_
Departures_ * newDualVector() const override
Provide new departure.
ObsAuxIncrement< MODEL > ObsAuxIncr_
Computes observation equivalent during model run.
Increment Class: Difference between two states.
ControlIncrement< MODEL > CtrlInc_
Base Class for Cost Function Terms.
Departures< MODEL > Departures_
void read(const eckit::Configuration &)
boost::shared_ptr< Observer< MODEL, State_ > > pobs_
Observer passed by to the model during integration.
Abstract base class for quantities.
Departures_ * multiplyCovar(const GeneralizedDepartures &) const override
Multiply by and .
boost::shared_ptr< ObserverTLAD_ > pobstlad_
Linearized observation operators.
boost::shared_ptr< PostBase< State_ > > initialize(const CtrlVar_ &) const override
Initialize before starting the integration of the model.
const util::Duration tslot_
Time slot.
Departures_ * multiplyCoInv(const GeneralizedDepartures &) const override
ObsFilters< MODEL > ObsFilters_
void finalizeTraj() override
ObsAuxCtrl_ & obsVar()
Get augmented observation control variable.
boost::scoped_ptr< Departures_ > gradFG_
Gradient at first guess : .
std::size_t size() const
Access.
Computes observation equivalent TL and AD to/from increments.