| 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 <cstring> |
| 12 |
|
| 13 |
#include "CellColumnsInterface.h" |
| 14 |
#include "atlas/field/FieldSet.h" |
| 15 |
#include "atlas/field/detail/FieldImpl.h" |
| 16 |
#include "atlas/runtime/Exception.h" |
| 17 |
|
| 18 |
namespace atlas { |
| 19 |
namespace functionspace { |
| 20 |
namespace detail { |
| 21 |
|
| 22 |
using atlas::FieldSet; |
| 23 |
using atlas::field::FieldImpl; |
| 24 |
using atlas::field::FieldSetImpl; |
| 25 |
|
| 26 |
// ---------------------------------------------------------------------- |
| 27 |
|
| 28 |
extern "C" { |
| 29 |
const CellColumns* atlas__CellsFunctionSpace__new(Mesh::Implementation* mesh, const eckit::Configuration* config) { |
| 30 |
ATLAS_ASSERT(mesh); |
| 31 |
Mesh m(mesh); |
| 32 |
return new CellColumns(m, *config); |
| 33 |
} |
| 34 |
|
| 35 |
void atlas__CellsFunctionSpace__delete(CellColumns* This) { |
| 36 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 37 |
delete (This); |
| 38 |
} |
| 39 |
|
| 40 |
int atlas__CellsFunctionSpace__nb_cells(const CellColumns* This) { |
| 41 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 42 |
return This->nb_cells(); |
| 43 |
} |
| 44 |
|
| 45 |
const Mesh::Implementation* atlas__CellsFunctionSpace__mesh(const CellColumns* This) { |
| 46 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 47 |
return This->mesh().get(); |
| 48 |
} |
| 49 |
|
| 50 |
const mesh::HybridElements* atlas__CellsFunctionSpace__cells(const CellColumns* This) { |
| 51 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 52 |
return &This->cells(); |
| 53 |
} |
| 54 |
|
| 55 |
void atlas__CellsFunctionSpace__halo_exchange_fieldset(const CellColumns* This, field::FieldSetImpl* fieldset) { |
| 56 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 57 |
ATLAS_ASSERT(fieldset != nullptr, "Cannot access uninitialised atlas_FieldSet"); |
| 58 |
FieldSet f(fieldset); |
| 59 |
This->haloExchange(f); |
| 60 |
} |
| 61 |
|
| 62 |
void atlas__CellsFunctionSpace__halo_exchange_field(const CellColumns* This, field::FieldImpl* field) { |
| 63 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 64 |
ATLAS_ASSERT(field != nullptr, "Cannot access uninitialised atlas_Field"); |
| 65 |
Field f(field); |
| 66 |
This->haloExchange(f); |
| 67 |
} |
| 68 |
|
| 69 |
const parallel::HaloExchange* atlas__CellsFunctionSpace__get_halo_exchange(const CellColumns* This) { |
| 70 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 71 |
return &This->halo_exchange(); |
| 72 |
} |
| 73 |
|
| 74 |
void atlas__CellsFunctionSpace__gather_fieldset(const CellColumns* This, const field::FieldSetImpl* local, |
| 75 |
field::FieldSetImpl* global) { |
| 76 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 77 |
ATLAS_ASSERT(local != nullptr, "Cannot access uninitialised local atlas_FieldSet"); |
| 78 |
ATLAS_ASSERT(global != nullptr, "Cannot access uninitialised global atlas_FieldSet"); |
| 79 |
const FieldSet l(local); |
| 80 |
FieldSet g(global); |
| 81 |
This->gather(l, g); |
| 82 |
} |
| 83 |
|
| 84 |
void atlas__CellsFunctionSpace__gather_field(const CellColumns* This, const field::FieldImpl* local, |
| 85 |
field::FieldImpl* global) { |
| 86 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 87 |
ATLAS_ASSERT(local != nullptr, "Cannot access uninitialised local atlas_Field"); |
| 88 |
ATLAS_ASSERT(global != nullptr, "Cannot access uninitialised global atlas_Field"); |
| 89 |
const Field l(local); |
| 90 |
Field g(global); |
| 91 |
This->gather(l, g); |
| 92 |
} |
| 93 |
|
| 94 |
const parallel::GatherScatter* atlas__CellsFunctionSpace__get_gather(const CellColumns* This) { |
| 95 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 96 |
return &This->gather(); |
| 97 |
} |
| 98 |
|
| 99 |
const parallel::GatherScatter* atlas__CellsFunctionSpace__get_scatter(const CellColumns* This) { |
| 100 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 101 |
return &This->scatter(); |
| 102 |
} |
| 103 |
|
| 104 |
void atlas__CellsFunctionSpace__scatter_fieldset(const CellColumns* This, const field::FieldSetImpl* global, |
| 105 |
field::FieldSetImpl* local) { |
| 106 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 107 |
ATLAS_ASSERT(local != nullptr, "Cannot access uninitialised local atlas_FieldSet"); |
| 108 |
ATLAS_ASSERT(global != nullptr, "Cannot access uninitialised global atlas_FieldSet"); |
| 109 |
const FieldSet g(global); |
| 110 |
FieldSet l(local); |
| 111 |
This->scatter(g, l); |
| 112 |
} |
| 113 |
|
| 114 |
void atlas__CellsFunctionSpace__scatter_field(const CellColumns* This, const field::FieldImpl* global, |
| 115 |
field::FieldImpl* local) { |
| 116 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 117 |
ATLAS_ASSERT(local != nullptr, "Cannot access uninitialised local atlas_Field"); |
| 118 |
ATLAS_ASSERT(global != nullptr, "Cannot access uninitialised global atlas_Field"); |
| 119 |
const Field g(global); |
| 120 |
Field l(local); |
| 121 |
This->scatter(g, l); |
| 122 |
} |
| 123 |
|
| 124 |
const parallel::Checksum* atlas__CellsFunctionSpace__get_checksum(const CellColumns* This) { |
| 125 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 126 |
return &This->checksum(); |
| 127 |
} |
| 128 |
|
| 129 |
void atlas__CellsFunctionSpace__checksum_fieldset(const CellColumns* This, const field::FieldSetImpl* fieldset, |
| 130 |
char*& checksum, int& size, int& allocated) { |
| 131 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 132 |
ATLAS_ASSERT(fieldset != nullptr, "Cannot access uninitialised atlas_FieldSet"); |
| 133 |
std::string checksum_str(This->checksum(fieldset)); |
| 134 |
size = static_cast<int>(checksum_str.size()); |
| 135 |
checksum = new char[size + 1]; |
| 136 |
allocated = true; |
| 137 |
std::strncpy(checksum, checksum_str.c_str(), size + 1); |
| 138 |
} |
| 139 |
|
| 140 |
void atlas__CellsFunctionSpace__checksum_field(const CellColumns* This, const field::FieldImpl* field, char*& checksum, |
| 141 |
int& size, int& allocated) { |
| 142 |
ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_functionspace_CellColumns"); |
| 143 |
ATLAS_ASSERT(field != nullptr, "Cannot access uninitialised atlas_Field"); |
| 144 |
std::string checksum_str(This->checksum(field)); |
| 145 |
size = static_cast<int>(checksum_str.size()); |
| 146 |
checksum = new char[size + 1]; |
| 147 |
allocated = true; |
| 148 |
std::strncpy(checksum, checksum_str.c_str(), size + 1); |
| 149 |
} |
| 150 |
|
| 151 |
} // extern C |
| 152 |
|
| 153 |
} // namespace detail |
| 154 |
} // namespace functionspace |
| 155 |
} // namespace atlas |