Debian Codegraph @

src/atlas/grid/detail/spacing/LinearSpacing.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 <array>
14 #include <string>
15
16 #include "atlas/grid/detail/spacing/Spacing.h"
17
18 namespace atlas {
19 namespace grid {
20 namespace spacing {
21
22 // clang-format off
23
24 /// @brief Linear spacing in interval
25 ///
26 /// There are N equally spaced points in the closed interval [start, stop] or the
27 /// half-open interval [start, stop) (depending on whether endpoint is True or False)
28 ///
29 /// Using the constructor LinearSpacing( start, end, N, endpoint ) we can create
30 /// LinearSpacing( 2, 3, 5, true ) --> { 2.0 , 2.25 , 2.5 , 2.75 , 3.0 }
31 /// LinearSpacing( 2, 3, 5, false ) --> { 2.0 , 2.2 , 2.4 , 2.6 , 2.8 }
32 ///
33 /// Configuration parameters can be passed as well with following keys:
34 ///
35 /// {"start":2 , "end":3, "N":5, "endpoint":true } --> { 2.0 , 2.25 , 2.5 , 2.75 , 3.0 }
36 /// {"start":2 , "end":3, "N":5, "endpoint":false} --> { 2.0 , 2.2 , 2.4 , 2.6 , 2.8 }
37 ///
38 /// Instead of the "end" key, you can provide the "length" key, to achieve the same results:
39 ///
40 /// {"start":2 , "length":1, "N":5, "endpoint":true } --> { 2.0 , 2.25 , 2.5 , 2.75 , 3.0 }
41 /// {"start":2 , "length":1, "N":5, "endpoint":false} --> { 2.0 , 2.2 , 2.4 , 2.6 , 2.8 }
42
43 // clang-format on
44
45 class LinearSpacing : public Spacing {
46 public:
47 using Interval = std::array<double, 2>;
48
49 public:
50 /// constructor
51 LinearSpacing(const eckit::Parametrisation& p);
52 LinearSpacing(double start, double end, long N, bool endpoint = true);
53 LinearSpacing(const Interval&, long N, bool endpoint = true);
54
55 // LinearSpacing( double centre, double step, long N, bool endpoint=true );
56
57 // class name
58 static std::string static_type() { return "linear"; }
59 virtual std::string type() const { return static_type(); }
60
61 double step() const;
62
63 bool endpoint() const;
64
65 virtual Spec spec() const;
66
67 public:
68 struct Params {
69 double start;
70 double end;
71 long N;
72 double length;
73 bool endpoint;
74 double step;
75 Params() = default;
76 Params(const eckit::Parametrisation& p);
77 Params(double start, double end, long N, bool endpoint);
78 };
79
80 protected:
81 // points are equally spaced between xmin and xmax
82 // Depending on value of endpoint, the spacing will be different
83 void setup(double start, double end, long N, bool endpoint);
84
85 double start_;
86 double end_;
87 long N_;
88 bool endpoint_;
89 };
90
91 } // namespace spacing
92 } // namespace grid
93 } // namespace atlas