Skip to content
Snippets Groups Projects
Commit bb8db790 authored by Moritz Hanke's avatar Moritz Hanke
Browse files

adds new basic_grid_data constructor "yac_generate_basic_grid_data_cloud"

parent 3791908d
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,7 @@ libyac_core_a_SOURCES = \
grid_cell.c \
grid_cell.h \
grid_curve2d.c \
grid_cloud.c \
grid_reg2d.c \
grid_reg2d_common.c \
grid_reg2d_common.h \
......
......@@ -71,6 +71,12 @@ 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_cloud(
size_t nbr_points, double * x_points, double * y_points);
struct yac_basic_grid_data yac_generate_basic_grid_data_cloud_deg(
size_t nbr_points, double * x_points, double * y_points);
void yac_basic_grid_data_compute_cell_areas(
struct yac_basic_grid_data grid, double * cell_areas);
......
// Copyright (c) 2024 The YAC Authors
//
// SPDX-License-Identifier: BSD-3-Clause
#include <string.h>
#include "basic_grid_data.h"
#include "geometry.h"
#include "utils_common.h"
static struct yac_basic_grid_data yac_generate_basic_grid_data_cloud_(
size_t nbr_points, double *x_points, double *y_points,
void (*LLtoXYZ_ptr)(double, double, double[])) {
yac_coordinate_pointer vertex_coordinates =
xmalloc(nbr_points * sizeof(*vertex_coordinates));
for (size_t i = 0; i < nbr_points; ++i)
LLtoXYZ_ptr(
x_points[i], y_points[i], &(vertex_coordinates[i][0]));
struct yac_basic_grid_data grid;
grid.vertex_coordinates = vertex_coordinates;
grid.cell_ids = NULL;
grid.vertex_ids = NULL;
grid.edge_ids = NULL;
grid.num_cells = 0;
grid.num_vertices = nbr_points;
grid.num_edges = 0;
grid.core_cell_mask = NULL;
grid.core_vertex_mask = NULL;
grid.core_edge_mask = NULL;
grid.num_vertices_per_cell = NULL;
grid.num_cells_per_vertex =
xcalloc(nbr_points, sizeof(*grid.num_cells_per_vertex));
grid.cell_to_vertex = NULL;
grid.cell_to_vertex_offsets = NULL;
grid.cell_to_edge = NULL;
grid.cell_to_edge_offsets = NULL;
grid.vertex_to_cell = NULL;
grid.vertex_to_cell_offsets =
xcalloc(nbr_points, sizeof(*grid.vertex_to_cell_offsets));
grid.edge_to_vertex = NULL;
grid.edge_type = NULL;
grid.num_total_cells = 0;
grid.num_total_vertices = nbr_points;
grid.num_total_edges = 0;
return grid;
}
struct yac_basic_grid_data yac_generate_basic_grid_data_cloud(
size_t nbr_points, double *x_points, double *y_points) {
return
yac_generate_basic_grid_data_cloud_(
nbr_points, x_points, y_points, LLtoXYZ);
}
struct yac_basic_grid_data yac_generate_basic_grid_data_cloud_deg(
size_t nbr_points, double *x_points, double *y_points) {
return
yac_generate_basic_grid_data_cloud_(
nbr_points, x_points, y_points, LLtoXYZ_deg);
}
......@@ -267,6 +267,43 @@ static void test_grid_data_3x3(
check_basic_grid_data(grid, ref_grid_data, grid_name);
}
static void test_grid_data_3x3_cloud(
struct yac_basic_grid_data grid, char * grid_name) {
double ref_coords_x[16] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
double ref_coords_y[16] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
double vertex_coordinates[16][3];
for (size_t i = 0; i < 16; ++i)
LLtoXYZ_deg(ref_coords_x[i], ref_coords_y[i], vertex_coordinates[i]);
struct yac_basic_grid_data ref_grid_data = {
.vertex_coordinates = vertex_coordinates,
.cell_ids = NULL,
.vertex_ids = NULL,
.edge_ids = NULL,
.num_cells = 0,
.num_vertices = 16,
.num_edges = 0,
.core_cell_mask = NULL,
.core_vertex_mask = NULL,
.core_edge_mask = NULL,
.num_vertices_per_cell = NULL,
.num_cells_per_vertex = (int[]){0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0},
.cell_to_vertex = NULL,
.cell_to_vertex_offsets = NULL,
.cell_to_edge = NULL,
.cell_to_edge_offsets = NULL,
.vertex_to_cell = NULL,
.vertex_to_cell_offsets = (size_t[]){0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0},
.edge_to_vertex = NULL,
.edge_type = NULL,
.num_total_cells = 0,
.num_total_vertices = 16,
.num_total_edges = 0};
check_basic_grid_data(grid, ref_grid_data, grid_name);
}
static void test_grid_data_3x2(
struct yac_basic_grid_data grid, char * grid_name, enum grid_type type) {
......@@ -1176,6 +1213,39 @@ int main (void) {
(double[]){ 0.5 ,0,-0.5,0,0.5 ,1,1.5,1}, 8);
}
{ // test setting up of unstructured 3x3 grids without cells
size_t num_vertices = 16;
size_t num_cells = 0;
double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
int * num_vertices_per_cell = NULL;
int * cell_to_vertex = NULL;
struct yac_basic_grid_data unstruct_grid =
yac_generate_basic_grid_data_unstruct_deg(
num_vertices, num_cells, num_vertices_per_cell,
coord_x, coord_y, cell_to_vertex);
test_grid_data_3x3_cloud(unstruct_grid, "unstructured 2d grid cloud");
yac_basic_grid_data_free(unstruct_grid);
}
{ // test setting up of unstructured 3x3 grids without cells
size_t num_coords = 16;
double coord_x[] = {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
double coord_y[] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3};
struct yac_basic_grid_data cloud_grid =
yac_generate_basic_grid_data_cloud_deg(num_coords, coord_x, coord_y);
test_grid_data_3x3_cloud(cloud_grid, "cloud 2d grid");
yac_basic_grid_data_free(cloud_grid);
}
return TEST_EXIT_CODE;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment