Debian Codegraph @

src/atlas/functionspace/detail/FunctionSpaceInterface.cc

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 #include <cstring>
12
13 #include "FunctionSpaceImpl.h"
14 #include "FunctionSpaceInterface.h"
15
16 #include "atlas/field/Field.h"
17 #include "atlas/field/FieldSet.h"
18 #include "atlas/field/detail/FieldImpl.h"
19 #include "atlas/library/config.h"
20 #include "atlas/runtime/Exception.h"
21 #include "atlas/util/Config.h"
22
23 namespace atlas {
24 namespace functionspace {
25
26 //-----------------------------------------------------------------------------
27
28 // C wrapper interfaces to C++ routines
29 extern "C" {
30 void atlas__FunctionSpace__delete(FunctionSpaceImpl* This) {
31 ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_FunctionSpace");
32 delete This;
33 This = nullptr;
34 }
35
36 void atlas__FunctionSpace__name(const FunctionSpaceImpl* This, char*& name, int& size) {
37 ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_FunctionSpace");
38 std::string s = This->type();
39 size = static_cast<int>(s.size());
40 name = new char[size + 1];
41 std::strncpy(name, s.c_str(), size + 1);
42 }
43
44 field::FieldImpl* atlas__FunctionSpace__create_field(const FunctionSpaceImpl* This,
45 const eckit::Configuration* options) {
46 ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_FunctionSpace");
47 ATLAS_ASSERT(options != nullptr);
48 field::FieldImpl* field;
49 {
50 Field f = This->createField(*options);
51 field = f.get();
52 field->attach();
53 }
54 field->detach();
55 return field;
56 }
57
58 //------------------------------------------------------------------------------
59
60 field::FieldImpl* atlas__FunctionSpace__create_field_template(const FunctionSpaceImpl* This,
61 const field::FieldImpl* field_template,
62 const eckit::Configuration* options) {
63 ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_FunctionSpace");
64 ATLAS_ASSERT(field_template != nullptr, "Cannot access uninitialised atlas_Field");
65 ATLAS_ASSERT(options != nullptr);
66 field::FieldImpl* field;
67 {
68 Field f = This->createField(Field(field_template), *options);
69 field = f.get();
70 field->attach();
71 }
72 field->detach();
73 return field;
74 }
75
76 //------------------------------------------------------------------------------
77
78 void atlas__FunctionSpace__halo_exchange_field(const FunctionSpaceImpl* This, field::FieldImpl* field) {
79 ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_FunctionSpace");
80 ATLAS_ASSERT(field != nullptr, "Cannot access uninitialised atlas_Field");
81 Field f(field);
82 This->haloExchange(f);
83 }
84
85 //------------------------------------------------------------------------------
86
87 void atlas__FunctionSpace__halo_exchange_fieldset(const FunctionSpaceImpl* This,
88 field::FieldSetImpl* fieldset) {
89 ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_FunctionSpace");
90 ATLAS_ASSERT(fieldset != nullptr, "Cannot access uninitialised atlas_FieldSet");
91 FieldSet f(fieldset);
92 This->haloExchange(f);
93 }
94
95 //------------------------------------------------------------------------------
96
97 void atlas__FunctionSpace__adjoint_halo_exchange_field(const FunctionSpaceImpl* This,
98 field::FieldImpl* field) {
99 ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_FunctionSpace");
100 ATLAS_ASSERT(field != nullptr, "Cannot access uninitialised atlas_Field");
101 Field f(field);
102 This->adjointHaloExchange(f);
103 }
104
105 //------------------------------------------------------------------------------
106
107 void atlas__FunctionSpace__adjoint_halo_exchange_fieldset(const FunctionSpaceImpl* This,
108 field::FieldSetImpl* fieldset) {
109 ATLAS_ASSERT(This != nullptr, "Cannot access uninitialised atlas_FunctionSpace");
110 ATLAS_ASSERT(fieldset != nullptr, "Cannot access uninitialised atlas_FieldSet");
111 FieldSet f(fieldset);
112 This->adjointHaloExchange(f);
113 }
114 }
115
116 // ------------------------------------------------------------------
117
118 } // namespace functionspace
119
120 // ------------------------------------------------------------------
121
122 } // namespace atlas