YAC 3.20.0
Yet Another Coupler
Loading...
Searching...
No Matches
basic_grid.c File Reference
#include <stdio.h>
#include <string.h>
#include <mpi.h>
#include <yaxt.h>
#include "grids/basic_grid.h"
#include "grids/grid_cell.h"
#include "field_data_set.h"
#include "io_utils.h"
#include "yac_mpi_internal.h"
#include "time.h"
#include "yac_config.h"
#include "geometry.h"
#include <netcdf.h>
Include dependency graph for basic_grid.c:

Go to the source code of this file.

Data Structures

struct  yac_basic_grid
 

Functions

struct yac_basic_gridyac_basic_grid_new (char const *name, struct yac_basic_grid_data grid_data)
 
struct yac_basic_gridyac_basic_grid_empty_new (char const *name)
 
void yac_basic_grid_delete (struct yac_basic_grid *grid)
 
yac_const_coordinate_pointer yac_basic_grid_get_field_coordinates (struct yac_basic_grid *grid, struct yac_interp_field field)
 
int const * yac_basic_grid_get_core_mask (struct yac_basic_grid *grid, enum yac_location location)
 
int const * yac_basic_grid_get_field_mask (struct yac_basic_grid *grid, struct yac_interp_field field)
 
char const * yac_basic_grid_get_name (struct yac_basic_grid *grid)
 
struct yac_basic_grid_datayac_basic_grid_get_data (struct yac_basic_grid *grid)
 
size_t yac_basic_grid_get_data_size (struct yac_basic_grid *grid, enum yac_location location)
 
size_t yac_basic_grid_get_data_size_f2c (struct yac_basic_grid *grid, int location)
 
size_t yac_basic_grid_get_named_mask_idx (struct yac_basic_grid *grid, enum yac_location location, char const *mask_name)
 
size_t yac_basic_grid_add_coordinates_nocpy (struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates)
 
size_t yac_basic_grid_add_coordinates_nocpy_f2c (struct yac_basic_grid *grid, int location, double *coordinates)
 
size_t yac_basic_grid_add_coordinates (struct yac_basic_grid *grid, enum yac_location location, yac_coordinate_pointer coordinates, size_t count)
 
size_t yac_basic_grid_add_coordinates_f2c (struct yac_basic_grid *grid, int location, double *coordinates, size_t count)
 
size_t yac_basic_grid_add_mask_nocpy (struct yac_basic_grid *grid, enum yac_location location, int const *mask, char const *mask_name)
 
size_t yac_basic_grid_add_mask_nocpy_f2c (struct yac_basic_grid *grid, int location, int const *mask, char const *mask_name)
 
size_t yac_basic_grid_add_mask (struct yac_basic_grid *grid, enum yac_location location, int const *mask, size_t count, char const *mask_name)
 
size_t yac_basic_grid_add_mask_f2c (struct yac_basic_grid *grid, int location, int const *mask, size_t count, char const *mask_name)
 
struct yac_field_datayac_basic_grid_get_field_data (struct yac_basic_grid *grid, enum yac_location location)
 
struct yac_basic_gridyac_basic_grid_reg_2d_new (char const *name, size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
 
struct yac_basic_gridyac_basic_grid_reg_2d_deg_new (char const *name, size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
 
struct yac_basic_gridyac_basic_grid_curve_2d_new (char const *name, size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
 
struct yac_basic_gridyac_basic_grid_curve_2d_deg_new (char const *name, size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices)
 
struct yac_basic_gridyac_basic_grid_unstruct_new (char const *name, 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_gridyac_basic_grid_unstruct_deg_new (char const *name, 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_gridyac_basic_grid_unstruct_ll_new (char const *name, 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_gridyac_basic_grid_unstruct_ll_deg_new (char const *name, 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_gridyac_basic_grid_unstruct_edge_new (char const *name, 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_gridyac_basic_grid_unstruct_edge_deg_new (char const *name, 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_gridyac_basic_grid_unstruct_edge_ll_new (char const *name, 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_gridyac_basic_grid_unstruct_edge_ll_deg_new (char const *name, 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_gridyac_basic_grid_cloud_new (char const *name, size_t nbr_points, double *x_points, double *y_points)
 
struct yac_basic_gridyac_basic_grid_cloud_deg_new (char const *name, size_t nbr_points, double *x_points, double *y_points)
 
struct yac_basic_gridyac_basic_grid_reg_2d_rot_new (char const *name, size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices, double north_pole_lon, double north_pole_lat)
 
struct yac_basic_gridyac_basic_grid_reg_2d_rot_deg_new (char const *name, size_t nbr_vertices[2], int cyclic[2], double *lon_vertices, double *lat_vertices, double north_pole_lon, double north_pole_lat)
 
static int def_dim (char const *filename, int ncid, char const *name, size_t dim_len, int file_is_new)
 
static void def_var (char const *filename, int ncid, char const *name, nc_type type, int ndims, const int *dimids, char const *att_name, char const *att_value, int file_is_new)
 
static void create_grid_file (char const *filename, char const *grid_name, size_t num_cells, int num_vertices_per_cell, int cell_center_coords_avaiable, int cell_global_ids_available, int core_cell_mask_available, int vertex_global_ids_available, int core_vertex_mask_available, int edge_global_ids_available, int core_edge_mask_available)
 
static void put_vara (int ncid, char const *grid_name, char const *var_ext, size_t *start, size_t *count, void const *buffer)
 
void yac_basic_grid_to_file_parallel (struct yac_basic_grid *grid, char const *filename, MPI_Comm comm)
 
void yac_basic_grid_compute_cell_areas (struct yac_basic_grid *grid, double *cell_areas)
 
static void report_mismatch (const char *grid_name, enum yac_location location, double const *coord, int is_fatal)
 
static void get_grid_cell (struct yac_basic_grid_data const *grid_data, size_t cell_idx, struct yac_grid_cell *buffer_cell)
 
static int check_cell_coords (yac_const_coordinate_pointer coords, struct yac_basic_grid *grid, int is_fatal)
 
static int check_corner_coords (yac_const_coordinate_pointer coords, struct yac_basic_grid *grid, int is_fatal)
 
static int check_edge_coords (yac_const_coordinate_pointer coords, struct yac_basic_grid *grid, int is_fatal)
 
int yac_basic_grid_check_coordinates (struct yac_basic_grid *grid, int fatal)
 

Variables

static struct yac_basic_grid_data yac_basic_grid_data_empty
 

Function Documentation

◆ check_cell_coords()

static int check_cell_coords ( yac_const_coordinate_pointer coords,
struct yac_basic_grid * grid,
int is_fatal )
static

Check CELL point coordinates. Each point coordinate should lie inside the bounding circle of the corresponding cell (the cell bounding circle already includes SIN_COS_TOL slack, added internally by yac_get_cell_bounding_circle).

Definition at line 1340 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_corner_coords()

static int check_corner_coords ( yac_const_coordinate_pointer coords,
struct yac_basic_grid * grid,
int is_fatal )
static

Check CORNER point coordinates. Each coordinate should be identical to the corresponding vertex coordinate within yac_sq_angle_tol.

Definition at line 1388 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_edge_coords()

static int check_edge_coords ( yac_const_coordinate_pointer coords,
struct yac_basic_grid * grid,
int is_fatal )
static

Check EDGE point coordinates. Each coordinate should lie inside the bounding circle whose centre is the normalised midpoint of the edge and whose angular radius equals half the edge length plus SIN_COS_TOL.

Definition at line 1426 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_grid_file()

static void create_grid_file ( char const * filename,
char const * grid_name,
size_t num_cells,
int num_vertices_per_cell,
int cell_center_coords_avaiable,
int cell_global_ids_available,
int core_cell_mask_available,
int vertex_global_ids_available,
int core_vertex_mask_available,
int edge_global_ids_available,
int core_edge_mask_available )
static

Definition at line 598 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ def_dim()

static int def_dim ( char const * filename,
int ncid,
char const * name,
size_t dim_len,
int file_is_new )
static

Definition at line 494 of file basic_grid.c.

Here is the caller graph for this function:

◆ def_var()

static void def_var ( char const * filename,
int ncid,
char const * name,
nc_type type,
int ndims,
const int * dimids,
char const * att_name,
char const * att_value,
int file_is_new )
static

Definition at line 528 of file basic_grid.c.

Here is the caller graph for this function:

◆ get_grid_cell()

static void get_grid_cell ( struct yac_basic_grid_data const * grid_data,
size_t cell_idx,
struct yac_grid_cell * buffer_cell )
static

Definition at line 1301 of file basic_grid.c.

Here is the caller graph for this function:

◆ put_vara()

static void put_vara ( int ncid,
char const * grid_name,
char const * var_ext,
size_t * start,
size_t * count,
void const * buffer )
static

Definition at line 724 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ report_mismatch()

static void report_mismatch ( const char * grid_name,
enum yac_location location,
double const * coord,
int is_fatal )
static

Emit mismatch message. If is_fatal is non-zero the function aborts via YAC_ASSERT_F, otherwise it writes a warning to stderr and returns.

Definition at line 1277 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_add_coordinates()

size_t yac_basic_grid_add_coordinates ( struct yac_basic_grid * grid,
enum yac_location location,
yac_coordinate_pointer coordinates,
size_t count )

Definition at line 222 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_add_coordinates_f2c()

size_t yac_basic_grid_add_coordinates_f2c ( struct yac_basic_grid * grid,
int location,
double * coordinates,
size_t count )

Definition at line 234 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_add_coordinates_nocpy()

size_t yac_basic_grid_add_coordinates_nocpy ( struct yac_basic_grid * grid,
enum yac_location location,
yac_coordinate_pointer coordinates )

Definition at line 202 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_add_coordinates_nocpy_f2c()

size_t yac_basic_grid_add_coordinates_nocpy_f2c ( struct yac_basic_grid * grid,
int location,
double * coordinates )

Definition at line 214 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_add_mask()

size_t yac_basic_grid_add_mask ( struct yac_basic_grid * grid,
enum yac_location location,
int const * mask,
size_t count,
char const * mask_name )

Definition at line 266 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_add_mask_f2c()

size_t yac_basic_grid_add_mask_f2c ( struct yac_basic_grid * grid,
int location,
int const * mask,
size_t count,
char const * mask_name )

Definition at line 278 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_add_mask_nocpy()

size_t yac_basic_grid_add_mask_nocpy ( struct yac_basic_grid * grid,
enum yac_location location,
int const * mask,
char const * mask_name )

Definition at line 244 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_add_mask_nocpy_f2c()

size_t yac_basic_grid_add_mask_nocpy_f2c ( struct yac_basic_grid * grid,
int location,
int const * mask,
char const * mask_name )

Definition at line 257 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_check_coordinates()

int yac_basic_grid_check_coordinates ( struct yac_basic_grid * grid,
int fatal )

Definition at line 1480 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_cloud_deg_new()

struct yac_basic_grid * yac_basic_grid_cloud_deg_new ( char const * name,
size_t nbr_points,
double * x_points,
double * y_points )

Definition at line 457 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_cloud_new()

struct yac_basic_grid * yac_basic_grid_cloud_new ( char const * name,
size_t nbr_points,
double * x_points,
double * y_points )

Definition at line 448 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_compute_cell_areas()

void yac_basic_grid_compute_cell_areas ( struct yac_basic_grid * grid,
double * cell_areas )

Definition at line 1264 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_curve_2d_deg_new()

struct yac_basic_grid * yac_basic_grid_curve_2d_deg_new ( char const * name,
size_t nbr_vertices[2],
int cyclic[2],
double * lon_vertices,
double * lat_vertices )

Definition at line 333 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_curve_2d_new()

struct yac_basic_grid * yac_basic_grid_curve_2d_new ( char const * name,
size_t nbr_vertices[2],
int cyclic[2],
double * lon_vertices,
double * lat_vertices )

Definition at line 322 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_delete()

void yac_basic_grid_delete ( struct yac_basic_grid * grid)

Definition at line 77 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_empty_new()

struct yac_basic_grid * yac_basic_grid_empty_new ( char const * name)

Definition at line 70 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_get_core_mask()

int const * yac_basic_grid_get_core_mask ( struct yac_basic_grid * grid,
enum yac_location location )

Definition at line 104 of file basic_grid.c.

Here is the caller graph for this function:

◆ yac_basic_grid_get_data()

struct yac_basic_grid_data * yac_basic_grid_get_data ( struct yac_basic_grid * grid)

Definition at line 137 of file basic_grid.c.

Here is the caller graph for this function:

◆ yac_basic_grid_get_data_size()

size_t yac_basic_grid_get_data_size ( struct yac_basic_grid * grid,
enum yac_location location )

Definition at line 145 of file basic_grid.c.

Here is the caller graph for this function:

◆ yac_basic_grid_get_data_size_f2c()

size_t yac_basic_grid_get_data_size_f2c ( struct yac_basic_grid * grid,
int location )

Definition at line 165 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_get_field_coordinates()

yac_const_coordinate_pointer yac_basic_grid_get_field_coordinates ( struct yac_basic_grid * grid,
struct yac_interp_field field )

Definition at line 86 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_get_field_data()

struct yac_field_data * yac_basic_grid_get_field_data ( struct yac_basic_grid * grid,
enum yac_location location )

Definition at line 287 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_get_field_mask()

int const * yac_basic_grid_get_field_mask ( struct yac_basic_grid * grid,
struct yac_interp_field field )

Definition at line 120 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_get_name()

char const * yac_basic_grid_get_name ( struct yac_basic_grid * grid)

Definition at line 130 of file basic_grid.c.

Here is the caller graph for this function:

◆ yac_basic_grid_get_named_mask_idx()

size_t yac_basic_grid_get_named_mask_idx ( struct yac_basic_grid * grid,
enum yac_location location,
char const * mask_name )

Definition at line 172 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_new()

struct yac_basic_grid * yac_basic_grid_new ( char const * name,
struct yac_basic_grid_data grid_data )

Definition at line 57 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_reg_2d_deg_new()

struct yac_basic_grid * yac_basic_grid_reg_2d_deg_new ( char const * name,
size_t nbr_vertices[2],
int cyclic[2],
double * lon_vertices,
double * lat_vertices )

Definition at line 311 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_reg_2d_new()

struct yac_basic_grid * yac_basic_grid_reg_2d_new ( char const * name,
size_t nbr_vertices[2],
int cyclic[2],
double * lon_vertices,
double * lat_vertices )

Definition at line 300 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_reg_2d_rot_deg_new()

struct yac_basic_grid * yac_basic_grid_reg_2d_rot_deg_new ( char const * name,
size_t nbr_vertices[2],
int cyclic[2],
double * lon_vertices,
double * lat_vertices,
double north_pole_lon,
double north_pole_lat )

Definition at line 479 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_reg_2d_rot_new()

struct yac_basic_grid * yac_basic_grid_reg_2d_rot_new ( char const * name,
size_t nbr_vertices[2],
int cyclic[2],
double * lon_vertices,
double * lat_vertices,
double north_pole_lon,
double north_pole_lat )

Definition at line 466 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_to_file_parallel()

void yac_basic_grid_to_file_parallel ( struct yac_basic_grid * grid,
char const * filename,
MPI_Comm comm )

Definition at line 747 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_unstruct_deg_new()

struct yac_basic_grid * yac_basic_grid_unstruct_deg_new ( char const * name,
size_t nbr_vertices,
size_t nbr_cells,
int * num_vertices_per_cell,
double * x_vertices,
double * y_vertices,
int * cell_to_vertex )

Definition at line 357 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_unstruct_edge_deg_new()

struct yac_basic_grid * yac_basic_grid_unstruct_edge_deg_new ( char const * name,
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 )

Definition at line 409 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_unstruct_edge_ll_deg_new()

struct yac_basic_grid * yac_basic_grid_unstruct_edge_ll_deg_new ( char const * name,
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 )

Definition at line 435 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_unstruct_edge_ll_new()

struct yac_basic_grid * yac_basic_grid_unstruct_edge_ll_new ( char const * name,
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 )

Definition at line 422 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_unstruct_edge_new()

struct yac_basic_grid * yac_basic_grid_unstruct_edge_new ( char const * name,
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 )

Definition at line 396 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_unstruct_ll_deg_new()

struct yac_basic_grid * yac_basic_grid_unstruct_ll_deg_new ( char const * name,
size_t nbr_vertices,
size_t nbr_cells,
int * num_vertices_per_cell,
double * x_vertices,
double * y_vertices,
int * cell_to_vertex )

Definition at line 383 of file basic_grid.c.

Here is the call graph for this function:

◆ yac_basic_grid_unstruct_ll_new()

struct yac_basic_grid * yac_basic_grid_unstruct_ll_new ( char const * name,
size_t nbr_vertices,
size_t nbr_cells,
int * num_vertices_per_cell,
double * x_vertices,
double * y_vertices,
int * cell_to_vertex )

Definition at line 370 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_basic_grid_unstruct_new()

struct yac_basic_grid * yac_basic_grid_unstruct_new ( char const * name,
size_t nbr_vertices,
size_t nbr_cells,
int * num_vertices_per_cell,
double * x_vertices,
double * y_vertices,
int * cell_to_vertex )

Definition at line 344 of file basic_grid.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ yac_basic_grid_data_empty

struct yac_basic_grid_data yac_basic_grid_data_empty
static
Initial value:
= {
.vertex_coordinates = NULL,
.cell_ids = NULL,
.vertex_ids = NULL,
.edge_ids = NULL,
.num_cells = 0,
.num_vertices = 0,
.num_edges = 0,
.core_cell_mask = NULL,
.core_vertex_mask = NULL,
.core_edge_mask = NULL,
.num_vertices_per_cell = NULL,
.num_cells_per_vertex = NULL,
.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 = NULL,
.edge_to_vertex = NULL,
.edge_type = NULL,
.num_total_cells = 0,
.num_total_vertices = 0,
.num_total_edges = 0
}

Definition at line 31 of file basic_grid.c.