| 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 FiniteElement : public Method { |
| 29 |
public: |
| 30 |
FiniteElement(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 |
} |
| 34 |
|
| 35 |
virtual ~FiniteElement() override {} |
| 36 |
|
| 37 |
virtual void print(std::ostream&) const override; |
| 38 |
|
| 39 |
protected: |
| 40 |
/** |
| 41 |
* @brief Create an interpolant sparse matrix relating two (pre-partitioned) |
| 42 |
* meshes, |
| 43 |
* using elements as per the Finite Element Method and ray-tracing to |
| 44 |
* calculate |
| 45 |
* source mesh elements intersections (and interpolation weights) with target |
| 46 |
* grid |
| 47 |
* node-containing rays |
| 48 |
* @param meshSource mesh containing source elements |
| 49 |
* @param meshTarget mesh containing target points |
| 50 |
*/ |
| 51 |
void setup(const FunctionSpace& source); |
| 52 |
|
| 53 |
/** |
| 54 |
* Find in which element the point is contained by projecting (ray-tracing) |
| 55 |
* the |
| 56 |
* point to the nearest element(s), returning the (normalized) interpolation |
| 57 |
* weights |
| 58 |
*/ |
| 59 |
Triplets projectPointToElements(size_t ip, const ElemIndex3::NodeList& elems) const; |
| 60 |
|
| 61 |
virtual const FunctionSpace& source() const override { return source_; } |
| 62 |
virtual const FunctionSpace& target() const override { return target_; } |
| 63 |
|
| 64 |
private: |
| 65 |
using Method::do_setup; |
| 66 |
virtual void do_setup(const FunctionSpace& source, const FunctionSpace& target) override; |
| 67 |
virtual void do_setup(const Grid& source, const Grid& target, const Cache&) override; |
| 68 |
virtual void do_setup(const FunctionSpace& source, const FunctionSpace& target, const Cache&) override; |
| 69 |
|
| 70 |
protected: |
| 71 |
mesh::MultiBlockConnectivity* connectivity_; |
| 72 |
std::unique_ptr<array::ArrayView<double, 2>> icoords_; |
| 73 |
std::unique_ptr<array::ArrayView<double, 2>> ocoords_; |
| 74 |
std::unique_ptr<array::ArrayView<gidx_t, 1>> igidx_; |
| 75 |
|
| 76 |
Field target_lonlat_; |
| 77 |
Field target_xyz_; |
| 78 |
Field target_ghost_; |
| 79 |
|
| 80 |
FunctionSpace source_; |
| 81 |
FunctionSpace target_; |
| 82 |
|
| 83 |
bool treat_failure_as_missing_value_{true}; |
| 84 |
double max_fraction_elems_to_try_{0.2}; |
| 85 |
}; |
| 86 |
|
| 87 |
} // namespace method |
| 88 |
} // namespace interpolation |
| 89 |
} // namespace atlas |