| 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 |
#pragma once |
| 11 |
|
| 12 |
#include <array> |
| 13 |
#include <functional> |
| 14 |
#include <type_traits> |
| 15 |
#include <memory> |
| 16 |
|
| 17 |
#include "atlas/array/DataType.h" |
| 18 |
#include "atlas/field/Field.h" |
| 19 |
#include "atlas/functionspace/detail/FunctionSpaceImpl.h" |
| 20 |
#include "atlas/functionspace/detail/StructuredColumns.h" |
| 21 |
#include "atlas/functionspace/StructuredColumns.h" |
| 22 |
#include "atlas/grid/StructuredGrid.h" |
| 23 |
#include "atlas/grid/Vertical.h" |
| 24 |
#include "atlas/library/config.h" |
| 25 |
#include "atlas/option.h" |
| 26 |
#include "atlas/parallel/mpi/mpi.h" |
| 27 |
#include "atlas/parallel/omp/omp.h" |
| 28 |
#include "atlas/runtime/Exception.h" |
| 29 |
#include "atlas/util/Config.h" |
| 30 |
#include "atlas/util/ObjectHandle.h" |
| 31 |
#include "atlas/util/Point.h" |
| 32 |
#include "atlas/util/Polygon.h" |
| 33 |
#include "atlas/util/vector.h" |
| 34 |
|
| 35 |
namespace atlas { |
| 36 |
namespace parallel { |
| 37 |
class GatherScatter; |
| 38 |
//class HaloExchange; |
| 39 |
//class Checksum; |
| 40 |
} // namespace parallel |
| 41 |
} // namespace atlas |
| 42 |
|
| 43 |
namespace atlas { |
| 44 |
class Field; |
| 45 |
//class FieldSet; |
| 46 |
class Grid; |
| 47 |
class StructuredGrid; |
| 48 |
} // namespace atlas |
| 49 |
|
| 50 |
namespace atlas { |
| 51 |
namespace grid { |
| 52 |
class Distribution; |
| 53 |
class Partitioner; |
| 54 |
} // namespace grid |
| 55 |
} // namespace atlas |
| 56 |
|
| 57 |
namespace atlas { |
| 58 |
namespace functionspace { |
| 59 |
namespace detail { |
| 60 |
|
| 61 |
// ------------------------------------------------------------------- |
| 62 |
|
| 63 |
class BlockStructuredColumns : public FunctionSpaceImpl { |
| 64 |
public: |
| 65 |
BlockStructuredColumns(const Grid&, const eckit::Configuration& = util::NoConfig()); |
| 66 |
|
| 67 |
BlockStructuredColumns(const Grid&, const grid::Partitioner&, const eckit::Configuration& = util::NoConfig()); |
| 68 |
|
| 69 |
BlockStructuredColumns(const Grid&, const grid::Distribution&, const eckit::Configuration& = util::NoConfig()); |
| 70 |
|
| 71 |
BlockStructuredColumns(const Grid&, const grid::Distribution&, const Vertical&, |
| 72 |
const eckit::Configuration& = util::NoConfig()); |
| 73 |
|
| 74 |
BlockStructuredColumns(const Grid&, const Vertical&, const eckit::Configuration& = util::NoConfig()); |
| 75 |
|
| 76 |
BlockStructuredColumns(const Grid&, const Vertical&, const grid::Partitioner&, |
| 77 |
const eckit::Configuration& = util::NoConfig()); |
| 78 |
|
| 79 |
static std::string static_type() { return "BlockStructuredColumns"; } |
| 80 |
std::string type() const override { return static_type(); } |
| 81 |
std::string distribution() const override { return structuredcolumns_->distribution(); } |
| 82 |
|
| 83 |
Field createField(const eckit::Configuration&) const override; |
| 84 |
Field createField(const Field&, const eckit::Configuration&) const override; |
| 85 |
|
| 86 |
using FunctionSpaceImpl::scatter; |
| 87 |
void scatter(const FieldSet&, FieldSet&) const override; |
| 88 |
void scatter(const Field&, Field&) const override; |
| 89 |
using FunctionSpaceImpl::gather; |
| 90 |
void gather(const FieldSet&, FieldSet&) const override; |
| 91 |
void gather(const Field&, Field&) const override; |
| 92 |
|
| 93 |
idx_t size() const override { return structuredcolumns_->size(); } |
| 94 |
idx_t index(idx_t jblk, idx_t jrof) const { |
| 95 |
return jblk * nproma_ + jrof; // local index; |
| 96 |
} |
| 97 |
idx_t nproma() const { return nproma_; } |
| 98 |
idx_t nblks() const { return nblks_; } |
| 99 |
|
| 100 |
const Vertical& vertical() const { return structuredcolumns_->vertical(); } |
| 101 |
const StructuredGrid& grid() const override { return structuredcolumns_->grid(); } |
| 102 |
|
| 103 |
idx_t levels() const { return structuredcolumns_->levels(); } |
| 104 |
Field lonlat() const override { return structuredcolumns_->lonlat(); } |
| 105 |
Field xy() const { return structuredcolumns_->xy(); } |
| 106 |
Field z() const { return structuredcolumns_->z(); } |
| 107 |
Field partition() const override { return structuredcolumns_->partition(); } |
| 108 |
Field global_index() const override { return structuredcolumns_->global_index(); } |
| 109 |
Field remote_index() const override { return structuredcolumns_->remote_index(); } |
| 110 |
Field index_i() const { return structuredcolumns_->index_i(); } |
| 111 |
Field index_j() const { return structuredcolumns_->index_j(); } |
| 112 |
Field ghost() const override { return structuredcolumns_->ghost(); } |
| 113 |
size_t footprint() const override { return structuredcolumns_->footprint(); } |
| 114 |
idx_t part() const override { return structuredcolumns_->part(); } |
| 115 |
idx_t nb_parts() const override { return structuredcolumns_->nb_parts(); } |
| 116 |
const StructuredColumns& structuredcolumns() const { return *structuredcolumns_; } |
| 117 |
idx_t block_begin(idx_t jblk) const { return jblk * nproma_; } |
| 118 |
idx_t block_size(idx_t jblk) const { return (jblk != nblks_-1 ? nproma_ : endblk_size_); } |
| 119 |
idx_t k_begin() const { return vertical().k_begin(); } |
| 120 |
idx_t k_end() const { return vertical().k_end(); } |
| 121 |
|
| 122 |
std::string checksum(const FieldSet&) const; |
| 123 |
std::string checksum(const Field&) const; |
| 124 |
|
| 125 |
const util::PartitionPolygon& polygon(idx_t halo = 0) const override { return structuredcolumns_->polygon(halo); } |
| 126 |
|
| 127 |
private: // methods |
| 128 |
array::ArrayShape config_shape(const eckit::Configuration&) const; |
| 129 |
array::ArrayAlignment config_alignment(const eckit::Configuration&) const; |
| 130 |
array::ArraySpec config_spec(const eckit::Configuration&) const; |
| 131 |
|
| 132 |
private: // data |
| 133 |
idx_t nproma_; |
| 134 |
idx_t endblk_size_; |
| 135 |
idx_t nblks_; |
| 136 |
|
| 137 |
detail::StructuredColumns* structuredcolumns_; |
| 138 |
functionspace::StructuredColumns structuredcolumns_handle_; |
| 139 |
|
| 140 |
void setup(const eckit::Configuration& config); |
| 141 |
}; |
| 142 |
|
| 143 |
// ------------------------------------------------------------------- |
| 144 |
|
| 145 |
} // namespace detail |
| 146 |
} // namespace functionspace |
| 147 |
} // namespace atlas |