| 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 "atlas/library/config.h" |
| 12 |
#if ATLAS_HAVE_ECTRANS |
| 13 |
#include "ectrans/transi.h" |
| 14 |
#else |
| 15 |
#include "transi/trans.h" |
| 16 |
#endif |
| 17 |
|
| 18 |
#include "atlas/functionspace/Spectral.h" |
| 19 |
#include "atlas/parallel/mpi/mpi.h" |
| 20 |
#include "atlas/runtime/Exception.h" |
| 21 |
#include "atlas/runtime/Log.h" |
| 22 |
#include "atlas/trans/ifs/VorDivToUVIFS.h" |
| 23 |
|
| 24 |
using atlas::FunctionSpace; |
| 25 |
using atlas::functionspace::Spectral; |
| 26 |
|
| 27 |
namespace atlas { |
| 28 |
namespace trans { |
| 29 |
|
| 30 |
namespace { |
| 31 |
static VorDivToUVBuilder<VorDivToUVIFS> builder_ifs("ifs"); // Deprecated |
| 32 |
static VorDivToUVBuilder<VorDivToUVIFS> builder_ectrans("ectrans"); |
| 33 |
} // namespace |
| 34 |
|
| 35 |
namespace { |
| 36 |
void trans_check(const int code, const char* msg, const eckit::CodeLocation& location) { |
| 37 |
if (code != TRANS_SUCCESS) { |
| 38 |
std::stringstream errmsg; |
| 39 |
errmsg << "atlas::trans ERROR: " << msg << " failed: \n"; |
| 40 |
errmsg << ::trans_error_msg(code); |
| 41 |
throw_Exception(errmsg.str(), location); |
| 42 |
} |
| 43 |
} |
| 44 |
#define TRANS_CHECK(CALL) trans_check(CALL, #CALL, Here()) |
| 45 |
|
| 46 |
} // namespace |
| 47 |
|
| 48 |
void VorDivToUVIFS::execute(const int nb_coeff, const int nb_fields, const double vorticity[], |
| 49 |
const double divergence[], double U[], double V[], const eckit::Configuration&) const { |
| 50 |
struct ::VorDivToUV_t vordiv_to_UV = new_vordiv_to_UV(); |
| 51 |
vordiv_to_UV.rspvor = vorticity; |
| 52 |
vordiv_to_UV.rspdiv = divergence; |
| 53 |
vordiv_to_UV.rspu = U; |
| 54 |
vordiv_to_UV.rspv = V; |
| 55 |
vordiv_to_UV.nfld = nb_fields; |
| 56 |
vordiv_to_UV.ncoeff = nb_coeff; |
| 57 |
vordiv_to_UV.nsmax = truncation_; |
| 58 |
TRANS_CHECK(::trans_vordiv_to_UV(&vordiv_to_UV)); |
| 59 |
} |
| 60 |
|
| 61 |
VorDivToUVIFS::VorDivToUVIFS(const int truncation, const eckit::Configuration&): truncation_(truncation) {} |
| 62 |
|
| 63 |
VorDivToUVIFS::VorDivToUVIFS(const FunctionSpace& fs, const eckit::Configuration&): |
| 64 |
truncation_(Spectral(fs).truncation()) {} |
| 65 |
|
| 66 |
VorDivToUVIFS::~VorDivToUVIFS() = default; |
| 67 |
|
| 68 |
} // namespace trans |
| 69 |
} // namespace atlas |