Debian Codegraph @

src/atlas/util/Unique.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 "atlas/util/Unique.h"
12 #include "atlas/util/PeriodicTransform.h"
13
14 namespace atlas {
15 namespace util {
16
17 uidx_t unique_lonlat(const double& lon, const double& lat, const PeriodicTransform& transform) {
18 std::array<double, 2> lonlat{lon, lat};
19 transform(lonlat);
20 return unique_lonlat(lonlat);
21 }
22
23
24 uidx_t UniqueLonLat::operator()(const mesh::Connectivity::Row& elem_nodes, const PeriodicTransform& transform) const {
25 std::array<double, 2> centroid;
26 centroid[LON] = 0.;
27 centroid[LAT] = 0.;
28 size_t npts = elem_nodes.size();
29 for (size_t jnode = 0; jnode < npts; ++jnode) {
30 centroid[LON] += lonlat(elem_nodes(jnode), LON);
31 centroid[LAT] += lonlat(elem_nodes(jnode), LAT);
32 }
33 centroid[LON] /= static_cast<double>(npts);
34 centroid[LAT] /= static_cast<double>(npts);
35 transform(centroid);
36 return unique_lonlat(centroid);
37 }
38
39 uidx_t atlas::util::UniqueLonLat::operator()(int node, const PeriodicTransform& transform) const {
40 std::array<double, 2> _lonlat{lonlat(node, LON), lonlat(node, LAT)};
41 transform(_lonlat);
42 return unique_lonlat(_lonlat[LON], _lonlat[LAT]);
43 }
44
45
46 } // namespace util
47 } // namespace atlas