Debian Codegraph @

src/atlas/interpolation/method/unstructured/SphericalMeanValue.h

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 #pragma once
12
13 #include "atlas/interpolation/method/Method.h"
14
15 #include <string>
16
17 #include "eckit/config/Configuration.h"
18
19 #include "atlas/array/ArrayView.h"
20 #include "atlas/functionspace/FunctionSpace.h"
21 #include "atlas/interpolation/method/PointIndex3.h"
22 #include "atlas/mesh/Elements.h"
23
24 namespace atlas {
25 namespace interpolation {
26 namespace method {
27
28 class SphericalMeanValue : public Method {
29 public:
30 SphericalMeanValue(const Config& config): Method(config) {
31 config.get("max_fraction_elems_to_try", max_fraction_elems_to_try_);
32 config.get("treat_failure_as_missing_value", treat_failure_as_missing_value_);
33 config.get("normalisation", normalisation_);
34 }
35
36 virtual ~SphericalMeanValue() override {}
37
38 virtual void print(std::ostream&) const override;
39
40 protected:
41 /**
42 * @brief Create an interpolant sparse matrix relating two (pre-partitioned)
43 * meshes,
44 * using elements as per the Finite Element Method and ray-tracing to
45 * calculate
46 * source mesh elements intersections (and interpolation weights) with target
47 * grid
48 * node-containing rays
49 * @param meshSource mesh containing source elements
50 * @param meshTarget mesh containing target points
51 */
52 void setup(const FunctionSpace& source);
53
54 /**
55 * Find in which element the point is contained by projecting (ray-tracing)
56 * the
57 * point to the nearest element(s), returning the (normalized) interpolation
58 * weights
59 */
60 Triplets projectPointToElements(size_t ip, const ElemIndex3::NodeList& elems) const;
61
62 virtual const FunctionSpace& source() const override { return source_; }
63 virtual const FunctionSpace& target() const override { return target_; }
64
65 private:
66 using Method::do_setup;
67 virtual void do_setup(const FunctionSpace& source, const FunctionSpace& target) override;
68 virtual void do_setup(const Grid& source, const Grid& target, const Cache&) override;
69 virtual void do_setup(const FunctionSpace& source, const FunctionSpace& target, const Cache&) override;
70
71 protected:
72 mesh::MultiBlockConnectivity* connectivity_;
73 std::unique_ptr<array::ArrayView<double, 2>> icoords_;
74 std::unique_ptr<array::ArrayView<double, 2>> ocoords_;
75 std::unique_ptr<array::ArrayView<gidx_t, 1>> igidx_;
76
77 Field target_lonlat_;
78 Field target_xyz_;
79 Field target_ghost_;
80
81 FunctionSpace source_;
82 FunctionSpace target_;
83
84 bool treat_failure_as_missing_value_{true};
85 double max_fraction_elems_to_try_{0.2};
86 bool normalisation_{true};
87 };
88
89 } // namespace method
90 } // namespace interpolation
91 } // namespace atlas