Debian Codegraph @

src/atlas/trans/VorDivToUV.h

raw
1 /*
2 * (C) Copyright 2013 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
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <memory>
14
15 #include "atlas/library/config.h"
16 #include "atlas/util/Config.h"
17 #include "atlas/util/Object.h"
18 #include "atlas/util/ObjectHandle.h"
19
20 //-----------------------------------------------------------------------------
21 // Forward declarations
22
23 namespace atlas {
24 class Field;
25 class FieldSet;
26 class FunctionSpace;
27 class Grid;
28 } // namespace atlas
29
30 //-----------------------------------------------------------------------------
31
32 namespace atlas {
33 namespace trans {
34
35 //-----------------------------------------------------------------------------
36
37 class VorDivToUVImpl : public util::Object {
38 public:
39 virtual ~VorDivToUVImpl() = 0;
40
41 virtual int truncation() const = 0;
42
43 // -- IFS type fields --
44 // These fields have special interpretation required. You need to know what
45 // you're doing.
46 // See IFS trans library.
47
48 /*!
49 * @brief Compute spectral wind (U/V) from spectral vorticity/divergence
50 *
51 * U = u*cos(lat)
52 * V = v*cos(lat)
53 *
54 * @param nb_fields [in] Number of fields
55 * @param vorticity [in] Spectral vorticity
56 * @param divergence [in] Spectral divergence
57 * @param U [out] Spectral wind U = u*cos(lat)
58 * @param V [out] Spectral wind V = v*cos(lat)
59 */
60 virtual void execute(const int nb_coeff, const int nb_fields, const double vorticity[], const double divergence[],
61 double U[], double V[], const eckit::Configuration& = util::NoConfig()) const = 0;
62 };
63
64 // ------------------------------------------------------------------
65
66 class VorDivToUVFactory {
67 public:
68 /*!
69 * \brief build VorDivToUV
70 * \return VorDivToUVImpl
71 */
72 static VorDivToUVImpl* build(const FunctionSpace& sp, const eckit::Configuration& = util::NoConfig());
73 static VorDivToUVImpl* build(int truncation, const eckit::Configuration& = util::NoConfig());
74
75 /*!
76 * \brief list all registered trans implementations
77 */
78 static void list(std::ostream&);
79
80 static bool has(const std::string& name);
81
82 private:
83 std::string name_;
84 virtual VorDivToUVImpl* make(const FunctionSpace& sp, const eckit::Configuration&) = 0;
85 virtual VorDivToUVImpl* make(int truncation, const eckit::Configuration&) = 0;
86
87 protected:
88 VorDivToUVFactory(const std::string&);
89 virtual ~VorDivToUVFactory();
90 };
91
92 //----------------------------------------------------------------------------------------------------------------------
93
94 template <class T>
95 class VorDivToUVBuilder : public VorDivToUVFactory {
96 virtual VorDivToUVImpl* make(const FunctionSpace& sp, const eckit::Configuration& config) {
97 return new T(sp, config);
98 }
99 virtual VorDivToUVImpl* make(int truncation, const eckit::Configuration& config) {
100 return new T(truncation, config);
101 }
102
103 public:
104 VorDivToUVBuilder(const std::string& name): VorDivToUVFactory(name) {}
105 };
106
107 //----------------------------------------------------------------------------------------------------------------------
108
109 class VorDivToUV : DOXYGEN_HIDE(public util::ObjectHandle<VorDivToUVImpl>) {
110 public:
111 using Handle::Handle;
112 VorDivToUV() = default;
113
114 VorDivToUV(const FunctionSpace& sp, const eckit::Configuration& = util::NoConfig());
115 VorDivToUV(int truncation, const eckit::Configuration& = util::NoConfig());
116
117 void hash(eckit::Hash&) const;
118
119 int truncation() const;
120
121 // -- IFS type fields --
122 // These fields have special interpretation required. You need to know what
123 // you're doing.
124 // See IFS trans library.
125
126 virtual void execute(const int nb_coeff, const int nb_fields, const double vorticity[], const double divergence[],
127 double U[], double V[], const eckit::Configuration& = util::NoConfig()) const;
128 };
129
130 //----------------------------------------------------------------------------------------------------------------------
131
132 } // namespace trans
133 } // namespace atlas