| 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 |
#include "eckit/utils/Hash.h" |
| 12 |
|
| 13 |
#include "atlas/functionspace.h" |
| 14 |
#include "atlas/grid/Grid.h" |
| 15 |
#include "atlas/library/defines.h" |
| 16 |
#include "atlas/runtime/Exception.h" |
| 17 |
#include "atlas/runtime/Log.h" |
| 18 |
#include "atlas/trans/Trans.h" |
| 19 |
#include "atlas/trans/detail/TransFactory.h" |
| 20 |
#include "atlas/trans/detail/TransImpl.h" |
| 21 |
|
| 22 |
namespace atlas { |
| 23 |
namespace trans { |
| 24 |
|
| 25 |
namespace { |
| 26 |
util::Config options(const eckit::Configuration& config) { |
| 27 |
util::Config opts = Trans::config(); |
| 28 |
opts.set(eckit::LocalConfiguration(config)); |
| 29 |
return opts; |
| 30 |
} |
| 31 |
} // namespace |
| 32 |
|
| 33 |
void Trans::listBackends(std::ostream& out) { |
| 34 |
TransFactory::list(out); |
| 35 |
} |
| 36 |
|
| 37 |
bool Trans::hasBackend(const std::string& backend) { |
| 38 |
return TransFactory::has(backend); |
| 39 |
} |
| 40 |
|
| 41 |
void Trans::backend(const std::string& backend) { |
| 42 |
ATLAS_ASSERT(hasBackend(backend)); |
| 43 |
TransFactory::backend(backend); |
| 44 |
} |
| 45 |
|
| 46 |
std::string Trans::backend() { |
| 47 |
return TransFactory::backend(); |
| 48 |
} |
| 49 |
|
| 50 |
const eckit::Configuration& Trans::config() { |
| 51 |
return TransFactory::config(); |
| 52 |
} |
| 53 |
|
| 54 |
void Trans::config(const eckit::Configuration& _config) { |
| 55 |
TransFactory::config(_config); |
| 56 |
} |
| 57 |
|
| 58 |
Trans::Trans(const FunctionSpace& gp, const FunctionSpace& sp, const eckit::Configuration& config): |
| 59 |
Handle(TransFactory::build(gp, sp, config)) {} |
| 60 |
|
| 61 |
Trans::Trans(const Grid& grid, int truncation, const eckit::Configuration& config): |
| 62 |
Handle(TransFactory::build(grid, truncation, config)) {} |
| 63 |
|
| 64 |
Trans::Trans(const Grid& grid, const Domain& domain, int truncation, const eckit::Configuration& config): |
| 65 |
Handle(TransFactory::build(grid, domain, truncation, config)) {} |
| 66 |
|
| 67 |
Trans::Trans(const Cache& cache, const FunctionSpace& gp, const FunctionSpace& sp, const eckit::Configuration& config): |
| 68 |
Handle(TransFactory::build(cache, gp, sp, config)) {} |
| 69 |
|
| 70 |
Trans::Trans(const Cache& cache, const Grid& grid, int truncation, const eckit::Configuration& config): |
| 71 |
Handle(TransFactory::build(cache, grid, truncation, config)) {} |
| 72 |
|
| 73 |
Trans::Trans(const Cache& cache, const Grid& grid, const Domain& domain, int truncation, |
| 74 |
const eckit::Configuration& config): |
| 75 |
Handle(TransFactory::build(cache, grid, domain, truncation, config)) {} |
| 76 |
|
| 77 |
int Trans::truncation() const { |
| 78 |
return get()->truncation(); |
| 79 |
} |
| 80 |
|
| 81 |
const Grid& Trans::grid() const { |
| 82 |
return get()->grid(); |
| 83 |
} |
| 84 |
|
| 85 |
const functionspace::Spectral& Trans::spectral() const { |
| 86 |
return get()->spectral(); |
| 87 |
} |
| 88 |
|
| 89 |
size_t Trans::spectralCoefficients() const { |
| 90 |
return get()->spectralCoefficients(); |
| 91 |
} |
| 92 |
|
| 93 |
void Trans::dirtrans(const Field& gpfield, Field& spfield, const eckit::Configuration& config) const { |
| 94 |
get()->dirtrans(gpfield, spfield, options(config)); |
| 95 |
} |
| 96 |
|
| 97 |
void Trans::dirtrans(const FieldSet& gpfields, FieldSet& spfields, const eckit::Configuration& config) const { |
| 98 |
get()->dirtrans(gpfields, spfields, options(config)); |
| 99 |
} |
| 100 |
|
| 101 |
void Trans::dirtrans_wind2vordiv(const Field& gpwind, Field& spvor, Field& spdiv, |
| 102 |
const eckit::Configuration& config) const { |
| 103 |
get()->dirtrans_wind2vordiv(gpwind, spvor, spdiv, options(config)); |
| 104 |
} |
| 105 |
|
| 106 |
void Trans::dirtrans_adj(const Field& spfield, Field& gpfield, const eckit::Configuration& config) const { |
| 107 |
get()->dirtrans_adj(spfield, gpfield, options(config)); |
| 108 |
} |
| 109 |
|
| 110 |
void Trans::dirtrans_adj(const FieldSet& spfields, FieldSet& gpfields, const eckit::Configuration& config) const { |
| 111 |
get()->dirtrans_adj(spfields, gpfields, options(config)); |
| 112 |
} |
| 113 |
|
| 114 |
void Trans::dirtrans_wind2vordiv_adj(const Field& spvor, const Field& spdiv, Field& gpwind, |
| 115 |
const eckit::Configuration& config) const { |
| 116 |
get()->dirtrans_wind2vordiv_adj(spvor, spdiv, gpwind, options(config)); |
| 117 |
} |
| 118 |
|
| 119 |
void Trans::invtrans(const Field& spfield, Field& gpfield, const eckit::Configuration& config) const { |
| 120 |
get()->invtrans(spfield, gpfield, options(config)); |
| 121 |
} |
| 122 |
|
| 123 |
void Trans::invtrans(const FieldSet& spfields, FieldSet& gpfields, const eckit::Configuration& config) const { |
| 124 |
get()->invtrans(spfields, gpfields, options(config)); |
| 125 |
} |
| 126 |
|
| 127 |
void Trans::invtrans_grad(const Field& spfield, Field& gradfield, const eckit::Configuration& config) const { |
| 128 |
get()->invtrans_grad(spfield, gradfield, options(config)); |
| 129 |
} |
| 130 |
|
| 131 |
void Trans::invtrans_grad(const FieldSet& spfields, FieldSet& gradfields, const eckit::Configuration& config) const { |
| 132 |
get()->invtrans_grad(spfields, gradfields, options(config)); |
| 133 |
} |
| 134 |
|
| 135 |
void Trans::invtrans_vordiv2wind(const Field& spvor, const Field& spdiv, Field& gpwind, |
| 136 |
const eckit::Configuration& config) const { |
| 137 |
get()->invtrans_vordiv2wind(spvor, spdiv, gpwind, options(config)); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
void Trans::invtrans_adj(const Field& gpfield, Field& spfield, const eckit::Configuration& config) const { |
| 142 |
get()->invtrans_adj(gpfield, spfield, options(config)); |
| 143 |
} |
| 144 |
|
| 145 |
void Trans::invtrans_adj(const FieldSet& gpfields, FieldSet& spfields, const eckit::Configuration& config) const { |
| 146 |
get()->invtrans_adj(gpfields, spfields, options(config)); |
| 147 |
} |
| 148 |
|
| 149 |
void Trans::invtrans_grad_adj(const Field& gradfield, Field& spfield, const eckit::Configuration& config) const { |
| 150 |
get()->invtrans_grad_adj(gradfield, spfield, options(config)); |
| 151 |
} |
| 152 |
|
| 153 |
void Trans::invtrans_grad_adj(const FieldSet& gradfields, FieldSet& spfields, |
| 154 |
const eckit::Configuration& config) const { |
| 155 |
get()->invtrans_grad_adj(gradfields, spfields, options(config)); |
| 156 |
} |
| 157 |
|
| 158 |
void Trans::invtrans_vordiv2wind_adj(const Field& gpwind, Field& spvor, Field& spdiv, |
| 159 |
const eckit::Configuration& config) const { |
| 160 |
get()->invtrans_vordiv2wind_adj(gpwind, spvor, spdiv, options(config)); |
| 161 |
} |
| 162 |
|
| 163 |
// -- IFS type fields -- |
| 164 |
// These fields have special interpretation required. You need to know what |
| 165 |
// you're doing. |
| 166 |
// See IFS trans library. |
| 167 |
|
| 168 |
/*! |
| 169 |
* @brief invtrans |
| 170 |
* @param nb_scalar_fields |
| 171 |
* @param scalar_spectra |
| 172 |
* @param nb_vordiv_fields |
| 173 |
* @param vorticity_spectra |
| 174 |
* @param divergence_spectra |
| 175 |
* @param gp_fields |
| 176 |
*/ |
| 177 |
void Trans::invtrans(const int nb_scalar_fields, const double scalar_spectra[], const int nb_vordiv_fields, |
| 178 |
const double vorticity_spectra[], const double divergence_spectra[], double gp_fields[], |
| 179 |
const eckit::Configuration& config) const { |
| 180 |
get()->invtrans(nb_scalar_fields, scalar_spectra, nb_vordiv_fields, vorticity_spectra, divergence_spectra, |
| 181 |
gp_fields, options(config)); |
| 182 |
} |
| 183 |
|
| 184 |
/*! |
| 185 |
* @brief invtrans |
| 186 |
* @param nb_fields |
| 187 |
* @param scalar_spectra |
| 188 |
* @param scalar_fields |
| 189 |
*/ |
| 190 |
void Trans::invtrans(const int nb_scalar_fields, const double scalar_spectra[], double gp_fields[], |
| 191 |
const eckit::Configuration& config) const { |
| 192 |
get()->invtrans(nb_scalar_fields, scalar_spectra, gp_fields, options(config)); |
| 193 |
} |
| 194 |
|
| 195 |
/*! |
| 196 |
* @brief Inverse transform of vorticity/divergence to wind(U/V) |
| 197 |
* @param nb_fields [in] Number of fields ( both components of wind count as 1 ) |
| 198 |
*/ |
| 199 |
void Trans::invtrans(const int nb_vordiv_fields, const double vorticity_spectra[], const double divergence_spectra[], |
| 200 |
double gp_fields[], const eckit::Configuration& config) const { |
| 201 |
get()->invtrans(nb_vordiv_fields, vorticity_spectra, divergence_spectra, gp_fields, options(config)); |
| 202 |
} |
| 203 |
|
| 204 |
/*! |
| 205 |
* @brief invtrans_adj |
| 206 |
* @param nb_scalar_fields |
| 207 |
* @param scalar_spectra |
| 208 |
* @param nb_vordiv_fields |
| 209 |
* @param vorticity_spectra |
| 210 |
* @param divergence_spectra |
| 211 |
* @param gp_fields |
| 212 |
*/ |
| 213 |
void Trans::invtrans_adj(const int nb_scalar_fields, const double gp_fields[], const int nb_vordiv_fields, |
| 214 |
double vorticity_spectra[], double divergence_spectra[], double scalar_spectra[], |
| 215 |
const eckit::Configuration& config) const { |
| 216 |
get()->invtrans_adj(nb_scalar_fields, gp_fields, nb_vordiv_fields, vorticity_spectra, divergence_spectra, |
| 217 |
scalar_spectra, options(config)); |
| 218 |
} |
| 219 |
|
| 220 |
/*! |
| 221 |
* @brief invtrans_adj |
| 222 |
* @param nb_fields |
| 223 |
* @param scalar_spectra |
| 224 |
* @param scalar_fields |
| 225 |
*/ |
| 226 |
void Trans::invtrans_adj(const int nb_scalar_fields, const double gp_fields[], double scalar_spectra[], |
| 227 |
const eckit::Configuration& config) const { |
| 228 |
get()->invtrans_adj(nb_scalar_fields, gp_fields, scalar_spectra, options(config)); |
| 229 |
} |
| 230 |
|
| 231 |
/*! |
| 232 |
* @brief Adjoint of Inverse transform of vorticity/divergence to wind(U/V) |
| 233 |
* @param nb_fields [in] Number of fields ( both components of wind count as 1 ) |
| 234 |
*/ |
| 235 |
void Trans::invtrans_adj(const int nb_vordiv_fields, const double gp_fields[], double vorticity_spectra[], |
| 236 |
double divergence_spectra[], const eckit::Configuration& config) const { |
| 237 |
get()->invtrans_adj(nb_vordiv_fields, gp_fields, vorticity_spectra, divergence_spectra, options(config)); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
/*! |
| 242 |
* @brief Direct transform of scalar fields |
| 243 |
*/ |
| 244 |
void Trans::dirtrans(const int nb_fields, const double scalar_fields[], double scalar_spectra[], |
| 245 |
const eckit::Configuration& config) const { |
| 246 |
get()->dirtrans(nb_fields, scalar_fields, scalar_spectra, options(config)); |
| 247 |
} |
| 248 |
|
| 249 |
/*! |
| 250 |
* @brief Direct transform of wind(U/V) to vorticity/divergence |
| 251 |
* @param nb_fields [in] Number of fields ( both components of wind count as 1 ) |
| 252 |
*/ |
| 253 |
void Trans::dirtrans(const int nb_fields, const double wind_fields[], double vorticity_spectra[], |
| 254 |
double divergence_spectra[], const eckit::Configuration& config) const { |
| 255 |
get()->dirtrans(nb_fields, wind_fields, vorticity_spectra, divergence_spectra, options(config)); |
| 256 |
} |
| 257 |
|
| 258 |
} // namespace trans |
| 259 |
} // namespace atlas |