YAC 3.21.0
Yet Another Coupler
Loading...
Searching...
No Matches
yac.pyx
Go to the documentation of this file.
1# Copyright (c) 2024 The YAC Authors
2#
3# SPDX-License-Identifier: BSD-3-Clause
4
5import cython
6import sys
7import traceback
8from enum import Enum
9import numpy as _np
10import logging
11from types import coroutine
12from dataclasses import dataclass, field
13
14from libc.stdlib cimport malloc, free
15
16cdef import from "<mpi.h>" nogil:
17 ctypedef struct _mpi_comm_t
18 ctypedef _mpi_comm_t* MPI_Comm
19 int MPI_Comm_c2f(MPI_Comm)
20 MPI_Comm MPI_Comm_f2c(int)
21 MPI_Comm MPI_COMM_WORLD
22
23cdef extern from "Python.h":
24 int Py_AtExit(void (*)())
25
26cdef extern from "yac.h":
27 # Import yac_int as an integer type (actual size determined by YAC_INT configuration)
28 ctypedef long long yac_int
29
30 cdef const int _LOCATION_CELL "YAC_LOCATION_CELL"
31 cdef const int _LOCATION_CORNER "YAC_LOCATION_CORNER"
32 cdef const int _LOCATION_EDGE "YAC_LOCATION_EDGE"
33
34 cdef const int _EXCHANGE_TYPE_NONE "YAC_EXCHANGE_TYPE_NONE"
35 cdef const int _EXCHANGE_TYPE_SOURCE "YAC_EXCHANGE_TYPE_SOURCE"
36 cdef const int _EXCHANGE_TYPE_TARGET "YAC_EXCHANGE_TYPE_TARGET"
37
38 cdef const int _ACTION_NONE "YAC_ACTION_NONE"
39 cdef const int _ACTION_REDUCTION "YAC_ACTION_REDUCTION"
40 cdef const int _ACTION_COUPLING "YAC_ACTION_COUPLING"
41 cdef const int _ACTION_GET_FOR_RESTART "YAC_ACTION_GET_FOR_RESTART"
42 cdef const int _ACTION_PUT_FOR_RESTART "YAC_ACTION_PUT_FOR_RESTART"
43 cdef const int _ACTION_OUT_OF_BOUND "YAC_ACTION_OUT_OF_BOUND"
44
45 cdef const int _REDUCTION_TIME_NONE "YAC_REDUCTION_TIME_NONE"
46 cdef const int _REDUCTION_TIME_ACCUMULATE "YAC_REDUCTION_TIME_ACCUMULATE"
47 cdef const int _REDUCTION_TIME_AVERAGE "YAC_REDUCTION_TIME_AVERAGE"
48 cdef const int _REDUCTION_TIME_MINIMUM "YAC_REDUCTION_TIME_MINIMUM"
49 cdef const int _REDUCTION_TIME_MAXIMUM "YAC_REDUCTION_TIME_MAXIMUM"
50
51 cdef const int _CALENDAR_NOT_SET "YAC_CALENDAR_NOT_SET"
52 cdef const int _PROLEPTIC_GREGORIAN "YAC_PROLEPTIC_GREGORIAN"
53 cdef const int _YEAR_OF_365_DAYS "YAC_YEAR_OF_365_DAYS"
54 cdef const int _YEAR_OF_360_DAYS "YAC_YEAR_OF_360_DAYS"
55
56 cdef const int _TIME_UNIT_MILLISECOND "YAC_TIME_UNIT_MILLISECOND"
57 cdef const int _TIME_UNIT_SECOND "YAC_TIME_UNIT_SECOND"
58 cdef const int _TIME_UNIT_MINUTE "YAC_TIME_UNIT_MINUTE"
59 cdef const int _TIME_UNIT_HOUR "YAC_TIME_UNIT_HOUR"
60 cdef const int _TIME_UNIT_DAY "YAC_TIME_UNIT_DAY"
61 cdef const int _TIME_UNIT_MONTH "YAC_TIME_UNIT_MONTH"
62 cdef const int _TIME_UNIT_YEAR "YAC_TIME_UNIT_YEAR"
63 cdef const int _TIME_UNIT_ISO_FORMAT "YAC_TIME_UNIT_ISO_FORMAT"
64
65 cdef const int _AVG_ARITHMETIC "YAC_AVG_ARITHMETIC"
66 cdef const int _AVG_DIST "YAC_AVG_DIST"
67 cdef const int _AVG_BARY "YAC_AVG_BARY"
68
69 cdef const int _NCC_AVG "YAC_NCC_AVG"
70 cdef const int _NCC_DIST "YAC_NCC_DIST"
71
72 cdef const int _NNN_AVG "YAC_NNN_AVG"
73 cdef const int _NNN_DIST "YAC_NNN_DIST"
74 cdef const int _NNN_GAUSS "YAC_NNN_GAUSS"
75 cdef const int _NNN_RBF "YAC_NNN_RBF"
76
77 cdef const int _DNN_AVG "YAC_DNN_AVG"
78 cdef const int _DNN_DIST "YAC_DNN_DIST"
79 cdef const int _DNN_GAUSS "YAC_DNN_GAUSS"
80 cdef const int _DNN_RBF "YAC_DNN_RBF"
81
82 cdef const int _DNN_SEARCH_DISTANCE_FIXED "YAC_DNN_SEARCH_DISTANCE_FIXED"
83 cdef const int _DNN_SEARCH_DISTANCE_CELL_AREA "YAC_DNN_SEARCH_DISTANCE_CELL_AREA"
84
85 cdef const int _CONSERV_DESTAREA "YAC_CONSERV_DESTAREA"
86 cdef const int _CONSERV_FRACAREA "YAC_CONSERV_FRACAREA"
87
88 cdef const int _SPMAP_AVG "YAC_SPMAP_AVG"
89 cdef const int _SPMAP_DIST "YAC_SPMAP_DIST"
90
91 cdef const int _SPMAP_NONE "YAC_SPMAP_NONE"
92 cdef const int _SPMAP_SRCAREA "YAC_SPMAP_SRCAREA"
93 cdef const int _SPMAP_INVTGTAREA "YAC_SPMAP_INVTGTAREA"
94 cdef const int _SPMAP_FRACAREA "YAC_SPMAP_FRACAREA"
95
96 cdef const int _FILE_MISSING_ERROR "YAC_FILE_MISSING_ERROR"
97 cdef const int _FILE_MISSING_CONT "YAC_FILE_MISSING_CONT"
98
99 cdef const int _FILE_SUCCESS_STOP "YAC_FILE_SUCCESS_STOP"
100 cdef const int _FILE_SUCCESS_CONT "YAC_FILE_SUCCESS_CONT"
101
102 cdef const int _CONFIG_OUTPUT_FORMAT_YAML "YAC_CONFIG_OUTPUT_FORMAT_YAML"
103 cdef const int _CONFIG_OUTPUT_FORMAT_JSON "YAC_CONFIG_OUTPUT_FORMAT_JSON"
104
105 cdef const int _CONFIG_OUTPUT_SYNC_LOC_DEF_COMP "YAC_CONFIG_OUTPUT_SYNC_LOC_DEF_COMP"
106 cdef const int _CONFIG_OUTPUT_SYNC_LOC_SYNC_DEF "YAC_CONFIG_OUTPUT_SYNC_LOC_SYNC_DEF"
107 cdef const int _CONFIG_OUTPUT_SYNC_LOC_ENDDEF "YAC_CONFIG_OUTPUT_SYNC_LOC_ENDDEF"
108
109 cdef const int _WGT_ON_EXISTING_ERROR "YAC_WGT_ON_EXISTING_ERROR"
110 cdef const int _WGT_ON_EXISTING_KEEP "YAC_WGT_ON_EXISTING_KEEP"
111 cdef const int _WGT_ON_EXISTING_OVERWRITE "YAC_WGT_ON_EXISTING_OVERWRITE"
112
113 void yac_cinit ()
114 void yac_cinit_instance ( int * yac_instance_id )
115 void yac_cinit_comm (MPI_Comm comm )
116 void yac_cinit_comm_instance (MPI_Comm comm, int * yac_instance_id )
119 void yac_ccleanup_instance (int yac_instance_id)
120 void yac_cdef_comp_instance ( int yac_instance_id,
121 const char * comp_name,
122 int * comp_id )
123 void yac_cdef_comps_instance ( int yac_instance_id,
124 const char ** comp_names,
125 int num_comps,
126 int * comp_ids )
127 void yac_cpredef_comp_instance ( int yac_instance_id,
128 const char * comp_name,
129 int * comp_id )
130 void yac_cget_comp_comm ( int comp_id, MPI_Comm* comp_comm )
131 void yac_cdef_datetime_instance ( int yac_instance_id,
132 const char * start_datetime,
133 const char * end_datetime )
134 void yac_cget_comps_comm_instance( int yac_instance_id,
135 const char ** comp_names,
136 int num_comps,
137 MPI_Comm * comps_comm)
138 void yac_cdef_calendar ( int calendar )
139 int yac_cget_calendar ( )
140 void yac_cenddef_instance ( int yac_instance_id )
141 int yac_cget_nbr_comps_instance ( int yac_instance_id )
142 int yac_cget_nbr_grids_instance ( int yac_instance_id )
143 int yac_cget_comp_nbr_grids_instance ( int yac_instance_id, const char* comp_name )
144 int yac_cget_nbr_fields_instance ( int yac_instance_id, const char * comp_name,
145 const char* grid_name)
146 void yac_cget_comp_names_instance ( int yac_instance_id, int nbr_comps,
147 const char ** comp_names )
148 void yac_cget_grid_names_instance ( int yac_instance_id, int nbr_grids,
149 const char ** grid_names )
150 void yac_cget_comp_grid_names_instance ( int yac_instance_id, const char* comp_name,
151 int nbr_grids, const char ** grid_names )
152 void yac_cget_field_names_instance ( int yac_instance_id, const char* comp_name,
153 const char* grid_name,
154 int nbr_fields, const char ** field_names )
155 int yac_cget_comp_id_instance ( int yac_instance_id,
156 const char* comp_name )
157 int yac_cget_grid_id ( const char* grid_name )
158 int yac_cget_points_id ( int grid_id,
159 int location,
160 const char* point_name )
161 int yac_cget_mask_id ( int grid_id,
162 int location,
163 const char* mask_name )
164 int yac_cget_field_is_defined_instance ( int yac_instance_id, const char* comp_name,
165 const char* grid_name,
166 const char* field_name )
167 int yac_cget_field_id_instance ( int yac_instance_id, const char* comp_name,
168 const char* grid_name,
169 const char * field_name )
170 const char* yac_cget_field_timestep_instance ( int yac_instance_id, const char* comp_name,
171 const char* grid_name,
172 const char * field_name )
173 int yac_cget_field_role_instance ( int yac_instance_id, const char* comp_name,
174 const char* grid_name, const char* field_name )
175 void yac_cget_field_source_instance ( int yac_instance_id, const char* tgt_comp_name,
176 const char* tgt_grid_name, const char* tgt_field_name,
177 const char** src_comp_name, const char** src_grid_name,
178 const char** src_field_name)
179 void yac_cenable_field_frac_mask_instance ( int yac_instance_id,
180 const char* comp_name,
181 const char* grid_name,
182 const char * field_name,
183 double frac_mask_fallback_value)
184 int yac_cget_field_collection_size_instance ( int yac_instance_id,
185 const char* comp_name,
186 const char* grid_name,
187 const char * field_name )
188 double yac_cget_field_frac_mask_fallback_value_instance ( int yac_instance_id,
189 const char* comp_name,
190 const char* grid_name,
191 const char * field_name )
192 void yac_cdef_component_metadata_instance ( int yac_instance_id,
193 const char* comp_name,
194 const char* metadata)
195 void yac_cdef_grid_metadata_instance ( int yac_instance_id,
196 const char* grid_name,
197 const char* metadata)
198 void yac_cdef_field_metadata_instance ( int yac_instance_id,
199 const char* comp_name,
200 const char* grid_name,
201 const char* field_name,
202 const char* metadata)
203 const char* yac_cget_component_metadata_instance(int yac_instance_id,
204 const char* comp_name)
205 const char* yac_cget_grid_metadata_instance(int yac_instance_id,
206 const char* grid_name)
207 const char* yac_cget_field_metadata_instance(int yac_instance_id,
208 const char* comp_name,
209 const char* grid_name,
210 const char* field_name)
211 char * yac_cget_start_datetime_instance ( int yac_instance_id )
212 char * yac_cget_end_datetime_instance ( int yac_instance_id )
213 char * yac_cget_version ()
214 const char * yac_cget_mpi_handshake_group_name ()
215 void yac_cdef_grid_reg2d ( const char * grid_name,
216 int nbr_vertices[2],
217 int cyclic[2],
218 double *x_vertices,
219 double *y_vertices,
220 int *grid_id)
221 void yac_cdef_points_reg2d_named ( const int grid_id,
222 int nbr_points[2],
223 const int location,
224 const double *x_points,
225 const double *y_points,
226 const char * name,
227 int *point_id )
228 void yac_cdef_grid_reg2d_rot ( const char * grid_name,
229 int nbr_vertices[2],
230 int cyclic[2],
231 double *x_vertices,
232 double *y_vertices,
233 double x_north_pole,
234 double y_north_pole,
235 int *grid_id)
236 void yac_cdef_points_reg2d_rot_named ( const int grid_id,
237 int nbr_points[2],
238 const int location,
239 const double *x_points,
240 const double *y_points,
241 double x_north_pole,
242 double y_north_pole,
243 const char * name,
244 int *point_id )
245 void yac_cdef_grid_curve2d ( const char * grid_name,
246 int nbr_vertices[2],
247 int cyclic[2],
248 double *x_vertices,
249 double *y_vertices,
250 int *grid_id)
251 void yac_cdef_points_curve2d_named ( const int grid_id,
252 int nbr_points[2],
253 const int location,
254 const double *x_points,
255 const double *y_points,
256 const char * name,
257 int *point_id )
258 void yac_cdef_grid_cloud ( const char * grid_name,
259 int nbr_points,
260 double *x_points,
261 double *y_points,
262 int *grid_id)
263 void yac_cdef_grid_unstruct ( const char * grid_name,
264 int nbr_vertices,
265 int nbr_cells,
266 int *num_vertices_per_cell,
267 double *x_vertices,
268 double *y_vertices,
269 int *cell_to_vertex,
270 int *grid_id)
271 void yac_cdef_grid_unstruct_ll ( const char * grid_name,
272 int nbr_vertices,
273 int nbr_cells,
274 int *num_vertices_per_cell,
275 double *x_vertices,
276 double *y_vertices,
277 int *cell_to_vertex,
278 int *grid_id)
279 void yac_cdef_grid_unstruct_edge ( const char * grid_name,
280 int nbr_vertices,
281 int nbr_cells,
282 int nbr_edges,
283 int *num_edges_per_cell,
284 double *x_vertices,
285 double *y_vertices,
286 int *cell_to_edge,
287 int *edge_to_vertex,
288 int *grid_id)
289 void yac_cdef_grid_unstruct_edge_ll ( const char * grid_name,
290 int nbr_vertices,
291 int nbr_cells,
292 int nbr_edges,
293 int *num_edges_per_cell,
294 double *x_vertices,
295 double *y_vertices,
296 int *cell_to_edge,
297 int *edge_to_vertex,
298 int *grid_id)
299 void yac_cdef_points_unstruct_named ( const int grid_id,
300 const int nbr_points,
301 const int location,
302 const double *x_points,
303 const double *y_points,
304 const char * name,
305 int *point_id )
306 void yac_cset_global_index_yac_int ( const yac_int * global_index,
307 int location,
308 int grid_id)
309 void yac_cdef_field ( const char * field_name,
310 const int component_id,
311 const int * point_ids,
312 const int num_pointsets,
313 int collection_size,
314 const char* timestep,
315 int timeunit,
316 int * field_id )
317 void yac_cdef_field_mask ( const char * field_name,
318 const int component_id,
319 const int * point_ids,
320 const int * mask_ids,
321 const int num_pointsets,
322 int collection_size,
323 const char* timestep,
324 int timeunit,
325 int * field_id )
326 void yac_csync_def_instance ( int yac_instance_id )
327 void yac_csync_def_comps_instance ( int yac_instance_id,
328 const char ** comp_names,
329 int num_comp_names )
330 void yac_cget_ext_couple_config(int * ext_couple_config_id)
331 void yac_cset_ext_couple_config_weight_file(int ext_couple_config_id,
332 const char * weight_file)
334 int ext_couple_config_id, int weight_file_on_existing)
335 void yac_cset_ext_couple_config_mapping_side(int ext_couple_config_id,
336 int mapping_side)
337 void yac_cset_ext_couple_config_scale_factor(int ext_couple_config_id,
338 double scale_factor)
339 void yac_cset_ext_couple_config_scale_summand(int ext_couple_config_id,
340 double scale_summand)
342 int ext_couple_config_id, size_t num_src_mask_names,
343 const char * const * src_mask_names)
345 int ext_couple_config_id, const char * tgt_mask_name)
347 int ext_couple_config_id, const char * yaxt_exchanger_name)
349 int ext_couple_config_id,
350 int collection_size,
351 const int * collection_indices);
353 int ext_couple_config_id, int use_raw_exchange);
354 void yac_cfree_ext_couple_config(int ext_couple_config_id)
355 void yac_cdef_couple_custom_instance(int yac_instance_id,
356 const char * src_comp_name,
357 const char * src_grid_name,
358 const char * src_field_name,
359 const char * tgt_comp_name,
360 const char * tgt_grid_name,
361 const char * tgt_field_name,
362 const char * coupling_timestep,
363 int time_unit, int time_reduction,
364 int interp_stack_config_id,
365 int src_lag, int tgt_lag,
366 int ext_couple_config_id)
367 void yac_cget_ ( const int field_id,
368 const int collection_size,
369 double *recv_field,
370 int *info,
371 int *ierror ) nogil
372 void yac_cget_async_ ( const int field_id,
373 const int collection_size,
374 double *recv_field,
375 int *info,
376 int *ierror )
377 void yac_cput_ ( const int field_id,
378 const int collection_size,
379 double * send_field,
380 int *info,
381 int *ierror ) nogil
382 void yac_cput_frac_ ( const int field_id,
383 const int collection_size,
384 double *send_field,
385 double *send_frac_mask,
386 int *info,
387 int *ierr ) nogil
388 void yac_cget_raw_ ( const int field_id,
389 const int collection_size,
390 double *src_field_buffer,
391 int *info,
392 int *ierror ) nogil
393 void yac_cget_raw_async_ ( const int field_id,
394 const int collection_size,
395 double *src_field_buffer,
396 int *info,
397 int *ierror )
398 void yac_cget_raw_frac_ ( const int field_id,
399 const int collection_size,
400 double *src_field_buffer,
401 double *src_frac_mask_buffer,
402 int *info,
403 int *ierror ) nogil
404 void yac_cget_raw_frac_async_ ( const int field_id,
405 const int collection_size,
406 double *src_field_buffer,
407 double *src_frac_mask_buffer,
408 int *info,
409 int *ierror )
410 void yac_cexchange_ ( const int send_field_id,
411 const int recv_field_id,
412 const int collection_size,
413 double *send_field ,
414 double *recv_field,
415 int *send_info,
416 int *recv_info,
417 int *ierror ) nogil
418 void yac_cexchange_frac_ ( const int send_field_id,
419 const int recv_field_id,
420 const int collection_size,
421 double *send_field,
422 double *send_frac_mask,
423 double *recv_field,
424 int *send_info,
425 int *recv_info,
426 int *ierror ) nogil
427 void yac_ctest ( int field_id, int * flag )
428 void yac_cwait ( int field_id ) nogil
429 void yac_cupdate( int field_id )
430 const char* yac_cget_field_name_from_field_id ( int field_id )
431 const char* yac_cget_component_name_from_field_id ( int field_id )
432 const char* yac_cget_grid_name_from_field_id ( int field_id )
433 int yac_cget_role_from_field_id ( int field_id )
434 const char* yac_cget_timestep_from_field_id ( int field_id )
435 size_t yac_cget_grid_size ( int location, int grid_id )
436 size_t yac_cget_points_size ( int points_id )
437 int yac_cget_collection_size_from_field_id ( const int field_id )
438 const char* yac_cget_field_datetime(int field_id)
439 void yac_cget_interp_stack_config(int * interp_stack_config_id)
441 int interp_stack_config_id, int reduction_type, int partial_coverage)
443 int interp_stack_config_id, int weight_type, int partial_coverage)
444 void yac_cadd_interp_stack_config_nnn(int interp_stack_config_id, int type,
445 size_t n,
446 double max_search_distance,
447 double scale)
448 void yac_cadd_interp_stack_config_dnn(int interp_stack_config_id, int type,
449 int search_distance_type,
450 double search_distance,
451 double scale)
452 void yac_cadd_interp_stack_config_rbf(int interp_stack_config_id,
453 size_t n,
454 double max_search_distance,
455 double scale)
457 int interp_stack_config_id, int order, int enforced_conserv,
458 int partial_coverage, int normalisation)
460 int interp_stack_config_id, double spread_distance,
461 double max_search_distance, int weight_type, int scale_type,
462 double src_sphere_radius, char * src_filename,
463 char * src_varname, int src_min_global_id,
464 double tgt_sphere_radius, char * tgt_filename,
465 char * tgt_varname, int tgt_min_global_id)
466 void yac_cadd_interp_stack_config_hcsbb(int interp_stack_config_id)
468 int interp_stack_config_id, char * filename,
469 int on_missing_file, int on_success)
471 int interp_stack_config_id, double value)
473 int interp_stack_config_id, char * constructor_key, char * do_search_key)
475 int interp_stack_config_id, int creep_distance)
476 void yac_cget_interp_stack_config_from_string_yaml(char * interp_stack_config,
477 int * interp_stack_config_id)
478 void yac_cget_interp_stack_config_from_string_json(char * interp_stack_config,
479 int * interp_stack_config_id)
480 void yac_cfree_interp_stack_config(int interp_stack_config_id)
481 void yac_cset_core_mask ( const int * is_core,
482 int location,
483 int grid_id)
484 void yac_cset_mask ( const int * is_valid,
485 int points_id )
486 void yac_cdef_mask_named ( const int grid_id,
487 const int nbr_points,
488 const int location,
489 const int * is_valid,
490 const char * name,
491 int *mask_id )
492 void yac_cfinalize()
493 ctypedef void (*yac_abort_func)(MPI_Comm comm, const char *msg,
494 const char *source, int line) except *
495 void yac_set_abort_handler(yac_abort_func custom_abort)
496 yac_abort_func yac_get_abort_handler()
497 void yac_cread_config_yaml_instance( int yac_instance_id,
498 const char * yaml_file)
499 void yac_cget_action( int field_id, int* action)
500 void yac_cset_config_output_file_instance( int yac_instance_id,
501 const char * filename,
502 int fileformat,
503 int sync_location,
504 int include_definitions);
505 void yac_cset_grid_output_file_instance( int yac_instance_id,
506 const char * gridname,
507 const char * filename);
508 void yac_cset_grids_output_file_instance( int yac_instance_id,
509 const char * filename);
510 void yac_cset_coordinates_check_instance( int yac_instance_id,
511 int apply_check);
513 int is_fatal);
514 void yac_ccompute_grid_cell_areas(int grid_id, double* cell_areas);
515 void yac_cget_raw_interp_weights_data ( const int field_id,
516 double * frac_mask_fallback_value,
517 double * scaling_factor,
518 double * scaling_summand,
519 size_t * num_fixed_values,
520 double ** fixed_values,
521 size_t ** num_tgt_per_fixed_value,
522 size_t ** tgt_idx_fixed,
523 size_t * num_wgt_tgt,
524 size_t ** wgt_tgt_idx,
525 size_t ** num_src_per_tgt,
526 double ** weights,
527 size_t ** src_field_idx,
528 size_t ** src_idx,
529 size_t * num_src_fields,
530 size_t ** src_field_buffer_sizes );
531 void yac_cget_raw_interp_weights_data_csr ( const int field_id,
532 double * frac_mask_fallback_value,
533 double * scaling_factor,
534 double * scaling_summand,
535 size_t * num_fixed_values,
536 double ** fixed_values,
537 size_t ** num_tgt_per_fixed_value,
538 size_t ** tgt_idx_fixed,
539 size_t ** src_indptr,
540 double ** weights,
541 size_t ** src_field_idx,
542 size_t ** src_idx,
543 size_t * num_src_fields,
544 size_t ** src_field_buffer_sizes );
545
546
547# helper functions for py interface (not in yac_interface.h)
548cdef extern void yac_cget_comp_size_c2py(int comp_id, int* size)
549cdef extern void yac_cget_comp_rank_c2py(int comp_id, int* rank)
550cdef extern void yac_cget_instance_size_c2py(int comp_id, int* size)
551cdef extern void yac_cget_instance_rank_c2py(int comp_id, int* rank)
552
553_logger = logging.getLogger("yac")
554_logger.addHandler(logging.NullHandler())
555
556class Location(Enum):
557 """
558 Location for points
559
560 Refers to @ref YAC_LOCATION_CELL, @ref YAC_LOCATION_CORNER and @ref YAC_LOCATION_EDGE
561 """
562 CELL = _LOCATION_CELL
563 CORNER = _LOCATION_CORNER
564 EDGE = _LOCATION_EDGE
565
566class ExchangeType(Enum):
567 """
568 Exchange type of a field
569
570 Refers to @ref YAC_EXCHANGE_TYPE_NONE, @ref YAC_EXCHANGE_TYPE_SOURCE and @ref YAC_EXCHANGE_TYPE_TARGET
571 """
572 NONE = _EXCHANGE_TYPE_NONE
573 SOURCE = _EXCHANGE_TYPE_SOURCE
574 TARGET = _EXCHANGE_TYPE_TARGET
575
576class Action(Enum):
577 """
578 Refers to @ref YAC_ACTION_NONE, @ref YAC_ACTION_REDUCTION etc.
579 """
580 NONE = _ACTION_NONE
581 REDUCTION = _ACTION_REDUCTION
582 COUPLING = _ACTION_COUPLING
583 GET_FOR_RESTART = _ACTION_GET_FOR_RESTART
584 PUT_FOR_RESTART = _ACTION_PUT_FOR_RESTART
585 OUT_OF_BOUND = _ACTION_OUT_OF_BOUND
586
587class Reduction(Enum):
588 """
589 Reduction type for the definition of interpolations
590
591 Refers to @ref YAC_REDUCTION_TIME_NONE, @ref YAC_REDUCTION_TIME_ACCUMULATE etc.
592 """
593 TIME_NONE = _REDUCTION_TIME_NONE
594 TIME_ACCUMULATE = _REDUCTION_TIME_ACCUMULATE
595 TIME_AVERAGE = _REDUCTION_TIME_AVERAGE
596 TIME_MINIMUM = _REDUCTION_TIME_MINIMUM
597 TIME_MAXIMUM = _REDUCTION_TIME_MAXIMUM
598
599class Calendar(Enum):
600 """
601 Calendar type for use in def_calendar
602
603 Refers to @ref YAC_CALENDAR_NOT_SET, @ref YAC_PROLEPTIC_GREGORIAN etc.
604 """
605 CALENDAR_NOT_SET = _CALENDAR_NOT_SET
606 PROLEPTIC_GREGORIAN = _PROLEPTIC_GREGORIAN
607 YEAR_OF_365_DAYS = _YEAR_OF_365_DAYS
608 YEAR_OF_360_DAYS = _YEAR_OF_360_DAYS
609
610def def_calendar(calendar : Calendar):
611 """
612 @see yac_cdef_calendar
613 """
614 yac_cdef_calendar(Calendar(calendar).value)
615
617 """
618 @see yac_cget_calendar
619 """
621
622
623class TimeUnit(Enum):
624 """
625 Refers to @ref YAC_TIME_UNIT_MILLISECOND, @ref YAC_TIME_UNIT_SECOND etc.
626 """
627 MILLISECOND = _TIME_UNIT_MILLISECOND
628 SECOND = _TIME_UNIT_SECOND
629 MINUTE = _TIME_UNIT_MINUTE
630 HOUR = _TIME_UNIT_HOUR
631 DAY = _TIME_UNIT_DAY
632 MONTH = _TIME_UNIT_MONTH
633 YEAR = _TIME_UNIT_YEAR
634 ISO_FORMAT = _TIME_UNIT_ISO_FORMAT
635
637 """
638 Reduction type for average interpolation
639
640 Refers to @ref YAC_AVG_ARITHMETIC, @ref YAC_AVG_DIST and @ref YAC_AVG_BARY
641 """
642 AVG_ARITHMETIC = _AVG_ARITHMETIC
643 AVG_DIST = _AVG_DIST
644 AVG_BARY = _AVG_BARY
645
647 """
648 Reduction type for ncc interpolation
649
650 Refers to @ref YAC_NCC_AVG and @ref YAC_NCC_DIST
651 """
652 AVG = _NCC_AVG
653 DIST = _NCC_DIST
654
656 """
657 Reduction type for nnn interpolation
658
659 Refers to @ref YAC_NNN_AVG, @ref YAC_NNN_DIST etc.
660 """
661 AVG = _NNN_AVG
662 DIST = _NNN_DIST
663 GAUSS = _NNN_GAUSS
664 RBF = _NNN_RBF
665
667 """
668 Reduction type for dnn interpolation
669
670 Refers to @ref YAC_DNN_AVG, @ref YAC_DNN_DIST, @ref YAC_DNN_GAUSS,
671 and @ref YAC_DNN_RBF
672 """
673 AVG = _DNN_AVG
674 DIST = _DNN_DIST
675 GAUSS = _DNN_GAUSS
676 RBF = _DNN_RBF
677
679 """
680 Search distance type for dnn interpolation
681
682 Refers to @ref YAC_DNN_SEARCH_DISTANCE_FIXED and
683 @ref YAC_DNN_SEARCH_DISTANCE_CELL_AREA
684 """
685 FIXED = _DNN_SEARCH_DISTANCE_FIXED
686 CELL_AREA = _DNN_SEARCH_DISTANCE_CELL_AREA
687
689 """
690 Normalization type for conservative interpolation
691
692 Refers to @ref YAC_CONSERV_DESTAREA and @ref YAC_CONSERV_FRACAREA
693 """
694 DESTAREA = _CONSERV_DESTAREA
695 FRACAREA = _CONSERV_FRACAREA
696
697class SPMAPWeightType(Enum):
698 """
699 Refers to @ref YAC_SPMAP_AVG and @ref YAC_SPMAP_DIST
700 """
701 AVG = _SPMAP_AVG
702 DIST = _SPMAP_DIST
703
704class SPMAPScaleType(Enum):
705 """
706 Refers to @ref YAC_SPMAP_NONE, @ref YAC_SPMAP_SRCAREA
707 @ref YAC_SPMAP_INVTGTAREA, and @ref YAC_SPMAP_FRACAREA
708 """
709 NONE = _SPMAP_NONE
710 SRCAREA = _SPMAP_SRCAREA
711 INVTGTAREA = _SPMAP_INVTGTAREA
712 FRACAREA = _SPMAP_FRACAREA
713
715 """
716 Refers to @ref YAC_FILE_MISSING_ERROR, @ref YAC_FILE_MISSING_CONT
717 """
718 ERROR = _FILE_MISSING_ERROR # abort on missing file
719 CONT = _FILE_MISSING_CONT # continue on missing file
720
722 """
723 Refers to @ref YAC_FILE_SUCCESS_STOP, @ref YAC_FILE_SUCCESS_CONT
724 """
725 STOP = _FILE_SUCCESS_STOP # prevents following interpolation method from computating further weights
726 CONT = _FILE_SUCCESS_CONT # continue weight computation with following interpolation methods
727
729 YAML = _CONFIG_OUTPUT_FORMAT_YAML
730 JSON = _CONFIG_OUTPUT_FORMAT_JSON
731
733 DEF_COMP = _CONFIG_OUTPUT_SYNC_LOC_DEF_COMP # after component definition
734 SYNC_DEF = _CONFIG_OUTPUT_SYNC_LOC_SYNC_DEF # after synchronization of definition
735 ENDDEF = _CONFIG_OUTPUT_SYNC_LOC_ENDDEF # after end of definitions
736
738 """
739 Handling of existing files, if weight file is to be written
740
741 Refers to @ref YAC_WGT_ON_EXISTING_ERROR, @ref YAC_WGT_ON_EXISTING_KEEP and
742 @ref YAC_WGT_ON_EXISTING_OVERWRITE
743 """
744 ERROR = _WGT_ON_EXISTING_ERROR # generate error and abort if file with
745 # same name already exists
746 KEEP = _WGT_ON_EXISTING_KEEP # keep existing file
747 OVERWRITE = _WGT_ON_EXISTING_OVERWRITE # overwrite existing file
748
749# replaces @classmethod @property (removed in Python 3.13)
750# see https://stackoverflow.com/questions/1697501/staticmethod-with-property
752 def __get__(self, cls, owner):
753 return classmethod(self.fget).__get__(None, owner)()
754
755class YAC:
756 """
757 Initializies a YAC instance and provides further functionality
758
759 The destructor finalizes the YAC instance by calling yac_cfinalize_instance
760 """
761 def __init__(self, comm = None, default_instance = False):
762 """
763 @see yac_cinit_instance
764 """
765 cdef int instance_id
766 cdef MPI_Comm c_comm
767 if comm is None:
768 if default_instance:
769 _logger.debug("init")
770 yac_cinit()
771 assert(YAC.default_instance_id_defined)
772 instance_id = yac_cget_default_instance_id()
773 else:
774 _logger.debug("init_instance")
775 yac_cinit_instance(&instance_id)
776 else:
777 from mpi4py import MPI
778 if type(comm) is MPI.Intracomm:
779 comm = MPI.Comm.py2f(comm)
780 if default_instance:
781 _logger.debug("init_comm")
782 yac_cinit_comm(MPI_Comm_f2c(comm))
783 assert(YAC.default_instance_id_defined)
784 instance_id = yac_cget_default_instance_id()
785 else:
786 _logger.debug("init_comm_instance")
787 yac_cinit_comm_instance(MPI_Comm_f2c(comm), &instance_id)
788 _logger.debug(f"instance_id={instance_id}")
789 self.instance_id = instance_id
790 self.owned_instance = True
791
792 @_classproperty
794 """
795 @return True if default_instance_id is defined
796 """
798
799 @_classproperty
801 """
802 @see yac_cget_default_instance_id
803
804 @return Default instance if exists, None if no default instance exists
805 """
808 else:
809 return None # cannot raise Exception here because this would break auto-completion
810
811 @classmethod
812 def from_id(cls, id):
813 yac = cls.__new__(cls)
814 yac.instance_id = id
815 yac.owned_instance = False
816 return yac
817
818 def __del__(self):
819 self.cleanup()
820
821 def cleanup(self):
822 """
823 @see yac_ccleanup_instance
824 """
825 if self.owned_instance:
826 if _logger is not None: # might already be deconstructed
827 _logger.debug(f"cleanup instance_id={self.instance_id}")
829 self.owned_instance = False
830
831 @property
832 def size(self):
833 """
834 number of processes in this instance
835 """
836 cdef int size
838 return size
839
840 @property
841 def rank(self):
842 """
843 process index in this instance
844 """
845 cdef int rank
847 return rank
848
849 def def_comp(self, comp_name : str):
850 """
851 @see yac_cdef_comp_instance
852 """
853 cdef int comp_id
854 _logger.debug(f"def_comp: comp_name={comp_name}")
855 yac_cdef_comp_instance(self.instance_id, comp_name.encode(), &comp_id)
856 _logger.debug(f"comp_id={comp_id}")
857 return Component(comp_id)
858
859 def def_comps(self, comp_names = []):
860 """
861 @see yac_cdef_comps_instance
862 """
863 cdef int comp_len = len(comp_names)
864 cdef const char **c_comp_names = <const char **>malloc(comp_len * sizeof(const char *))
865 cdef int *c_comp_ids = <int*>malloc(comp_len * sizeof(int))
866 _logger.debug(f"def_comps: comp_names={comp_names}")
867 byte_comp_names = [c.encode() for c in comp_names]
868 for i in range(comp_len):
869 c_comp_names[i] = byte_comp_names[i]
870 yac_cdef_comps_instance(self.instance_id, c_comp_names, comp_len, c_comp_ids)
871 comp_list = [Component(c_comp_ids[i]) for i in range(comp_len) ]
872 free(c_comp_names)
873 free(c_comp_ids)
874 _logger.debug("comp_list={comp_list}")
875 return comp_list
876
877 def predef_comp(self, comp_name :str):
878 """
879 @see yac_cpredef_comp_instance
880 """
881 cdef int comp_id
882 _logger.debug(f"predef_comp: comp_name={comp_name}")
883 yac_cpredef_comp_instance(self.instance_id, comp_name.encode(), &comp_id)
884 _logger.debug("comp_id={comp_id}")
885 return Component(comp_id)
886
887 def def_datetime(self, start_datetime, end_datetime):
888 """
889 @see yac_cdef_datetime_instance
890
891 The parameters can be given either as a string in iso8601
892 format or as datetime objects
893
894 Datetimes are interpreted with UTC semantics and are stored without a
895 timezone offset. If no time zone is provided, UTC is assumed.
896 Explicitly specifying UTC as `Z` or `+00:00` is allowed; using other
897 time zones than UTC is not supported and will lead to an error.
898 """
899 try:
900 import datetime
901 if(type(start_datetime) is datetime.datetime):
902 start_datetime = start_datetime.isoformat()
903 except:
904 pass
905 if start_datetime is not None:
906 _logger.debug(f"def_datetime start: {start_datetime}")
907 yac_cdef_datetime_instance ( self.instance_id,
908 start_datetime.encode(),
909 NULL)
910
911 try:
912 if(type(end_datetime) is datetime.datetime):
913 end_datetime = end_datetime.isoformat()
914 except:
915 pass
916 if end_datetime is not None:
917 _logger.debug(f"def_datetime end: {end_datetime}")
918 yac_cdef_datetime_instance ( self.instance_id,
919 NULL,
920 end_datetime.encode())
921
922 @property
923 def start_datetime(self):
924 """
925 @see yac_cget_start_datetime_instance (`datetime.datetime`, read-only).
926 """
927 cdef const char * start = yac_cget_start_datetime_instance(self.instance_id)
928 return bytes(start).decode('UTF-8')
929
930 @property
931 def end_datetime(self):
932 """
933 @see yac_cget_end_datetime_instance (`datetime.datetime`, read-only).
934 """
935 cdef const char * end = yac_cget_end_datetime_instance(self.instance_id)
936 return bytes(end).decode('UTF-8')
937
938 def sync_def(self):
939 """
940 @see yac_csync_def_instance
941 """
942 _logger.debug("sync_def")
944
945 def sync_def_comps(self, comp_names : list):
946 """
947 @see yac_csync_def_comps_instance
948 """
949 _logger.debug(f"sync_def_comps: comp_names={comp_names}")
950 cptr = [c.encode() for c in comp_names]
951 cdef const char ** comp_names_c_ptr = <const char **>malloc(len(comp_names) * sizeof(const char *))
952 for i in range(len(comp_names)):
953 comp_names_c_ptr[i] = cptr[i]
954 yac_csync_def_comps_instance(self.instance_id, comp_names_c_ptr, len(comp_names))
955 free(comp_names_c_ptr)
956
957 def def_couple(self,
958 src_comp : str, src_grid : str, src_field,
959 tgt_comp : str, tgt_grid : str, tgt_field,
960 coupling_timestep : str, timeunit : TimeUnit,
961 time_reduction : Reduction,
962 interp_stack, src_lag = 0, tgt_lag = 0,
963 weight_file = None,
964 weight_file_on_existing : WeightFileOnExisting =
965 WeightFileOnExisting.OVERWRITE,
966 mapping_on_source = 1,
967 scale_factor = 1.0, scale_summand = 0.0,
968 src_masks_names = None, tgt_mask_name = None,
969 yaxt_exchanger_name = None,
970 collection_selection = None,
971 use_raw_exchange = False):
972 """
973 @see yac_cdef_couple_instance
974 """
975 cdef char * weight_file_ptr
976 if weight_file is None:
977 weight_file_ptr = NULL
978 else:
979 weight_file_bytes = weight_file.encode()
980 weight_file_ptr = weight_file_bytes
981 cdef const char ** src_mask_names_ptr = NULL
982 cdef const char * tgt_mask_name_ptr = NULL
983 cdef const char * yaxt_exchanger_name_ptr = NULL
984 cdef int couple_config_id
985 cdef const int[::1] collection_selection_view
986 yac_cget_ext_couple_config(&couple_config_id)
988 weight_file_ptr)
990 couple_config_id,
991 WeightFileOnExisting(weight_file_on_existing).value)
993 mapping_on_source)
995 scale_factor)
997 scale_summand)
998 if src_masks_names is not None:
999 if type(src_masks_names) is str:
1000 src_masks = [src_masks_names]
1001 src_masks_enc = [s.encode() for s in src_masks_names]
1002 src_mask_names_ptr = <const char **>malloc(len(src_masks_enc) * sizeof(char*))
1003 for i in range(len(src_masks_enc)):
1004 src_mask_names_ptr[i] = src_masks_enc[i]
1006 len(src_masks_enc),
1007 src_mask_names_ptr)
1008 free(src_mask_names_ptr)
1009 if tgt_mask_name is not None:
1010 yac_cset_ext_couple_config_tgt_mask_name(couple_config_id, tgt_mask_name.encode())
1011 if yaxt_exchanger_name is not None:
1012 yac_cset_ext_couple_config_yaxt_exchanger_name(couple_config_id, yaxt_exchanger_name.encode())
1013 if collection_selection is not None:
1014 collection_selection_view = _np.ascontiguousarray(collection_selection, dtype=_np.intc)
1016 len(collection_selection),
1017 &collection_selection_view[0])
1018 yac_cset_ext_couple_config_use_raw_exchange(couple_config_id, 1 if use_raw_exchange else 0)
1019 _logger.debug(f"def_couple {(src_comp.encode(), src_grid.encode(), src_field.encode())}, {(tgt_comp.encode(), tgt_grid.encode(), tgt_field.encode())}")
1021 src_comp.encode(), src_grid.encode(), src_field.encode(),
1022 tgt_comp.encode(), tgt_grid.encode(), tgt_field.encode(),
1023 coupling_timestep.encode(), TimeUnit(timeunit).value,
1024 Reduction(time_reduction).value,
1025 interp_stack.interp_stack_id, src_lag, tgt_lag,
1026 couple_config_id)
1027 yac_cfree_ext_couple_config(couple_config_id)
1028
1029 def enddef(self):
1030 """
1031 @see yac_cenddef_instance
1032 """
1033 _logger.debug("enddef")
1035
1036 def get_component(self, comp_name : str):
1037 """
1038 @see yac_cget_comp_id_instance
1039 """
1040 return Component(yac_cget_comp_id_instance(self.instance_id, comp_name.encode()))
1041
1042 def get_grid(self, grid_name : str):
1043 """
1044 @see yac_cget_grid_id
1045 """
1046 return Grid(yac_cget_grid_id(grid_name.encode()))
1047
1048 @property
1050 """
1051 @see yac_cget_comp_names
1052 """
1053 cdef int nbr_components = yac_cget_nbr_comps_instance(self.instance_id)
1054 cdef const char **ret = <const char **>malloc(nbr_components * sizeof(const char *))
1055 yac_cget_comp_names_instance(self.instance_id, nbr_components, ret)
1056 comp_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_components)]
1057 free(ret)
1058 return comp_list
1059
1060 @property
1061 def grid_names(self):
1062 """
1063 @see yac_cget_grid_names
1064 """
1065 cdef int nbr_grids = yac_cget_nbr_grids_instance(self.instance_id)
1066 cdef const char **ret = <const char **>malloc(nbr_grids * sizeof(const char *))
1067 yac_cget_grid_names_instance(self.instance_id, nbr_grids, ret)
1068 grid_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_grids)]
1069 free(ret)
1070 return grid_list
1071
1072 def get_comp_grid_names(self, comp_name):
1073 """
1074 @see yac_cget_comp_grid_names
1075 """
1076 cdef int nbr_grids = yac_cget_comp_nbr_grids_instance(self.instance_id, comp_name.encode())
1077 cdef const char **ret = <const char **>malloc(nbr_grids * sizeof(const char *))
1078 yac_cget_comp_grid_names_instance(self.instance_id, comp_name.encode(), nbr_grids, ret)
1079 grid_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_grids)]
1080 free(ret)
1081 return grid_list
1082
1083 def get_field_names(self, comp_name : str, grid_name : str):
1084 """
1085 @see yac_cget_field_names
1086 """
1087 cdef int nbr_fields = yac_cget_nbr_fields_instance(self.instance_id,
1088 comp_name.encode(),
1089 grid_name.encode())
1090 cdef const char **ret = <const char **>malloc(nbr_fields * sizeof(const char *))
1091 yac_cget_field_names_instance(self.instance_id, comp_name.encode(),
1092 grid_name.encode(), nbr_fields, ret)
1093 field_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_fields)]
1094 free(ret)
1095 return field_list
1096
1097 def get_field_is_defined(self, comp_name : str, grid_name : str, field_name : str):
1098 """
1099 @see yac_cget_field_is_defined
1100 """
1101 return yac_cget_field_is_defined_instance (self.instance_id,
1102 comp_name.encode(),
1103 grid_name.encode(),
1104 field_name.encode()) != 0
1105
1106 def get_field_id(self, comp_name : str, grid_name : str, field_name : str):
1107 """
1108 @see yac_cget_field_id
1109 """
1110 return yac_cget_field_id_instance (self.instance_id,
1111 comp_name.encode(),
1112 grid_name.encode(),
1113 field_name.encode())
1114
1115 def get_field(self, comp_name : str, grid_name : str, field_name : str):
1116 """
1117 @see yac_cget_field_id
1118 """
1119 return Field(yac_cget_field_id_instance (self.instance_id,
1120 comp_name.encode(),
1121 grid_name.encode(),
1122 field_name.encode()))
1123
1124 def get_field_timestep(self, comp_name : str, grid_name : str, field_name : str):
1125 """
1126 @see yac_cget_field_timestep
1127 """
1128 cdef const char* timestep = yac_cget_field_timestep_instance(self.instance_id,
1129 comp_name.encode(),
1130 grid_name.encode(),
1131 field_name.encode())
1132 return bytes(timestep).decode('UTF-8') if timestep != NULL else None
1133
1134 def get_field_role(self, comp_name : str, grid_name : str, field_name : str):
1135 """
1136 @see yac_cget_field_role
1137 """
1138 return ExchangeType(yac_cget_field_role_instance (self.instance_id,
1139 comp_name.encode(),
1140 grid_name.encode(),
1141 field_name.encode()))
1142
1143 def get_field_source(self, comp_name : str, grid_name : str,
1144 field_name : str):
1145 cdef const char* src_comp
1146 cdef const char* src_grid
1147 cdef const char* src_field
1149 comp_name.encode(),
1150 grid_name.encode(),
1151 field_name.encode(),
1152 &src_comp,
1153 &src_grid,
1154 &src_field)
1155 return (bytes(src_comp).decode("UTF-8"),
1156 bytes(src_grid).decode("UTF-8"),
1157 bytes(src_field).decode("UTF-8"))
1158
1159 def get_field_collection_size(self, comp_name : str, grid_name : str, field_name : str):
1160 """
1161 @see yac_cget_field_collection_size
1162
1163 @retval int the collection size, if defined for this field
1164 @retval None if no collection size is defined for this field
1165 """
1166 cdef int collection_size = yac_cget_field_collection_size_instance(
1167 self.instance_id,
1168 comp_name.encode(),
1169 grid_name.encode(),
1170 field_name.encode())
1171 return None if collection_size == -1 else collection_size
1172
1173 def get_field_frac_mask_fallback_value(self, comp_name : str, grid_name : str, field_name : str):
1174 """
1175 @see yac_cget_field_frac_mask_fallback_value
1176 """
1178 comp_name.encode(),
1179 grid_name.encode(),
1180 field_name.encode())
1181
1182 def enable_field_frac_mask(self, comp_name : str, grid_name : str, field_name : str,
1183 frac_mask_fallback_value : _np.float64):
1184 """
1185 @see yac_cenable_field_frac_mask
1186 """
1187 _logger.debug(f"enable_field_frac_mask {(comp_name, grid_name, field_name)})")
1189 comp_name.encode(),
1190 grid_name.encode(),
1191 field_name.encode(),
1192 frac_mask_fallback_value)
1193
1194 def def_component_metadata(self, comp_name : str, metadata : bytes):
1195 """
1196 @see yac_cdef_component_metadata
1197 """
1198 _logger.debug(f"def_component_metadata comp_name={comp_name}")
1200 comp_name.encode(), metadata)
1201
1202 def def_grid_metadata(self, grid_name : str, metadata : bytes):
1203 """
1204 @see yac_cdef_grid_metadata
1205 """
1206 _logger.debug(f"def_grid_metadata grid_name={grid_name}")
1208 grid_name.encode(), metadata)
1209
1210 def def_field_metadata(self, comp_name : str, grid_name : str,
1211 field_name : str,metadata : bytes):
1212 """
1213 @see yac_cdef_field_metadata
1214 """
1215 _logger.debug("def_field_metadata (comp_name, grid_name, field_name)="
1216 f"{(comp_name, grid_name, field_name)}")
1217 yac_cdef_field_metadata_instance(self.instance_id, comp_name.encode(),
1218 grid_name.encode(), field_name.encode(),
1219 metadata)
1220
1221 def get_component_metadata(self, comp_name : str):
1222 """
1223 @see yac_cget_component_metadata
1224 """
1225 cdef const char* metadata = yac_cget_component_metadata_instance(self.instance_id,
1226 comp_name.encode())
1227 return bytes(metadata).decode('UTF-8') if metadata != NULL else None
1228
1229 def get_grid_metadata(self, grid_name : str):
1230 """
1231 @see yac_cget_grid_metadata
1232 """
1233 cdef const char* metadata = yac_cget_grid_metadata_instance(self.instance_id,
1234 grid_name.encode())
1235 return bytes(metadata).decode('UTF-8') if metadata != NULL else None
1236
1237 def get_field_metadata(self, comp_name : str, grid_name : str, field_name :str):
1238 """
1239 @see yac_cget_field_metadata
1240 """
1241 cdef const char* metadata = yac_cget_field_metadata_instance(self.instance_id,
1242 comp_name.encode(),
1243 grid_name.encode(),
1244 field_name.encode())
1245 return bytes(metadata).decode('UTF-8') if metadata != NULL else None
1246
1247 def get_comps_comm(self, comp_names):
1248 """
1249 @see yac_cget_comps_comm
1250 """
1251 from mpi4py import MPI
1252 cdef MPI_Comm comm
1253 cptr = [c.encode() for c in comp_names]
1254 cdef const char ** comp_names_c_ptr = <const char **>malloc(len(comp_names) * sizeof(const char *))
1255 for i in range(len(comp_names)):
1256 comp_names_c_ptr[i] = cptr[i]
1257 yac_cget_comps_comm_instance(self.instance_id, comp_names_c_ptr, len(comp_names), &comm)
1258 free(comp_names_c_ptr)
1259 # convert to mpi4py communicator
1260 return MPI.Comm.f2py(MPI_Comm_c2f(comm))
1261
1262 def read_config_yaml(self, yaml_file : str):
1263 """
1264 @see yac_cread_config_yaml_instance
1265 """
1266 _logger.debug(f"read_config_yaml yaml_file={yaml_file}")
1267 yac_cread_config_yaml_instance(self.instance_id, yaml_file.encode())
1268
1269 def set_config_output_file(self, filename : str,
1270 fileformat : ConfigOutputFormat,
1271 sync_location : ConfigOutputSyncLoc,
1272 include_definitions : bool = False):
1273 """
1274 @see yac_cset_config_output_file_instance
1275 """
1277 filename.encode(),
1278 fileformat.value,
1279 sync_location.value,
1280 1 if include_definitions else 0)
1281
1282 def set_grid_output_file(self, gridname : str, filename : str):
1283 """
1284 @see yac_cset_grid_output_file_instance
1285 """
1287 gridname.encode(),
1288 filename.encode())
1289
1290 def set_grids_output_file(self, filename : str):
1291 """
1292 @see yac_cset_grids_output_file_instance
1293 """
1295 filename.encode())
1296
1297 def set_coordinates_check(self, check_coordinates : bool):
1298 """
1299 @see yac_cset_coordinates_check_instance
1300 """
1302 1 if check_coordinates else 0)
1303
1304 def set_coordinates_mismatch_is_fatal(self, mismatch_is_fatal : bool):
1305 """
1306 @see yac_cset_coordinates_mismatch_is_fatal_instance
1307 """
1309 1 if mismatch_is_fatal else 0)
1310
1312 """
1313 Stores the component_id and provides further functionality
1314 """
1315 def __init__(self, comp_id):
1316 self.comp_id = comp_id
1317
1318 @property
1319 def comp_comm(self):
1320 """
1321 @see yac_cget_comp_comm (`MPI.Comm`, read-only)
1322 """
1323 from mpi4py import MPI
1324 cdef MPI_Comm comm
1325 yac_cget_comp_comm(self.comp_id, &comm)
1326 # convert to mpi4py communicator
1327 return MPI.Comm.f2py(MPI_Comm_c2f(comm))
1328
1329 @property
1330 def size(self):
1331 """
1332 number of processes in this component
1333 """
1334 cdef int size
1335 yac_cget_comp_size_c2py(self.comp_id, &size)
1336 return size
1337
1338 @property
1339 def rank(self):
1340 """
1341 process index in the component
1342 """
1343 cdef int rank
1344 yac_cget_comp_rank_c2py(self.comp_id, &rank)
1345 return rank
1346
1347class Mask:
1348 """
1349 Stores the mask_id
1350 """
1351 def __init__(self, mask_id):
1352 self.mask_id = mask_id
1353
1354class Grid:
1355 """
1356 Stores the grid_id and provides further functionality
1357
1358 Base class for Reg2dGrid and UnstructuredGrid
1359 """
1360 def __init__(self, grid_id):
1361 _logger.debug(f"grid_id={grid_id}")
1362 self.grid_id = grid_id
1363
1364 def set_global_index(self, global_index, location : Location):
1365 """
1366 Set global indices for grid points using yac_int type.
1367 Accepts integer arrays and automatically converts to the appropriate type.
1368
1369 @see yac_cset_global_index_yac_int
1370 @see yac_cset_global_index
1371 """
1372 # Declare all cdef variables at function start
1373 cdef size_t yac_int_size
1374 cdef size_t expected_size
1375 cdef const int[::1] global_index_view32
1376 cdef const long long[::1] global_index_view64
1377
1378 global_index_arr = _np.asarray(global_index)
1379
1380 # Check expected size
1381 expected_size = yac_cget_grid_size(location.value, self.grid_id)
1382 assert <size_t>len(global_index_arr) == expected_size, \
1383 f"Wrong number of indices provided: expected {expected_size}, got {len(global_index_arr)}"
1384
1385 # Convert to appropriate dtype based on yac_int size
1386 # yac_int can be int (4 bytes), long (4 or 8 bytes), or long long (8 bytes)
1387 yac_int_size = sizeof(yac_int)
1388
1389 if yac_int_size == 4:
1390 # yac_int is 32-bit
1391 global_index_view32 = _np.ascontiguousarray(
1392 global_index_arr, dtype=_np.int32)
1393 _logger.debug(f"set_global_index grid_id={self.grid_id} (yac_int: 32-bit)")
1394 yac_cset_global_index_yac_int(<yac_int*>&global_index_view32[0],
1395 location.value, self.grid_id)
1396 elif yac_int_size == 8:
1397 # yac_int is 64-bit
1398 global_index_view64 = _np.ascontiguousarray(
1399 global_index_arr, dtype=_np.int64)
1400 _logger.debug(f"set_global_index grid_id={self.grid_id} (yac_int: 64-bit)")
1401 yac_cset_global_index_yac_int(<yac_int*>&global_index_view64[0],
1402 location.value, self.grid_id)
1403 else:
1404 raise RuntimeError(f"Unsupported yac_int size: {yac_int_size} bytes")
1405
1406 def get_points(self,
1407 location : Location,
1408 point_name : str):
1409 """
1410 @see yac_cget_points_id
1411 """
1412 return Points(yac_cget_points_id(self.grid_id,
1413 location.value,
1414 point_name.encode()))
1415
1416 def get_mask(self,
1417 location : Location,
1418 mask_name : str):
1419 """
1420 @see yac_cget_mask_id
1421 """
1422 return Mask(yac_cget_mask_id(self.grid_id,
1423 location.value,
1424 mask_name.encode()))
1425
1426 @property
1427 def nbr_cells(self):
1428 """
1429 @see yac_cget_grid_size (`int`, read-only)
1430 """
1431 return yac_cget_grid_size ( Location.CELL.value, self.grid_id )
1432
1433 @property
1434 def nbr_corners(self):
1435 """
1436 @see yac_cget_grid_size (`int`, read-only)
1437 """
1438 return yac_cget_grid_size ( Location.CORNER.value, self.grid_id )
1439
1440 @property
1441 def nbr_edges(self):
1442 """
1443 @see yac_cget_grid_size (`int`, read-only)
1444 """
1445 return yac_cget_grid_size ( Location.EDGE.value, self.grid_id )
1446
1447 def set_core_mask(self, is_core, location : Location):
1448 """
1449 @see yac_cset_core_mask
1450 """
1451 cdef size_t len_is_core = len(is_core)
1452 assert(len_is_core == yac_cget_grid_size( location.value, self.grid_id ) )
1453 cdef const int[::1] np_mask = _np.ascontiguousarray(is_core, dtype=_np.intc)
1454 _logger.debug(f"set_core_mask grid_id={self.grid_id}")
1455 yac_cset_core_mask ( &np_mask[0], location.value, self.grid_id)
1456
1457 def def_mask(self, location : Location,
1458 is_valid, name = None):
1459 cdef int len_is_valid = len(is_valid)
1460 cdef const int[::1] np_mask = _np.ascontiguousarray(is_valid, dtype=_np.int32)
1461 cdef int mask_id
1462 cdef char* c_name = NULL
1463 if name is not None:
1464 name_enc = name.encode()
1465 c_name = name_enc
1466 _logger.debug(f"def_mask_named grid_id={self.grid_id}, name={name}")
1467 yac_cdef_mask_named ( self.grid_id,
1468 len_is_valid,
1469 location.value,
1470 &np_mask[0],
1471 c_name,
1472 &mask_id )
1473 return Mask(mask_id)
1474
1475 def compute_grid_cell_areas(self, cell_areas = None):
1476 """
1477 @see yac_ccompute_grid_cell_areas
1478 """
1479 if cell_areas is None:
1480 cell_areas = _np.empty(self.nbr_cells)
1481 cdef double[::1] np_cell_areas = _np.ascontiguousarray(cell_areas, dtype=_np.double)
1482 yac_ccompute_grid_cell_areas(self.grid_id, &np_cell_areas[0])
1483 return cell_areas
1484
1486 """
1487 Stores the points_id and provides further functionality
1488 """
1489 def __init__(self, points_id):
1490 self.points_id = points_id
1491
1492 @property
1493 def size(self):
1494 """
1495 @see yac_cget_points_size (`int`, read-only)
1496 """
1497 return yac_cget_points_size ( self.points_id )
1498
1499 def set_mask(self, is_valid):
1500 """
1501 @see yac_cset_mask
1502 """
1503 cdef size_t len_is_valid = len(is_valid)
1504 assert len_is_valid==self.size
1505 cdef const int[::1] np_mask = _np.ascontiguousarray(is_valid, dtype=_np.intc)
1506 _logger.debug(f"set_mask points_id={self.points_id}")
1507 yac_cset_mask ( &np_mask[0],
1508 self.points_id )
1509
1511 """
1512 A stuctured 2d Grid
1513 """
1514 def __init__(self, grid_name : str, x_vertices, y_vertices,
1515 cyclic = [False, False], north_pole = None):
1516 """
1517 @see yac_cdef_grid_reg2d
1518 """
1519 cdef int grid_id
1520 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1521 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1522 cdef int[2] cyclic_view = cyclic
1523 cdef const double[::1] n_p
1524 self.north_pole = north_pole
1525 if north_pole is None:
1526 _logger.debug(f"def_grid_reg2d grid_name={grid_name}")
1527 yac_cdef_grid_reg2d(grid_name.encode(), [len(x),len(y)],
1528 cyclic_view, <double*>&x[0], <double*>&y[0],
1529 &grid_id)
1530 else:
1531 n_p = _np.ascontiguousarray(north_pole, dtype=_np.double)
1532 _logger.debug(f"def_grid_reg2d_rot grid_name={grid_name}")
1533 yac_cdef_grid_reg2d_rot(grid_name.encode(), [len(x),len(y)],
1534 cyclic_view, <double*>&x[0], <double*>&y[0],
1535 n_p[0], n_p[1], &grid_id)
1536 super().__init__(grid_id)
1537
1538 def def_points(self, location : Location,
1539 x_vertices, y_vertices, name = None):
1540 """
1541 @see yac_cdef_points_reg2d_named
1542 """
1543 cdef int points_id
1544 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1545 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1546 cdef const double[::1] n_p
1547 cdef char* c_name = NULL
1548 if name is not None:
1549 name_enc = name.encode()
1550 c_name = name_enc
1551 if self.north_pole is None:
1552 _logger.debug(f"def_points_reg2d_named grid_id={self.grid_id}, name={name}")
1554 location.value, &x[0], &y[0], c_name,
1555 &points_id)
1556 else:
1557 n_p = _np.ascontiguousarray(self.north_pole, dtype=_np.double)
1558 _logger.debug(f"def_points_reg2d_rot_named grid_id={self.grid_id}, name={name}")
1559 yac_cdef_points_reg2d_rot_named(self.grid_idgrid_id, [len(x), len(y)],
1560 location.value, &x[0], &y[0],
1561 n_p[0], n_p[1], c_name,
1562 &points_id)
1563 _logger.debug(f"points_id={points_id}")
1564 return Points(points_id)
1565
1566 def def_points_unstruct(self, location : Location,
1567 x_vertices, y_vertices, name = None):
1568 """
1569 @see yac_cdef_points_unstruct_named
1570 """
1571 assert len(x_vertices) == len(y_vertices)
1572 cdef int points_id
1573 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1574 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1575 cdef char* c_name = NULL
1576 if name is not None:
1577 name_enc = name.encode()
1578 c_name = name_enc
1579 _logger.debug(f"def_points_unstruct_named grid_id={self.grid_id}, name={name}")
1581 location.value, &x[0], &y[0], c_name,
1582 &points_id)
1583 _logger.debug(f"points_id={points_id}")
1584 return Points(points_id)
1585
1587 """
1588 A curvilinear stuctured 2d Grid
1589 """
1590 def __init__(self, grid_name : str, x_vertices, y_vertices,
1591 cyclic = [False, False]):
1592 """
1593 @see yac_cdef_grid_curve2d
1594 """
1595 cdef int grid_id
1596 cdef const double[::1] x = _np.ascontiguousarray(x_vertices.flatten(), dtype=_np.double)
1597 cdef const double[::1] y = _np.ascontiguousarray(y_vertices.flatten(), dtype=_np.double)
1598 cdef int[2] cyclic_view = cyclic
1599 _logger.debug(f"def_grid_curve2d grid_name={grid_name}")
1600 yac_cdef_grid_curve2d(grid_name.encode(),
1601 [_np.shape(x_vertices)[1], _np.shape(y_vertices)[0]],
1602 cyclic_view, <double*>&x[0], <double*>&y[0], &grid_id)
1603 super().__init__(grid_id)
1604
1605 def def_points(self, location : Location,
1606 x_vertices, y_vertices, name = None):
1607 """
1608 @see yac_cdef_points_curve2d_named
1609 """
1610 assert x_vertices.shape == y_vertices.shape
1611 cdef int points_id
1612 cdef const double[::1] x = _np.ascontiguousarray(x_vertices.flatten(), dtype=_np.double)
1613 cdef const double[::1] y = _np.ascontiguousarray(y_vertices.flatten(), dtype=_np.double)
1614 cdef char* c_name = NULL
1615 if name is not None:
1616 name_enc = name.encode()
1617 c_name = name_enc
1618 _logger.debug(f"def_points_curve2d_named grid_id={self.grid_id}, name={name}")
1621 [_np.shape(x_vertices)[1], _np.shape(x_vertices)[0]],
1622 location.value, &x[0], &y[0], c_name, &points_id)
1623 _logger.debug(f"points_id={points_id}")
1624 return Points(points_id)
1625
1626 def def_points_unstruct(self, location : Location,
1627 x_vertices, y_vertices, name = None):
1628 """
1629 @see yac_cdef_points_unstruct_named
1630 """
1631 assert len(x_vertices) == len(y_vertices)
1632 cdef int points_id
1633 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1634 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1635 cdef char* c_name = NULL
1636 if name is not None:
1637 name_enc = name.encode()
1638 c_name = name_enc
1639 _logger.debug(f"def_points_unstruct_named grid_id={self.grid_id}, name={name}")
1641 location.value, &x[0], &y[0], c_name,
1642 &points_id)
1643 _logger.debug(f"points_id={points_id}")
1644 return Points(points_id)
1645
1646
1648 def __init__(self, grid_id):
1649 super().__init__(grid_id)
1650
1651 def def_points(self, location : Location,
1652 x_points, y_points, name = None):
1653 """
1654 @see yac_cdef_points_unstruct_named
1655 """
1656 cdef int points_id
1657 cdef const double[::1] x_points_view = _np.ascontiguousarray(x_points, dtype=_np.double)
1658 cdef const double[::1] y_points_view = _np.ascontiguousarray(y_points, dtype=_np.double)
1659 cdef char* c_name = NULL
1660 if name is not None:
1661 name_enc = name.encode()
1662 c_name = name_enc
1663 _logger.debug(f"yac_cdef_points_unstruct_named grid_id={self.grid_id}, name={name}")
1665 self.grid_idgrid_id, len(x_points_view), location.value,
1666 &x_points_view[0], &y_points_view[0], c_name, &points_id)
1667 _logger.debug(f"points_id={points_id}")
1668 return Points(points_id)
1669
1671 """
1672 An unstuctured 2d Grid
1673 """
1674 def __init__(self, grid_name : str, num_vertices_per_cell,
1675 x_vertices, y_vertices, cell_to_vertex, use_ll_edges=False):
1676 """
1677 @see yac_cdef_grid_unstruct and @see yac_cdef_grid_unstruct_ll
1678 """
1679 cdef int grid_id
1680 cdef const int[::1] num_vertices_per_cell_view = _np.ascontiguousarray(num_vertices_per_cell, dtype=_np.intc)
1681 cdef const double[::1] x_vertices_view = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1682 cdef const double[::1] y_vertices_view = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1683 cdef const int[::1] cell_to_vertex_view = _np.ascontiguousarray(cell_to_vertex, dtype=_np.intc)
1684 assert len(num_vertices_per_cell_view) > 0, \
1685 "UnstrucuredGrid needs at least one cell. Use CloudGrid if you dont need to define cells."
1686 if not use_ll_edges:
1687 _logger.debug(f"def_grid_unstruct grid_name={grid_name}")
1688 yac_cdef_grid_unstruct(grid_name.encode(), len(x_vertices_view),
1689 len(num_vertices_per_cell_view),
1690 <int*>&num_vertices_per_cell_view[0],
1691 <double*>&x_vertices_view[0],
1692 <double*>&y_vertices_view[0],
1693 <int*>&cell_to_vertex_view[0], &grid_id)
1694 else:
1695 _logger.debug(f"def_grid_unstruct_ll grid_name={grid_name}")
1696 yac_cdef_grid_unstruct_ll(grid_name.encode(), len(x_vertices_view),
1697 len(num_vertices_per_cell_view),
1698 <int*>&num_vertices_per_cell_view[0],
1699 <double*>&x_vertices_view[0],
1700 <double*>&y_vertices_view[0],
1701 <int*>&cell_to_vertex_view[0], &grid_id)
1702 super().__init__(grid_id)
1703
1705 """
1706 @see yac_cdef_grid_cloud
1707 """
1708 def __init__(self, grid_name : str, x_vertices, y_vertices):
1709 cdef int grid_id
1710 cdef const double[::1] x_vertices_view = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1711 cdef const double[::1] y_vertices_view = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1712 _logger.debug(f"def_grid_cloud grid_name={grid_name}")
1713 yac_cdef_grid_cloud (grid_name.encode(),
1714 len(x_vertices_view),
1715 <double*>&x_vertices_view[0],
1716 <double*>&y_vertices_view[0],
1717 &grid_id)
1718 super().__init__(grid_id)
1719
1720 def def_points(self, x_points, y_points, name = None):
1721 return super().def_points(Location.CORNER, x_points, y_points, name)
1722
1723
1725 def __init__(self, grid_name : str, num_edges_per_cell,
1726 x_vertices, y_vertices, cell_to_edge, edge_to_vertex,
1727 use_ll_edges=False):
1728 cdef int grid_id
1729 cdef const int[::1] num_edges_per_cell_view = _np.ascontiguousarray(num_edges_per_cell, dtype=_np.intc)
1730 cdef const double[::1] x_vertices_view = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1731 cdef const double[::1] y_vertices_view = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1732 cdef const int[::1] cell_to_edge_view = _np.ascontiguousarray(cell_to_edge, dtype=_np.intc)
1733 cdef const int[:, ::1] edge_to_vertex_view = _np.ascontiguousarray(edge_to_vertex, dtype=_np.intc)
1734 assert edge_to_vertex_view.shape[1] == 2, \
1735 "dimension 1 of edge_to_vertex must be 2"
1736 assert len(num_edges_per_cell_view) > 0, \
1737 "UnstrucuredGridEdge needs at least one cell. Use CloudGrid if you dont need to define cells."
1738 if not use_ll_edges:
1739 _logger.debug(f"def_grid_unstruct_edge grid_name={grid_name}")
1740 yac_cdef_grid_unstruct_edge(grid_name.encode(), len(x_vertices_view),
1741 len(num_edges_per_cell_view),
1742 edge_to_vertex_view.shape[0],
1743 <int*>&num_edges_per_cell_view[0],
1744 <double*>&x_vertices_view[0],
1745 <double*>&y_vertices_view[0],
1746 <int*>&cell_to_edge_view[0],
1747 <int*>&edge_to_vertex_view[0,0],
1748 &grid_id)
1749 else:
1750 _logger.debug(f"def_grid_unstruct_edge_ll grid_name={grid_name}")
1751 yac_cdef_grid_unstruct_edge_ll(grid_name.encode(), len(x_vertices_view),
1752 len(num_edges_per_cell_view),
1753 edge_to_vertex_view.shape[0],
1754 <int*>&num_edges_per_cell_view[0],
1755 <double*>&x_vertices_view[0],
1756 <double*>&y_vertices_view[0],
1757 <int*>&cell_to_edge_view[0],
1758 <int*>&edge_to_vertex_view[0,0],
1759 &grid_id)
1760 super().__init__(grid_id)
1761
1762
1763class Field:
1764 """
1765 Store the field_id
1766 """
1767 def __init__(self, field_id, size=None):
1768 self.field_id = field_id
1769 self._size = size
1770
1771 @classmethod
1772 def create(cls, field_name : str, comp : Component, points, collection_size,
1773 timestep : str, timeunit : TimeUnit, masks = None):
1774 """
1775 @see yac_cdef_field
1776 """
1777 from collections.abc import Iterable
1778 cdef int field_id
1779 if not isinstance(points, Iterable):
1780 points = [points]
1781 cdef const int[:] point_ids_array = _np.array([p.points_id for p in points], dtype=_np.intc)
1782 size = sum(p.size for p in points)
1783 cdef const int[:] mask_ids_array
1784 if masks is None:
1785 _logger.debug(f"def_field field_name={field_name}, comp_id={comp.comp_id}, point_ids={[p.points_id for p in points]}")
1786 yac_cdef_field(field_name.encode(), comp.comp_id,
1787 &point_ids_array[0], len(point_ids_array),
1788 collection_size, timestep.encode(), TimeUnit(timeunit).value, &field_id)
1789 else:
1790 if not isinstance(masks, Iterable):
1791 masks = [masks]
1792 mask_ids_array = _np.array([m.mask_id for m in masks], dtype=_np.intc)
1793 _logger.debug(f"def_field_mask field_name={field_name}, comp_id={comp.comp_id}, point_ids={[p.points_id for p in points]}")
1794 yac_cdef_field_mask(field_name.encode(), comp.comp_id,
1795 &point_ids_array[0], &mask_ids_array[0],
1796 len(point_ids_array),
1797 collection_size, timestep.encode(), TimeUnit(timeunit).value, &field_id)
1798 _logger.debug(f"field_id={field_id}")
1799 return Field(field_id, size)
1800
1801 def test(self):
1802 """
1803 @see yac_ctest
1804
1805 """
1806 cdef int flag
1807 _logger.debug(f"test field_id={self.field_id}")
1808 yac_ctest ( self.field_id, &flag )
1809 _logger.debug(f"flag={flag}")
1810 return flag
1811
1812 def wait(self):
1813 """
1814 @see yac_cwait
1815
1816 """
1817 cdef int field_id = self.field_id
1818 _logger.debug(f"wait field_id={field_id}")
1819 with cython.nogil:
1820 yac_cwait ( field_id )
1821
1822 @coroutine
1823 def wait_coro(self):
1824 """
1825 Coroutine. Blocks until the communication is completed.
1826 """
1827 while self.test() == 0:
1828 yield
1829
1830 @cython.boundscheck(False)
1831 def get(self, buf=None, asyn=False):
1832 """
1833 @see yac_cget_ and variants
1834
1835 @param[out] buf receive buffer, if `None` a numpy array of correct size is allocated
1836 @param[in] asyn if True the call returns immediately and must be completed
1837 with `test` or `wait`
1838
1839 @returns a tuple `(data, action)`. If no data is to be received
1840 (i.e. `action` is `Action.NONE` or `Action.OUT_OF_BOUND`),
1841 `update` is called instead and `data` is `None`.
1842 """
1843 cdef int info
1844 cdef int ierror
1845 action = self.action
1846 if action in (Action.NONE, Action.OUT_OF_BOUND):
1847 self.update()
1848 return None, action
1849 if buf is None:
1850 buf = _np.empty((self.collection_sizecollection_size, self.sizesize), dtype=_np.double)
1851 buf = _np.ascontiguousarray(buf.reshape(self.collection_sizecollection_size, self.sizesize), dtype=_np.double)
1852 if buf.base is None:
1853 _logger.warning("get: non-contiguous buffer passed to get. Reallocated memory.")
1854 cdef double[:,::1] buf_view = buf
1855 cdef int field_id = self.field_id
1856 cdef int collection_size = self.collection_sizecollection_size
1857 if asyn:
1858 _logger.debug(f"get_async_ field_id={self.field_id}")
1859 yac_cget_async_(field_id, collection_size, &buf_view[0,0], &info, &ierror)
1860 else:
1861 _logger.debug(f"get_ field_id={self.field_id}")
1862 with cython.nogil:
1863 yac_cget_(field_id, collection_size, &buf_view[0,0], &info, &ierror)
1864 if ierror != 0:
1865 raise RuntimeError("yac_cget returned error number " + str(ierror))
1866 _logger.debug(f"info={info}")
1867 return buf, Action(info)
1868
1869 async def get_coro(self, buf=None):
1870 """
1871 Coroutine. Executes a get operation.
1872
1873 @see yac_cget_async_
1874
1875 @param[out] buf receive buffer, if `None` a numpy array of correct size is allocated
1876 """
1877 buf, info = self.get(buf, asyn=True)
1878 await self.wait_coro()
1879 return buf, info
1880
1881 @cython.boundscheck(False)
1882 def get_raw(self, buf, frac_mask=None, asyn=False):
1883 """
1884 @see yac_cget_raw_ and variants
1885
1886 @param[inout] buf receive buffer, if `None` a numpy array of correct size is allocated
1887 @param[inout] frac_mask receive buffer for frac_mask, if `None` a numpy array of correct size is allocated
1888 @param[in] asyn if True the call returns immediately and must be completed
1889 with `test` or `wait`
1890
1891 @returns a tuple `(data, frac_mask, action)`. If no data is to be
1892 received (i.e. `action` is `Action.NONE` or
1893 `Action.OUT_OF_BOUND`), `update` is called instead and
1894 `data` and `frac_mask` are `None`.
1895 """
1896 cdef int info
1897 cdef int ierror
1898 action = self.action
1899 if action in (Action.NONE, Action.OUT_OF_BOUND):
1900 self.update()
1901 return None, None, action
1902 buf = _np.ascontiguousarray(buf.reshape(self.collection_sizecollection_size, -1), dtype=_np.double)
1903 if buf.base is None:
1904 _logger.warning("get: non-contiguous buffer passed to get_raw. Reallocated memory.")
1905 cdef double[:,::1] buf_view = buf
1906 if frac_mask is not None:
1907 frac_mask = _np.ascontiguousarray(frac_mask.reshape(self.collection_sizecollection_size, -1), dtype=_np.double)
1908 if frac_mask is not None and frac_mask.base is None:
1909 _logger.warning("get: non-contiguous frac_mask buffer passed to get_raw. Reallocated memory.")
1910 cdef double[:,::1] frac_mask_view = frac_mask
1911 cdef int field_id = self.field_id
1912 cdef int collection_size = self.collection_sizecollection_size
1913 if asyn:
1914 if frac_mask is not None:
1915 _logger.debug(f"get_raw_frac_async_ field_id={self.field_id}")
1916 yac_cget_raw_frac_async_(field_id, collection_size, &buf_view[0,0],
1917 &frac_mask_view[0,0], &info, &ierror)
1918 else:
1919 _logger.debug(f"get_raw_async_ field_id={self.field_id}")
1920 yac_cget_raw_async_(field_id, collection_size, &buf_view[0,0], &info, &ierror)
1921 else:
1922 if frac_mask is not None:
1923 _logger.debug(f"get_raw_frac_ field_id={self.field_id}")
1924 with cython.nogil:
1925 yac_cget_raw_frac_(field_id, collection_size, &buf_view[0,0],
1926 &frac_mask_view[0,0], &info, &ierror)
1927 else:
1928 _logger.debug(f"get_raw_ field_id={self.field_id}")
1929 with cython.nogil:
1930 yac_cget_raw_(field_id, collection_size, &buf_view[0,0], &info, &ierror)
1931 if ierror != 0:
1932 raise RuntimeError("yac_cget returned error number " + str(ierror))
1933 _logger.debug(f"info={info}")
1934 return buf, frac_mask, Action(info)
1935
1936 @cython.boundscheck(False)
1937 def put(self, buf, frac_mask = None):
1938 """
1939 @see yac_cput_
1940 """
1941 cdef int info
1942 cdef int ierror
1943 cdef const double[:,:,::1] buf_view = _np.ascontiguousarray(buf.reshape(-1,self.collection_sizecollection_size,self.sizesize), dtype=_np.double)
1944 cdef const double[:,:,::1] frac_mask_view
1945 cdef int field_id = self.field_id
1946 cdef int collection_size = self.collection_sizecollection_size
1947 if frac_mask is not None:
1948 frac_mask_view = _np.ascontiguousarray(
1949 frac_mask.reshape(-1,self.collection_sizecollection_size,self.sizesize), dtype=_np.double)
1950 _logger.debug(f"put_frac_ field_id={self.field_id}")
1951 with cython.nogil:
1952 yac_cput_frac_(field_id, collection_size, <double*>&buf_view[0,0,0],
1953 <double*>&frac_mask_view[0,0,0], &info, &ierror)
1954 else:
1955 _logger.debug(f"put_ field_id={self.field_id}")
1956 with cython.nogil:
1957 yac_cput_(field_id, collection_size, <double*>&buf_view[0,0,0], &info, &ierror)
1958 if ierror != 0:
1959 raise RuntimeError("yac_cput returned error number " + str(ierror))
1960 _logger.debug(f"info={info}")
1961 return Action(info)
1962
1963 async def put_coro(self, buf, frac_mask = None):
1964 """
1965 Coroutine. Executes a put operation.
1966
1967 @see yac_cput_
1968 """
1969 await self.wait_coro()
1970 return self.put(buf, frac_mask)
1971
1972 def update(self):
1973 """
1974 @see yac_cupdate
1975 """
1976 _logger.debug(f"update field_id={self.field_id}")
1977 yac_cupdate(self.field_id)
1978
1979 @classmethod
1980 @cython.boundscheck(False)
1981 def exchange(cls, send_field, recv_field, send_buf, recv_buf=None, send_frac_mask=None):
1982 """
1983 @see yac_cexchange_frac_
1984
1985 @returns a tuple `(data, send_info, recv_info)`. If no data is to be
1986 received on the recv side (i.e. `recv_info` is
1987 `Action.NONE` or `Action.OUT_OF_BOUND`), the send side is
1988 handled via `put`, `update` is called on the recv side and
1989 `data` is `None`.
1990 """
1991 assert send_field.collection_size == recv_field.collection_size, "exchange can only be used with fields of the same collection_size"
1992 cdef int collection_size = send_field.collection_size
1993 cdef int send_info
1994 cdef int recv_info
1995 cdef int ierror
1996 recv_action = recv_field.action
1997 if recv_action in (Action.NONE, Action.OUT_OF_BOUND):
1998 recv_field.update()
1999 send_action = send_field.put(send_buf, send_frac_mask)
2000 return None, send_action, recv_action
2001 cdef const double[:,:,::1] send_buf_view = _np.ascontiguousarray(send_buf.reshape(-1,collection_size,send_field.size), dtype=_np.double)
2002 cdef const double[:,:,::1] frac_mask_view
2003 if recv_buf is None:
2004 recv_buf = _np.empty((collection_size, recv_field.size), dtype=_np.double)
2005 recv_buf = _np.ascontiguousarray(recv_buf.reshape(collection_size, recv_field.size), dtype=_np.double)
2006 cdef double[:,::1] recv_buf_view = recv_buf
2007 cdef int send_field_id = send_field.field_id
2008 cdef int recv_field_id = recv_field.field_id
2009 if send_frac_mask is None:
2010 _logger.debug(f"exchange_ with send_field.field_id={send_field.field_id} and recv_field.field_id={recv_field.field_id}")
2011 with cython.nogil:
2012 yac_cexchange_(send_field_id, recv_field_id, collection_size,
2013 <double*>&send_buf_view[0,0,0],
2014 <double*>&recv_buf_view[0,0],
2015 &send_info, &recv_info, &ierror)
2016 else:
2017 _logger.debug(f"exchange_frac_ with send_field.field_id={send_field.field_id} and recv_field.field_id={recv_field.field_id}")
2018 frac_mask_view = _np.ascontiguousarray(
2019 send_frac_mask.reshape(-1,collection_size,send_field.size), dtype=_np.double)
2020 with cython.nogil:
2021 yac_cexchange_frac_(send_field_id, recv_field_id, collection_size,
2022 <double*>&send_buf_view[0,0,0],
2023 <double*>&frac_mask_view[0,0,0],
2024 <double*>&recv_buf_view[0,0],
2025 &send_info, &recv_info, &ierror)
2026 if ierror != 0:
2027 raise RuntimeError("yac_cexchange_frac_ returned error number " + str(ierror))
2028
2029 return recv_buf, Action(send_info), Action(recv_info)
2030
2031 @property
2032 def name(self):
2033 """
2034 @see yac_cget_field_name_from_field_id
2035 """
2036 cdef const char* field_name = yac_cget_field_name_from_field_id ( self.field_id )
2037 return bytes(field_name).decode('UTF-8')
2038
2039 @property
2040 def grid_name(self):
2041 """
2042 @see yac_cget_grid_name_from_field_id
2043 """
2044 cdef const char* grid_name = yac_cget_grid_name_from_field_id ( self.field_id )
2045 return bytes(grid_name).decode('UTF-8')
2046
2047 @property
2049 """
2050 @see yac_cget_component_name_from_field_id
2051 """
2052 cdef const char* component_name = yac_cget_component_name_from_field_id ( self.field_id )
2053 return bytes(component_name).decode('UTF-8')
2054
2055 @property
2056 def role(self):
2057 """
2058 @see yac_cget_role_from_field_id
2059 """
2060 return ExchangeType(yac_cget_role_from_field_id ( self.field_id ))
2061
2062 @property
2063 def timestep(self):
2064 """
2065 @see yac_cget_timestep_from_field_id
2066 """
2067 cdef const char* timestep = yac_cget_timestep_from_field_id ( self.field_id )
2068 return bytes(timestep).decode('UTF-8') if timestep != NULL else None
2069
2070 @property
2072 """
2073 @see yac_cget_collection_size_from_field_id
2074 """
2076
2077 @property
2078 def size(self):
2079 """
2080 The size of the corresponding points object
2081 """
2082 return self._size
2083
2084 @property
2085 def datetime(self):
2086 """
2087 @see yac_cget_field_datetime
2088 """
2089 cdef const char* dt = yac_cget_field_datetime(self.field_id)
2090 return bytes(dt).decode('UTF-8') if dt != NULL else None
2091
2092 @property
2093 def action(self):
2094 """
2095 @see yac_cget_action
2096
2097 Can be checked before calling `get`/`get_raw` to determine whether
2098 the next call will actually receive data. If it is `Action.NONE` or
2099 `Action.OUT_OF_BOUND`, `get`/`get_raw` will return `None` instead of
2100 data and `update` can be called instead.
2101 """
2102 cdef int action
2103 yac_cget_action(self.field_id, &action)
2104 return Action(action)
2105
2107 """
2108 @see yac_cget_raw_interp_weights_data
2109
2110 Returns a dictionary with the corresponding values
2111 """
2112 cdef double frac_mask_fallback_value;
2113 cdef double scaling_factor;
2114 cdef double scaling_summand;
2115 cdef size_t num_fixed_values;
2116 cdef double * fixed_values;
2117 cdef size_t * num_tgt_per_fixed_value;
2118 cdef size_t * tgt_idx_fixed;
2119 cdef size_t num_wgt_tgt;
2120 cdef size_t * wgt_tgt_idx;
2121 cdef size_t * num_src_per_tgt;
2122 cdef double * weights;
2123 cdef size_t * src_field_idx;
2124 cdef size_t * src_idx;
2125 cdef size_t num_src_fields;
2126 cdef size_t * src_field_buffer_sizes;
2127 yac_cget_raw_interp_weights_data ( self.field_id,
2128 &frac_mask_fallback_value,
2129 &scaling_factor,
2130 &scaling_summand,
2131 &num_fixed_values,
2132 &fixed_values,
2133 &num_tgt_per_fixed_value,
2134 &tgt_idx_fixed,
2135 &num_wgt_tgt,
2136 &wgt_tgt_idx,
2137 &num_src_per_tgt,
2138 &weights,
2139 &src_field_idx,
2140 &src_idx,
2141 &num_src_fields,
2142 &src_field_buffer_sizes );
2143
2144 result = RawInterpWeights(
2145 frac_mask_fallback_value=frac_mask_fallback_value,
2146 scaling_factor=scaling_factor,
2147 scaling_summand=scaling_summand)
2148
2149 if num_fixed_values > 0:
2150 result.fixed_values = _np.array(<double[:num_fixed_values]> fixed_values)
2151 result.num_tgt_per_fixed_value = _np.array(<size_t[:num_fixed_values]> num_tgt_per_fixed_value)
2152 tgt_idx_fixed_size = _np.sum(result.num_tgt_per_fixed_value)
2153 result.tgt_idx_fixed = _np.array(<size_t[:tgt_idx_fixed_size]> tgt_idx_fixed)
2154
2155 if num_wgt_tgt > 0:
2156 result.wgt_tgt_idx = _np.array(<size_t[:num_wgt_tgt]>wgt_tgt_idx)
2157 result.num_src_per_tgt = _np.array(<size_t[:num_wgt_tgt]> num_src_per_tgt)
2158 num_weights = _np.sum(result.num_src_per_tgt)
2159 result.weights = _np.array(<double[:num_weights]>weights)
2160 result.src_field_idx = _np.array(<size_t[:num_weights]> src_field_idx)
2161 result.src_idx = _np.array(<size_t[:num_weights]> src_idx)
2162
2163 if num_src_fields > 0:
2164 result.src_field_buffer_sizes = _np.array(<size_t[:num_src_fields]> src_field_buffer_sizes)
2165
2166 free(fixed_values);
2167 free(num_tgt_per_fixed_value);
2168 free(tgt_idx_fixed);
2169 free(wgt_tgt_idx);
2170 free(num_src_per_tgt);
2171 free(weights);
2172 free(src_field_idx);
2173 free(src_idx);
2174 free(src_field_buffer_sizes);
2175 return result
2176
2178 """
2179 @see yac_cget_raw_interp_weights_data
2180
2181 Returns a dictionary with the corresponding values
2182 """
2183 cdef double frac_mask_fallback_value;
2184 cdef double scaling_factor;
2185 cdef double scaling_summand;
2186 cdef size_t num_fixed_values;
2187 cdef double * fixed_values;
2188 cdef size_t * num_tgt_per_fixed_value;
2189 cdef size_t * tgt_idx_fixed;
2190 cdef size_t * src_indptr;
2191 cdef double * weights;
2192 cdef size_t * src_field_idx;
2193 cdef size_t * src_idx;
2194 cdef size_t num_src_fields;
2195 cdef size_t * src_field_buffer_sizes;
2196 yac_cget_raw_interp_weights_data_csr ( self.field_id,
2197 &frac_mask_fallback_value,
2198 &scaling_factor,
2199 &scaling_summand,
2200 &num_fixed_values,
2201 &fixed_values,
2202 &num_tgt_per_fixed_value,
2203 &tgt_idx_fixed,
2204 &src_indptr,
2205 &weights,
2206 &src_field_idx,
2207 &src_idx,
2208 &num_src_fields,
2209 &src_field_buffer_sizes );
2210
2211 result = RawInterpWeightsCSR(
2212 frac_mask_fallback_value=frac_mask_fallback_value,
2213 scaling_factor=scaling_factor,
2214 scaling_summand=scaling_summand)
2215
2216 if num_fixed_values > 0:
2217 result.fixed_values = _np.array(<double[:num_fixed_values]> fixed_values)
2218 result.num_tgt_per_fixed_value = _np.array(<size_t[:num_fixed_values]> num_tgt_per_fixed_value)
2219 tgt_idx_fixed_size = _np.sum(result.num_tgt_per_fixed_value)
2220 result.tgt_idx_fixed = _np.array(<size_t[:tgt_idx_fixed_size]> tgt_idx_fixed)
2221
2222 result.src_indptr = _np.array(<size_t[:self.sizesize + 1]> src_indptr)
2223 num_weights = result.src_indptr[-1]
2224 result.weights = _np.array(<double[:num_weights]>weights)
2225 result.src_field_idx = _np.array(<size_t[:num_weights]> src_field_idx)
2226 result.src_idx = _np.array(<size_t[:num_weights]> src_idx)
2227
2228 if num_src_fields > 0:
2229 result.src_field_buffer_sizes = _np.array(<size_t[:num_src_fields]> src_field_buffer_sizes)
2230
2231 free(fixed_values);
2232 free(num_tgt_per_fixed_value);
2233 free(tgt_idx_fixed);
2234 free(src_indptr);
2235 free(weights);
2236 free(src_field_idx);
2237 free(src_idx);
2238 free(src_field_buffer_sizes);
2239 return result
2240
2241
2242@dataclass
2244 frac_mask_fallback_value : float
2245 scaling_factor : float
2246 scaling_summand : float
2247 fixed_values : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.float64))
2248 num_tgt_per_fixed_value : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2249 tgt_idx_fixed : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2250 wgt_tgt_idx : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2251 num_src_per_tgt : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2252 weights : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.float64))
2253 src_field_idx : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2254 src_idx : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2255 src_field_buffer_sizes : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2256
2257
2258@dataclass
2260 frac_mask_fallback_value : float
2261 scaling_factor : float
2262 scaling_summand : float
2263 fixed_values : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.float64))
2264 num_tgt_per_fixed_value : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2265 tgt_idx_fixed : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2266 src_indptr : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2267 weights : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.float64))
2268 src_field_idx : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2269 src_idx : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2270 src_field_buffer_sizes : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
2271
2273 def __init__(self):
2274 """
2275 @see yac_cget_interp_stack_config
2276 """
2277 cdef int interp_stack_config_id
2278 _logger.debug(f"get_interp_stack_config")
2279 yac_cget_interp_stack_config(&interp_stack_config_id)
2280 _logger.debug(f"interp_stack_config_id={interp_stack_config_id}")
2281 self.interp_stack_id = interp_stack_config_id
2282
2283 @classmethod
2284 def from_string_yaml(cls, interp_stack_string : str):
2285 interp_stack = cls.__new__(cls)
2286 cdef int interp_stack_config_id
2287 _logger.debug(f"get_interp_stack_config_from_string_yaml: interp_stack_string={interp_stack_string}")
2288 yac_cget_interp_stack_config_from_string_yaml(interp_stack_string.encode(), &interp_stack_config_id)
2289 _logger.debug(f"interp_stack_config_id_from_string_yaml={interp_stack_config_id}")
2290 interp_stack.interp_stack_id = interp_stack_config_id
2291 return interp_stack
2292
2293 @classmethod
2294 def from_string_json(cls, interp_stack_string : str):
2295 interp_stack = cls.__new__(cls)
2296 cdef int interp_stack_config_id
2297 _logger.debug(f"get_interp_stack_config_from_string_json: interp_stack_string={interp_stack_string}")
2298 yac_cget_interp_stack_config_from_string_json(interp_stack_string.encode(), &interp_stack_config_id)
2299 _logger.debug(f"interp_stack_config_id_from_string_json={interp_stack_config_id}")
2300 interp_stack.interp_stack_id = interp_stack_config_id
2301 return interp_stack
2302
2303 def add_average(self,
2304 reduction_type : AverageReductionType = AverageReductionType.AVG_ARITHMETIC,
2305 partial_coverage : bool = False):
2306 """
2307 @see yac_cadd_interp_stack_config_average
2308 """
2309 _logger.debug(f"add_interp_stack_config_average interp_stack_id={self.interp_stack_id}")
2311 AverageReductionType(reduction_type).value,
2312 partial_coverage)
2313
2314 def add_ncc(self,
2315 reduction_type : NCCReductionType = NCCReductionType.AVG,
2316 partial_coverage : bool = False):
2317 """
2318 @see yac_cadd_interp_stack_config_ncc
2319 """
2320 _logger.debug(f"add_interp_stack_config_ncc interp_stack_id={self.interp_stack_id}")
2322 NCCReductionType(reduction_type).value,
2323 partial_coverage)
2324
2325 def add_nnn(self,
2326 reduction_type : NNNReductionType = NNNReductionType.AVG,
2327 n : int = 1,
2328 max_search_distance : _np.float64 = 0.0,
2329 scale : _np.float64 = 1.0):
2330 """
2331 @see yac_cadd_interp_stack_config_nnn
2332 """
2333 _logger.debug(f"add_interp_stack_config_nnn interp_stack_id={self.interp_stack_id}")
2335 NNNReductionType(reduction_type).value,
2336 n, max_search_distance, scale)
2337
2338 def add_dnn(self,
2339 reduction_type : DNNReductionType = DNNReductionType.DIST,
2340 search_distance_type : DNNSearchDistanceType = DNNSearchDistanceType.CELL_AREA,
2341 search_distance : _np.float64 = 1.0,
2342 scale : _np.float64 = 0.0):
2343 """
2344 @see yac_cadd_interp_stack_config_dnn
2345 """
2346 _logger.debug(f"add_interp_stack_config_dnn interp_stack_id={self.interp_stack_id}")
2348 DNNReductionType(reduction_type).value,
2349 DNNSearchDistanceType(search_distance_type).value,
2350 search_distance, scale)
2351
2352 def add_rbf(self,
2353 n : int = 9,
2354 max_search_distance : _np.float64 = 0.0,
2355 scale : _np.float64 = 1.487973e+01):
2356 """
2357 @see yac_cadd_interp_stack_config_rbf
2358 """
2359 _logger.debug(f"add_interp_stack_config_rbf interp_stack_id={self.interp_stack_id}")
2361 n, max_search_distance, scale)
2362
2364 order : int = 1,
2365 enforced_conserv : bool = False,
2366 partial_coverage : bool = False,
2367 normalisation : ConservNormalizationType = ConservNormalizationType.DESTAREA):
2368 """
2369 @see yac_cadd_interp_stack_config_conservative
2370 """
2371 _logger.debug(f"add_interp_stack_config_conservative interp_stack_id={self.interp_stack_id}")
2373 order, enforced_conserv,
2374 partial_coverage,
2375 ConservNormalizationType(normalisation).value)
2376
2377 def add_spmap(self,
2378 spread_distance : _np.float64 = 0.0,
2379 max_search_distance : _np.float64 = 0.0,
2380 weight_type : SPMAPWeightType = SPMAPWeightType.AVG,
2381 scale_type : SPMAPScaleType = SPMAPScaleType.NONE,
2382 src_sphere_radius : _np.float64 = 1.0,
2383 src_filename : str = None,
2384 src_varname : str = None,
2385 src_min_global_id : int = 0,
2386 tgt_sphere_radius : _np.float64 = 1.0,
2387 tgt_filename : str = None,
2388 tgt_varname : str = None,
2389 tgt_min_global_id : int = 0):
2390 """
2391 @see yac_cadd_interp_stack_config_spmap
2392 """
2393 _logger.debug(f"add_interp_stack_config_spmap interp_stack_id={self.interp_stack_id}")
2394 cdef char * src_filename_ptr
2395 if src_filename is None:
2396 src_filename_ptr = NULL
2397 else:
2398 src_filename_bytes = src_filename.encode()
2399 src_filename_ptr = src_filename_bytes
2400 cdef char * src_varname_ptr
2401 if src_varname is None:
2402 src_varname_ptr = NULL
2403 else:
2404 src_varname_bytes = src_varname.encode()
2405 src_varname_ptr = src_varname_bytes
2406 cdef char * tgt_filename_ptr
2407 if tgt_filename is None:
2408 tgt_filename_ptr = NULL
2409 else:
2410 tgt_filename_bytes = tgt_filename.encode()
2411 tgt_filename_ptr = tgt_filename_bytes
2412 cdef char * tgt_varname_ptr
2413 if tgt_varname is None:
2414 tgt_varname_ptr = NULL
2415 else:
2416 tgt_varname_bytes = tgt_varname.encode()
2417 tgt_varname_ptr = tgt_varname_bytes
2419 spread_distance, max_search_distance,
2420 SPMAPWeightType(weight_type).value,
2421 SPMAPScaleType(scale_type).value,
2422 src_sphere_radius, src_filename_ptr,
2423 src_varname_ptr, src_min_global_id,
2424 tgt_sphere_radius, tgt_filename_ptr,
2425 tgt_varname_ptr, tgt_min_global_id)
2426
2427 def add_hcsbb(self):
2428 """
2429 @see yac_cadd_interp_stack_config_hcsbb
2430 """
2431 _logger.debug(f"add_interp_stack_config_hcsbb interp_stack_id={self.interp_stack_id}")
2433
2435 filename : str,
2436 on_missing_file : UserFileOnMissingFile = UserFileOnMissingFile.ERROR,
2437 on_success : UserFileOnSuccess = UserFileOnSuccess.CONT):
2438 """
2439 @see yac_cadd_interp_stack_config_user_file
2440 """
2441 _logger.debug(f"add_interp_stack_config_user_file interp_stack_id={self.interp_stack_id}")
2443 self.interp_stack_id,
2444 filename.encode(),
2445 UserFileOnMissingFile(on_missing_file).value,
2446 UserFileOnSuccess(on_success).on_success)
2447
2448 def add_fixed(self, value : _np.float64 = _np.finfo(_np.double).max):
2449 """
2450 @see yac_cadd_interp_stack_config_fixed
2451 """
2452 _logger.debug(f"add_interp_stack_config_fixed interp_stack_id={self.interp_stack_id}")
2454
2455 def add_check(self,
2456 constructor_key : str,
2457 do_search_key : str):
2458 """
2459 @see yac_cadd_interp_stack_config_check
2460 """
2461 _logger.debug(f"add_interp_stack_config_check interp_stack_id={self.interp_stack_id}")
2463 constructor_key.encode(), do_search_key.encode())
2464
2465 def add_creep(self,
2466 creep_distance : int = -1):
2467 """
2468 @see yac_cadd_interp_stack_config_creep
2469 """
2470 _logger.debug(f"add_interp_stack_config_creep interp_stack_id={self.interp_stack_id}")
2472 creep_distance)
2473
2474 def __del__(self):
2475 """
2476 @see yac_cfree_interp_stack_config
2477 """
2478 _logger.debug(f"free_interp_stack_config interp_stack_id={self.interp_stack_id}")
2480
2482 """
2483 @see yac_cget_version
2484 """
2485 cdef const char* version_str = yac_cget_version()
2486 return bytes(version_str).decode('UTF-8')
2487
2488
2490 """
2491 @see yac_cget_mpi_handshake_group_name
2492 """
2493 cdef const char* group_name = yac_cget_mpi_handshake_group_name()
2494 return bytes(group_name).decode('UTF-8')
2495
2496
2497if Py_AtExit(yac_cfinalize) < 0:
2498 print(
2499 b"WARNING: %s\n",
2500 b"could not register yac_cfinalize with Py_AtExit()",
2501 )
2502
2503cdef yac_abort_func _prev_abort_func = yac_get_abort_handler()
2504
2505cdef void yac_python_abort(MPI_Comm comm, const char* msg,
2506 const char* source, int line) noexcept with gil:
2507 traceback.print_stack()
2508 _prev_abort_func(comm, msg, source, line)
2509
2510yac_set_abort_handler(yac_python_abort)
2511
2512
2513def _yac_excepthook(typ, value, tb):
2514 traceback.print_tb(tb)
2515 _prev_abort_func(MPI_COMM_WORLD,
2516 str(value).encode(),
2517 tb.tb_frame.f_code.co_filename.encode(),
2518 tb.tb_frame.f_lineno)
2519
2520sys.excepthook = _yac_excepthook
char const * grid_names[]
char const * component_names[]
Refers to YAC_ACTION_NONE, YAC_ACTION_REDUCTION etc.
Definition yac.pyx:576
Reduction type for average interpolation.
Definition yac.pyx:636
Calendar type for use in def_calendar.
Definition yac.pyx:599
def_points(self, x_points, y_points, name=None)
Definition yac.pyx:1720
__init__(self, str grid_name, x_vertices, y_vertices)
Definition yac.pyx:1708
Stores the component_id and provides further functionality.
Definition yac.pyx:1311
__init__(self, comp_id)
Definition yac.pyx:1315
size(self)
number of processes in this component
Definition yac.pyx:1330
comp_comm(self)
Definition yac.pyx:1319
rank(self)
process index in the component
Definition yac.pyx:1339
Normalization type for conservative interpolation.
Definition yac.pyx:688
A curvilinear stuctured 2d Grid.
Definition yac.pyx:1586
__init__(self, str grid_name, x_vertices, y_vertices, cyclic=[False, False])
Definition yac.pyx:1591
def_points(self, Location location, x_vertices, y_vertices, name=None)
Definition yac.pyx:1606
def_points_unstruct(self, Location location, x_vertices, y_vertices, name=None)
Definition yac.pyx:1627
Reduction type for dnn interpolation.
Definition yac.pyx:666
Search distance type for dnn interpolation.
Definition yac.pyx:678
Exchange type of a field.
Definition yac.pyx:566
Store the field_id.
Definition yac.pyx:1763
wait(self)
Definition yac.pyx:1812
datetime(self)
Definition yac.pyx:2085
grid_name(self)
Definition yac.pyx:2040
test(self)
Definition yac.pyx:1801
get_raw(self, buf, frac_mask=None, asyn=False)
Definition yac.pyx:1882
put_coro(self, buf, frac_mask=None)
Coroutine.
Definition yac.pyx:1963
get_coro(self, buf=None)
Coroutine.
Definition yac.pyx:1869
size(self)
The size of the corresponding points object.
Definition yac.pyx:2078
wait_coro(self)
Coroutine.
Definition yac.pyx:1823
get_raw_interp_weights_data(self)
Definition yac.pyx:2106
update(self)
Definition yac.pyx:1972
action(self)
Definition yac.pyx:2093
get(self, buf=None, asyn=False)
Definition yac.pyx:1831
exchange(cls, send_field, recv_field, send_buf, recv_buf=None, send_frac_mask=None)
Definition yac.pyx:1981
collection_size(self)
Definition yac.pyx:2071
create(cls, str field_name, Component comp, points, collection_size, str timestep, TimeUnit timeunit, masks=None)
Definition yac.pyx:1773
collection_size
Definition yac.pyx:1949
get_raw_interp_weights_data_csr(self)
Definition yac.pyx:2177
role(self)
Definition yac.pyx:2056
__init__(self, field_id, size=None)
Definition yac.pyx:1767
timestep(self)
Definition yac.pyx:2063
put(self, buf, frac_mask=None)
Definition yac.pyx:1937
component_name(self)
Definition yac.pyx:2048
Stores the grid_id and provides further functionality.
Definition yac.pyx:1354
get_mask(self, Location location, str mask_name)
Definition yac.pyx:1418
nbr_corners(self)
Definition yac.pyx:1434
set_core_mask(self, is_core, Location location)
Definition yac.pyx:1447
nbr_cells(self)
Definition yac.pyx:1427
get_points(self, Location location, str point_name)
Definition yac.pyx:1408
__init__(self, grid_id)
Definition yac.pyx:1360
set_global_index(self, global_index, Location location)
Set global indices for grid points using yac_int type.
Definition yac.pyx:1364
nbr_edges(self)
Definition yac.pyx:1441
def_mask(self, Location location, is_valid, name=None)
Definition yac.pyx:1458
compute_grid_cell_areas(self, cell_areas=None)
Definition yac.pyx:1475
add_check(self, str constructor_key, str do_search_key)
Definition yac.pyx:2457
add_creep(self, int creep_distance=-1)
Definition yac.pyx:2466
add_user_file(self, str filename, UserFileOnMissingFile on_missing_file=UserFileOnMissingFile.ERROR, UserFileOnSuccess on_success=UserFileOnSuccess.CONT)
Definition yac.pyx:2437
add_nnn(self, NNNReductionType reduction_type=NNNReductionType.AVG, int n=1, _np.float64 max_search_distance=0.0, _np.float64 scale=1.0)
Definition yac.pyx:2329
add_rbf(self, int n=9, _np.float64 max_search_distance=0.0, _np.float64 scale=1.487973e+01)
Definition yac.pyx:2355
add_spmap(self, _np.float64 spread_distance=0.0, _np.float64 max_search_distance=0.0, SPMAPWeightType weight_type=SPMAPWeightType.AVG, SPMAPScaleType scale_type=SPMAPScaleType.NONE, _np.float64 src_sphere_radius=1.0, str src_filename=None, str src_varname=None, int src_min_global_id=0, _np.float64 tgt_sphere_radius=1.0, str tgt_filename=None, str tgt_varname=None, int tgt_min_global_id=0)
Definition yac.pyx:2389
add_ncc(self, NCCReductionType reduction_type=NCCReductionType.AVG, bool partial_coverage=False)
Definition yac.pyx:2316
add_conservative(self, int order=1, bool enforced_conserv=False, bool partial_coverage=False, ConservNormalizationType normalisation=ConservNormalizationType.DESTAREA)
Definition yac.pyx:2367
from_string_json(cls, str interp_stack_string)
Definition yac.pyx:2294
from_string_yaml(cls, str interp_stack_string)
Definition yac.pyx:2284
add_dnn(self, DNNReductionType reduction_type=DNNReductionType.DIST, DNNSearchDistanceType search_distance_type=DNNSearchDistanceType.CELL_AREA, _np.float64 search_distance=1.0, _np.float64 scale=0.0)
Definition yac.pyx:2342
add_average(self, AverageReductionType reduction_type=AverageReductionType.AVG_ARITHMETIC, bool partial_coverage=False)
Definition yac.pyx:2305
add_fixed(self, _np.float64 value=_np.finfo(_np.double).max)
Definition yac.pyx:2448
Location for points.
Definition yac.pyx:556
Stores the mask_id.
Definition yac.pyx:1347
__init__(self, mask_id)
Definition yac.pyx:1351
Reduction type for ncc interpolation.
Definition yac.pyx:646
Reduction type for nnn interpolation.
Definition yac.pyx:655
Stores the points_id and provides further functionality.
Definition yac.pyx:1485
set_mask(self, is_valid)
Definition yac.pyx:1499
__init__(self, points_id)
Definition yac.pyx:1489
size(self)
Definition yac.pyx:1493
Reduction type for the definition of interpolations.
Definition yac.pyx:587
A stuctured 2d Grid.
Definition yac.pyx:1510
def_points_unstruct(self, Location location, x_vertices, y_vertices, name=None)
Definition yac.pyx:1567
def_points(self, Location location, x_vertices, y_vertices, name=None)
Definition yac.pyx:1539
__init__(self, str grid_name, x_vertices, y_vertices, cyclic=[False, False], north_pole=None)
Definition yac.pyx:1515
Refers to YAC_SPMAP_NONE, YAC_SPMAP_SRCAREA YAC_SPMAP_INVTGTAREA, and YAC_SPMAP_FRACAREA.
Definition yac.pyx:704
Refers to YAC_SPMAP_AVG and YAC_SPMAP_DIST.
Definition yac.pyx:697
Refers to YAC_TIME_UNIT_MILLISECOND, YAC_TIME_UNIT_SECOND etc.
Definition yac.pyx:623
__init__(self, str grid_name, num_edges_per_cell, x_vertices, y_vertices, cell_to_edge, edge_to_vertex, use_ll_edges=False)
Definition yac.pyx:1727
An unstuctured 2d Grid.
Definition yac.pyx:1670
__init__(self, str grid_name, num_vertices_per_cell, x_vertices, y_vertices, cell_to_vertex, use_ll_edges=False)
Definition yac.pyx:1675
Refers to YAC_FILE_MISSING_ERROR, YAC_FILE_MISSING_CONT.
Definition yac.pyx:714
Refers to YAC_FILE_SUCCESS_STOP, YAC_FILE_SUCCESS_CONT.
Definition yac.pyx:721
Handling of existing files, if weight file is to be written.
Definition yac.pyx:737
Initializies a YAC instance and provides further functionality.
Definition yac.pyx:755
set_coordinates_check(self, bool check_coordinates)
Definition yac.pyx:1297
get_field_is_defined(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1097
read_config_yaml(self, str yaml_file)
Definition yac.pyx:1262
enddef(self)
Definition yac.pyx:1029
get_grid(self, str grid_name)
Definition yac.pyx:1042
set_coordinates_mismatch_is_fatal(self, bool mismatch_is_fatal)
Definition yac.pyx:1304
default_instance_id_defined(cls)
Definition yac.pyx:793
def_comp(self, str comp_name)
Definition yac.pyx:849
sync_def_comps(self, list comp_names)
Definition yac.pyx:945
predef_comp(self, str comp_name)
Definition yac.pyx:877
def_couple(self, str src_comp, str src_grid, src_field, str tgt_comp, str tgt_grid, tgt_field, str coupling_timestep, TimeUnit timeunit, Reduction time_reduction, interp_stack, src_lag=0, tgt_lag=0, weight_file=None, WeightFileOnExisting weight_file_on_existing=WeightFileOnExisting.OVERWRITE, mapping_on_source=1, scale_factor=1.0, scale_summand=0.0, src_masks_names=None, tgt_mask_name=None, yaxt_exchanger_name=None, collection_selection=None, use_raw_exchange=False)
Definition yac.pyx:971
get_grid_metadata(self, str grid_name)
Definition yac.pyx:1229
instance_id
Definition yac.pyx:789
def_component_metadata(self, str comp_name, bytes metadata)
Definition yac.pyx:1194
sync_def(self)
Definition yac.pyx:938
def_field_metadata(self, str comp_name, str grid_name, str field_name, bytes metadata)
Definition yac.pyx:1211
def_grid_metadata(self, str grid_name, bytes metadata)
Definition yac.pyx:1202
start_datetime(self)
Definition yac.pyx:923
get_field_metadata(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1237
get_comps_comm(self, comp_names)
Definition yac.pyx:1247
cleanup(self)
Definition yac.pyx:821
get_field_names(self, str comp_name, str grid_name)
Definition yac.pyx:1083
get_field_id(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1106
def_comps(self, comp_names=[])
Definition yac.pyx:859
size(self)
number of processes in this instance
Definition yac.pyx:832
set_grid_output_file(self, str gridname, str filename)
Definition yac.pyx:1282
get_component(self, str comp_name)
Definition yac.pyx:1036
from_id(cls, id)
Definition yac.pyx:812
get_component_metadata(self, str comp_name)
Definition yac.pyx:1221
def_datetime(self, start_datetime, end_datetime)
Definition yac.pyx:887
get_field_role(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1134
get_field_source(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1144
owned_instance
Definition yac.pyx:790
enable_field_frac_mask(self, str comp_name, str grid_name, str field_name, _np.float64 frac_mask_fallback_value)
Definition yac.pyx:1183
get_comp_grid_names(self, comp_name)
Definition yac.pyx:1072
rank(self)
process index in this instance
Definition yac.pyx:841
get_field_timestep(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1124
get_field(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1115
get_field_frac_mask_fallback_value(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1173
end_datetime(self)
Definition yac.pyx:931
__del__(self)
Definition yac.pyx:818
__init__(self, comm=None, default_instance=False)
Definition yac.pyx:761
set_grids_output_file(self, str filename)
Definition yac.pyx:1290
get_field_collection_size(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1159
set_config_output_file(self, str filename, ConfigOutputFormat fileformat, ConfigOutputSyncLoc sync_location, bool include_definitions=False)
Definition yac.pyx:1272
default_instance_id_defined
Definition yac.pyx:806
default_instance(cls)
Definition yac.pyx:800
__init__(self, grid_id)
Definition yac.pyx:1648
def_points(self, Location location, x_points, y_points, name=None)
Definition yac.pyx:1652
__get__(self, cls, owner)
Definition yac.pyx:752
enum callback_type type
version()
Definition yac.pyx:2481
get_calendar()
Definition yac.pyx:616
mpi_handshake_group_name()
Definition yac.pyx:2489
_prev_abort_func
Definition yac.pyx:2503
def_calendar(Calendar calendar)
Definition yac.pyx:610
_yac_excepthook(typ, value, tb)
Definition yac.pyx:2513
char const * name
Definition toy_scrip.c:114
int yac_cget_points_id(int grid_id, int location, const char *point_name)
Definition yac.c:5076
void yac_ccompute_grid_cell_areas(int grid_id, double *cell_areas)
Definition yac.c:5795
void yac_cadd_interp_stack_config_ncc(int interp_stack_config_id, int weight_type, int partial_coverage)
Definition yac.c:5873
const char * yac_cget_field_metadata_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:2047
void yac_cget_instance_size_c2py(int yac_instance_id, int *size)
Definition yac.c:786
void yac_cset_global_index_yac_int(yac_int const *global_index, int location, int grid_id)
Definition yac.c:5714
void yac_cpredef_comp_instance(int yac_instance_id, char const *name, int *comp_id)
Definition yac.c:1266
char * yac_cget_start_datetime_instance(int yac_instance_id)
Definition yac.c:1048
void yac_cdef_field_mask(char const *name, int const comp_id, int const *point_ids, int const *mask_ids, int const num_pointsets, int collection_size, const char *timestep, int time_unit, int *field_id)
Definition yac.c:1854
void yac_cset_grid_output_file_instance(int yac_instance_id, const char *gridname, const char *filename)
Definition yac.c:877
void yac_cget_(int const field_id, int const collection_size, double *recv_field, int *info, int *ierr)
Definition yac.c:3280
int yac_cget_nbr_grids_instance(int yac_instance_id)
Definition yac.c:5152
void yac_cfree_ext_couple_config(int ext_couple_config_id)
Definition yac.c:2100
const char * yac_cget_grid_metadata_instance(int yac_instance_id, const char *grid_name)
Definition yac.c:2034
char * yac_cget_end_datetime_instance(int yac_instance_id)
Definition yac.c:1063
void yac_cadd_interp_stack_config_user_file_2(int interp_stack_config_id, char const *filename, int on_missing_file, int on_succes)
Definition yac.c:6479
void yac_cset_ext_couple_config_tgt_mask_name(int ext_couple_config_id, char const *tgt_mask_name)
Definition yac.c:2270
void yac_cdef_grid_curve2d(const char *grid_name, int nbr_vertices[2], int cyclic[2], double *x_vertices, double *y_vertices, int *grid_id)
Definition yac.c:5529
void yac_cget_grid_names_instance(int yac_instance_id, int nbr_grids, const char **grid_names)
Definition yac.c:5241
void yac_cset_ext_couple_config_scale_factor(int ext_couple_config_id, double scale_factor)
Definition yac.c:2193
void yac_cset_ext_couple_config_weight_file_on_existing(int ext_couple_config_id, int weight_file_on_existing)
Definition yac.c:2146
void yac_cadd_interp_stack_config_creep(int interp_stack_config_id, int creep_distance)
Definition yac.c:6533
void yac_cput_frac_(int const field_id, int const collection_size, double *send_field, double *send_frac_mask, int *info, int *ierr)
Definition yac.c:3621
void yac_cget_comp_rank_c2py(int comp_id, int *rank)
Definition yac.c:1161
void yac_cdef_points_curve2d_named(int const grid_id, int const *nbr_points, int const located, double const *x_points, double const *y_points, char const *name, int *point_id)
Definition yac.c:1553
void yac_cset_grids_output_file_instance(int yac_instance_id, const char *filename)
Definition yac.c:898
void yac_cget_comp_size_c2py(int comp_id, int *size)
Definition yac.c:1154
int yac_cget_comp_nbr_grids_instance(int yac_instance_id, const char *comp_name)
Definition yac.c:5165
void yac_cdef_grid_unstruct_ll(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:5567
void yac_cdef_points_reg2d_rot_named(int const grid_id, int const *nbr_points, int const located, double const *x_points, double const *y_points, double x_north_pole, double y_north_pole, char const *name, int *point_id)
Definition yac.c:1652
void yac_csync_def_instance(int yac_instance_id)
Definition yac.c:4918
static void cleanup()
Definition yac.c:986
void yac_cget_interp_stack_config_from_string_json(char const *interp_stack_config, int *interp_stack_config_id)
Definition yac.c:6596
void yac_cdef_grid_reg2d_rot(const char *grid_name, int nbr_vertices[2], int cyclic[2], double *x_vertices, double *y_vertices, double x_north_pole, double y_north_pole, int *grid_id)
Definition yac.c:5645
void yac_cinit(void)
Definition yac.c:737
void yac_cget_raw_(int const field_id, int const collection_size, double *src_field_buffer, int *info, int *ierr)
Definition yac.c:3388
void yac_cfinalize()
Finalises YAC.
Definition yac.c:1007
void yac_cadd_interp_stack_config_check(int interp_stack_config_id, char const *constructor_key, char const *do_search_key)
Definition yac.c:6521
void yac_cenddef_instance(int yac_instance_id)
Definition yac.c:4984
void yac_cset_ext_couple_config_src_mask_names(int ext_couple_config_id, size_t num_src_mask_names, char const *const *src_mask_names)
Definition yac.c:2245
void yac_cget_raw_async_(int const field_id, int const collection_size, double *src_field_buffer, int *info, int *ierr)
Definition yac.c:3445
int yac_cget_nbr_comps_instance(int yac_instance_id)
Definition yac.c:5141
void yac_cdef_points_unstruct_named(int const grid_id, int const nbr_points, int const located, double const *x_points, double const *y_points, char const *name, int *point_id)
Definition yac.c:1607
int yac_cget_nbr_fields_instance(int yac_instance_id, const char *comp_name, const char *grid_name)
Definition yac.c:5191
void yac_cset_coordinates_mismatch_is_fatal_instance(int yac_instance_id, int is_fatal)
Definition yac.c:931
void yac_cget_ext_couple_config(int *ext_couple_config_id)
Definition yac.c:2079
const char * yac_cget_mpi_handshake_group_name(void)
Retrieve the MPI handshake group name used by YAC.
Definition yac.c:1088
void yac_cdef_grid_unstruct_edge(const char *grid_name, int nbr_vertices, int nbr_cells, int nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex, int *grid_id)
Definition yac.c:5587
void yac_cdef_points_reg2d_named(int const grid_id, int const *nbr_points, int const located, double const *x_points, double const *y_points, char const *name, int *point_id)
Definition yac.c:1499
void yac_cdef_grid_metadata_instance(int yac_instance_id, const char *grid_name, const char *metadata)
Definition yac.c:1991
void yac_cset_ext_couple_config_weight_file(int ext_couple_config_id, char const *weight_file)
Definition yac.c:2116
const char * yac_cget_component_metadata_instance(int yac_instance_id, const char *comp_name)
Definition yac.c:2021
void yac_cread_config_yaml_instance(int yac_instance_id, const char *yaml_filename)
Definition yac.c:808
void yac_cset_ext_couple_config_yaxt_exchanger_name(int ext_couple_config_id, char const *yaxt_exchanger_name)
Definition yac.c:2292
const char * yac_cget_field_timestep_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:5400
void yac_cset_ext_couple_config_scale_summand(int ext_couple_config_id, double scale_summand)
Definition yac.c:2215
void yac_cget_comp_comm(int comp_id, MPI_Comm *comp_comm)
Definition yac.c:1132
const char * yac_cget_field_datetime(int field_id)
Definition yac.c:2935
void yac_cdef_comp_instance(int yac_instance_id, char const *comp_name, int *comp_id)
Definition yac.c:1339
void yac_cupdate(int field_id)
Definition yac.c:2962
void yac_cget_action(int field_id, int *action)
Definition yac.c:2893
void yac_cexchange_(int const send_field_id, int const recv_field_id, int const collection_size, double *send_field, double *recv_field, int *send_info, int *recv_info, int *ierr)
Definition yac.c:4284
int yac_cget_collection_size_from_field_id(int field_id)
Definition yac.c:5384
void yac_cdef_grid_reg2d(const char *grid_name, int nbr_vertices[2], int cyclic[2], double *x_vertices, double *y_vertices, int *grid_id)
Definition yac.c:5511
int yac_cget_comp_id_instance(int yac_instance_id, const char *comp_name)
Definition yac.c:5047
int yac_cdefault_instance_defined(void)
Definition yac.c:696
void yac_cdef_couple_custom_instance(int yac_instance_id, char const *src_comp_name, char const *src_grid_name, char const *src_field_name, char const *tgt_comp_name, char const *tgt_grid_name, char const *tgt_field_name, char const *coupling_timestep, int time_unit, int time_reduction, int interp_stack_config_id, int src_lag, int tgt_lag, int ext_couple_config_id)
Definition yac.c:2428
void yac_cset_ext_couple_config_use_raw_exchange(int ext_couple_config_id, int use_raw_exchange)
Definition yac.c:2312
int yac_cget_grid_id(const char *grid_name)
Definition yac.c:5066
void yac_cset_config_output_file_instance(int yac_instance_id, const char *filename, int fileformat, int sync_location, int include_definitions)
Definition yac.c:838
void yac_cinit_comm_instance(MPI_Comm comm, int *yac_instance_id)
Definition yac.c:700
void yac_cget_instance_rank_c2py(int yac_instance_id, int *rank)
Definition yac.c:776
void yac_cenable_field_frac_mask_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name, double frac_mask_fallback_value)
Definition yac.c:1957
void yac_cget_interp_stack_config_from_string_yaml(char const *interp_stack_config, int *interp_stack_config_id)
Definition yac.c:6588
void yac_cadd_interp_stack_config_conservative(int interp_stack_config_id, int order, int enforced_conserv, int partial_coverage, int normalisation)
Definition yac.c:5948
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:5547
char * yac_cget_version(void)
Definition yac.c:1081
int yac_cget_default_instance_id()
Definition yac.c:691
void yac_cexchange_frac_(int const send_field_id, int const recv_field_id, int const collection_size, double *send_field, double *send_frac_mask, double *recv_field, int *send_info, int *recv_info, int *ierr)
Definition yac.c:4395
void yac_cdef_component_metadata_instance(int yac_instance_id, const char *comp_name, const char *metadata)
Definition yac.c:1978
void yac_cdef_calendar(int calendar)
Definition yac.c:1036
void yac_cget_raw_frac_async_(int const field_id, int const collection_size, double *src_field_buffer, double *src_frac_mask_buffer, int *info, int *ierr)
Definition yac.c:3457
void yac_cset_coordinates_check_instance(int yac_instance_id, int apply_check)
Definition yac.c:916
void yac_cadd_interp_stack_config_rbf(int interp_stack_config_id, size_t n, double max_search_distance, double scale)
Definition yac.c:5936
int yac_cget_mask_id(int grid_id, int location, const char *mask_name)
Definition yac.c:5090
int yac_cget_calendar()
Definition yac.c:1041
void yac_cget_raw_frac_(int const field_id, int const collection_size, double *src_field_buffer, double *src_frac_mask_buffer, int *info, int *ierr)
Definition yac.c:3400
void yac_cput_(int const field_id, int const collection_size, double *send_field, int *info, int *ierr)
Definition yac.c:3601
void yac_cget_comp_grid_names_instance(int yac_instance_id, const char *comp_name, int nbr_grids, const char **grid_names)
Definition yac.c:5265
void yac_cget_async_(int const field_id, int const collection_size, double *recv_field, int *info, int *ierr)
Definition yac.c:3289
void yac_cadd_interp_stack_config_hcsbb(int interp_stack_config_id)
Definition yac.c:6470
void yac_cget_comps_comm_instance(int yac_instance_id, char const **comp_names, int num_comps, MPI_Comm *comps_comm)
Definition yac.c:1172
void yac_cadd_interp_stack_config_fixed(int interp_stack_config_id, double value)
Definition yac.c:6511
double yac_cget_field_frac_mask_fallback_value_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:5419
void yac_cget_field_source_instance(int yac_instance_id, const char *tgt_comp_name, const char *tgt_grid_name, const char *tgt_field_name, const char **src_comp_name, const char **src_grid_name, const char **src_field_name)
Definition yac.c:5484
void yac_cadd_interp_stack_config_spmap(int interp_stack_config_id, double spread_distance, double max_search_distance, int weight_type, int scale_type, double src_sphere_radius, char const *src_filename, char const *src_varname, int src_min_global_id, double tgt_sphere_radius, char const *tgt_filename, char const *tgt_varname, int tgt_min_global_id)
Definition yac.c:6246
void yac_cdef_grid_unstruct_edge_ll(const char *grid_name, int nbr_vertices, int nbr_cells, int nbr_edges, int *num_edges_per_cell, double *x_vertices, double *y_vertices, int *cell_to_edge, int *edge_to_vertex, int *grid_id)
Definition yac.c:5608
void yac_cset_ext_couple_config_mapping_side(int ext_couple_config_id, int mapping_side)
Definition yac.c:2171
void yac_ccleanup_instance(int yac_instance_id)
Clean-up a YAC instance (see Restarting YAC)
Definition yac.c:969
int yac_cget_field_collection_size_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name)
Definition yac.c:5430
void yac_cfree_interp_stack_config(int interp_stack_config_id)
Definition yac.c:5834
void yac_cadd_interp_stack_config_nnn(int interp_stack_config_id, int type, size_t n, double max_search_distance, double scale)
Definition yac.c:5890
size_t yac_cget_grid_size(int located, int grid_id)
Definition yac.c:5784
void yac_cinit_instance(int *yac_instance_id)
Definition yac.c:725
void yac_cget_interp_stack_config(int *interp_stack_config_id)
Definition yac.c:5818
void yac_cset_ext_couple_config_collection_selection(int ext_couple_config_id, int collection_size, int const *collection_indices)
Definition yac.c:2356
void yac_cadd_interp_stack_config_average(int interp_stack_config_id, int reduction_type, int partial_coverage)
Definition yac.c:5855
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:1929
void yac_csync_def_comps_instance(int yac_instance_id, char const **comp_names, int num_comp_names)
Definition yac.c:4928
void yac_cdef_field_metadata_instance(int yac_instance_id, const char *comp_name, const char *grid_name, const char *field_name, const char *metadata)
Definition yac.c:2005
void yac_cadd_interp_stack_config_dnn(int interp_stack_config_id, int weight_type, int search_distance_type, double search_distance, double scale)
Definition yac.c:5910
void yac_cget_field_names_instance(int yac_instance_id, const char *comp_name, const char *grid_name, int nbr_fields, const char **field_names)
Definition yac.c:5311
void yac_cdef_comps_instance(int yac_instance_id, char const **comp_names, int num_comps, int *comp_ids)
Definition yac.c:1294
void yac_cget_comp_names_instance(int yac_instance_id, int nbr_comps, const char **comp_names)
Definition yac.c:5216
void yac_cinit_comm(MPI_Comm comm)
Definition yac.c:712
yac_abort_func yac_get_abort_handler(void)
void yac_set_abort_handler(yac_abort_func custom_abort)