| 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 "SpectralInterface.h" |
| 12 |
|
| 13 |
#include "atlas/array/LocalView.h" |
| 14 |
#include "atlas/field/FieldSet.h" |
| 15 |
#include "atlas/field/detail/FieldImpl.h" |
| 16 |
#include "atlas/runtime/Exception.h" |
| 17 |
#include "atlas/trans/Trans.h" |
| 18 |
|
| 19 |
namespace atlas { |
| 20 |
namespace functionspace { |
| 21 |
|
| 22 |
namespace detail { |
| 23 |
struct SpectralFortranAccess { |
| 24 |
const Spectral& fs_; |
| 25 |
SpectralFortranAccess(const Spectral& fs): fs_(fs) {} |
| 26 |
int nump() const { return fs_.nump(); } |
| 27 |
array::LocalView<const int, 1> nvalue() const { return fs_.nvalue(); } |
| 28 |
array::LocalView<const int, 1> nmyms() const { return fs_.nmyms(); } |
| 29 |
array::LocalView<const int, 1> nasm0() const { return fs_.nasm0(); } |
| 30 |
}; |
| 31 |
} // namespace detail |
| 32 |
|
| 33 |
using detail::SpectralFortranAccess; |
| 34 |
|
| 35 |
// ---------------------------------------------------------------------- |
| 36 |
|
| 37 |
extern "C" { |
| 38 |
const detail::Spectral* atlas__SpectralFunctionSpace__new__config(const eckit::Configuration* config) { |
| 39 |
ATLAS_ASSERT(config != nullptr); |
| 40 |
return new detail::Spectral(*config); |
| 41 |
} |
| 42 |
|
| 43 |
void atlas__SpectralFunctionSpace__delete(detail::Spectral* This) { |
| 44 |
ATLAS_ASSERT(This != nullptr); |
| 45 |
delete This; |
| 46 |
} |
| 47 |
|
| 48 |
field::FieldImpl* atlas__fs__Spectral__create_field(const detail::Spectral* This, const eckit::Configuration* options) { |
| 49 |
ATLAS_ASSERT(This != nullptr); |
| 50 |
ATLAS_ASSERT(options); |
| 51 |
field::FieldImpl* field; |
| 52 |
{ |
| 53 |
Field f = This->createField(*options); |
| 54 |
field = f.get(); |
| 55 |
field->attach(); |
| 56 |
} |
| 57 |
field->detach(); |
| 58 |
return field; |
| 59 |
} |
| 60 |
|
| 61 |
void atlas__SpectralFunctionSpace__gather(const detail::Spectral* This, const field::FieldImpl* local, |
| 62 |
field::FieldImpl* global) { |
| 63 |
ATLAS_ASSERT(This != nullptr); |
| 64 |
ATLAS_ASSERT(global != nullptr); |
| 65 |
ATLAS_ASSERT(local != nullptr); |
| 66 |
const Field l(local); |
| 67 |
Field g(global); |
| 68 |
This->gather(l, g); |
| 69 |
} |
| 70 |
|
| 71 |
void atlas__SpectralFunctionSpace__scatter(const detail::Spectral* This, const field::FieldImpl* global, |
| 72 |
field::FieldImpl* local) { |
| 73 |
ATLAS_ASSERT(This != nullptr); |
| 74 |
ATLAS_ASSERT(global != nullptr); |
| 75 |
ATLAS_ASSERT(local != nullptr); |
| 76 |
const Field g(global); |
| 77 |
Field l(local); |
| 78 |
This->scatter(g, l); |
| 79 |
} |
| 80 |
|
| 81 |
void atlas__SpectralFunctionSpace__gather_fieldset(const detail::Spectral* This, const field::FieldSetImpl* local, |
| 82 |
field::FieldSetImpl* global) { |
| 83 |
ATLAS_ASSERT(This != nullptr); |
| 84 |
ATLAS_ASSERT(global != nullptr); |
| 85 |
ATLAS_ASSERT(local != nullptr); |
| 86 |
const FieldSet l(local); |
| 87 |
FieldSet g(global); |
| 88 |
This->gather(l, g); |
| 89 |
} |
| 90 |
|
| 91 |
void atlas__SpectralFunctionSpace__scatter_fieldset(const detail::Spectral* This, const field::FieldSetImpl* global, |
| 92 |
field::FieldSetImpl* local) { |
| 93 |
ATLAS_ASSERT(This != nullptr); |
| 94 |
ATLAS_ASSERT(global != nullptr); |
| 95 |
ATLAS_ASSERT(local != nullptr); |
| 96 |
const FieldSet g(global); |
| 97 |
FieldSet l(local); |
| 98 |
This->scatter(g, l); |
| 99 |
} |
| 100 |
|
| 101 |
void atlas__SpectralFunctionSpace__norm(const detail::Spectral* This, const field::FieldImpl* field, double norm[], |
| 102 |
int rank) { |
| 103 |
ATLAS_ASSERT(This != nullptr); |
| 104 |
ATLAS_ASSERT(field != nullptr); |
| 105 |
ATLAS_ASSERT(norm != nullptr); |
| 106 |
This->norm(field, norm, rank); |
| 107 |
} |
| 108 |
|
| 109 |
void atlas__SpectralFunctionSpace__nspec2(const detail::Spectral* This, int& nspec2) { |
| 110 |
nspec2 = This->nb_spectral_coefficients(); |
| 111 |
} |
| 112 |
|
| 113 |
void atlas__SpectralFunctionSpace__nspec2g(const detail::Spectral* This, int& nspec2g) { |
| 114 |
nspec2g = This->nb_spectral_coefficients_global(); |
| 115 |
} |
| 116 |
|
| 117 |
void atlas__SpectralFunctionSpace__truncation(const detail::Spectral* This, int& truncation) { |
| 118 |
truncation = This->truncation(); |
| 119 |
} |
| 120 |
|
| 121 |
void atlas__SpectralFunctionSpace__nump(const detail::Spectral* This, int& nump) { |
| 122 |
nump = detail::SpectralFortranAccess(*This).nump(); |
| 123 |
} |
| 124 |
|
| 125 |
void atlas__SpectralFunctionSpace__nmyms(const detail::Spectral* This, const int*& nmyms, int& size) { |
| 126 |
const auto nmyms_ = SpectralFortranAccess(*This).nmyms(); |
| 127 |
nmyms = nmyms_.data(); |
| 128 |
size = nmyms_.size(); |
| 129 |
} |
| 130 |
|
| 131 |
void atlas__SpectralFunctionSpace__nasm0(const detail::Spectral* This, const int*& nasm0, int& size) { |
| 132 |
const auto nasm0_ = SpectralFortranAccess(*This).nasm0(); |
| 133 |
nasm0 = nasm0_.data(); |
| 134 |
size = nasm0_.size(); |
| 135 |
} |
| 136 |
|
| 137 |
void atlas__SpectralFunctionSpace__nvalue(const detail::Spectral* This, const int*& nvalue, int& size) { |
| 138 |
const auto nvalue_ = SpectralFortranAccess(*This).nvalue(); |
| 139 |
nvalue = nvalue_.data(); |
| 140 |
size = nvalue_.size(); |
| 141 |
} |
| 142 |
|
| 143 |
void atlas__SpectralFunctionSpace__levels(const detail::Spectral* This, int& levels) { |
| 144 |
levels = This->levels(); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
} // extern "C" |
| 149 |
|
| 150 |
} // namespace functionspace |
| 151 |
} // namespace atlas |