Skip to content

Commit c1dd11b

Browse files
committed
Add option to change output functionspace in atlas_test_interpolation_structured2D_to_area
1 parent dc35fed commit c1dd11b

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

src/tests/interpolation/test_interpolation_structured2D_to_area.cc

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
#include "atlas/domain/Domain.h"
2727
#include "atlas/parallel/mpi/mpi.h"
2828
#include "atlas/functionspace/NodeColumns.h"
29+
#include "atlas/functionspace/PointCloud.h"
2930
#include "atlas/grid/Partitioner.h"
3031

32+
#include "atlas/util/GridPointsJSONWriter.h"
33+
3134
#include "tests/AtlasTestEnvironment.h"
3235

3336
using atlas::util::Config;
@@ -41,6 +44,15 @@ std::string input_gridname(const std::string& default_grid) {
4144
return eckit::Resource<std::string>("--input-grid", default_grid);
4245
}
4346

47+
int output_rank(const int& default_rank) {
48+
return eckit::Resource<int>("--output-rank", default_rank);
49+
}
50+
51+
std::string output_functionspace(const std::string& default_fs) {
52+
return eckit::Resource<std::string>("--output-functionspace", default_fs);
53+
}
54+
55+
4456
FieldSet create_source_fields(functionspace::StructuredColumns& fs, idx_t nb_fields, idx_t nb_levels) {
4557
using Value = double;
4658
FieldSet fields_source;
@@ -66,13 +78,16 @@ FieldSet create_target_fields(FunctionSpace& fs, idx_t nb_fields, idx_t nb_level
6678
}
6779

6880
void do_test( std::string type, int input_halo, bool expect_failure ) {
81+
idx_t outrank = output_rank(-1);
6982
idx_t nb_fields = 2;
7083
idx_t nb_levels = 19;
7184

7285
// Setup Grid and functionspace
7386
Grid inputGrid(input_gridname("O40"));
7487
functionspace::StructuredColumns inputFS(inputGrid, option::levels(nb_levels) | option::halo(input_halo));
7588

89+
inputFS.polygon(0).outputPythonScript("input.py");
90+
7691
// Setup source field_set
7792
FieldSet fields_source = create_source_fields(inputFS, nb_fields, nb_levels);
7893

@@ -85,11 +100,45 @@ void do_test( std::string type, int input_halo, bool expect_failure ) {
85100
RectangularLonLatDomain rd({boundingBoxWest, boundingBoxEast}, {boundingBoxSouth, boundingBoxNorth});
86101
Grid areaGrid(inputGrid, rd);
87102

88-
Mesh areaMesh = MeshGenerator("structured").generate( areaGrid, grid::MatchingPartitioner(inputFS) );
89-
atlas::FunctionSpace outputFS = atlas::functionspace::NodeColumns{areaMesh};
103+
util::GridPointsJSONWriter input_writer(inputGrid,
104+
util::Config
105+
("partition",mpi::rank())
106+
("partitioner.partitions",mpi::size())
107+
("field","lonlat")
108+
);
109+
if( mpi::rank() == outrank ) {
110+
Log::info() << "input grid coordinates of rank " << outrank << ": \n";
111+
input_writer.write(Log::info());
112+
}
113+
114+
util::GridPointsJSONWriter output_writer(areaGrid, grid::MatchingPartitioner(inputFS),
115+
util::Config
116+
("partition",mpi::rank())
117+
("field","lonlat")
118+
);
119+
if( mpi::rank() == outrank ) {
120+
Log::info() << "output grid coordinates of rank " << outrank << ": \n";
121+
output_writer.write(Log::info());
122+
}
123+
124+
FunctionSpace outputFS;
125+
std::string output_functionspace_type = output_functionspace("NodeColumns");
90126

91-
output::Gmsh gmsh{"area.msh"};
92-
gmsh.write(areaMesh);
127+
if (output_functionspace_type=="NodeColumns") {
128+
Mesh areaMesh = MeshGenerator("structured").generate( areaGrid, grid::MatchingPartitioner(inputFS) );
129+
output::Gmsh gmsh{"area.msh"};
130+
gmsh.write(areaMesh);
131+
outputFS = atlas::functionspace::NodeColumns{areaMesh};
132+
}
133+
else if (output_functionspace_type=="StructuredColumns") {
134+
outputFS = functionspace::StructuredColumns(areaGrid, grid::MatchingPartitioner(inputFS) );
135+
}
136+
else if (output_functionspace_type=="PointCloud") {
137+
outputFS = atlas::functionspace::PointCloud{areaGrid, grid::MatchingPartitioner(inputFS)};
138+
}
139+
else {
140+
ATLAS_NOTIMPLEMENTED;
141+
}
93142

94143
// setup interpolation
95144
Interpolation interpolation(option::type(type)|Config("matrix_free",false), inputFS, outputFS);
@@ -100,7 +149,10 @@ void do_test( std::string type, int input_halo, bool expect_failure ) {
100149
// execute interpolation
101150
interpolation.execute(fields_source, fields_target);
102151

103-
gmsh.write(fields_target);
152+
if (atlas::functionspace::NodeColumns(outputFS)) {
153+
output::Gmsh gmsh{"area.msh","a"};
154+
gmsh.write(fields_target);
155+
}
104156
}
105157

106158
CASE("test structured-linear2D, halo 3") {

0 commit comments

Comments
 (0)