| 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 |
#pragma once |
| 12 |
|
| 13 |
#include <string> |
| 14 |
|
| 15 |
#include "atlas/util/Object.h" |
| 16 |
#include "atlas/util/ObjectHandle.h" |
| 17 |
|
| 18 |
namespace eckit { |
| 19 |
class Parametrisation; |
| 20 |
} |
| 21 |
namespace atlas { |
| 22 |
namespace numerics { |
| 23 |
class Method; |
| 24 |
} |
| 25 |
} // namespace atlas |
| 26 |
namespace atlas { |
| 27 |
namespace field { |
| 28 |
class FieldImpl; |
| 29 |
} |
| 30 |
namespace functionspace { |
| 31 |
class FunctionSpaceImpl; |
| 32 |
} |
| 33 |
} // namespace atlas |
| 34 |
namespace atlas { |
| 35 |
class Field; |
| 36 |
class FunctionSpace; |
| 37 |
} // namespace atlas |
| 38 |
|
| 39 |
namespace atlas { |
| 40 |
namespace numerics { |
| 41 |
|
| 42 |
#ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 43 |
class NablaImpl : public util::Object { |
| 44 |
public: |
| 45 |
NablaImpl(const Method&, const eckit::Parametrisation&); |
| 46 |
virtual ~NablaImpl(); |
| 47 |
|
| 48 |
virtual void gradient(const Field& scalar, Field& grad) const = 0; |
| 49 |
virtual void divergence(const Field& vector, Field& div) const = 0; |
| 50 |
virtual void curl(const Field& vector, Field& curl) const = 0; |
| 51 |
virtual void laplacian(const Field& scalar, Field& laplacian) const = 0; |
| 52 |
|
| 53 |
virtual const FunctionSpace& functionspace() const = 0; |
| 54 |
|
| 55 |
private: |
| 56 |
util::ObjectHandle<Method> method_; |
| 57 |
}; |
| 58 |
#endif |
| 59 |
|
| 60 |
// ------------------------------------------------------------------ |
| 61 |
|
| 62 |
class Nabla : DOXYGEN_HIDE(public util::ObjectHandle<NablaImpl>) { |
| 63 |
public: |
| 64 |
using Handle::Handle; |
| 65 |
Nabla() = default; |
| 66 |
Nabla(const Method&); |
| 67 |
Nabla(const Method&, const eckit::Parametrisation&); |
| 68 |
|
| 69 |
void gradient(const Field& scalar, Field& grad) const; |
| 70 |
void divergence(const Field& vector, Field& div) const; |
| 71 |
void curl(const Field& vector, Field& curl) const; |
| 72 |
void laplacian(const Field& scalar, Field& laplacian) const; |
| 73 |
}; |
| 74 |
|
| 75 |
// ------------------------------------------------------------------ |
| 76 |
|
| 77 |
#ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 78 |
|
| 79 |
class NablaFactory { |
| 80 |
public: |
| 81 |
static const Nabla::Implementation* build(const Method&, const eckit::Parametrisation&); |
| 82 |
static void list(std::ostream&); |
| 83 |
static bool has(const std::string& name); |
| 84 |
|
| 85 |
private: |
| 86 |
virtual const Nabla::Implementation* make(const Method&, const eckit::Parametrisation&) = 0; |
| 87 |
|
| 88 |
protected: |
| 89 |
NablaFactory(const std::string&); |
| 90 |
virtual ~NablaFactory(); |
| 91 |
|
| 92 |
private: |
| 93 |
std::string name_; |
| 94 |
}; |
| 95 |
|
| 96 |
// ------------------------------------------------------------------ |
| 97 |
|
| 98 |
template <class T> |
| 99 |
class NablaBuilder : public NablaFactory { |
| 100 |
public: |
| 101 |
NablaBuilder(const std::string& name): NablaFactory(name) {} |
| 102 |
|
| 103 |
private: |
| 104 |
virtual const Nabla::Implementation* make(const Method& method, const eckit::Parametrisation& p) { |
| 105 |
return new T(method, p); |
| 106 |
} |
| 107 |
}; |
| 108 |
|
| 109 |
// ------------------------------------------------------------------ |
| 110 |
extern "C" { |
| 111 |
|
| 112 |
void atlas__Nabla__delete(Nabla::Implementation* This); |
| 113 |
const Nabla::Implementation* atlas__Nabla__create(const Method* method, const eckit::Parametrisation* params); |
| 114 |
void atlas__Nabla__gradient(const Nabla::Implementation* This, const field::FieldImpl* scalar, field::FieldImpl* grad); |
| 115 |
void atlas__Nabla__divergence(const Nabla::Implementation* This, const field::FieldImpl* vector, field::FieldImpl* div); |
| 116 |
void atlas__Nabla__curl(const Nabla::Implementation* This, const field::FieldImpl* vector, field::FieldImpl* curl); |
| 117 |
void atlas__Nabla__laplacian(const Nabla::Implementation* This, const field::FieldImpl* scalar, |
| 118 |
field::FieldImpl* laplacian); |
| 119 |
const functionspace::FunctionSpaceImpl* atlas__Nabla__functionspace(const Nabla::Implementation* This); |
| 120 |
} |
| 121 |
#endif |
| 122 |
|
| 123 |
} // namespace numerics |
| 124 |
} // namespace atlas |