11 #ifndef OOPS_ASSIMILATION_MINIMIZER_H_ 12 #define OOPS_ASSIMILATION_MINIMIZER_H_ 16 #include <boost/noncopyable.hpp> 18 #include "eckit/config/Configuration.h" 28 #include "oops/util/abor1_cpp.h" 29 #include "oops/util/dot_product.h" 30 #include "oops/util/formats.h" 31 #include "oops/util/Logger.h" 32 #include "oops/util/PrintAdjTest.h" 39 template<
typename MODEL>
class Minimizer :
private boost::noncopyable {
51 virtual const std::string
classname()
const = 0;
56 void adjTests(
const eckit::Configuration &);
60 void tlmTests(
const eckit::Configuration &);
72 template<
typename MODEL>
75 this->tlmTests(config);
78 this->adjTests(config);
84 this->tlmPropagTest(config, *dx);
94 template<
typename MODEL>
98 if (config.has(
"onlineDiagnostics")) {
99 const eckit::LocalConfiguration onlineDiag(config,
"onlineDiagnostics");
100 bool runTlmTaylorTest = onlineDiag.getBool(
"tlmTaylorTest");
101 bool runTlmApproxTest = onlineDiag.getBool(
"tlmApproxTest");
108 if (outerIteration_ == 0 && runTlmApproxTest) this->tlmApproxTest(H);
111 if (outerIteration_ == 0 && runTlmTaylorTest) this->tlmTaylorTest(H);
117 template<
typename MODEL>
121 if (config.has(
"onlineDiagnostics")) {
122 const eckit::LocalConfiguration onlineDiag(config,
"onlineDiagnostics");
123 bool runAdjTlmTest = onlineDiag.getBool(
"adjTlmTest");
124 bool runAdjObsTest = onlineDiag.getBool(
"adjObsTest");
131 if (runAdjTlmTest) this->adjModelTest(Ht, H);
134 if (runAdjObsTest) this->adjObsTest(Ht, H);
140 template<
typename MODEL>
151 <<
"TLM Linear Approximation Test - starting: " << outerIteration_
152 << std::endl << std::endl;
158 J_.jb().randomize(dx);
167 J_.addIncrement(mpertxx, dx);
168 J_.runNL(mpertxx, pp);
176 Log::info() << std::endl <<
"TLM Linear Approximation Test: done." << std::endl;
181 template<
typename MODEL>
192 if (config.has(
"onlineDiagnostics")) {
193 const eckit::LocalConfiguration onlineDiag(config,
"onlineDiagnostics");
194 bool runTlmPropagTest = onlineDiag.getBool(
"tlmPropagTest");
196 if (runTlmPropagTest) {
198 Log::info() <<
"TLM Propagation Test - starting: " << outerIteration_
199 << std::endl << std::endl;
210 Log::info() << std::endl <<
"TLM Propagation Test: done." << std::endl;
217 template<
typename MODEL>
225 <<
"TLM Taylor Test: " << outerIteration_
232 J_.jb().randomize(dx);
245 for (
unsigned int jj = 0; jj < 14; ++jj) {
248 pmdx *= 1./pow(10.0, jj);
249 double denom = sqrt(dot_product(pmdx, pmdx));
254 pdx *= 1./pow(10.0, jj);
255 J_.addIncrement(mpertxx, pdx);
256 J_.runNL(mpertxx, pp);
260 diff_nl.
state()[0].
diff(mpertxx.state()[0], mxx.state()[0]);
261 double nom = sqrt(dot_product(diff_nl, diff_nl));
265 <<
"TLM Taylor test: p = " << std::setw(8) << 1./pow(10.0, jj)
266 <<
", ||M(x) - M(x+p dx)|| / ||p M'(dx)|| = " 267 << util::full_precision(1.+std::abs(1.-nom/denom))
275 template<
typename MODEL>
287 J_.jb().randomize(dx1);
288 J_.jb().randomize(dx2);
298 mtdx2.
state()[0].updateTime(mdx1.
state()[0].validTime() - dx1.state()[0].validTime());
302 double adj_tst_fwd = dot_product(mdx1, dx2);
305 double adj_tst_bwd = dot_product(dx1, mtdx2);
308 Log::info() <<
"Model Adjoint Test: " << outerIteration_ << std::endl
309 << util::PrintAdjTest(adj_tst_fwd, adj_tst_bwd,
"M")
310 << std::endl << std::endl;
315 template<
typename MODEL>
333 J_.jb().randomize(dx1);
334 J_.jb().randomize(dx2);
345 double adj_tst_fwd = dot_product(hdx1, hdx2);
348 double adj_tst_bwd = dot_product(dx1, hthdx2);
351 Log::info() <<
"Obs Adjoint Test: " << outerIteration_ << std::endl
352 << util::PrintAdjTest(adj_tst_fwd, adj_tst_bwd,
"H")
353 << std::endl << std::endl;
359 template <
typename MODEL>
369 static std::map < std::string, MinFactory<MODEL> * > &
getMakers() {
370 static std::map < std::string, MinFactory<MODEL> * > makers_;
377 template<
class MODEL,
class FCT>
381 return new FCT(
conf, J);
389 template <
typename MODEL>
391 if (getMakers().find(
name) != getMakers().
end()) {
392 Log::error() <<
name <<
" already registered in minimizer factory." << std::endl;
393 ABORT(
"Element already registered in MinFactory.");
395 getMakers()[
name] =
this;
400 template <
typename MODEL>
403 std::string
id = config.getString(
"algorithm");
404 Log::info() <<
"Minimizer algorithm=" <<
id << std::endl;
405 typename std::map<std::string, MinFactory<MODEL>*>::iterator
j = getMakers().find(
id);
406 if (
j == getMakers().
end()) {
407 Log::error() <<
id <<
" does not exist in minimizer factory." << std::endl;
408 ABORT(
"Element does not exist in MinFactory.");
410 return (*j).second->make(config, J);
417 #endif // OOPS_ASSIMILATION_MINIMIZER_H_
Container of dual space vectors for all terms of the cost function.
void tlmApproxTest(const H_ &)
ControlIncrement< MODEL > * minimize(const eckit::Configuration &)
CostFunction< MODEL > CostFct_
virtual Minimizer< MODEL > * make(const eckit::Configuration &, const CostFct_ &)=0
MinMaker(const std::string &name)
************************************************************************GNU Lesser General Public License **This file is part of the GFDL Flexible Modeling System(FMS). ! *! *FMS is free software without even the implied warranty of MERCHANTABILITY or *FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License *for more details **You should have received a copy of the GNU Lesser General Public *License along with FMS If see< http:! ***********************************************************************!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! MPP_TRANSMIT !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine MPP_TRANSMIT_(put_data, put_len, to_pe, get_data, get_len, from_pe, block, tag, recv_request, send_request)!a message-passing routine intended to be reminiscent equally of both MPI and SHMEM!put_data and get_data are contiguous MPP_TYPE_ arrays!at each call, your put_data array is put to to_pe 's get_data! your get_data array is got from from_pe 's put_data!i.e we assume that typically(e.g updating halo regions) each PE performs a put _and_ a get!special PE designations:! NULL_PE:to disable a put or a get(e.g at boundaries)! ANY_PE:if remote PE for the put or get is to be unspecific! ALL_PES:broadcast and collect operations(collect not yet implemented)!ideally we would not pass length, but this f77-style call performs better(arrays passed by address, not descriptor)!further, this permits< length > contiguous words from an array of any rank to be passed(avoiding f90 rank conformance check)!caller is responsible for completion checks(mpp_sync_self) before and after integer, intent(in) ::put_len, to_pe, get_len, from_pe MPP_TYPE_, intent(in) ::put_data(*) MPP_TYPE_, intent(out) ::get_data(*) logical, intent(in), optional ::block integer, intent(in), optional ::tag integer, intent(out), optional ::recv_request, send_request logical ::block_comm integer ::i MPP_TYPE_, allocatable, save ::local_data(:) !local copy used by non-parallel code(no SHMEM or MPI) integer ::comm_tag integer ::rsize if(.NOT.module_is_initialized) call mpp_error(FATAL, 'MPP_TRANSMIT:You must first call mpp_init.') if(to_pe.EQ.NULL_PE .AND. from_pe.EQ.NULL_PE) return block_comm=.true. if(PRESENT(block)) block_comm=block if(debug) then call SYSTEM_CLOCK(tick) write(stdout_unit,'(a, i18, a, i6, a, 2i6, 2i8)')&'T=', tick, ' PE=', pe, ' MPP_TRANSMIT begin:to_pe, from_pe, put_len, get_len=', to_pe, from_pe, put_len, get_len end if comm_tag=DEFAULT_TAG if(present(tag)) comm_tag=tag!do put first and then get if(to_pe.GE.0 .AND. to_pe.LT.npes) then!use non-blocking sends if(debug .and.(current_clock.NE.0)) call SYSTEM_CLOCK(start_tick)!z1l:truly non-blocking send.! if(request(to_pe).NE.MPI_REQUEST_NULL) then !only one message from pe-> to_pe in queue *PE waiting for to_pe ! call error else get_len so only do gets but you cannot have a pure get with MPI call a get means do a wait to ensure put on remote PE is complete error call increase mpp_nml request_multiply call MPP_TRANSMIT end
CostFunction< MODEL > CostFct_
void diff(const State4D_ &, const State4D_ &)
Linear algebra operators.
void adjModelTest(const Ht_ &, const H_ &)
Encapsulates the model state.
void multiply(CtrlInc_ &dx, DualVector< MODEL > &dy, const bool idModel=false) const
l_size ! loop over number of fields ke do j
void adjTests(const eckit::Configuration &)
static Minimizer< MODEL > * create(const eckit::Configuration &, const CostFct_ &)
virtual ControlIncrement< MODEL > * doMinimize(const eckit::Configuration &)=0
The namespace for the main oops code.
virtual const std::string classname() const =0
void adjObsTest(const Ht_ &, const H_ &)
Increment4D_ & state()
Get state control variable.
void multiply(const DualVector< MODEL > &dy, ControlIncrement< MODEL > &dx, const bool idModel=false) const
Minimizer(const CostFct_ &J)
subroutine, public info(self)
CostFunction< MODEL > CostFct_
void tlmTests(const eckit::Configuration &)
virtual Minimizer< MODEL > * make(const eckit::Configuration &conf, const CostFct_ &J)
DualVector< MODEL > Dual_
static std::map< std::string, MinFactory< MODEL > *> & getMakers()
void tlmTaylorTest(const H_ &)
ControlIncrement< MODEL > CtrlInc_
Control model post processing.
A Minimizer knows how to minimize a cost function.
void tlmPropagTest(const eckit::Configuration &config, const CtrlInc_ &)
MinFactory(const std::string &)