@@ -47,48 +47,117 @@ std::array<size_t, 3> kijfromindex(const std::array<size_t, 3> &ndims, const siz
4747 return std::array<size_t , 3 >{k, i, j};
4848}
4949
50- void create_vertex_coordinates (const Config &config, const std::array<size_t , 3 > ndims,
50+ double get_radians_from_metres (const double lower_latitude,
51+ double delta_east = 0.0 , double delta_north = 0.0 ) {
52+ constexpr double EarthRadiusMeters = 6378137.0 ; // semi‑major axis a
53+ double dLon = 0.0 ;
54+ double dLat = 0.0 ;
55+
56+ if (delta_east != 0.0 ) {
57+ double cosLat = std::cos (lower_latitude);
58+ dLon = (delta_east*1000.0 ) / (EarthRadiusMeters * cosLat);
59+ return dLon;
60+ }
61+
62+ if (delta_north != 0.0 ) {
63+ dLat = (delta_north*1000.0 ) / EarthRadiusMeters;
64+ return dLat;
65+ }
66+
67+ return 0.0 ;
68+ }
69+
70+
71+ void create_vertex_coordinates (const Config &config, const std::array<size_t , 3 > partition_size,
72+ std::vector<std::vector<double >> gridbox_bounds,
5173 std::vector<double > &vertex_longitudes,
5274 std::vector<double > &vertex_latitudes) {
5375 const auto lower_longitude = config.get_yac_dynamics ().lower_longitude ;
5476 const auto upper_longitude = config.get_yac_dynamics ().upper_longitude ;
5577 const auto lower_latitude = config.get_yac_dynamics ().lower_latitude ;
5678 const auto upper_latitude = config.get_yac_dynamics ().upper_latitude ;
5779
80+ auto vertex_longitudes_new = std::vector<double >(partition_size[EASTWARD ] + 1 , 0 );
81+ auto vertex_latitudes_new = std::vector<double >(partition_size[NORTHWARD ] + 1 , 0 );
82+
83+ constexpr double RadToDeg = 180.0 / M_PI ;
84+ constexpr double DegToRad = M_PI / 180.0 ;
85+
86+ // use partition_origins and partition_sizes
5887 // Defines the vertex longitude and latitude values in radians for grid creation
5988 // The values are later permuted by YAC to generate all vertex coordinates
89+
90+ // ********* 1 process ***************
91+
6092 for (size_t i = 0 ; i < vertex_longitudes.size (); i++)
6193 vertex_longitudes[i] =
62- lower_longitude + i * ((upper_longitude - lower_longitude) / ndims [EASTWARD ]);
94+ lower_longitude + i * ((upper_longitude - lower_longitude) / partition_size [EASTWARD ]);
6395
6496 for (size_t i = 0 ; i < vertex_latitudes.size (); i++)
6597 vertex_latitudes[i] =
66- lower_latitude + i * ((upper_latitude - lower_latitude) / ndims[NORTHWARD ]);
98+ lower_latitude + i * ((upper_latitude - lower_latitude) / partition_size[NORTHWARD ]);
99+
100+ // ***** multiprocess **********
101+ for (size_t i = 0 ; i < vertex_longitudes.size (); i++) {
102+ auto dLon = get_radians_from_metres (lower_latitude,
103+ (gridbox_bounds[EASTWARD ][i] - gridbox_bounds[EASTWARD ].front ()));
104+
105+ // auto dLon = ((gridbox_bounds[EASTWARD][i] - gridbox_bounds[EASTWARD].front())
106+ // *1000.0*DegToRad)/111111.0;
107+ vertex_longitudes_new[i] = lower_longitude + dLon;
108+ std::cout << " dLon : " << dLon <<std::endl;
109+ }
110+
111+ for (size_t i = 0 ; i < vertex_latitudes.size (); i++) {
112+ auto dLat = get_radians_from_metres (lower_latitude,
113+ 0.0 , (gridbox_bounds[NORTHWARD ][i] - gridbox_bounds[NORTHWARD ].front ()));
114+
115+ // auto dLat = ((gridbox_bounds[NORTHWARD][i] - gridbox_bounds[NORTHWARD].front())
116+ // *1000.0*DegToRad)/111111.0;
117+ vertex_latitudes_new[i] = lower_latitude + dLat;
118+ std::cout << " dLat : " << dLat <<std::endl;
119+ }
120+
121+ for (size_t i = 0 ; i < vertex_longitudes.size (); i++)
122+ std::cout << " vertex_lon old vs new " << vertex_longitudes[i] << " vs "
123+ << vertex_longitudes_new[i] << std::endl;
124+
125+ for (size_t i = 0 ; i < vertex_latitudes.size (); i++)
126+ std::cout << " vertex_lat old vs new " << vertex_latitudes[i] << " vs "
127+ << vertex_latitudes_new[i] << std::endl;
67128}
68129
69130/* Creates the YAC grid and defines the cell and edge points based on ndims data */
70131void create_grid_and_points_definitions (const Config &config, const std::array<size_t , 3 > ndims,
71132 const std::string grid_name, int &grid_id,
72- int &cell_point_id, int &edge_point_id) {
133+ int &cell_point_id, int &edge_point_id,
134+ std::array<size_t , 3 > partition_size,
135+ std::array<size_t , 3 > partition_origin,
136+ std::vector<std::vector<double >> gridbox_bounds) {
73137 int cyclic_dimension[2 ] = {0 , 0 };
74- int total_cells[2 ] = {static_cast <int >(ndims[EASTWARD ]), static_cast <int >(ndims[NORTHWARD ])};
75- int total_vertices[2 ] = {static_cast <int >(ndims[EASTWARD ] + 1 ),
76- static_cast <int >(ndims[NORTHWARD ] + 1 )};
77- int total_edges[2 ] = {static_cast <int >(ndims[EASTWARD ] * (ndims[NORTHWARD ] + 1 )),
78- static_cast <int >(ndims[NORTHWARD ] * (ndims[EASTWARD ] + 1 ))};
79-
80- auto vertex_longitudes = std::vector<double >(ndims[EASTWARD ] + 1 , 0 );
81- auto vertex_latitudes = std::vector<double >(ndims[NORTHWARD ] + 1 , 0 );
82- auto cell_center_longitudes = std::vector<double >(ndims[EASTWARD ]);
83- auto cell_center_latitudes = std::vector<double >(ndims[NORTHWARD ]);
138+ int total_cells[2 ] = {static_cast <int >(partition_size[EASTWARD ]),
139+ static_cast <int >(partition_size[NORTHWARD ])};
140+ int total_vertices[2 ] = {static_cast <int >(partition_size[EASTWARD ] + 1 ),
141+ static_cast <int >(partition_size[NORTHWARD ] + 1 )};
142+ int total_edges[2 ] = {static_cast <int >(partition_size[EASTWARD ] *
143+ (partition_size[NORTHWARD ] + 1 )),
144+ static_cast <int >(partition_size[NORTHWARD ] *
145+ (partition_size[EASTWARD ] + 1 ))};
146+
147+ auto vertex_longitudes = std::vector<double >(partition_size[EASTWARD ] + 1 , 0 );
148+ auto vertex_latitudes = std::vector<double >(partition_size[NORTHWARD ] + 1 , 0 );
149+ auto cell_center_longitudes = std::vector<double >(partition_size[EASTWARD ]);
150+ auto cell_center_latitudes = std::vector<double >(partition_size[NORTHWARD ]);
151+
84152 std::vector<double > edge_centers_longitudes;
85153 std::vector<double > edge_centers_latitudes;
86154
87- create_vertex_coordinates (config, ndims, vertex_longitudes, vertex_latitudes);
155+ create_vertex_coordinates (config, partition_size, gridbox_bounds,
156+ vertex_longitudes, vertex_latitudes);
88157
89158 // Defines a regular 2D grid
90- yac_cdef_grid_reg2d (grid_name.c_str (), total_vertices, cyclic_dimension, vertex_longitudes. data (),
91- vertex_latitudes.data (), &grid_id);
159+ yac_cdef_grid_reg2d (grid_name.c_str (), total_vertices, cyclic_dimension,
160+ vertex_longitudes. data (), vertex_latitudes.data (), &grid_id);
92161
93162 // --- Point definitions ---
94163 // Defines the cell center longitude and latitude values in radians
@@ -183,8 +252,6 @@ void CartesianDynamics::send_yac_field(int field_id, double* field_data,
183252 auto ncells = ndims_north * ndims_east;
184253
185254 int info, ierror;
186- // auto field_size = ncells*ndims_vertical;
187- // double **collection_data;
188255
189256 send_buffer = new double **[ndims_vertical];
190257
@@ -204,12 +271,9 @@ void CartesianDynamics::send_yac_field(int field_id, double* field_data,
204271 }
205272 }
206273
207- // for (size_t i = 0; i < field_size; i++) {
208- // field_data[i] = field_data[i]*conversion_factor;
209- // }
210274 yac_cput (field_id, ndims_vertical, send_buffer, &info, &ierror);
211275
212- std::cout << " yac_cput_ completed with info as: " << info << std::endl;
276+ std::cout << " yac_cput completed with info as: " << info << std::endl;
213277
214278 for (size_t j = 0 ; j < ndims_vertical; ++j) {
215279 delete send_buffer[j][0 ];
@@ -227,7 +291,7 @@ void CartesianDynamics::send_fields_to_yac(double* h_temp,
227291}
228292
229293CartesianDynamics::CartesianDynamics (const Config &config, const std::array<size_t , 3 > i_ndims,
230- const unsigned int nsteps)
294+ const unsigned int nsteps, const CartesianDecomposition& decomp )
231295 : ndims(i_ndims),
232296 config(config),
233297 get_wvel(nullwinds()),
@@ -244,8 +308,33 @@ CartesianDynamics::CartesianDynamics(const Config &config, const std::array<size
244308 int edge_point_id = -1 ;
245309 std::string grid_name = " cleo_grid" ;
246310
311+ partition_size = decomp.get_local_partition_size ();
312+ partition_origin = decomp.get_local_partition_origin ();
313+ gridbox_bounds = decomp.get_local_gridbox_bounds ();
314+ domain_bounds = decomp.get_domain_bounds ();
315+
316+ std::cout << " Partition Size in z:" << partition_size[0 ] << std::endl;
317+ std::cout << " Partition Size in x:" << partition_size[1 ] << std::endl;
318+ std::cout << " Partition Size in y:" << partition_size[2 ] << std::endl;
319+
320+ std::cout << " ndims Size in z:" << ndims[0 ] << std::endl;
321+ std::cout << " ndims Size in x:" << ndims[1 ] << std::endl;
322+ std::cout << " ndims Size in y:" << ndims[2 ] << std::endl;
323+
324+
325+ std::cout << " gridbox_bounds in z direction: " << gridbox_bounds[0 ].front () << " ; "
326+ << gridbox_bounds[0 ].back () <<std::endl;
327+ std::cout << " gridbox_bounds in x direction: " << gridbox_bounds[1 ].front () << " ; "
328+ << gridbox_bounds[1 ].back () <<std::endl;
329+ std::cout << " gridbox_bounds in y direction: " << gridbox_bounds[2 ].front () << " ; "
330+ << gridbox_bounds[2 ].back () <<std::endl;
331+
332+ std::cout << " Domain_bounds in z direction: " << domain_bounds[0 ][0 ] << " ; "
333+ << domain_bounds[1 ][0 ] <<std::endl;
334+
247335 create_grid_and_points_definitions (config, ndims, grid_name, grid_id, cell_point_id,
248- edge_point_id);
336+ edge_point_id, partition_size, partition_origin,
337+ gridbox_bounds);
249338
250339 // --- Interpolation stack ---
251340 int interp_stack_id;
0 commit comments