IODA Bundle
oops/interface/ModelAuxControl.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #ifndef OOPS_INTERFACE_MODELAUXCONTROL_H_
12 #define OOPS_INTERFACE_MODELAUXCONTROL_H_
13 
14 #include <iostream>
15 #include <memory>
16 #include <string>
17 
18 #include "oops/base/Geometry.h"
19 #include "oops/util/Logger.h"
20 #include "oops/util/ObjectCounter.h"
21 #include "oops/util/Printable.h"
22 #include "oops/util/Timer.h"
23 
24 namespace eckit {
25  class Configuration;
26 }
27 
28 namespace oops {
29 
30 // -----------------------------------------------------------------------------
31 
32 template <typename MODEL>
33 class ModelAuxControl : public util::Printable,
34  private util::ObjectCounter<ModelAuxControl<MODEL> > {
35  typedef typename MODEL::ModelAuxControl ModelAuxControl_;
37 
38  public:
39  static const std::string classname() {return "oops::ModelAuxControl";}
40 
41  ModelAuxControl(const Geometry_ &, const eckit::Configuration &);
42  ModelAuxControl(const Geometry_ &, const ModelAuxControl &);
43  explicit ModelAuxControl(const ModelAuxControl &, const bool copy = true);
45 
46 /// Interfacing
47  const ModelAuxControl_ & modelauxcontrol() const {return *aux_;}
49 
50 /// I/O and diagnostics
51  void read(const eckit::Configuration &);
52  void write(const eckit::Configuration &) const;
53  double norm() const;
54 
55  private:
57  void print(std::ostream &) const;
58  std::unique_ptr<ModelAuxControl_> aux_;
59 };
60 
61 // =============================================================================
62 
63 template<typename MODEL>
65  const eckit::Configuration & conf) : aux_()
66 {
67  Log::trace() << "ModelAuxControl<MODEL>::ModelAuxControl starting" << std::endl;
68  util::Timer timer(classname(), "ModelAuxControl");
69  aux_.reset(new ModelAuxControl_(resol.geometry(), conf));
70  Log::trace() << "ModelAuxControl<MODEL>::ModelAuxControl done" << std::endl;
71 }
72 
73 // -----------------------------------------------------------------------------
74 
75 template<typename MODEL>
77  const ModelAuxControl & other) : aux_()
78 {
79  Log::trace() << "ModelAuxControl<MODEL>::ModelAuxControl interpolated starting" << std::endl;
80  util::Timer timer(classname(), "ModelAuxControl");
81  aux_.reset(new ModelAuxControl_(resol.geometry(), *other.aux_));
82  Log::trace() << "ModelAuxControl<MODEL>::ModelAuxControl interpolated done" << std::endl;
83 }
84 
85 // -----------------------------------------------------------------------------
86 
87 template<typename MODEL>
89  const bool copy) : aux_()
90 {
91  Log::trace() << "ModelAuxControl<MODEL>::ModelAuxControl copy starting" << std::endl;
92  util::Timer timer(classname(), "ModelAuxControl");
93  aux_.reset(new ModelAuxControl_(*other.aux_, copy));
94  Log::trace() << "ModelAuxControl<MODEL>::ModelAuxControl copy done" << std::endl;
95 }
96 
97 // -----------------------------------------------------------------------------
98 
99 template<typename MODEL>
101  Log::trace() << "ModelAuxControl<MODEL>::~ModelAuxControl starting" << std::endl;
102  util::Timer timer(classname(), "~ModelAuxControl");
103  aux_.reset();
104  Log::trace() << "ModelAuxControl<MODEL>::~ModelAuxControl done" << std::endl;
105 }
106 
107 // -----------------------------------------------------------------------------
108 
109 template<typename MODEL>
110 void ModelAuxControl<MODEL>::read(const eckit::Configuration & conf) {
111  Log::trace() << "ModelAuxControl<MODEL>::read starting" << std::endl;
112  util::Timer timer(classname(), "read");
113  aux_->read(conf);
114  Log::trace() << "ModelAuxControl<MODEL>::read done" << std::endl;
115 }
116 
117 // -----------------------------------------------------------------------------
118 
119 template<typename MODEL>
120 void ModelAuxControl<MODEL>::write(const eckit::Configuration & conf) const {
121  Log::trace() << "ModelAuxControl<MODEL>::write starting" << std::endl;
122  util::Timer timer(classname(), "write");
123  aux_->write(conf);
124  Log::trace() << "ModelAuxControl<MODEL>::write done" << std::endl;
125 }
126 
127 // -----------------------------------------------------------------------------
128 
129 template<typename MODEL>
131  Log::trace() << "ModelAuxControl<MODEL>::norm starting" << std::endl;
132  util::Timer timer(classname(), "norm");
133  double zz = aux_->norm();
134  Log::trace() << "ModelAuxControl<MODEL>::norm done" << std::endl;
135  return zz;
136 }
137 
138 // -----------------------------------------------------------------------------
139 
140 template<typename MODEL>
141 void ModelAuxControl<MODEL>::print(std::ostream & os) const {
142  Log::trace() << "ModelAuxControl<MODEL>::print starting" << std::endl;
143  util::Timer timer(classname(), "print");
144  os << *aux_;
145  Log::trace() << "ModelAuxControl<MODEL>::print done" << std::endl;
146 }
147 
148 // -----------------------------------------------------------------------------
149 
150 } // namespace oops
151 
152 #endif // OOPS_INTERFACE_MODELAUXCONTROL_H_
Geometry class used in oops; subclass of interface class interface::Geometry.
MODEL::ModelAuxControl ModelAuxControl_
const ModelAuxControl_ & modelauxcontrol() const
Interfacing.
ModelAuxControl & operator=(const ModelAuxControl &)
ModelAuxControl(const Geometry_ &, const eckit::Configuration &)
void read(const eckit::Configuration &)
I/O and diagnostics.
static const std::string classname()
void write(const eckit::Configuration &) const
void print(std::ostream &) const
std::unique_ptr< ModelAuxControl_ > aux_
const Geometry_ & geometry() const
IODA_DL void copy(const ObjectSelection &from, ObjectSelection &to, const ScaleMapping &scale_map)
Generic data copying function.
Definition: Copying.cpp:63
The namespace for the main oops code.