Skip to content

Commit

Permalink
Add atlas_TriangularMeshBuilder with Fortran interface for serial meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck committed Nov 8, 2023
1 parent 5ea733a commit 803fe2a
Show file tree
Hide file tree
Showing 13 changed files with 2,085 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/atlas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ mesh/detail/MeshImpl.cc
mesh/detail/MeshImpl.h
mesh/detail/MeshIntf.cc
mesh/detail/MeshIntf.h
mesh/detail/MeshBuilderIntf.cc
mesh/detail/MeshBuilderIntf.h
mesh/detail/PartitionGraph.cc
mesh/detail/PartitionGraph.h
mesh/detail/AccumulateFacets.h
Expand Down
54 changes: 51 additions & 3 deletions src/atlas/mesh/MeshBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,33 @@ Mesh MeshBuilder::operator()(size_t nb_nodes, const double lons[], const double
const gidx_t tri_global_indices[], size_t nb_quads, const gidx_t quad_boundary_nodes[],
const gidx_t quad_global_indices[],
const eckit::Configuration& config) const {
return this->operator()(
nb_nodes, global_indices,
lons, lats, 1, 1,
lons, lats, 1, 1,
ghosts, partitions, remote_indices, remote_index_base,
nb_tris, tri_global_indices, tri_boundary_nodes,
nb_quads, quad_global_indices, quad_boundary_nodes,
config
);
}

Mesh MeshBuilder::operator()(size_t nb_nodes, const gidx_t global_indices[],
const double x[], const double y[], size_t xstride, size_t ystride,
const double lon[], const double lat[], size_t lonstride, size_t latstride,
const int ghosts[], const int partitions[], const idx_t remote_index[], const idx_t remote_index_base,
size_t nb_triags, const gidx_t triag_global_index[], const gidx_t triag_nodes_global[],
size_t nb_quads, const gidx_t quad_global_index[], const gidx_t quad_nodes_global[],
const eckit::Configuration& config) const {
auto* lons = lon;
auto* lats = lat;
auto* remote_indices = remote_index;
auto nb_tris = nb_triags;
auto* tri_boundary_nodes = triag_nodes_global;
auto* tri_global_indices = triag_global_index;
auto* quad_boundary_nodes = quad_nodes_global;
auto* quad_global_indices = quad_global_index;

// Get MPI comm from config name or fall back to atlas default comm
auto mpi_comm_name = [](const auto& config) {
return config.getString("mpi_comm", atlas::mpi::comm().name());
Expand Down Expand Up @@ -199,9 +226,8 @@ Mesh MeshBuilder::operator()(size_t nb_nodes, const double lons[], const double
auto halo = array::make_view<int, 1>(mesh.nodes().halo());

for (size_t i = 0; i < nb_nodes; ++i) {
xy(i, size_t(XX)) = lons[i];
xy(i, size_t(YY)) = lats[i];
// Identity projection, therefore (lon,lat) = (x,y)
xy(i, size_t(XX)) = x[i];
xy(i, size_t(YY)) = y[i];
lonlat(i, size_t(LON)) = lons[i];
lonlat(i, size_t(LAT)) = lats[i];
ghost(i) = ghosts[i];
Expand Down Expand Up @@ -274,5 +300,27 @@ Mesh MeshBuilder::operator()(size_t nb_nodes, const double lons[], const double

//----------------------------------------------------------------------------------------------------------------------

Mesh TriangularMeshBuilder::operator()(size_t nb_nodes, const gidx_t nodes_global_index[], const double x[], const double y[], const double lon[], const double lat[],
size_t nb_triags, const gidx_t triangle_global_index[], const gidx_t triangle_nodes_global_index[]) const {
std::vector<int> ghost(nb_nodes,0);
std::vector<int> partition(nb_nodes,0);
std::vector<idx_t> remote_index(nb_nodes);
idx_t remote_index_base = 0;
std::iota(remote_index.begin(), remote_index.end(), remote_index_base);

size_t nb_quads = 0;
std::vector<gidx_t> quad_nodes_global_index;
std::vector<gidx_t> quad_global_index;

return meshbuilder_(
nb_nodes, nodes_global_index,
x, y, 1, 1, lon, lat, 1, 1,
ghost.data(), partition.data(), remote_index.data(), remote_index_base,
nb_triags, triangle_global_index, triangle_nodes_global_index,
nb_quads, quad_global_index.data(), quad_nodes_global_index.data());
}

//----------------------------------------------------------------------------------------------------------------------

} // namespace mesh
} // namespace atlas
40 changes: 39 additions & 1 deletion src/atlas/mesh/MeshBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace mesh {
*
* The Mesh's Grid can be initialized via the call operator's optional config argument.
*/
class MeshBuilder {
class MeshBuilder : public eckit::Owned {
public:
MeshBuilder(const eckit::Configuration& = util::NoConfig()) {}

Expand Down Expand Up @@ -69,6 +69,15 @@ class MeshBuilder {
const gidx_t quad_global_indices[],
const eckit::Configuration& config = util::NoConfig()) const;

Mesh operator()(size_t nb_nodes, const gidx_t global_index[],
const double x[], const double y[], size_t xstride, size_t ystride,
const double lon[], const double lat[], size_t lonstride, size_t latstride,
const int ghost[], const int partition[], const idx_t remote_index[], const idx_t remote_index_base,
size_t nb_triags, const gidx_t triag_global_index[], const gidx_t triag_nodes_global[],
size_t nb_quads, const gidx_t quad_global_index[], const gidx_t quad_nodes_global[],
const eckit::Configuration& config = util::NoConfig()) const;


/**
* \brief C++-interface to construct a Mesh from external connectivity data
*
Expand All @@ -86,5 +95,34 @@ class MeshBuilder {

//-----------------------------------------------------------------------------


class TriangularMeshBuilder {
public:
TriangularMeshBuilder(const eckit::Configuration& config = util::NoConfig()) :
meshbuilder_(config) {}

/**
* \brief C-interface to construct a Triangular Mesh from external connectivity data
*
* The inputs x, y, lons, lats, ghost, global_index, remote_index, and partition are vectors of
* size nb_nodes, ranging over the nodes locally owned by (or in the ghost nodes of) the MPI
* task. The global index is a uniform labeling of the nodes across all MPI tasks; the remote
* index is a remote_index_base-based vector index for the node on its owning task.
*
* The triangle connectivities (boundary_nodes and global_index) are vectors ranging over the
* cells owned by the MPI task. Each cell is defined by a list of nodes defining its boundary;
* note that each boundary node must be locally known (whether as an owned of ghost node on the
* MPI task), in other words, must be an element of the node global_indices. The boundary nodes
* are ordered node-varies-fastest, element-varies-slowest order. The cell global index is,
* here also, a uniform labeling over the of the cells across all MPI tasks.
*/
Mesh operator()(size_t nb_nodes, const gidx_t node_global_index[], const double x[], const double y[], const double lon[], const double lat[],
size_t nb_triags, const gidx_t triangle_global_index[], const gidx_t triangle_nodes_global_index[]) const;
private:
MeshBuilder meshbuilder_;
};

//-----------------------------------------------------------------------------

} // namespace mesh
} // namespace atlas
Loading

0 comments on commit 803fe2a

Please sign in to comment.