YAC 3.13.2
Yet Another Coupler
Loading...
Searching...
No Matches
dummy_io_c.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <mpi.h>
6
7#include <stdlib.h>
8#include <stdio.h>
9#include <unistd.h>
10#include <string.h>
11#include "yac.h"
12
17#define NBR_CELLS 2
18#define NBR_VERTICES 4
19#define YAC_RAD (0.01745329251994329576923690768489) // M_PI / 180
20
21#define STR_USAGE "Usage: %s -c configFilename\n"
22#define YAC_ASSERT_ARGS(exp, msg) \
23 { \
24 if(!((exp))) { \
25 fprintf(stderr, "ERROR: %s\n" STR_USAGE, msg, argv[0]); \
26 exit(EXIT_FAILURE); \
27 } \
28 }
29
30static void parse_arguments(
31 int argc, char ** argv, char const ** configFilename);
32
33int main (int argc, char *argv[]) {
34
35 int no_of_fields = 8;
36
37 const char * fieldName[] = { "atmos_out1",
38 "atmos_out2",
39 "atmos_out3",
40 "atmos_out4",
41 "ocean_out1",
42 "ocean_out2",
43 "ocean_out3",
44 "ocean_out4"};
45
46 char * comp_name = "dummy_io";
47
48 char * grid_name[] = { "ocean_grid",
49 "atmos_grid"};
50
51 const int nbr_cells = NBR_CELLS;
52 const int nbr_vertices = NBR_VERTICES;
54
55 int i;
56 int comp_id;
57
58 int cell_point_ids[2];
59
60 int grid_ids[2];
61
64
65 double * buffer_lon;
66 double * buffer_lat;
67 int * cell_to_vertex;
68
69 int * cell_mask;
70 int * field_id;
71
72 MPI_Comm local_comm;
73
74 int size, rank;
75
76 MPI_Init (0, NULL);
77
78 // Initialise the coupler
79 char const * configFilename = "toy_dummy.yaml"; // default configuration file
80 parse_arguments(argc, argv, &configFilename);
81 yac_cinit ();
82 yac_cread_config_yaml(configFilename);
83
84 // Inform the coupler about what we are
85 yac_cdef_comp ( comp_name, &comp_id );
86
87 printf ( "YAC Version %s\n", yac_cget_version() );
88
89 yac_cget_comp_comm ( comp_id, &local_comm );
90
91 MPI_Comm_rank ( local_comm, &rank );
92 MPI_Comm_size ( local_comm, &size );
93
94 printf (" %s rank %d : local size %d \n", comp_name, rank, size );
95
96 /* Here we define two grids (although numerically identical) to mimick
97 two different Output server groups */
98
99 for ( int igrid = 0; igrid < 2; igrid++ ) {
100
101 buffer_lon = malloc ( nbr_vertices * sizeof(*buffer_lon) );
102 buffer_lat = malloc ( nbr_vertices * sizeof(*buffer_lat) );
103 cell_to_vertex = malloc ( 3 * nbr_cells * sizeof(*cell_to_vertex) );
104
105 /* Define vertices
106
107 0
108 / \
109 / o \
110 / \
111 1-------2 Eq.
112 \ /
113 \ o /
114 \ /
115 3
116
117 */
118
119 buffer_lon[0] = 0.0 * YAC_RAD; buffer_lat[0] = 1.1 * YAC_RAD;
120 buffer_lon[1] = -1.0 * YAC_RAD; buffer_lat[1] = 0.0 * YAC_RAD;
121 buffer_lon[2] = 1.0 * YAC_RAD; buffer_lat[2] = 0.0 * YAC_RAD;
122 buffer_lon[3] = 0.0 * YAC_RAD; buffer_lat[3] = -1.0 * YAC_RAD;
123
124 // Connectivity
125
126 cell_to_vertex[0] = 0; cell_to_vertex[1] = 1; cell_to_vertex[2] = 2; // cell 1
127 cell_to_vertex[3] = 1; cell_to_vertex[4] = 3; cell_to_vertex[5] = 2; // cell 2
128
129 for ( i = 0; i < nbr_cells; ++i ) nbr_vertices_per_cell[i] = 3;
130
131 // Define unstructured grid
132
133 yac_cdef_grid_unstruct ( grid_name[igrid],
134 nbr_vertices,
135 nbr_cells,
140 &grid_ids[igrid] );
141
142 // Decomposition information
143
144 for (int i = 0; i < nbr_cells; ++i ) {
145 global_index[i] = i;
146 cell_core_mask[i] = 1;
147 }
148
151
152 // Center points in cells (needed e.g. for nearest neighbour)
153
154 buffer_lon[0] = 0.0 * YAC_RAD; buffer_lat[0] = 0.5 * YAC_RAD;
155 buffer_lon[1] = 0.0 * YAC_RAD; buffer_lat[1] = -0.5 * YAC_RAD;
156
157 yac_cdef_points_unstruct ( grid_ids[igrid],
158 nbr_cells,
162 &cell_point_ids[igrid] );
163
164 free ( buffer_lon );
165 free ( buffer_lat );
166
167 // Mask generation
168
169 cell_mask = malloc (nbr_cells * sizeof(*cell_mask));
170
171 for ( i = 0; i < nbr_cells; ++i )
172 cell_mask[i] = 1;
173
175 cell_point_ids[igrid] );
176
177 free (cell_mask);
178 }
179
180 field_id = malloc ( no_of_fields * sizeof(*field_id));
181
182 // atmosphere output
183
184 for ( i = 0; i < no_of_fields-4; i++ )
186 comp_id,
187 &cell_point_ids[1],
188 1,1,"1",YAC_TIME_UNIT_SECOND,
189 &field_id[i] );
190
191 // ocean output
192
193 for ( i = no_of_fields-4; i < no_of_fields; i++ )
195 comp_id,
196 &cell_point_ids[0],
197 1,1,"1",YAC_TIME_UNIT_SECOND,
198 &field_id[i] );
199
200 yac_cenddef ( );
201
202 yac_cfinalize ();
203
204 MPI_Finalize ();
205
206 return 0;
207}
208
209static void parse_arguments(
210 int argc, char ** argv, char const ** configFilename) {
211
212 int opt;
213 while ((opt = getopt(argc, argv, "c:")) != -1) {
214 YAC_ASSERT_ARGS((opt == 'c'), "invalid command argument")
215 switch (opt) {
216 default:
217 case 'c':
218 *configFilename = optarg;
219 break;
220 }
221 }
222}
#define NBR_CELLS
#define NBR_VERTICES
#define YAC_RAD
const char * fieldName[]
int nbr_vertices_per_cell[NBR_CELLS]
int * cell_to_vertex
int * cell_mask
double * buffer_lat
double * buffer_lon
int cell_point_ids[1]
const int no_of_fields
int * cell_core_mask
int * global_index
int * field_id
int comp_id
static void parse_arguments(int argc, char **argv, enum experiment_type *experiment)
Definition toy_scrip.c:490
#define YAC_ASSERT_ARGS(exp, msg)
Definition toy_scrip.c:145
void yac_cenddef(void)
Definition yac.c:4400
void yac_cset_global_index(int const *global_index, int location, int grid_id)
Definition yac.c:5049
int const YAC_LOCATION_CELL
Definition yac.c:34
void yac_cinit(void)
Definition yac.c:514
void yac_cfinalize()
Finalises YAC.
Definition yac.c:740
void yac_cget_comp_comm(int comp_id, MPI_Comm *comp_comm)
Definition yac.c:856
int const YAC_TIME_UNIT_SECOND
Definition yac.c:59
void yac_cdef_grid_unstruct(const char *grid_name, int nbr_vertices, int nbr_cells, int *num_vertices_per_cell, double *x_vertices, double *y_vertices, int *cell_to_vertex, int *grid_id)
Definition yac.c:4867
void yac_cdef_points_unstruct(int const grid_id, int const nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
Definition yac.c:1181
char * yac_cget_version(void)
Definition yac.c:826
void yac_cread_config_yaml(const char *yaml_filename)
Definition yac.c:595
void yac_cset_core_mask(int const *is_core, int location, int grid_id)
Definition yac.c:5065
void yac_cset_mask(int const *is_valid, int points_id)
Definition yac.c:1304
void yac_cdef_comp(char const *comp_name, int *comp_id)
Definition yac.c:1013
void yac_cdef_field(char const *name, int const comp_id, int const *point_ids, int const num_pointsets, int collection_size, const char *timestep, int time_unit, int *field_id)
Definition yac.c:1396