| 1 |
/* |
| 2 |
* (C) Crown Copyright 2024 Met Office |
| 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 |
*/ |
| 7 |
|
| 8 |
#pragma once |
| 9 |
|
| 10 |
#include <vector> |
| 11 |
|
| 12 |
#include "atlas/functionspace/FunctionSpace.h" |
| 13 |
#include "atlas/interpolation/Cache.h" |
| 14 |
#include "atlas/interpolation/method/Intersect.h" |
| 15 |
#include "atlas/interpolation/method/Method.h" |
| 16 |
#include "atlas/linalg/sparse/SparseMatrixStorage.h" |
| 17 |
#include "atlas/linalg/sparse/SparseMatrixView.h" |
| 18 |
#include "atlas/grid/Grid.h" |
| 19 |
|
| 20 |
#include "eckit/config/Configuration.h" |
| 21 |
|
| 22 |
|
| 23 |
namespace atlas { |
| 24 |
namespace interpolation { |
| 25 |
namespace method { |
| 26 |
|
| 27 |
|
| 28 |
class Binning : public Method { |
| 29 |
public: |
| 30 |
/// @brief Binning procedure to carry out a regridding from high |
| 31 |
/// to low resolution |
| 32 |
/// |
| 33 |
/// @details This method is part of the family of the Interpolation operations; |
| 34 |
/// it relies on the evaluation of the transpose of an interpolation matrix. |
| 35 |
/// The rigridding from high to low resolution is carried out by using |
| 36 |
/// a 'binning matrix': |
| 37 |
/// binning matrix: B = N A^T W |
| 38 |
/// area weights matrix: W |
| 39 |
/// interpolation matrix: A |
| 40 |
/// normalization factor matrix: N |
| 41 |
/// |
| 42 |
/// Setup, configuration variables: |
| 43 |
/// <type>: method used to evaluate the 'B' matrix; |
| 44 |
/// value: 'binning' |
| 45 |
/// <scheme>: method used to evaluate the 'A' matrix; |
| 46 |
/// value: 'cubedsphere-bilinear', 'structured-bilinear', ... |
| 47 |
/// <adjoint>: flag to control the adjoint operation |
| 48 |
/// value: 'true', 'false' |
| 49 |
/// |
| 50 |
|
| 51 |
using ValueType = double; |
| 52 |
using IndexType = int; |
| 53 |
using SparseMatrixStorage = linalg::SparseMatrixStorage; |
| 54 |
using SparseMatrixView = linalg::SparseMatrixView<ValueType, IndexType>; |
| 55 |
|
| 56 |
Binning(const Config& config); |
| 57 |
~Binning() override {} |
| 58 |
|
| 59 |
void print(std::ostream&) const override; |
| 60 |
const FunctionSpace& source() const override { return source_; } |
| 61 |
const FunctionSpace& target() const override { return target_; } |
| 62 |
|
| 63 |
private: |
| 64 |
using Method::do_setup; |
| 65 |
void do_setup(const FunctionSpace& source, |
| 66 |
const FunctionSpace& target) override; |
| 67 |
void do_setup(const Grid& source, const Grid& target, const Cache&) override; |
| 68 |
void do_setup(const FunctionSpace& source, const FunctionSpace& target, const Cache&) override; |
| 69 |
|
| 70 |
SparseMatrixStorage transposeAndHaloExchange(const SparseMatrixView& interpMatrix) const; |
| 71 |
std::vector<double> getAreaWeights() const; |
| 72 |
|
| 73 |
eckit::LocalConfiguration interpAncillaryScheme_{}; |
| 74 |
|
| 75 |
FunctionSpace source_{}; |
| 76 |
FunctionSpace target_{}; |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
} // namespace method |
| 81 |
} // namespace interpolation |
| 82 |
} // namespace atlas |