28 size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges,
29 int *num_vertices_per_cell_,
32 void (*LLtoXYZ_ptr)(double, double,
double[])) {
37 for (
size_t i = 0; i < nbr_vertices; ++i)
48 size_t total_num_cell_corners = 0;
51 for (
size_t i = 0; i < nbr_cells; ++i) {
59 for (
size_t i = 0; i < total_num_cell_corners; ++i)
68 for (
size_t i = 0, accu = 0; i < nbr_vertices; ++i) {
72 for (
size_t i = 0, k = 0; i < nbr_cells; ++i) {
74 for (
size_t j = 0; j < curr_num_vertices; ++j, ++k)
109 size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges,
110 int *num_edges_per_cell,
double *x_vertices,
double *y_vertices,
111 int *cell_to_edge_,
int *edge_to_vertex_,
112 void (*LLtoXYZ_ptr)(double, double,
double[])) {
115 size_t total_num_cell_edges = 0;
116 for (
size_t i = 0; i < nbr_cells; ++i)
117 total_num_cell_edges += (
size_t)(num_edges_per_cell[i]);
122 for (
size_t i = 0; i < total_num_cell_edges; ++i) {
124 "ERROR(yac_generate_basic_grid_data_unstruct_edge_): "
125 "Index %zu in cell_to_edge (%d) is negative.",
128 "ERROR(yac_generate_basic_grid_data_unstruct_edge_): "
129 "Index %zu in cell_to_edge (%d) is not smaller than nbr_edges (%zu).",
130 i, cell_to_edge_[i], nbr_edges)
137 for (
size_t i = 0; i < 2 * nbr_edges; ++i) {
139 "ERROR(yac_generate_basic_grid_data_unstruct_edge_): "
140 "Index %zu in edge_to_vertex (%d) is negative.",
141 i, edge_to_vertex_[i])
142 YAC_ASSERT_F((
size_t)(edge_to_vertex_[i]) < nbr_vertices,
143 "ERROR(yac_generate_basic_grid_data_unstruct_edge_): "
144 "Index %zu in edge_to_vertex (%d) is not smaller than nbr_vertices (%zu).",
145 i, edge_to_vertex_[i], nbr_edges)
152 for (
size_t i = 0, k = 0; i < nbr_cells; ++i) {
153 size_t curr_num_vertices = (size_t)(num_edges_per_cell[i]);
154 if (curr_num_vertices == 0)
continue;
157 size_t curr_vertex = first_vertex;
158 for (
size_t j = 0; j < curr_num_vertices; ++j, ++k) {
161 prev_vertex = curr_vertex;
162 curr_vertex = curr_edge_vertices[curr_edge_vertices[0] == prev_vertex];
164 (curr_edge_vertices[0] == prev_vertex) ||
165 (curr_edge_vertices[1] == prev_vertex),
166 "ERROR(yac_generate_basic_grid_data_unstruct_edge_): "
167 "inconsistent definition of cell_to_edge or edge_to_vertex")
170 first_vertex == curr_vertex,
171 "ERROR(yac_generate_basic_grid_data_unstruct_edge_): "
172 "inconsistent definition of cell_to_edge or edge_to_vertex")
177 nbr_vertices, nbr_cells, nbr_edges, num_edges_per_cell,
184 double *x_vertices,
double *y_vertices,
int *cell_to_vertex_,
185 void (*LLtoXYZ_ptr)(double, double,
double[])) {
188 size_t total_num_cell_corners = 0;
189 for (
size_t i = 0; i < nbr_cells; ++i)
195 for (
size_t i = 0; i < total_num_cell_corners; ++i) {
197 "ERROR(yac_generate_basic_grid_data_unstruct_): "
198 "Index %zu in cell_to_vertex (%d) is negative.",
199 i, cell_to_vertex_[i])
200 YAC_ASSERT_F((
size_t)(cell_to_vertex_[i]) < nbr_vertices,
201 "ERROR(yac_generate_basic_grid_data_unstruct_): "
202 "Index %zu in cell_to_vertex (%d) is not smaller than nbr_vertices (%zu).",
203 i, cell_to_vertex_[i], nbr_vertices)
209 xmalloc(total_num_cell_corners *
sizeof(*temp_edges));
210 for (
size_t i = 0, offset = 0, k = 0; i < nbr_cells; ++i) {
211 size_t * curr_cell_to_vertex = cell_to_vertex + offset;
212 size_t curr_num_edges = num_vertices_per_cell[i];
213 offset += curr_num_edges;
214 for (
size_t j = 0; j < curr_num_edges; ++j, ++k) {
216 curr_cell_to_vertex[j] > curr_cell_to_vertex[(j+1)%curr_num_edges];
217 temp_edges[k].
vertex[order] = curr_cell_to_vertex[j];
218 temp_edges[k].
vertex[order^1] = curr_cell_to_vertex[(j+1)%curr_num_edges];
222 qsort(temp_edges, total_num_cell_corners,
226 size_t * cell_to_edge =
227 xmalloc(total_num_cell_corners *
sizeof(*cell_to_edge));
228 size_t nbr_edges = 0;
230 for (
size_t i = 0, prev_indices[2] = {SIZE_MAX, SIZE_MAX};
231 i < total_num_cell_corners; ++i) {
234 if ((prev_indices[0] != temp_edges[i].
vertex[0]) ||
235 (prev_indices[1] != temp_edges[i].
vertex[1])) {
237 prev_indices[0] = temp_edges[i].
vertex[0];
238 prev_indices[1] = temp_edges[i].
vertex[1];
239 edge_to_vertex[nbr_edges][0] = prev_indices[0];
240 edge_to_vertex[nbr_edges][1] = prev_indices[1];
244 cell_to_edge[curr_cell_to_edge_idx] = nbr_edges - 1;
247 xrealloc(edge_to_vertex, nbr_edges *
sizeof(*edge_to_vertex));
251 nbr_vertices, nbr_cells, nbr_edges, num_vertices_per_cell,
252 x_vertices, y_vertices, edge_to_vertex, cell_to_vertex, cell_to_edge,
257 size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell_,
258 double *x_vertices,
double *y_vertices,
int *cell_to_vertex_) {
262 nbr_vertices, nbr_cells, num_vertices_per_cell_,
263 x_vertices, y_vertices, cell_to_vertex_,
LLtoXYZ);
267 size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell_,
268 double *x_vertices,
double *y_vertices,
int *cell_to_vertex_) {
272 nbr_vertices, nbr_cells, num_vertices_per_cell_,
273 x_vertices, y_vertices, cell_to_vertex_,
LLtoXYZ_deg);
277 size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges,
278 int *num_edges_per_cell,
double *x_vertices,
double *y_vertices,
283 nbr_vertices, nbr_cells, nbr_edges, num_edges_per_cell,
288 size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges,
289 int *num_edges_per_cell,
double *x_vertices,
double *y_vertices,
294 nbr_vertices, nbr_cells, nbr_edges, num_edges_per_cell,
300 double *x_vertices,
double *y_vertices,
301 double (*get_angle_ptr)(
double,
double),
302 double angle_tol,
double pole_y_vertex) {
304 for (
size_t i = 0; i < grid_data.
num_edges; ++i) {
311 pole_y_vertex) < angle_tol) ^
313 pole_y_vertex) < angle_tol));
318 is_lon_edge || is_lat_edge,
319 "ERROR(yac_generate_basic_grid_data_unstruct_ll): "
320 "edge is neither lon nor lat ((%lf,%lf),(%lf,%lf))",
330 size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell_,
331 double *x_vertices,
double *y_vertices,
int *cell_to_vertex_,
332 void (*LLtoXYZ_ptr)(double, double,
double[]),
333 double (*get_angle_ptr)(double, double),
334 double angle_tol,
double pole_y_vertex) {
338 nbr_vertices, nbr_cells, num_vertices_per_cell_,
339 x_vertices, y_vertices, cell_to_vertex_, LLtoXYZ_ptr);
342 grid_data, x_vertices, y_vertices, get_angle_ptr, angle_tol, pole_y_vertex);
348 size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell_,
349 double *x_vertices,
double *y_vertices,
int *cell_to_vertex_) {
353 nbr_vertices, nbr_cells, num_vertices_per_cell_,
354 x_vertices, y_vertices, cell_to_vertex_,
LLtoXYZ,
359 size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell_,
360 double *x_vertices,
double *y_vertices,
int *cell_to_vertex_) {
364 nbr_vertices, nbr_cells, num_vertices_per_cell_,
365 x_vertices, y_vertices, cell_to_vertex_,
LLtoXYZ_deg,
371 size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges,
372 int *num_edges_per_cell,
double *x_vertices,
double *y_vertices,
374 void (*LLtoXYZ_ptr)(double, double,
double[]),
375 double (*get_angle_ptr)(double, double),
376 double angle_tol,
double pole_y_vertex) {
380 nbr_vertices, nbr_cells, nbr_edges, num_edges_per_cell,
384 grid_data, x_vertices, y_vertices, get_angle_ptr, angle_tol, pole_y_vertex);
390 size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges,
391 int *num_edges_per_cell,
double *x_vertices,
double *y_vertices,
396 nbr_vertices, nbr_cells, nbr_edges, num_edges_per_cell,
402 size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges,
403 int *num_edges_per_cell,
double *x_vertices,
double *y_vertices,
408 nbr_vertices, nbr_cells, nbr_edges, num_edges_per_cell,
static void LLtoXYZ_deg(double lon, double lat, double p_out[])
static double get_angle(double a_lon, double b_lon)
static void LLtoXYZ(double lon, double lat, double p_out[])
static double get_angle_deg(double a_lon, double b_lon)
@ YAC_GREAT_CIRCLE_EDGE
great circle
@ YAC_LAT_CIRCLE_EDGE
latitude circle
@ YAC_LON_CIRCLE_EDGE
longitude circle
static struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_(size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex_, void(*LLtoXYZ_ptr)(double, double, double[]))
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_edge(size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex)
static struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_ll_(size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell_, double *x_vertices, double *y_vertices, int *cell_to_vertex_, void(*LLtoXYZ_ptr)(double, double, double[]), double(*get_angle_ptr)(double, double), double angle_tol, double pole_y_vertex)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_edge_deg(size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_deg(size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell_, double *x_vertices, double *y_vertices, int *cell_to_vertex_)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_ll_deg(size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell_, double *x_vertices, double *y_vertices, int *cell_to_vertex_)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_edge_ll(size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex)
static void set_ll_edge_type(struct yac_basic_grid_data grid_data, double *x_vertices, double *y_vertices, double(*get_angle_ptr)(double, double), double angle_tol, double pole_y_vertex)
static struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_edge_ll_(size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex, void(*LLtoXYZ_ptr)(double, double, double[]), double(*get_angle_ptr)(double, double), double angle_tol, double pole_y_vertex)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_edge_ll_deg(size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct(size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell_, double *x_vertices, double *y_vertices, int *cell_to_vertex_)
static struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_base(size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_vertices_per_cell_, double *x_vertices, double *y_vertices, yac_size_t_2_pointer edge_to_vertex, size_t *cell_to_vertex, size_t *cell_to_edge, void(*LLtoXYZ_ptr)(double, double, double[]))
static struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_edge_(size_t nbr_vertices, size_t nbr_cells, size_t nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge_, int *edge_to_vertex_, void(*LLtoXYZ_ptr)(double, double, double[]))
static int compare_temp_edges(void const *a, void const *b)
struct yac_basic_grid_data yac_generate_basic_grid_data_unstruct_ll(size_t nbr_vertices, size_t nbr_cells, int *num_vertices_per_cell_, double *x_vertices, double *y_vertices, int *cell_to_vertex_)
#define xrealloc(ptr, size)
#define xcalloc(nmemb, size)
yac_coordinate_pointer vertex_coordinates
size_t * cell_to_edge_offsets
size_t * vertex_to_cell_offsets
yac_size_t_2_pointer edge_to_vertex
enum yac_edge_type * edge_type
size_t num_total_vertices
size_t * cell_to_vertex_offsets
int * num_vertices_per_cell
int * num_cells_per_vertex
#define YAC_ASSERT_F(exp, format,...)
#define YAC_ASSERT(exp, msg)
size_t(* yac_size_t_2_pointer)[2]
double(* yac_coordinate_pointer)[3]