| 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 |
#include "atlas/mesh/Mesh.h" |
| 12 |
|
| 13 |
#include "atlas/grid/Distribution.h" |
| 14 |
#include "atlas/grid/Grid.h" |
| 15 |
#include "atlas/grid/Partitioner.h" |
| 16 |
#include "atlas/mesh/Nodes.h" |
| 17 |
#include "atlas/meshgenerator/MeshGenerator.h" |
| 18 |
#include "atlas/parallel/mpi/mpi.h" |
| 19 |
#include "atlas/runtime/Exception.h" |
| 20 |
|
| 21 |
namespace atlas { |
| 22 |
|
| 23 |
//---------------------------------------------------------------------------------------------------------------------- |
| 24 |
|
| 25 |
Mesh::Mesh(): Handle(new Implementation()) {} |
| 26 |
|
| 27 |
Mesh::Mesh(const Grid& grid, const eckit::Configuration& config): |
| 28 |
Handle([&]() { |
| 29 |
if (config.has("mpi_comm")) { |
| 30 |
mpi::scope::push(config.getString("mpi_comm")); |
| 31 |
} |
| 32 |
auto cfg = grid.meshgenerator() | util::Config(config); |
| 33 |
auto meshgenerator = MeshGenerator{grid.meshgenerator() | config}; |
| 34 |
auto mesh = meshgenerator.generate(grid, grid::Partitioner(grid.partitioner() | config)); |
| 35 |
if (config.has("mpi_comm")) { |
| 36 |
mpi::scope::pop(); |
| 37 |
} |
| 38 |
mesh.get()->attach(); |
| 39 |
return mesh.get(); |
| 40 |
}()) { |
| 41 |
get()->detach(); |
| 42 |
} |
| 43 |
|
| 44 |
Mesh::Mesh(const Grid& grid, const grid::Partitioner& partitioner, const eckit::Configuration& config): |
| 45 |
Handle([&]() { |
| 46 |
auto mpi_comm = partitioner.mpi_comm(); |
| 47 |
if (config.has("mpi_comm")) { |
| 48 |
mpi_comm = config.getString("mpi_comm"); |
| 49 |
ATLAS_ASSERT(mpi_comm == partitioner.mpi_comm()); |
| 50 |
} |
| 51 |
mpi::Scope mpi_scope(mpi_comm); |
| 52 |
auto meshgenerator = MeshGenerator{grid.meshgenerator() | config}; |
| 53 |
auto mesh = meshgenerator.generate(grid, partitioner); |
| 54 |
mesh.get()->attach(); |
| 55 |
return mesh.get(); |
| 56 |
}()) { |
| 57 |
get()->detach(); |
| 58 |
} |
| 59 |
|
| 60 |
Mesh::Mesh(const Grid& grid, const grid::Distribution& distribution, const eckit::Configuration& config): |
| 61 |
Handle([&]() { |
| 62 |
auto mpi_comm = mpi::comm().name(); |
| 63 |
if (config.has("mpi_comm")) { |
| 64 |
mpi_comm = config.getString("mpi_comm"); |
| 65 |
} |
| 66 |
mpi::Scope mpi_scope(mpi_comm); |
| 67 |
auto meshgenerator = MeshGenerator{grid.meshgenerator() | config}; |
| 68 |
auto mesh = meshgenerator.generate(grid, distribution); |
| 69 |
mesh.get()->attach(); |
| 70 |
return mesh.get(); |
| 71 |
}()) { |
| 72 |
get()->detach(); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
Mesh::Mesh(eckit::Stream& stream): Handle(new Implementation(stream)) {} |
| 78 |
|
| 79 |
Mesh::operator bool() const { |
| 80 |
return get()->nodes().size() > 0; |
| 81 |
} |
| 82 |
|
| 83 |
//---------------------------------------------------------------------------------------------------------------------- |
| 84 |
|
| 85 |
} // namespace atlas |