| 1 |
/* |
| 2 |
* (C) Crown Copyright 2021 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 |
#include "atlas/redistribution/Redistribution.h" |
| 9 |
#include "atlas/field/Field.h" |
| 10 |
#include "atlas/field/FieldSet.h" |
| 11 |
#include "atlas/functionspace/FunctionSpace.h" |
| 12 |
#include "atlas/redistribution/detail/RedistributeGeneric.h" |
| 13 |
#include "atlas/redistribution/detail/RedistributionImplFactory.h" |
| 14 |
#include "atlas/runtime/Exception.h" |
| 15 |
|
| 16 |
|
| 17 |
namespace atlas { |
| 18 |
|
| 19 |
// Use redistribution implementation factory to make object. |
| 20 |
Redistribution::Redistribution(): Handle(){}; |
| 21 |
Redistribution::Redistribution(const FunctionSpace& sourceFunctionSpace, const FunctionSpace& targetFunctionSpace, |
| 22 |
const util::Config& config): |
| 23 |
Handle([&]() -> redistribution::detail::RedistributionImpl* { |
| 24 |
std::string type = redistribution::detail::RedistributeGeneric::static_type(); |
| 25 |
config.get("type", type); |
| 26 |
|
| 27 |
auto impl = redistribution::detail::RedistributionImplFactory::build(type); |
| 28 |
impl->setup(sourceFunctionSpace, targetFunctionSpace); |
| 29 |
return impl; |
| 30 |
}()) {} |
| 31 |
|
| 32 |
void Redistribution::execute(const Field& source, Field& target) const { |
| 33 |
get()->execute(source, target); |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
void Redistribution::execute(const FieldSet& source, FieldSet& target) const { |
| 38 |
get()->execute(source, target); |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
const FunctionSpace& Redistribution::source() const { |
| 43 |
return get()->source(); |
| 44 |
} |
| 45 |
|
| 46 |
const FunctionSpace& Redistribution::target() const { |
| 47 |
return get()->target(); |
| 48 |
} |
| 49 |
|
| 50 |
} // namespace atlas |