YAC 3.7.1
Yet Another Coupler
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
6from enum import Enum
7import numpy as _np
8import logging
9from types import coroutine
10from dataclasses import dataclass, field
11
12from libc.stdlib cimport malloc, free
13
14cdef import from "<mpi.h>" nogil:
15 ctypedef struct _mpi_comm_t
16 ctypedef _mpi_comm_t* MPI_Comm
17 int MPI_Comm_c2f(MPI_Comm)
18 MPI_Comm MPI_Comm_f2c(int)
19
20cdef extern from "Python.h":
21 int Py_AtExit(void (*)())
22
23cdef extern from "yac.h":
24 cdef const int _LOCATION_CELL "YAC_LOCATION_CELL"
25 cdef const int _LOCATION_CORNER "YAC_LOCATION_CORNER"
26 cdef const int _LOCATION_EDGE "YAC_LOCATION_EDGE"
27
28 cdef const int _EXCHANGE_TYPE_NONE "YAC_EXCHANGE_TYPE_NONE"
29 cdef const int _EXCHANGE_TYPE_SOURCE "YAC_EXCHANGE_TYPE_SOURCE"
30 cdef const int _EXCHANGE_TYPE_TARGET "YAC_EXCHANGE_TYPE_TARGET"
31
32 cdef const int _ACTION_NONE "YAC_ACTION_NONE"
33 cdef const int _ACTION_REDUCTION "YAC_ACTION_REDUCTION"
34 cdef const int _ACTION_COUPLING "YAC_ACTION_COUPLING"
35 cdef const int _ACTION_GET_FOR_RESTART "YAC_ACTION_GET_FOR_RESTART"
36 cdef const int _ACTION_PUT_FOR_RESTART "YAC_ACTION_PUT_FOR_RESTART"
37 cdef const int _ACTION_OUT_OF_BOUND "YAC_ACTION_OUT_OF_BOUND"
38
39 cdef const int _REDUCTION_TIME_NONE "YAC_REDUCTION_TIME_NONE"
40 cdef const int _REDUCTION_TIME_ACCUMULATE "YAC_REDUCTION_TIME_ACCUMULATE"
41 cdef const int _REDUCTION_TIME_AVERAGE "YAC_REDUCTION_TIME_AVERAGE"
42 cdef const int _REDUCTION_TIME_MINIMUM "YAC_REDUCTION_TIME_MINIMUM"
43 cdef const int _REDUCTION_TIME_MAXIMUM "YAC_REDUCTION_TIME_MAXIMUM"
44
45 cdef const int _CALENDAR_NOT_SET "YAC_CALENDAR_NOT_SET"
46 cdef const int _PROLEPTIC_GREGORIAN "YAC_PROLEPTIC_GREGORIAN"
47 cdef const int _YEAR_OF_365_DAYS "YAC_YEAR_OF_365_DAYS"
48 cdef const int _YEAR_OF_360_DAYS "YAC_YEAR_OF_360_DAYS"
49
50 cdef const int _TIME_UNIT_MILLISECOND "YAC_TIME_UNIT_MILLISECOND"
51 cdef const int _TIME_UNIT_SECOND "YAC_TIME_UNIT_SECOND"
52 cdef const int _TIME_UNIT_MINUTE "YAC_TIME_UNIT_MINUTE"
53 cdef const int _TIME_UNIT_HOUR "YAC_TIME_UNIT_HOUR"
54 cdef const int _TIME_UNIT_DAY "YAC_TIME_UNIT_DAY"
55 cdef const int _TIME_UNIT_MONTH "YAC_TIME_UNIT_MONTH"
56 cdef const int _TIME_UNIT_YEAR "YAC_TIME_UNIT_YEAR"
57 cdef const int _TIME_UNIT_ISO_FORMAT "YAC_TIME_UNIT_ISO_FORMAT"
58
59 cdef const int _AVG_ARITHMETIC "YAC_AVG_ARITHMETIC"
60 cdef const int _AVG_DIST "YAC_AVG_DIST"
61 cdef const int _AVG_BARY "YAC_AVG_BARY"
62
63 cdef const int _NCC_AVG "YAC_NCC_AVG"
64 cdef const int _NCC_DIST "YAC_NCC_DIST"
65
66 cdef const int _NNN_AVG "YAC_NNN_AVG"
67 cdef const int _NNN_DIST "YAC_NNN_DIST"
68 cdef const int _NNN_GAUSS "YAC_NNN_GAUSS"
69 cdef const int _NNN_RBF "YAC_NNN_RBF"
70
71 cdef const int _CONSERV_DESTAREA "YAC_CONSERV_DESTAREA"
72 cdef const int _CONSERV_FRACAREA "YAC_CONSERV_FRACAREA"
73
74 cdef const int _SPMAP_AVG "YAC_SPMAP_AVG"
75 cdef const int _SPMAP_DIST "YAC_SPMAP_DIST"
76
77 cdef const int _SPMAP_NONE "YAC_SPMAP_NONE"
78 cdef const int _SPMAP_SRCAREA "YAC_SPMAP_SRCAREA"
79 cdef const int _SPMAP_INVTGTAREA "YAC_SPMAP_INVTGTAREA"
80 cdef const int _SPMAP_FRACAREA "YAC_SPMAP_FRACAREA"
81
82 cdef const int _FILE_MISSING_ERROR "YAC_FILE_MISSING_ERROR"
83 cdef const int _FILE_MISSING_CONT "YAC_FILE_MISSING_CONT"
84
85 cdef const int _FILE_SUCCESS_STOP "YAC_FILE_SUCCESS_STOP"
86 cdef const int _FILE_SUCCESS_CONT "YAC_FILE_SUCCESS_CONT"
87
88 cdef const int _CONFIG_OUTPUT_FORMAT_YAML "YAC_CONFIG_OUTPUT_FORMAT_YAML"
89 cdef const int _CONFIG_OUTPUT_FORMAT_JSON "YAC_CONFIG_OUTPUT_FORMAT_JSON"
90
91 cdef const int _CONFIG_OUTPUT_SYNC_LOC_DEF_COMP "YAC_CONFIG_OUTPUT_SYNC_LOC_DEF_COMP"
92 cdef const int _CONFIG_OUTPUT_SYNC_LOC_SYNC_DEF "YAC_CONFIG_OUTPUT_SYNC_LOC_SYNC_DEF"
93 cdef const int _CONFIG_OUTPUT_SYNC_LOC_ENDDEF "YAC_CONFIG_OUTPUT_SYNC_LOC_ENDDEF"
94
95 cdef const int _WGT_ON_EXISTING_ERROR "YAC_WGT_ON_EXISTING_ERROR"
96 cdef const int _WGT_ON_EXISTING_KEEP "YAC_WGT_ON_EXISTING_KEEP"
97 cdef const int _WGT_ON_EXISTING_OVERWRITE "YAC_WGT_ON_EXISTING_OVERWRITE"
98
99 void yac_cinit ()
100 void yac_cinit_instance ( int * yac_instance_id )
101 void yac_cinit_comm (MPI_Comm comm )
102 void yac_cinit_comm_instance (MPI_Comm comm, int * yac_instance_id )
104 void yac_ccleanup_instance (int yac_instance_id)
105 void yac_cdef_comp_instance ( int yac_instance_id,
106 const char * comp_name,
107 int * comp_id )
108 void yac_cdef_comps_instance ( int yac_instance_id,
109 const char ** comp_names,
110 int num_comps,
111 int * comp_ids )
112 void yac_cpredef_comp_instance ( int yac_instance_id,
113 const char * comp_name,
114 int * comp_id )
115 void yac_cget_comp_comm ( int comp_id, MPI_Comm* comp_comm )
116 void yac_cdef_datetime_instance ( int yac_instance_id,
117 const char * start_datetime,
118 const char * end_datetime )
119 void yac_cget_comps_comm_instance( int yac_instance_id,
120 const char ** comp_names,
121 int num_comps,
122 MPI_Comm * comps_comm)
123 void yac_cdef_calendar ( int calendar )
124 int yac_cget_calendar ( )
125 void yac_cenddef_instance ( int yac_instance_id )
126 int yac_cget_nbr_comps_instance ( int yac_instance_id )
127 int yac_cget_nbr_grids_instance ( int yac_instance_id )
128 int yac_cget_comp_nbr_grids_instance ( int yac_instance_id, const char* comp_name )
129 int yac_cget_nbr_fields_instance ( int yac_instance_id, const char * comp_name,
130 const char* grid_name)
131 void yac_cget_comp_names_instance ( int yac_instance_id, int nbr_comps,
132 const char ** comp_names )
133 void yac_cget_grid_names_instance ( int yac_instance_id, int nbr_grids,
134 const char ** grid_names )
135 void yac_cget_comp_grid_names_instance ( int yac_instance_id, const char* comp_name,
136 int nbr_grids, const char ** grid_names )
137 void yac_cget_field_names_instance ( int yac_instance_id, const char* comp_name,
138 const char* grid_name,
139 int nbr_fields, const char ** field_names )
140 int yac_cget_field_id_instance ( int yac_instance_id, const char* comp_name,
141 const char* grid_name,
142 const char * field_name )
143 const char* yac_cget_field_timestep_instance ( int yac_instance_id, const char* comp_name,
144 const char* grid_name,
145 const char * field_name )
146 int yac_cget_field_role_instance ( int yac_instance_id, const char* comp_name,
147 const char* grid_name, const char* field_name )
148 void yac_cget_field_source_instance ( int yac_instance_id, const char* tgt_comp_name,
149 const char* tgt_grid_name, const char* tgt_field_name,
150 const char** src_comp_name, const char** src_grid_name,
151 const char** src_field_name)
152 void yac_cenable_field_frac_mask_instance ( int yac_instance_id,
153 const char* comp_name,
154 const char* grid_name,
155 const char * field_name,
156 double frac_mask_fallback_value)
157 int yac_cget_field_collection_size_instance ( int yac_instance_id,
158 const char* comp_name,
159 const char* grid_name,
160 const char * field_name )
161 double yac_cget_field_frac_mask_fallback_value_instance ( int yac_instance_id,
162 const char* comp_name,
163 const char* grid_name,
164 const char * field_name )
165 void yac_cdef_component_metadata_instance ( int yac_instance_id,
166 const char* comp_name,
167 const char* metadata)
168 void yac_cdef_grid_metadata_instance ( int yac_instance_id,
169 const char* grid_name,
170 const char* metadata)
171 void yac_cdef_field_metadata_instance ( int yac_instance_id,
172 const char* comp_name,
173 const char* grid_name,
174 const char* field_name,
175 const char* metadata)
176 const char* yac_cget_component_metadata_instance(int yac_instance_id,
177 const char* comp_name)
178 const char* yac_cget_grid_metadata_instance(int yac_instance_id,
179 const char* grid_name)
180 const char* yac_cget_field_metadata_instance(int yac_instance_id,
181 const char* comp_name,
182 const char* grid_name,
183 const char* field_name)
184 char * yac_cget_start_datetime_instance ( int yac_instance_id )
185 char * yac_cget_end_datetime_instance ( int yac_instance_id )
186 char * yac_cget_version ()
187 void yac_cdef_grid_reg2d ( const char * grid_name,
188 int nbr_vertices[2],
189 int cyclic[2],
190 double *x_vertices,
191 double *y_vertices,
192 int *grid_id)
193 void yac_cdef_points_reg2d ( const int grid_id,
194 int nbr_points[2],
195 const int location,
196 const double *x_points,
197 const double *y_points,
198 int *point_id )
199 void yac_cdef_grid_reg2d_rot ( const char * grid_name,
200 int nbr_vertices[2],
201 int cyclic[2],
202 double *x_vertices,
203 double *y_vertices,
204 double x_north_pole,
205 double y_north_pole,
206 int *grid_id)
207 void yac_cdef_points_reg2d_rot ( const int grid_id,
208 int nbr_points[2],
209 const int location,
210 const double *x_points,
211 const double *y_points,
212 double x_north_pole,
213 double y_north_pole,
214 int *point_id )
215 void yac_cdef_grid_curve2d ( 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_curve2d ( const int grid_id,
222 int nbr_points[2],
223 const int location,
224 const double *x_points,
225 const double *y_points,
226 int *point_id )
227 void yac_cdef_grid_cloud ( const char * grid_name,
228 int nbr_points,
229 double *x_points,
230 double *y_points,
231 int *grid_id)
232 void yac_cdef_grid_unstruct ( const char * grid_name,
233 int nbr_vertices,
234 int nbr_cells,
235 int *num_vertices_per_cell,
236 double *x_vertices,
237 double *y_vertices,
238 int *cell_to_vertex,
239 int *grid_id)
240 void yac_cdef_grid_unstruct_ll ( const char * grid_name,
241 int nbr_vertices,
242 int nbr_cells,
243 int *num_vertices_per_cell,
244 double *x_vertices,
245 double *y_vertices,
246 int *cell_to_vertex,
247 int *grid_id)
248 void yac_cdef_grid_unstruct_edge ( const char * grid_name,
249 int nbr_vertices,
250 int nbr_cells,
251 int nbr_edges,
252 int *num_edges_per_cell,
253 double *x_vertices,
254 double *y_vertices,
255 int *cell_to_edge,
256 int *edge_to_vertex,
257 int *grid_id)
258 void yac_cdef_grid_unstruct_edge_ll ( const char * grid_name,
259 int nbr_vertices,
260 int nbr_cells,
261 int nbr_edges,
262 int *num_edges_per_cell,
263 double *x_vertices,
264 double *y_vertices,
265 int *cell_to_edge,
266 int *edge_to_vertex,
267 int *grid_id)
268 void yac_cdef_points_unstruct ( const int grid_id,
269 const int nbr_points,
270 const int location,
271 const double *x_points,
272 const double *y_points,
273 int *point_id )
274 void yac_cset_global_index ( const int * global_index,
275 int location,
276 int grid_id)
277 void yac_cdef_field ( const char * field_name,
278 const int component_id,
279 const int * point_ids,
280 const int num_pointsets,
281 int collection_size,
282 const char* timestep,
283 int timeunit,
284 int * field_id )
285 void yac_cdef_field_mask ( const char * field_name,
286 const int component_id,
287 const int * point_ids,
288 const int * mask_ids,
289 const int num_pointsets,
290 int collection_size,
291 const char* timestep,
292 int timeunit,
293 int * field_id )
294 void yac_csync_def_instance ( int yac_instance_id )
295 void yac_cget_ext_couple_config(int * ext_couple_config_id)
296 void yac_cset_ext_couple_config_weight_file(int ext_couple_config_id,
297 const char * weight_file)
299 int ext_couple_config_id, int weight_file_on_existing)
300 void yac_cset_ext_couple_config_mapping_side(int ext_couple_config_id,
301 int mapping_side)
302 void yac_cset_ext_couple_config_scale_factor(int ext_couple_config_id,
303 double scale_factor)
304 void yac_cset_ext_couple_config_scale_summand(int ext_couple_config_id,
305 double scale_summand)
307 int ext_couple_config_id, size_t num_src_mask_names,
308 const char * const * src_mask_names)
310 int ext_couple_config_id, const char * tgt_mask_name)
312 int ext_couple_config_id, const char * yaxt_exchanger_name)
314 int ext_couple_config_id, int use_raw_exchange);
315 void yac_cfree_ext_couple_config(int ext_couple_config_id)
316 void yac_cdef_couple_custom_instance(int yac_instance_id,
317 const char * src_comp_name,
318 const char * src_grid_name,
319 const char * src_field_name,
320 const char * tgt_comp_name,
321 const char * tgt_grid_name,
322 const char * tgt_field_name,
323 const char * coupling_timestep,
324 int time_unit, int time_reduction,
325 int interp_stack_config_id,
326 int src_lag, int tgt_lag,
327 int ext_couple_config_id)
328 void yac_cget_ ( const int field_id,
329 const int collection_size,
330 double *recv_field,
331 int *info,
332 int *ierror ) nogil
333 void yac_cget_async_ ( const int field_id,
334 const int collection_size,
335 double *recv_field,
336 int *info,
337 int *ierror )
338 void yac_cput_ ( const int field_id,
339 const int collection_size,
340 double * send_field,
341 int *info,
342 int *ierror ) nogil
343 void yac_cput_frac_ ( const int field_id,
344 const int collection_size,
345 double *send_field,
346 double *send_frac_mask,
347 int *info,
348 int *ierr ) nogil
349 void yac_cget_raw_ ( const int field_id,
350 const int collection_size,
351 double *src_field_buffer,
352 int *info,
353 int *ierror ) nogil
354 void yac_cget_raw_async_ ( const int field_id,
355 const int collection_size,
356 double *src_field_buffer,
357 int *info,
358 int *ierror )
359 void yac_cget_raw_frac_ ( const int field_id,
360 const int collection_size,
361 double *src_field_buffer,
362 double *src_frac_mask_buffer,
363 int *info,
364 int *ierror ) nogil
365 void yac_cget_raw_frac_async_ ( const int field_id,
366 const int collection_size,
367 double *src_field_buffer,
368 double *src_frac_mask_buffer,
369 int *info,
370 int *ierror )
371 void yac_cexchange_ ( const int send_field_id,
372 const int recv_field_id,
373 const int collection_size,
374 double *send_field ,
375 double *recv_field,
376 int *send_info,
377 int *recv_info,
378 int *ierror ) nogil
379 void yac_cexchange_frac_ ( const int send_field_id,
380 const int recv_field_id,
381 const int collection_size,
382 double *send_field,
383 double *send_frac_mask,
384 double *recv_field,
385 int *send_info,
386 int *recv_info,
387 int *ierror ) nogil
388 void yac_ctest ( int field_id, int * flag )
389 void yac_cwait ( int field_id ) nogil
390 void yac_cupdate( int field_id )
391 const char* yac_cget_field_name_from_field_id ( int field_id )
392 const char* yac_cget_component_name_from_field_id ( int field_id )
393 const char* yac_cget_grid_name_from_field_id ( int field_id )
394 int yac_cget_role_from_field_id ( int field_id )
395 const char* yac_cget_timestep_from_field_id ( int field_id )
396 size_t yac_cget_grid_size ( int location, int grid_id )
397 size_t yac_cget_points_size ( int points_id )
398 int yac_cget_collection_size_from_field_id ( const int field_id )
399 const char* yac_cget_field_datetime(int field_id)
400 void yac_cget_interp_stack_config(int * interp_stack_config_id)
402 int interp_stack_config_id, int reduction_type, int partial_coverage)
404 int interp_stack_config_id, int weight_type, int partial_coverage)
405 void yac_cadd_interp_stack_config_nnn(int interp_stack_config_id, int type,
406 size_t n,
407 double max_search_distance,
408 double scale)
409 void yac_cadd_interp_stack_config_rbf(int interp_stack_config_id,
410 size_t n,
411 double max_search_distance,
412 double scale)
414 int interp_stack_config_id, int order, int enforced_conserv,
415 int partial_coverage, int normalisation)
417 int interp_stack_config_id, double spread_distance,
418 double max_search_distance, int weight_type, int scale_type,
419 double src_sphere_radius, char * src_filename,
420 char * src_varname, int src_min_global_id,
421 double tgt_sphere_radius, char * tgt_filename,
422 char * tgt_varname, int tgt_min_global_id)
423 void yac_cadd_interp_stack_config_hcsbb(int interp_stack_config_id)
425 int interp_stack_config_id, char * filename,
426 int on_missing_file, int on_success)
428 int interp_stack_config_id, double value)
430 int interp_stack_config_id, char * constructor_key, char * do_search_key)
432 int interp_stack_config_id, int creep_distance)
433 void yac_cget_interp_stack_config_from_string_yaml(char * interp_stack_config,
434 int * interp_stack_config_id)
435 void yac_cget_interp_stack_config_from_string_json(char * interp_stack_config,
436 int * interp_stack_config_id)
437 void yac_cfree_interp_stack_config(int interp_stack_config_id)
438 void yac_cset_core_mask ( const int * is_core,
439 int location,
440 int grid_id)
441 void yac_cset_mask ( const int * is_valid,
442 int points_id )
443 void yac_cdef_mask_named ( const int grid_id,
444 const int nbr_points,
445 const int location,
446 const int * is_valid,
447 const char * name,
448 int *mask_id )
449 void yac_cfinalize()
450 ctypedef void (*yac_abort_func)(MPI_Comm comm, const char *msg,
451 const char *source, int line) except *
452 void yac_set_abort_handler(yac_abort_func custom_abort)
453 yac_abort_func yac_get_abort_handler()
454 void yac_cread_config_yaml_instance( int yac_instance_id,
455 const char * yaml_file)
456 void yac_cget_action( int field_id, int* action)
457 void yac_cset_config_output_file_instance( int yac_instance_id,
458 const char * filename,
459 int fileformat,
460 int sync_location,
461 int include_definitions);
462 void yac_cset_grid_output_file_instance( int yac_instance_id,
463 const char * gridname,
464 const char * filename);
465 void yac_ccompute_grid_cell_areas(int grid_id, double* cell_areas);
466 void yac_cget_raw_interp_weights_data ( const int field_id,
467 double * frac_mask_fallback_value,
468 double * scaling_factor,
469 double * scaling_summand,
470 size_t * num_fixed_values,
471 double ** fixed_values,
472 size_t ** num_tgt_per_fixed_value,
473 size_t ** tgt_idx_fixed,
474 size_t * num_wgt_tgt,
475 size_t ** wgt_tgt_idx,
476 size_t ** num_src_per_tgt,
477 double ** weights,
478 size_t ** src_field_idx,
479 size_t ** src_idx,
480 size_t * num_src_fields,
481 size_t ** src_field_buffer_sizes );
482 void yac_cget_raw_interp_weights_data_csr ( const int field_id,
483 double * frac_mask_fallback_value,
484 double * scaling_factor,
485 double * scaling_summand,
486 size_t * num_fixed_values,
487 double ** fixed_values,
488 size_t ** num_tgt_per_fixed_value,
489 size_t ** tgt_idx_fixed,
490 size_t ** src_indptr,
491 double ** weights,
492 size_t ** src_field_idx,
493 size_t ** src_idx,
494 size_t * num_src_fields,
495 size_t ** src_field_buffer_sizes );
496
497
498# helper functions for py interface (not in yac_interface.h)
499cdef extern void yac_cget_comp_size_c2py(int comp_id, int* size)
500cdef extern void yac_cget_comp_rank_c2py(int comp_id, int* rank)
501
502_logger = logging.getLogger("yac")
503_logger.addHandler(logging.NullHandler())
504
505class Location(Enum):
506 """
507 Location for points
508
509 Refers to @ref YAC_LOCATION_CELL, @ref YAC_LOCATION_CORNER and @ref YAC_LOCATION_EDGE
510 """
511 CELL = _LOCATION_CELL
512 CORNER = _LOCATION_CORNER
513 EDGE = _LOCATION_EDGE
514
515class ExchangeType(Enum):
516 """
517 Exchange type of a field
518
519 Refers to @ref YAC_EXCHANGE_TYPE_NONE, @ref YAC_EXCHANGE_TYPE_SOURCE and @ref YAC_EXCHANGE_TYPE_TARGET
520 """
521 NONE = _EXCHANGE_TYPE_NONE
522 SOURCE = _EXCHANGE_TYPE_SOURCE
523 TARGET = _EXCHANGE_TYPE_TARGET
524
525class Action(Enum):
526 """
527 Refers to @ref YAC_ACTION_NONE, @ref YAC_ACTION_REDUCTION etc.
528 """
529 NONE = _ACTION_NONE
530 REDUCTION = _ACTION_REDUCTION
531 COUPLING = _ACTION_COUPLING
532 GET_FOR_RESTART = _ACTION_GET_FOR_RESTART
533 PUT_FOR_RESTART = _ACTION_PUT_FOR_RESTART
534 OUT_OF_BOUND = _ACTION_OUT_OF_BOUND
535
536class Reduction(Enum):
537 """
538 Reduction type for the definition of interpolations
539
540 Refers to @ref YAC_REDUCTION_TIME_NONE, @ref YAC_REDUCTION_TIME_ACCUMULATE etc.
541 """
542 TIME_NONE = _REDUCTION_TIME_NONE
543 TIME_ACCUMULATE = _REDUCTION_TIME_ACCUMULATE
544 TIME_AVERAGE = _REDUCTION_TIME_AVERAGE
545 TIME_MINIMUM = _REDUCTION_TIME_MINIMUM
546 TIME_MAXIMUM = _REDUCTION_TIME_MAXIMUM
547
548class Calendar(Enum):
549 """
550 Calendar type for use in def_calendar
551
552 Refers to @ref YAC_CALENDAR_NOT_SET, @ref YAC_PROLEPTIC_GREGORIAN etc.
553 """
554 CALENDAR_NOT_SET = _CALENDAR_NOT_SET
555 PROLEPTIC_GREGORIAN = _PROLEPTIC_GREGORIAN
556 YEAR_OF_365_DAYS = _YEAR_OF_365_DAYS
557 YEAR_OF_360_DAYS = _YEAR_OF_360_DAYS
558
559def def_calendar(calendar : Calendar):
560 """
561 @see yac_cdef_calendar
562 """
563 yac_cdef_calendar(Calendar(calendar).value)
564
566 """
567 @see yac_cget_calendar
568 """
570
571
572class TimeUnit(Enum):
573 """
574 Refers to @ref YAC_TIME_UNIT_MILLISECOND, @ref YAC_TIME_UNIT_SECOND etc.
575 """
576 MILLISECOND = _TIME_UNIT_MILLISECOND
577 SECOND = _TIME_UNIT_SECOND
578 MINUTE = _TIME_UNIT_MINUTE
579 HOUR = _TIME_UNIT_HOUR
580 DAY = _TIME_UNIT_DAY
581 MONTH = _TIME_UNIT_MONTH
582 YEAR = _TIME_UNIT_YEAR
583 ISO_FORMAT = _TIME_UNIT_ISO_FORMAT
584
586 """
587 Reduction type for average interpolation
588
589 Refers to @ref YAC_AVG_ARITHMETIC, @ref YAC_AVG_DIST and @ref YAC_AVG_BARY
590 """
591 AVG_ARITHMETIC = _AVG_ARITHMETIC
592 AVG_DIST = _AVG_DIST
593 AVG_BARY = _AVG_BARY
594
596 """
597 Reduction type for ncc interpolation
598
599 Refers to @ref YAC_NCC_AVG and @ref YAC_NCC_DIST
600 """
601 AVG = _NCC_AVG
602 DIST = _NCC_DIST
603
605 """
606 Reduction type for nnn interpolation
607
608 Refers to @ref YAC_NNN_AVG, @ref YAC_NNN_DIST etc.
609 """
610 AVG = _NNN_AVG
611 DIST = _NNN_DIST
612 GAUSS = _NNN_GAUSS
613 RBF = _NNN_RBF
614
616 """
617 Normalization type for conservative interpolation
618
619 Refers to @ref YAC_CONSERV_DESTAREA and @ref YAC_CONSERV_FRACAREA
620 """
621 DESTAREA = _CONSERV_DESTAREA
622 FRACAREA = _CONSERV_FRACAREA
623
624class SPMAPWeightType(Enum):
625 """
626 Refers to @ref YAC_SPMAP_AVG and @ref YAC_SPMAP_DIST
627 """
628 AVG = _SPMAP_AVG
629 DIST = _SPMAP_DIST
630
631class SPMAPScaleType(Enum):
632 """
633 Refers to @ref YAC_SPMAP_NONE, @ref YAC_SPMAP_SRCAREA
634 @ref YAC_SPMAP_INVTGTAREA, and @ref YAC_SPMAP_FRACAREA
635 """
636 NONE = _SPMAP_NONE
637 SRCAREA = _SPMAP_SRCAREA
638 INVTGTAREA = _SPMAP_INVTGTAREA
639 FRACAREA = _SPMAP_FRACAREA
640
642 """
643 Refers to @ref YAC_FILE_MISSING_ERROR, @ref YAC_FILE_MISSING_CONT
644 """
645 ERROR = _FILE_MISSING_ERROR # abort on missing file
646 CONT = _FILE_MISSING_CONT # continue on missing file
647
649 """
650 Refers to @ref YAC_FILE_SUCCESS_STOP, @ref YAC_FILE_SUCCESS_CONT
651 """
652 STOP = _FILE_SUCCESS_STOP # prevents following interpolation method from computating further weights
653 CONT = _FILE_SUCCESS_CONT # continue weight computation with following interpolation methods
654
656 YAML = _CONFIG_OUTPUT_FORMAT_YAML
657 JSON = _CONFIG_OUTPUT_FORMAT_JSON
658
660 DEF_COMP = _CONFIG_OUTPUT_SYNC_LOC_DEF_COMP # after component definition
661 SYNC_DEF = _CONFIG_OUTPUT_SYNC_LOC_SYNC_DEF # after synchronization of definition
662 ENDDEF = _CONFIG_OUTPUT_SYNC_LOC_ENDDEF # after end of definitions
663
665 """
666 Handling of existing files, if weight file is to be written
667
668 Refers to @ref YAC_WGT_ON_EXISTING_ERROR, @ref YAC_WGT_ON_EXISTING_KEEP and
669 @ref YAC_WGT_ON_EXISTING_OVERWRITE
670 """
671 ERROR = _WGT_ON_EXISTING_ERROR # generate error and abort if file with
672 # same name already exists
673 KEEP = _WGT_ON_EXISTING_KEEP # keep existing file
674 OVERWRITE = _WGT_ON_EXISTING_OVERWRITE # overwrite existing file
675
676# replaces @classmethod @property (removed in Python 3.13)
677# see https://stackoverflow.com/questions/1697501/staticmethod-with-property
679 def __get__(self, cls, owner):
680 return classmethod(self.fget).__get__(None, owner)()
681
682class YAC:
683 """
684 Initializies a YAC instance and provides further functionality
685
686 The destructor finalizes the YAC instance by calling yac_cfinalize_instance
687 """
688 def __init__(self, comm = None, default_instance = False):
689 """
690 @see yac_cinit_instance
691 """
692 cdef int instance_id
693 cdef MPI_Comm c_comm
694 if comm is None:
695 if default_instance:
696 _logger.debug("init")
697 yac_cinit()
698 instance_id = yac_cget_default_instance_id()
699 else:
700 _logger.debug("init_instance")
701 yac_cinit_instance(&instance_id)
702 else:
703 from mpi4py import MPI
704 if type(comm) is MPI.Intracomm:
705 comm = MPI.Comm.py2f(comm)
706 if default_instance:
707 _logger.debug("init_comm")
708 yac_cinit_comm(MPI_Comm_f2c(comm))
709 instance_id = yac_cget_default_instance_id()
710 else:
711 _logger.debug("init_comm_instance")
712 yac_cinit_comm_instance(MPI_Comm_f2c(comm), &instance_id)
713 _logger.debug(f"instance_id={instance_id}")
714 self.instance_id = instance_id
715 self.owned_instance = True
716
717 @_classproperty
721 @classmethod
722 def from_id(cls, id):
723 yac = cls.__new__(cls)
724 yac.instance_id = id
725 yac.owned_instance = False
726 return yac
727
728 def __del__(self):
729 self.cleanup()
730
731 def cleanup(self):
732 """
733 @see yac_ccleanup_instance
734 """
735 if self.owned_instance:
736 _logger.debug(f"cleanup instance_id={self.instance_id}")
738 self.owned_instance = False
739
740 def def_comp(self, comp_name : str):
741 """
742 @see yac_cdef_comp_instance
743 """
744 cdef int comp_id
745 _logger.debug(f"def_comp: comp_name={comp_name}")
746 yac_cdef_comp_instance(self.instance_id, comp_name.encode(), &comp_id)
747 _logger.debug(f"comp_id={comp_id}")
748 return Component(comp_id)
749
750 def def_comps(self, comp_names = []):
751 """
752 @see yac_cdef_comps_instance
753 """
754 cdef int comp_len = len(comp_names)
755 cdef const char **c_comp_names = <const char **>malloc(comp_len * sizeof(const char *))
756 cdef int *c_comp_ids = <int*>malloc(comp_len * sizeof(int))
757 _logger.debug(f"def_comps: comp_names={comp_names}")
758 byte_comp_names = [c.encode() for c in comp_names]
759 for i in range(comp_len):
760 c_comp_names[i] = byte_comp_names[i]
761 yac_cdef_comps_instance(self.instance_id, c_comp_names, comp_len, c_comp_ids)
762 comp_list = [Component(c_comp_ids[i]) for i in range(comp_len) ]
763 free(c_comp_names)
764 free(c_comp_ids)
765 _logger.debug("comp_list={comp_list}")
766 return comp_list
767
768 def predef_comp(self, comp_name :str):
769 """
770 @see yac_cpredef_comp_instance
771 """
772 cdef int comp_id
773 _logger.debug(f"predef_comp: comp_name={comp_name}")
774 yac_cpredef_comp_instance(self.instance_id, comp_name.encode(), &comp_id)
775 _logger.debug("comp_id={comp_id}")
776 return Component(comp_id)
777
778 def def_datetime(self, start_datetime, end_datetime):
779 """
780 @see yac_cdef_datetime_instance
781
782 The parameters can be given either as a string in iso8601
783 format or as datetime objects
784 """
785 try:
786 import datetime
787 if(type(start_datetime) is datetime.datetime):
788 start_datetime = start_datetime.isoformat()
789 except:
790 pass
791 if start_datetime is not None:
792 _logger.debug(f"def_datetime start: {start_datetime}")
793 yac_cdef_datetime_instance ( self.instance_id,
794 start_datetime.encode(),
795 NULL)
796
797 try:
798 if(type(end_datetime) is datetime.datetime):
799 end_datetime = end_datetime.isoformat()
800 except:
801 pass
802 if end_datetime is not None:
803 _logger.debug(f"def_datetime end: {end_datetime}")
804 yac_cdef_datetime_instance ( self.instance_id,
805 NULL,
806 end_datetime.encode())
807
808 @property
809 def start_datetime(self):
810 """
811 @see yac_cget_start_datetime_instance (`datetime.datetime`, read-only).
812 """
814 return bytes.decode(start)
815
816 @property
817 def end_datetime(self):
818 """
819 @see yac_cget_end_datetime_instance (`datetime.datetime`, read-only).
820 """
822 return bytes.decode(end)
823
824 def sync_def(self):
825 """
826 @see yac_csync_def_instance
827 """
828 _logger.debug("sync_def")
830
831 def def_couple(self,
832 src_comp : str, src_grid : str, src_field,
833 tgt_comp : str, tgt_grid : str, tgt_field,
834 coupling_timestep : str, timeunit : TimeUnit,
835 time_reduction : Reduction,
836 interp_stack, src_lag = 0, tgt_lag = 0,
837 weight_file = None,
838 weight_file_on_existing : WeightFileOnExisting =
839 WeightFileOnExisting.OVERWRITE,
840 mapping_on_source = 1,
841 scale_factor = 1.0, scale_summand = 0.0,
842 src_masks_names = None, tgt_mask_name = None,
843 yaxt_exchanger_name = None,
844 use_raw_exchange = False):
845 """
846 @see yac_cdef_couple_instance
847 """
848 cdef char * weight_file_ptr
849 if weight_file is None:
850 weight_file_ptr = NULL
851 else:
852 weight_file_bytes = weight_file.encode()
853 weight_file_ptr = weight_file_bytes
854 cdef const char ** src_mask_names_ptr = NULL
855 cdef const char * tgt_mask_name_ptr = NULL
856 cdef const char * yaxt_exchanger_name_ptr = NULL
857 cdef int couple_config_id
858 yac_cget_ext_couple_config(&couple_config_id)
860 weight_file_ptr)
862 couple_config_id,
863 WeightFileOnExisting(weight_file_on_existing).value)
865 mapping_on_source)
867 scale_factor)
869 scale_summand)
870 if src_masks_names is not None:
871 if type(src_masks_names) is str:
872 src_masks = [src_masks_names]
873 src_masks_enc = [s.encode() for s in src_masks_names]
874 src_mask_names_ptr = <const char **>malloc(len(src_masks_enc) * sizeof(char*))
875 for i in range(len(src_masks_enc)):
876 src_mask_names_ptr[i] = src_masks_enc[i]
878 len(src_masks_enc),
879 src_mask_names_ptr)
880 free(src_mask_names_ptr)
881 if tgt_mask_name is not None:
882 yac_cset_ext_couple_config_tgt_mask_name(couple_config_id, tgt_mask_name.encode())
883 if yaxt_exchanger_name is not None:
884 yac_cset_ext_couple_config_yaxt_exchanger_name(couple_config_id, yaxt_exchanger_name.encode())
885 yac_cset_ext_couple_config_use_raw_exchange(couple_config_id, 1 if use_raw_exchange else 0)
886 _logger.debug(f"def_couple {(src_comp.encode(), src_grid.encode(), src_field.encode())}, {(tgt_comp.encode(), tgt_grid.encode(), tgt_field.encode())}")
888 src_comp.encode(), src_grid.encode(), src_field.encode(),
889 tgt_comp.encode(), tgt_grid.encode(), tgt_field.encode(),
890 coupling_timestep.encode(), TimeUnit(timeunit).value,
891 Reduction(time_reduction).value,
892 interp_stack.interp_stack_id, src_lag, tgt_lag,
893 couple_config_id)
894 yac_cfree_ext_couple_config(couple_config_id)
895
896 def enddef(self):
897 """
898 @see yac_cenddef_instance
899 """
900 _logger.debug("enddef")
902
903 @property
905 """
906 @see yac_cget_comp_names
907 """
908 cdef int nbr_components = yac_cget_nbr_comps_instance(self.instance_id)
909 cdef const char **ret = <const char **>malloc(nbr_components * sizeof(const char *))
910 yac_cget_comp_names_instance(self.instance_id, nbr_components, ret)
911 comp_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_components) ]
912 free(ret)
913 return comp_list
914
915 @property
916 def grid_names(self):
917 """
918 @see yac_cget_grid_names
919 """
920 cdef int nbr_grids = yac_cget_nbr_grids_instance(self.instance_id)
921 cdef const char **ret = <const char **>malloc(nbr_grids * sizeof(const char *))
922 yac_cget_grid_names_instance(self.instance_id, nbr_grids, ret)
923 grid_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_grids) ]
924 free(ret)
925 return grid_list
926
927 def get_comp_grid_names(self, comp_name):
928 """
929 @see yac_cget_comp_grid_names
930 """
931 cdef int nbr_grids = yac_cget_comp_nbr_grids_instance(self.instance_id, comp_name.encode())
932 cdef const char **ret = <const char **>malloc(nbr_grids * sizeof(const char *))
933 yac_cget_comp_grid_names_instance(self.instance_id, comp_name.encode(), nbr_grids, ret)
934 grid_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_grids) ]
935 free(ret)
936 return grid_list
937
938 def get_field_names(self, comp_name : str, grid_name : str):
939 """
940 @see yac_cget_field_names
941 """
942 cdef int nbr_fields = yac_cget_nbr_fields_instance(self.instance_id,
943 comp_name.encode(),
944 grid_name.encode())
945 cdef const char **ret = <const char **>malloc(nbr_fields * sizeof(const char *))
946 yac_cget_field_names_instance(self.instance_id, comp_name.encode(),
947 grid_name.encode(), nbr_fields, ret)
948 field_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_fields) ]
949 free(ret)
950 return field_list
951
952 def get_field_id(self, comp_name : str, grid_name : str, field_name : str):
953 """
954 @see yac_cget_field_id
955 """
956 return yac_cget_field_id_instance (self.instance_id,
957 comp_name.encode(),
958 grid_name.encode(),
959 field_name.encode())
960
961 def get_field_timestep(self, comp_name : str, grid_name : str, field_name : str):
962 """
963 @see yac_cget_field_timestep
964 """
966 comp_name.encode(),
967 grid_name.encode(),
968 field_name.encode()).decode('UTF-8')
969
970 def get_field_role(self, comp_name : str, grid_name : str, field_name : str):
971 """
972 @see yac_cget_field_role
973 """
974 return ExchangeType(yac_cget_field_role_instance (self.instance_id,
975 comp_name.encode(),
976 grid_name.encode(),
977 field_name.encode()))
978
979 def get_field_source(self, comp_name : str, grid_name : str,
980 field_name : str):
981 cdef const char* src_comp
982 cdef const char* src_grid
983 cdef const char* src_field
985 comp_name.encode(),
986 grid_name.encode(),
987 field_name.encode(),
988 &src_comp,
989 &src_grid,
990 &src_field)
991 return (src_comp.decode("UTF-8"),
992 src_grid.decode("UTF-8"),
993 src_field.decode("UTF-8"))
994
995 def get_field_collection_size(self, comp_name : str, grid_name : str, field_name : str):
996 """
997 @see yac_cget_field_collection_size
998 """
1000 comp_name.encode(),
1001 grid_name.encode(),
1002 field_name.encode())
1003
1004 def get_field_frac_mask_fallback_value(self, comp_name : str, grid_name : str, field_name : str):
1005 """
1006 @see yac_cget_field_frac_mask_fallback_value
1007 """
1009 comp_name.encode(),
1010 grid_name.encode(),
1011 field_name.encode())
1012
1013 def enable_field_frac_mask(self, comp_name : str, grid_name : str, field_name : str,
1014 frac_mask_fallback_value : _np.float64):
1015 """
1016 @see yac_cenable_field_frac_mask
1017 """
1018 _logger.debug(f"enable_field_frac_mask {(comp_name, grid_name, field_name)})")
1020 comp_name.encode(),
1021 grid_name.encode(),
1022 field_name.encode(),
1023 frac_mask_fallback_value)
1024
1025 def def_component_metadata(self, comp_name : str, metadata : bytes):
1026 """
1027 @see yac_cdef_component_metadata
1028 """
1029 _logger.debug(f"def_component_metadata comp_name={comp_name}")
1031 comp_name.encode(), metadata)
1032
1033 def def_grid_metadata(self, grid_name : str, metadata : bytes):
1034 """
1035 @see yac_cdef_grid_metadata
1036 """
1037 _logger.debug(f"def_grid_metadata grid_name={grid_name}")
1039 grid_name.encode(), metadata)
1040
1041 def def_field_metadata(self, comp_name : str, grid_name : str,
1042 field_name : str,metadata : bytes):
1043 """
1044 @see yac_cdef_field_metadata
1045 """
1046 _logger.debug("def_field_metadata (comp_name, grid_name, field_name)="
1047 f"{(comp_name, grid_name, field_name)}")
1048 yac_cdef_field_metadata_instance(self.instance_id, comp_name.encode(),
1049 grid_name.encode(), field_name.encode(),
1050 metadata)
1051
1052 def get_component_metadata(self, comp_name : str):
1053 """
1054 @see yac_cget_component_metadata
1055 """
1056 cdef const char* metadata = yac_cget_component_metadata_instance(self.instance_id,
1057 comp_name.encode())
1058 return bytes(metadata).decode('UTF-8') if metadata != NULL else None
1059
1060 def get_grid_metadata(self, grid_name : str):
1061 """
1062 @see yac_cget_grid_metadata
1063 """
1064 cdef const char* metadata = yac_cget_grid_metadata_instance(self.instance_id,
1065 grid_name.encode())
1066 return bytes(metadata).decode('UTF-8') if metadata != NULL else None
1067
1068 def get_field_metadata(self, comp_name : str, grid_name : str, field_name :str):
1069 """
1070 @see yac_cget_field_metadata
1071 """
1072 cdef const char* metadata = yac_cget_field_metadata_instance(self.instance_id,
1073 comp_name.encode(),
1074 grid_name.encode(),
1075 field_name.encode())
1076 return bytes(metadata).decode('UTF-8') if metadata != NULL else None
1077
1078 def get_comps_comm(self, comp_names):
1079 """
1080 @see yac_cget_comps_comm
1081 """
1082 from mpi4py import MPI
1083 cdef MPI_Comm comm
1084 cptr = [c.encode() for c in comp_names]
1085 cdef const char ** comp_names_c_ptr = <const char **>malloc(len(comp_names) * sizeof(const char *))
1086 for i in range(len(comp_names)):
1087 comp_names_c_ptr[i] = cptr[i]
1088 yac_cget_comps_comm_instance(self.instance_id, comp_names_c_ptr, len(comp_names), &comm)
1089 free(comp_names_c_ptr)
1090 # convert to mpi4py communicator
1091 return MPI.Comm.f2py(MPI_Comm_c2f(comm))
1092
1093 def read_config_yaml(self, yaml_file : str):
1094 """
1095 @see yac_cread_config_yaml_instance
1096 """
1097 _logger.debug(f"read_config_yaml yaml_file={yaml_file}")
1098 yac_cread_config_yaml_instance(self.instance_id, yaml_file.encode())
1099
1100 def set_config_output_file(self, filename : str,
1101 fileformat : ConfigOutputFormat,
1102 sync_location : ConfigOutputSyncLoc,
1103 include_definitions : bool = False):
1104 """
1105 @see yac_cset_config_output_file_instance
1106 """
1108 filename.encode(),
1109 fileformat.value,
1110 sync_location.value,
1111 1 if include_definitions else 0)
1112
1113 def set_grid_output_file(self, gridname : str, filename : str):
1114 """
1115 @see yac_cset_grid_output_file_instance
1116 """
1118 gridname.encode(),
1119 filename.encode())
1120
1122 """
1123 Stores the component_id and provides further functionality
1124 """
1125 def __init__(self, comp_id):
1126 self.comp_id = comp_id
1127
1128 @property
1129 def comp_comm(self):
1130 """
1131 @see yac_cget_comp_comm (`MPI.Comm`, read-only)
1132 """
1133 from mpi4py import MPI
1134 cdef MPI_Comm comm
1135 yac_cget_comp_comm(self.comp_id, &comm)
1136 # convert to mpi4py communicator
1137 return MPI.Comm.f2py(MPI_Comm_c2f(comm))
1138
1139 @property
1140 def size(self):
1141 """
1142 number of processes in this component
1143 """
1144 cdef int size
1145 yac_cget_comp_size_c2py(self.comp_id, &size)
1146 return size
1147
1148 @property
1149 def rank(self):
1150 """
1151 process index in the component
1152 """
1153 cdef int rank
1154 yac_cget_comp_rank_c2py(self.comp_id, &rank)
1155 return rank
1156
1157class Mask:
1158 """
1159 Stores the mask_id
1160 """
1161 def __init__(self, mask_id):
1162 self.mask_id = mask_id
1163
1164class Grid:
1165 """
1166 Stores the grid_id and provides further functionality
1167
1168 Base class for Reg2dGrid and UnstructuredGrid
1169 """
1170 def __init__(self, grid_id):
1171 _logger.debug(f"grid_id={grid_id}")
1172 self.grid_id = grid_id
1173
1174 def set_global_index(self, global_index, location : Location):
1175 """
1176 @see yac_cset_global_index
1177 """
1178 cdef const int[::1] global_index_view = _np.ascontiguousarray(global_index, dtype=_np.intc)
1179 assert len(global_index_view) == yac_cget_grid_size ( location.value, self.grid_id ), \
1180 "Wrong number of indices provided"
1181 _logger.debug(f"set_global_index grid_id={self.grid_id}")
1182 yac_cset_global_index(&global_index_view[0], location.value, self.grid_id)
1183
1184 @property
1185 def nbr_cells(self):
1186 """
1187 @see yac_cget_grid_size (`int`, read-only)
1188 """
1189 return yac_cget_grid_size ( Location.CELL.value, self.grid_id )
1190
1191 @property
1192 def nbr_corners(self):
1193 """
1194 @see yac_cget_grid_size (`int`, read-only)
1195 """
1196 return yac_cget_grid_size ( Location.CORNER.value, self.grid_id )
1197
1198 @property
1199 def nbr_edges(self):
1200 """
1201 @see yac_cget_grid_size (`int`, read-only)
1202 """
1203 return yac_cget_grid_size ( Location.EDGE.value, self.grid_id )
1204
1205 def set_core_mask(self, is_core, location : Location):
1206 """
1207 @see yac_cset_core_mask
1208 """
1209 cdef size_t len_is_core = len(is_core)
1210 assert(len_is_core == yac_cget_grid_size( location.value, self.grid_id ) )
1211 cdef const int[::1] np_mask = _np.ascontiguousarray(is_core, dtype=_np.intc)
1212 _logger.debug(f"set_core_mask grid_id={self.grid_id}")
1213 yac_cset_core_mask ( &np_mask[0], location.value, self.grid_id)
1214
1215 def def_mask(self, location : Location,
1216 is_valid, name = None):
1217 cdef int len_is_valid = len(is_valid)
1218 cdef const int[::1] np_mask = _np.ascontiguousarray(is_valid, dtype=_np.int32)
1219 cdef int mask_id
1220 cdef char* c_name = NULL
1221 if name is not None:
1222 name_enc = name.encode()
1223 c_name = name_enc
1224 _logger.debug(f"def_mask_named grid_id={self.grid_id}, name={name}")
1225 yac_cdef_mask_named ( self.grid_id,
1226 len_is_valid,
1227 location.value,
1228 &np_mask[0],
1229 c_name,
1230 &mask_id )
1231 return Mask(mask_id)
1232
1233 def compute_grid_cell_areas(self, cell_areas = None):
1234 """
1235 @see yac_ccompute_grid_cell_areas
1236 """
1237 if cell_areas is None:
1238 cell_areas = _np.empty(self.nbr_cells)
1239 cdef double[::1] np_cell_areas = _np.ascontiguousarray(cell_areas, dtype=_np.double)
1240 yac_ccompute_grid_cell_areas(self.grid_id, &np_cell_areas[0])
1241 return cell_areas
1242
1244 """
1245 Stores the points_id and provides further functionality
1246 """
1247 def __init__(self, points_id):
1248 self.points_id = points_id
1249
1250 @property
1251 def size(self):
1252 """
1253 @see yac_cget_points_size (`int`, read-only)
1254 """
1255 return yac_cget_points_size ( self.points_id )
1256
1257 def set_mask(self, is_valid):
1258 """
1259 @see yac_cset_mask
1260 """
1261 cdef size_t len_is_valid = len(is_valid)
1262 assert len_is_valid==self.size
1263 cdef const int[::1] np_mask = _np.ascontiguousarray(is_valid, dtype=_np.intc)
1264 _logger.debug(f"set_mask points_id={self.points_id}")
1265 yac_cset_mask ( &np_mask[0],
1266 self.points_id )
1267
1269 """
1270 A stuctured 2d Grid
1271 """
1272 def __init__(self, grid_name : str, x_vertices, y_vertices,
1273 cyclic = [False, False], north_pole = None):
1274 """
1275 @see yac_cdef_grid_reg2d
1276 """
1277 cdef int grid_id
1278 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1279 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1280 cdef int[2] cyclic_view = cyclic
1281 cdef const double[::1] n_p
1282 self.north_pole = north_pole
1283 if north_pole is None:
1284 _logger.debug(f"def_grid_reg2d grid_name={grid_name}")
1285 yac_cdef_grid_reg2d(grid_name.encode(), [len(x),len(y)],
1286 cyclic_view, <double*>&x[0], <double*>&y[0],
1287 &grid_id)
1288 else:
1289 n_p = _np.ascontiguousarray(north_pole, dtype=_np.double)
1290 _logger.debug(f"def_grid_reg2d_rot grid_name={grid_name}")
1291 yac_cdef_grid_reg2d_rot(grid_name.encode(), [len(x),len(y)],
1292 cyclic_view, <double*>&x[0], <double*>&y[0],
1293 n_p[0], n_p[1], &grid_id)
1294 super().__init__(grid_id)
1295
1296 def def_points(self, location : Location,
1297 x_vertices, y_vertices):
1298 """
1299 @see yac_cdef_points_reg2d
1300 """
1301 cdef int points_id
1302 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1303 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1304 cdef const double[::1] n_p
1305 if self.north_pole is None:
1306 _logger.debug(f"def_points_reg2d grid_id={self.grid_id}")
1308 location.value, &x[0], &y[0], &points_id)
1309 else:
1310 n_p = _np.ascontiguousarray(self.north_pole, dtype=_np.double)
1311 _logger.debug(f"def_points_reg2d_rot grid_id={self.grid_id}")
1312 yac_cdef_points_reg2d_rot(self.grid_idgrid_id, [len(x), len(y)],
1313 location.value, &x[0], &y[0],
1314 n_p[0], n_p[1],
1315 &points_id)
1316 _logger.debug(f"points_id={points_id}")
1317 return Points(points_id)
1318
1319 def def_points_unstruct(self, location : Location,
1320 x_vertices, y_vertices):
1321 """
1322 @see yac_cdef_points_unstruct
1323 """
1324 assert len(x_vertices) == len(y_vertices)
1325 cdef int points_id
1326 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1327 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1328 _logger.debug(f"def_points_unstruct grid_id={self.grid_id}")
1330 location.value, &x[0], &y[0], &points_id)
1331 _logger.debug(f"points_id={points_id}")
1332 return Points(points_id)
1333
1335 """
1336 A curvilinear stuctured 2d Grid
1337 """
1338 def __init__(self, grid_name : str, x_vertices, y_vertices,
1339 cyclic = [False, False]):
1340 """
1341 @see yac_cdef_grid_curve2d
1342 """
1343 cdef int grid_id
1344 cdef const double[::1] x = _np.ascontiguousarray(x_vertices.flatten(), dtype=_np.double)
1345 cdef const double[::1] y = _np.ascontiguousarray(y_vertices.flatten(), dtype=_np.double)
1346 cdef int[2] cyclic_view = cyclic
1347 _logger.debug(f"def_grid_curve2d grid_name={grid_name}")
1348 yac_cdef_grid_curve2d(grid_name.encode(),
1349 [_np.shape(x_vertices)[1], _np.shape(y_vertices)[0]],
1350 cyclic_view, <double*>&x[0], <double*>&y[0], &grid_id)
1351 super().__init__(grid_id)
1352
1353 def def_points(self, location : Location,
1354 x_vertices, y_vertices):
1355 """
1356 @see yac_cdef_points_curve2d
1357 """
1358 assert x_vertices.shape == y_vertices.shape
1359 cdef int points_id
1360 cdef const double[::1] x = _np.ascontiguousarray(x_vertices.flatten(), dtype=_np.double)
1361 cdef const double[::1] y = _np.ascontiguousarray(y_vertices.flatten(), dtype=_np.double)
1362 _logger.debug(f"def_points_curve2d grid_id={self.grid_id}")
1364 [_np.shape(x_vertices)[1], _np.shape(x_vertices)[0]],
1365 location.value, &x[0], &y[0], &points_id)
1366 _logger.debug(f"points_id={points_id}")
1367 return Points(points_id)
1368
1369 def def_points_unstruct(self, location : Location,
1370 x_vertices, y_vertices):
1371 """
1372 @see yac_cdef_points_unstruct
1373 """
1374 assert len(x_vertices) == len(y_vertices)
1375 cdef int points_id
1376 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1377 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1378 _logger.debug(f"def_points_unstruct grid_id={self.grid_id}")
1380 location.value, &x[0], &y[0], &points_id)
1381 _logger.debug(f"points_id={points_id}")
1382 return Points(points_id)
1383
1384
1386 def __init__(self, grid_id):
1387 super().__init__(grid_id)
1388
1389 def def_points(self, location : Location,
1390 x_points, y_points):
1391 """
1392 @see yac_cdef_points_unstruct
1393 """
1394 cdef int points_id
1395 cdef const double[::1] x_points_view = _np.ascontiguousarray(x_points, dtype=_np.double)
1396 cdef const double[::1] y_points_view = _np.ascontiguousarray(y_points, dtype=_np.double)
1397 _logger.debug(f"yac_cdef_points_unstruct grid_id={self.grid_id}")
1398 yac_cdef_points_unstruct(self.grid_idgrid_id, len(x_points_view), location.value,
1399 &x_points_view[0], &y_points_view[0], &points_id)
1400 _logger.debug(f"points_id={points_id}")
1401 return Points(points_id)
1402
1404 """
1405 An unstuctured 2d Grid
1406 """
1407 def __init__(self, grid_name : str, num_vertices_per_cell,
1408 x_vertices, y_vertices, cell_to_vertex, use_ll_edges=False):
1409 """
1410 @see yac_cdef_grid_unstruct and @see yac_cdef_grid_unstruct_ll
1411 """
1412 cdef int grid_id
1413 cdef const int[::1] num_vertices_per_cell_view = _np.ascontiguousarray(num_vertices_per_cell, dtype=_np.intc)
1414 cdef const double[::1] x_vertices_view = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1415 cdef const double[::1] y_vertices_view = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1416 cdef const int[::1] cell_to_vertex_view = _np.ascontiguousarray(cell_to_vertex, dtype=_np.intc)
1417 assert len(num_vertices_per_cell_view) > 0, \
1418 "UnstrucuredGrid needs at least one cell. Use CloudGrid if you dont need to define cells."
1419 if not use_ll_edges:
1420 _logger.debug(f"def_grid_unstruct grid_name={grid_name}")
1421 yac_cdef_grid_unstruct(grid_name.encode(), len(x_vertices_view),
1422 len(num_vertices_per_cell_view),
1423 <int*>&num_vertices_per_cell_view[0],
1424 <double*>&x_vertices_view[0],
1425 <double*>&y_vertices_view[0],
1426 <int*>&cell_to_vertex_view[0], &grid_id)
1427 else:
1428 _logger.debug(f"def_grid_unstruct_ll grid_name={grid_name}")
1429 yac_cdef_grid_unstruct_ll(grid_name.encode(), len(x_vertices_view),
1430 len(num_vertices_per_cell_view),
1431 <int*>&num_vertices_per_cell_view[0],
1432 <double*>&x_vertices_view[0],
1433 <double*>&y_vertices_view[0],
1434 <int*>&cell_to_vertex_view[0], &grid_id)
1435 super().__init__(grid_id)
1436
1438 """
1439 @see yac_cdef_grid_cloud
1440 """
1441 def __init__(self, grid_name : str, x_vertices, y_vertices):
1442 cdef int grid_id
1443 cdef const double[::1] x_vertices_view = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1444 cdef const double[::1] y_vertices_view = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1445 _logger.debug(f"def_grid_cloud grid_name={grid_name}")
1446 yac_cdef_grid_cloud (grid_name.encode(),
1447 len(x_vertices_view),
1448 <double*>&x_vertices_view[0],
1449 <double*>&y_vertices_view[0],
1450 &grid_id)
1451 super().__init__(grid_id)
1452
1453 def def_points(self, x_points, y_points):
1454 return super().def_points(Location.CORNER, x_points, y_points)
1455
1456
1458 def __init__(self, grid_name : str, num_edges_per_cell,
1459 x_vertices, y_vertices, cell_to_edge, edge_to_vertex,
1460 use_ll_edges=False):
1461 cdef int grid_id
1462 cdef const int[::1] num_edges_per_cell_view = _np.ascontiguousarray(num_edges_per_cell, dtype=_np.intc)
1463 cdef const double[::1] x_vertices_view = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1464 cdef const double[::1] y_vertices_view = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1465 cdef const int[::1] cell_to_edge_view = _np.ascontiguousarray(cell_to_edge, dtype=_np.intc)
1466 cdef const int[:, ::1] edge_to_vertex_view = _np.ascontiguousarray(edge_to_vertex, dtype=_np.intc)
1467 assert edge_to_vertex_view.shape[1] == 2, \
1468 "dimension 1 of edge_to_vertex must be 2"
1469 assert len(num_edges_per_cell_view) > 0, \
1470 "UnstrucuredGridEdge needs at least one cell. Use CloudGrid if you dont need to define cells."
1471 if not use_ll_edges:
1472 _logger.debug(f"def_grid_unstruct_edge grid_name={grid_name}")
1473 yac_cdef_grid_unstruct_edge(grid_name.encode(), len(x_vertices_view),
1474 len(num_edges_per_cell_view),
1475 edge_to_vertex_view.shape[0],
1476 <int*>&num_edges_per_cell_view[0],
1477 <double*>&x_vertices_view[0],
1478 <double*>&y_vertices_view[0],
1479 <int*>&cell_to_edge_view[0],
1480 <int*>&edge_to_vertex_view[0,0],
1481 &grid_id)
1482 else:
1483 _logger.debug(f"def_grid_unstruct_edge_ll grid_name={grid_name}")
1484 yac_cdef_grid_unstruct_edge_ll(grid_name.encode(), len(x_vertices_view),
1485 len(num_edges_per_cell_view),
1486 edge_to_vertex_view.shape[0],
1487 <int*>&num_edges_per_cell_view[0],
1488 <double*>&x_vertices_view[0],
1489 <double*>&y_vertices_view[0],
1490 <int*>&cell_to_edge_view[0],
1491 <int*>&edge_to_vertex_view[0,0],
1492 &grid_id)
1493 super().__init__(grid_id)
1494
1495
1496class Field:
1497 """
1498 Store the field_id
1499 """
1500 def __init__(self, field_id, size=None):
1501 self.field_id = field_id
1502 self._size = size
1503
1504 @classmethod
1505 def create(cls, field_name : str, comp : Component, points, collection_size,
1506 timestep : str, timeunit : TimeUnit, masks = None):
1507 """
1508 @see yac_cdef_field
1509 """
1510 from collections.abc import Iterable
1511 cdef int field_id
1512 if not isinstance(points, Iterable):
1513 points = [points]
1514 cdef const int[:] point_ids_array = _np.array([p.points_id for p in points], dtype=_np.intc)
1515 size = sum(p.size for p in points)
1516 cdef const int[:] mask_ids_array
1517 if masks is None:
1518 _logger.debug(f"def_field field_name={field_name}, comp_id={comp.comp_id}, point_ids={[p.points_id for p in points]}")
1519 yac_cdef_field(field_name.encode(), comp.comp_id,
1520 &point_ids_array[0], len(point_ids_array),
1521 collection_size, timestep.encode(), TimeUnit(timeunit).value, &field_id)
1522 else:
1523 if not isinstance(masks, Iterable):
1524 masks = [masks]
1525 mask_ids_array = _np.array([m.mask_id for m in masks], dtype=_np.intc)
1526 _logger.debug(f"def_field_mask field_name={field_name}, comp_id={comp.comp_id}, point_ids={[p.points_id for p in points]}")
1527 yac_cdef_field_mask(field_name.encode(), comp.comp_id,
1528 &point_ids_array[0], &mask_ids_array[0],
1529 len(point_ids_array),
1530 collection_size, timestep.encode(), TimeUnit(timeunit).value, &field_id)
1531 _logger.debug(f"field_id={field_id}")
1532 return Field(field_id, size)
1533
1534 def test(self):
1535 """
1536 @see yac_ctest
1537
1538 """
1539 cdef int flag
1540 _logger.debug(f"test field_id={self.field_id}")
1541 yac_ctest ( self.field_id, &flag )
1542 _logger.debug(f"flag={flag}")
1543 return flag
1544
1545 def wait(self):
1546 """
1547 @see yac_cwait
1548
1549 """
1550 cdef int field_id = self.field_id
1551 _logger.debug(f"wait field_id={field_id}")
1552 with cython.nogil:
1553 yac_cwait ( field_id )
1554
1555 @coroutine
1556 def wait_coro(self):
1557 """
1558 Coroutine. Blocks until the communication is completed.
1559 """
1560 while self.test() == 0:
1561 yield
1562
1563 @cython.boundscheck(False)
1564 def get(self, buf=None, asyn=False):
1565 """
1566 @see yac_cget_ and variants
1567
1568 @param[out] buf receive buffer, if `None` a numpy array of correct size is allocated
1569 @param[in] asyn if True the call returns immediately and must be completed
1570 with `test` or `wait`
1571 """
1572 cdef int info
1573 cdef int ierror
1574 buf_in = buf
1575 if buf is None:
1576 buf = _np.empty((self.collection_sizecollection_size, self.sizesize), dtype=_np.double)
1577 buf = _np.ascontiguousarray(buf.reshape(self.collection_sizecollection_size, self.sizesize), dtype=_np.double)
1578 if buf_in is not None and buf.base is None:
1579 _logger.warning("get: non-contiguous buffer passed to get. Reallocated memory.")
1580 cdef double[:,::1] buf_view = buf
1581 cdef int field_id = self.field_id
1582 cdef int collection_size = self.collection_sizecollection_size
1583 if asyn:
1584 _logger.debug(f"get_async_ field_id={self.field_id}")
1585 yac_cget_async_(field_id, collection_size, &buf_view[0,0], &info, &ierror)
1586 else:
1587 _logger.debug(f"get_ field_id={self.field_id}")
1588 with cython.nogil:
1589 yac_cget_(field_id, collection_size, &buf_view[0,0], &info, &ierror)
1590 if ierror != 0:
1591 raise RuntimeError("yac_cget returned error number " + str(ierror))
1592 _logger.debug(f"info={info}")
1593 return buf, Action(info)
1594
1595 async def get_coro(self, buf=None):
1596 """
1597 Coroutine. Executes a get operation.
1598
1599 @see yac_cget_async_
1600
1601 @param[out] buf receive buffer, if `None` a numpy array of correct size is allocated
1602 """
1603 buf, info = self.get(buf, asyn=True)
1604 await self.wait_coro()
1605 return buf, info
1606
1607 @cython.boundscheck(False)
1608 def get_raw(self, buf, frac_mask=None, asyn=False):
1609 """
1610 @see yac_cget_raw_ and variants
1611
1612 @param[inout] buf receive buffer, if `None` a numpy array of correct size is allocated
1613 @param[inout] frac_mask receive buffer for frac_mask, if `None` a numpy array of correct size is allocated
1614 @param[in] asyn if True the call returns immediately and must be completed
1615 with `test` or `wait`
1616 """
1617 cdef int info
1618 cdef int ierror
1619 buf = _np.ascontiguousarray(buf.reshape(self.collection_sizecollection_size, -1), dtype=_np.double)
1620 if buf.base is None:
1621 _logger.warning("get: non-contiguous buffer passed to get_raw. Reallocated memory.")
1622 cdef double[:,::1] buf_view = buf
1623 if frac_mask is not None:
1624 frac_mask = _np.ascontiguousarray(frac_mask.reshape(self.collection_sizecollection_size, -1), dtype=_np.double)
1625 if frac_mask is not None and frac_mask.base is None:
1626 _logger.warning("get: non-contiguous frac_mask buffer passed to get_raw. Reallocated memory.")
1627 cdef double[:,::1] frac_mask_view = frac_mask
1628 cdef int field_id = self.field_id
1629 cdef int collection_size = self.collection_sizecollection_size
1630 if asyn:
1631 if frac_mask is not None:
1632 _logger.debug(f"get_raw_frac_async_ field_id={self.field_id}")
1633 yac_cget_raw_frac_async_(field_id, collection_size, &buf_view[0,0],
1634 &frac_mask_view[0,0], &info, &ierror)
1635 else:
1636 _logger.debug(f"get_raw_async_ field_id={self.field_id}")
1637 yac_cget_raw_async_(field_id, collection_size, &buf_view[0,0], &info, &ierror)
1638 else:
1639 if frac_mask is not None:
1640 _logger.debug(f"get_raw_frac_ field_id={self.field_id}")
1641 with cython.nogil:
1642 yac_cget_raw_frac_(field_id, collection_size, &buf_view[0,0],
1643 &frac_mask_view[0,0], &info, &ierror)
1644 else:
1645 _logger.debug(f"get_raw_ field_id={self.field_id}")
1646 with cython.nogil:
1647 yac_cget_raw_(field_id, collection_size, &buf_view[0,0], &info, &ierror)
1648 if ierror != 0:
1649 raise RuntimeError("yac_cget returned error number " + str(ierror))
1650 _logger.debug(f"info={info}")
1651 return buf, frac_mask, Action(info)
1652
1653 @cython.boundscheck(False)
1654 def put(self, buf, frac_mask = None):
1655 """
1656 @see yac_cput_
1657 """
1658 cdef int info
1659 cdef int ierror
1660 cdef const double[:,:,::1] buf_view = _np.ascontiguousarray(buf.reshape(-1,self.collection_sizecollection_size,self.sizesize), dtype=_np.double)
1661 cdef const double[:,:,::1] frac_mask_view
1662 cdef int field_id = self.field_id
1663 cdef int collection_size = self.collection_sizecollection_size
1664 if frac_mask is not None:
1665 frac_mask_view = _np.ascontiguousarray(
1666 frac_mask.reshape(-1,self.collection_sizecollection_size,self.sizesize), dtype=_np.double)
1667 _logger.debug(f"put_frac_ field_id={self.field_id}")
1668 with cython.nogil:
1669 yac_cput_frac_(field_id, collection_size, <double*>&buf_view[0,0,0],
1670 <double*>&frac_mask_view[0,0,0], &info, &ierror)
1671 else:
1672 _logger.debug(f"put_ field_id={self.field_id}")
1673 with cython.nogil:
1674 yac_cput_(field_id, collection_size, <double*>&buf_view[0,0,0], &info, &ierror)
1675 if ierror != 0:
1676 raise RuntimeError("yac_cput returned error number " + str(ierror))
1677 _logger.debug(f"info={info}")
1678 return Action(info)
1679
1680 async def put_coro(self, buf, frac_mask = None):
1681 """
1682 Coroutine. Executes a put operation.
1683
1684 @see yac_cput_
1685 """
1686 await self.wait_coro()
1687 return self.put(buf, frac_mask)
1688
1689 def update(self):
1690 """
1691 @see yac_cupdate
1692 """
1693 _logger.debug(f"update field_id={self.field_id}")
1694 yac_cupdate(self.field_id)
1695
1696 @classmethod
1697 @cython.boundscheck(False)
1698 def exchange(cls, send_field, recv_field, send_buf, recv_buf=None, send_frac_mask=None):
1699 """
1700 @see yac_cexchange_frac_
1701 """
1702 assert send_field.collection_size == recv_field.collection_size, "exchange can only be used with fields of the same collection_size"
1703 cdef int collection_size = send_field.collection_size
1704 cdef int send_info
1705 cdef int recv_info
1706 cdef int ierror
1707 cdef const double[:,:,::1] send_buf_view = _np.ascontiguousarray(send_buf.reshape(-1,collection_size,send_field.size), dtype=_np.double)
1708 cdef const double[:,:,::1] frac_mask_view
1709 if recv_buf is None:
1710 recv_buf = _np.empty((collection_size, recv_field.size), dtype=_np.double)
1711 recv_buf = _np.ascontiguousarray(recv_buf.reshape(collection_size, recv_field.size), dtype=_np.double)
1712 cdef double[:,::1] recv_buf_view = recv_buf
1713 cdef int send_field_id = send_field.field_id
1714 cdef int recv_field_id = recv_field.field_id
1715 if send_frac_mask is None:
1716 _logger.debug(f"exchange_ with send_field.field_id={send_field.field_id} and recv_field.field_id={recv_field.field_id}")
1717 with cython.nogil:
1718 yac_cexchange_(send_field_id, recv_field_id, collection_size,
1719 <double*>&send_buf_view[0,0,0],
1720 <double*>&recv_buf_view[0,0],
1721 &send_info, &recv_info, &ierror)
1722 else:
1723 _logger.debug(f"exchange_frac_ with send_field.field_id={send_field.field_id} and recv_field.field_id={recv_field.field_id}")
1724 frac_mask_view = _np.ascontiguousarray(
1725 send_frac_mask.reshape(-1,collection_size,send_field.size), dtype=_np.double)
1726 with cython.nogil:
1727 yac_cexchange_frac_(send_field_id, recv_field_id, collection_size,
1728 <double*>&send_buf_view[0,0,0],
1729 <double*>&frac_mask_view[0,0,0],
1730 <double*>&recv_buf_view[0,0],
1731 &send_info, &recv_info, &ierror)
1732 if ierror != 0:
1733 raise RuntimeError("yac_cexchange_frac_ returned error number " + str(ierror))
1734
1735 return recv_buf, send_info, recv_info
1736
1737 @property
1738 def name(self):
1739 """
1740 @see yac_cget_field_name_from_field_id
1741 """
1742 return bytes.decode(yac_cget_field_name_from_field_id ( self.field_id ))
1743
1744 @property
1745 def grid_name(self):
1746 """
1747 @see yac_cget_grid_name_from_field_id
1748 """
1749 return bytes.decode(yac_cget_grid_name_from_field_id ( self.field_id ))
1750
1751 @property
1753 """
1754 @see yac_cget_component_name_from_field_id
1755 """
1756 return bytes.decode(yac_cget_component_name_from_field_id ( self.field_id ))
1757
1758 @property
1759 def role(self):
1760 """
1761 @see yac_cget_role_from_field_id
1762 """
1763 return ExchangeType(yac_cget_role_from_field_id ( self.field_id ))
1764
1765 @property
1766 def timestep(self):
1767 """
1768 @see yac_cget_timestep_from_field_id
1769 """
1770 return bytes.decode(yac_cget_timestep_from_field_id ( self.field_id ))
1771
1772 @property
1774 """
1775 @see yac_cget_collection_size_from_field_id
1776 """
1778
1779 @property
1780 def size(self):
1781 """
1782 The size of the corresponding points object
1783 """
1784 return self._size
1785
1786 @property
1787 def datetime(self):
1788 """
1789 @see yac_cget_field_datetime
1790 """
1791 return bytes.decode(yac_cget_field_datetime(self.field_id))
1792
1793 @property
1794 def action(self):
1795 """
1796 @see yac_cget_action
1797 """
1798 cdef int action
1799 yac_cget_action(self.field_id, &action)
1800 return Action(action)
1801
1803 """
1804 @see yac_cget_raw_interp_weights_data
1805
1806 Returns a dictionary with the corresponding values
1807 """
1808 cdef double frac_mask_fallback_value;
1809 cdef double scaling_factor;
1810 cdef double scaling_summand;
1811 cdef size_t num_fixed_values;
1812 cdef double * fixed_values;
1813 cdef size_t * num_tgt_per_fixed_value;
1814 cdef size_t * tgt_idx_fixed;
1815 cdef size_t num_wgt_tgt;
1816 cdef size_t * wgt_tgt_idx;
1817 cdef size_t * num_src_per_tgt;
1818 cdef double * weights;
1819 cdef size_t * src_field_idx;
1820 cdef size_t * src_idx;
1821 cdef size_t num_src_fields;
1822 cdef size_t * src_field_buffer_sizes;
1823 yac_cget_raw_interp_weights_data ( self.field_id,
1824 &frac_mask_fallback_value,
1825 &scaling_factor,
1826 &scaling_summand,
1827 &num_fixed_values,
1828 &fixed_values,
1829 &num_tgt_per_fixed_value,
1830 &tgt_idx_fixed,
1831 &num_wgt_tgt,
1832 &wgt_tgt_idx,
1833 &num_src_per_tgt,
1834 &weights,
1835 &src_field_idx,
1836 &src_idx,
1837 &num_src_fields,
1838 &src_field_buffer_sizes );
1839
1840 result = RawInterpWeights(
1841 frac_mask_fallback_value=frac_mask_fallback_value,
1842 scaling_factor=scaling_factor,
1843 scaling_summand=scaling_summand)
1844
1845 if num_fixed_values > 0:
1846 result.fixed_values = _np.array(<double[:num_fixed_values]> fixed_values)
1847 result.num_tgt_per_fixed_value = _np.array(<size_t[:num_fixed_values]> num_tgt_per_fixed_value)
1848 tgt_idx_fixed_size = _np.sum(result.num_tgt_per_fixed_value)
1849 result.tgt_idx_fixed = _np.array(<size_t[:tgt_idx_fixed_size]> tgt_idx_fixed)
1850
1851 if num_wgt_tgt > 0:
1852 result.wgt_tgt_idx = _np.array(<size_t[:num_wgt_tgt]>wgt_tgt_idx)
1853 result.num_src_per_tgt = _np.array(<size_t[:num_wgt_tgt]> num_src_per_tgt)
1854 num_weights = _np.sum(result.num_src_per_tgt)
1855 result.weights = _np.array(<double[:num_weights]>weights)
1856 result.src_field_idx = _np.array(<size_t[:num_weights]> src_field_idx)
1857 result.src_idx = _np.array(<size_t[:num_weights]> src_idx)
1858
1859 if num_src_fields > 0:
1860 result.src_field_buffer_sizes = _np.array(<size_t[:num_src_fields]> src_field_buffer_sizes)
1861
1862 free(fixed_values);
1863 free(num_tgt_per_fixed_value);
1864 free(tgt_idx_fixed);
1865 free(wgt_tgt_idx);
1866 free(num_src_per_tgt);
1867 free(weights);
1868 free(src_field_idx);
1869 free(src_idx);
1870 free(src_field_buffer_sizes);
1871 return result
1872
1874 """
1875 @see yac_cget_raw_interp_weights_data
1876
1877 Returns a dictionary with the corresponding values
1878 """
1879 cdef double frac_mask_fallback_value;
1880 cdef double scaling_factor;
1881 cdef double scaling_summand;
1882 cdef size_t num_fixed_values;
1883 cdef double * fixed_values;
1884 cdef size_t * num_tgt_per_fixed_value;
1885 cdef size_t * tgt_idx_fixed;
1886 cdef size_t * src_indptr;
1887 cdef double * weights;
1888 cdef size_t * src_field_idx;
1889 cdef size_t * src_idx;
1890 cdef size_t num_src_fields;
1891 cdef size_t * src_field_buffer_sizes;
1892 yac_cget_raw_interp_weights_data_csr ( self.field_id,
1893 &frac_mask_fallback_value,
1894 &scaling_factor,
1895 &scaling_summand,
1896 &num_fixed_values,
1897 &fixed_values,
1898 &num_tgt_per_fixed_value,
1899 &tgt_idx_fixed,
1900 &src_indptr,
1901 &weights,
1902 &src_field_idx,
1903 &src_idx,
1904 &num_src_fields,
1905 &src_field_buffer_sizes );
1906
1907 result = RawInterpWeightsCSR(
1908 frac_mask_fallback_value=frac_mask_fallback_value,
1909 scaling_factor=scaling_factor,
1910 scaling_summand=scaling_summand)
1911
1912 if num_fixed_values > 0:
1913 result.fixed_values = _np.array(<double[:num_fixed_values]> fixed_values)
1914 result.num_tgt_per_fixed_value = _np.array(<size_t[:num_fixed_values]> num_tgt_per_fixed_value)
1915 tgt_idx_fixed_size = _np.sum(result.num_tgt_per_fixed_value)
1916 result.tgt_idx_fixed = _np.array(<size_t[:tgt_idx_fixed_size]> tgt_idx_fixed)
1917
1918 result.src_indptr = _np.array(<size_t[:self.sizesize + 1]> src_indptr)
1919 num_weights = result.src_indptr[-1]
1920 result.weights = _np.array(<double[:num_weights]>weights)
1921 result.src_field_idx = _np.array(<size_t[:num_weights]> src_field_idx)
1922 result.src_idx = _np.array(<size_t[:num_weights]> src_idx)
1923
1924 if num_src_fields > 0:
1925 result.src_field_buffer_sizes = _np.array(<size_t[:num_src_fields]> src_field_buffer_sizes)
1926
1927 free(fixed_values);
1928 free(num_tgt_per_fixed_value);
1929 free(tgt_idx_fixed);
1930 free(src_indptr);
1931 free(weights);
1932 free(src_field_idx);
1933 free(src_idx);
1934 free(src_field_buffer_sizes);
1935 return result
1936
1937
1938@dataclass
1940 frac_mask_fallback_value : float
1941 scaling_factor : float
1942 scaling_summand : float
1943 fixed_values : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.float64))
1944 num_tgt_per_fixed_value : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1945 tgt_idx_fixed : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1946 wgt_tgt_idx : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1947 num_src_per_tgt : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1948 weights : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.float64))
1949 src_field_idx : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1950 src_idx : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1951 src_field_buffer_sizes : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1952
1953
1954@dataclass
1956 frac_mask_fallback_value : float
1957 scaling_factor : float
1958 scaling_summand : float
1959 fixed_values : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.float64))
1960 num_tgt_per_fixed_value : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1961 tgt_idx_fixed : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1962 src_indptr : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1963 weights : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.float64))
1964 src_field_idx : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1965 src_idx : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1966 src_field_buffer_sizes : _np.ndarray = field(default_factory=lambda: _np.empty(shape=[0], dtype=_np.uintp))
1967
1969 def __init__(self):
1970 """
1971 @see yac_cget_interp_stack_config
1972 """
1973 cdef int interp_stack_config_id
1974 _logger.debug(f"get_interp_stack_config")
1975 yac_cget_interp_stack_config(&interp_stack_config_id)
1976 _logger.debug(f"interp_stack_config_id={interp_stack_config_id}")
1977 self.interp_stack_id = interp_stack_config_id
1978
1979 @classmethod
1980 def from_string_yaml(cls, interp_stack_string : str):
1981 interp_stack = cls.__new__(cls)
1982 cdef int interp_stack_config_id
1983 _logger.debug(f"get_interp_stack_config_from_string_yaml: interp_stack_string={interp_stack_string}")
1984 yac_cget_interp_stack_config_from_string_yaml(interp_stack_string.encode(), &interp_stack_config_id)
1985 _logger.debug(f"interp_stack_config_id_from_string_yaml={interp_stack_config_id}")
1986 interp_stack.interp_stack_id = interp_stack_config_id
1987 return interp_stack
1988
1989 @classmethod
1990 def from_string_json(cls, interp_stack_string : str):
1991 interp_stack = cls.__new__(cls)
1992 cdef int interp_stack_config_id
1993 _logger.debug(f"get_interp_stack_config_from_string_json: interp_stack_string={interp_stack_string}")
1994 yac_cget_interp_stack_config_from_string_json(interp_stack_string.encode(), &interp_stack_config_id)
1995 _logger.debug(f"interp_stack_config_id_from_string_json={interp_stack_config_id}")
1996 interp_stack.interp_stack_id = interp_stack_config_id
1997 return interp_stack
1998
1999 def add_average(self, reduction_type : AverageReductionType, partial_coverage):
2000 """
2001 @see yac_cadd_interp_stack_config_average
2002 """
2003 _logger.debug(f"add_interp_stack_config_average interp_stack_id={self.interp_stack_id}")
2005 AverageReductionType(reduction_type).value,
2006 partial_coverage)
2007
2008 def add_ncc(self, reduction_type : NCCReductionType, partial_coverage):
2009 """
2010 @see yac_cadd_interp_stack_config_ncc
2011 """
2012 _logger.debug(f"add_interp_stack_config_ncc interp_stack_id={self.interp_stack_id}")
2014 NCCReductionType(reduction_type).value,
2015 partial_coverage)
2016
2017 def add_nnn(self, reduction_type : NNNReductionType, n : int,
2018 max_search_distance : _np.float64, scale : _np.float64):
2019 """
2020 @see yac_cadd_interp_stack_config_nnn
2021 """
2022 _logger.debug(f"add_interp_stack_config_nnn interp_stack_id={self.interp_stack_id}")
2024 NNNReductionType(reduction_type).value,
2025 n, max_search_distance, scale)
2026
2027 def add_rbf(self, n : int = 9, max_search_distance : _np.float64 = 0.0,
2028 scale : _np.float64 = 1.487973e+01):
2029 """
2030 @see yac_cadd_interp_stack_config_rbf
2031 """
2032 _logger.debug(f"add_interp_stack_config_rbf interp_stack_id={self.interp_stack_id}")
2034 n, max_search_distance, scale)
2035
2036 def add_conservative(self, order : int, enforced_conserv : int,
2037 partial_coverage : int, normalisation : ConservNormalizationType):
2038 """
2039 @see yac_cadd_interp_stack_config_conservative
2040 """
2041 _logger.debug(f"add_interp_stack_config_conservative interp_stack_id={self.interp_stack_id}")
2043 order, enforced_conserv,
2044 partial_coverage,
2045 ConservNormalizationType(normalisation).value)
2046
2047 def add_spmap(self, spread_distance : _np.float64, max_search_distance : _np.float64,
2048 weight_type : SPMAPWeightType, scale_type : SPMAPScaleType,
2049 src_sphere_radius : _np.float64 = 1.0, src_filename : str = None,
2050 src_varname : str = None, src_min_global_id : int = 0,
2051 tgt_sphere_radius : _np.float64 = 1.0, tgt_filename : str = None,
2052 tgt_varname : str = None, tgt_min_global_id : int = 0):
2053 """
2054 @see yac_cadd_interp_stack_config_spmap
2055 """
2056 _logger.debug(f"add_interp_stack_config_spmap interp_stack_id={self.interp_stack_id}")
2057 cdef char * src_filename_ptr
2058 if src_filename is None:
2059 src_filename_ptr = NULL
2060 else:
2061 src_filename_bytes = src_filename.encode()
2062 src_filename_ptr = src_filename_bytes
2063 cdef char * src_varname_ptr
2064 if src_varname is None:
2065 src_varname_ptr = NULL
2066 else:
2067 src_varname_bytes = src_varname.encode()
2068 src_varname_ptr = src_varname_bytes
2069 cdef char * tgt_filename_ptr
2070 if tgt_filename is None:
2071 tgt_filename_ptr = NULL
2072 else:
2073 tgt_filename_bytes = tgt_filename.encode()
2074 tgt_filename_ptr = tgt_filename_bytes
2075 cdef char * tgt_varname_ptr
2076 if tgt_varname is None:
2077 tgt_varname_ptr = NULL
2078 else:
2079 tgt_varname_bytes = tgt_varname.encode()
2080 tgt_varname_ptr = tgt_varname_bytes
2082 spread_distance, max_search_distance,
2083 SPMAPWeightType(weight_type).value,
2084 SPMAPScaleType(scale_type).value,
2085 src_sphere_radius, src_filename_ptr,
2086 src_varname_ptr, src_min_global_id,
2087 tgt_sphere_radius, tgt_filename_ptr,
2088 tgt_varname_ptr, tgt_min_global_id)
2089
2090 def add_hcsbb(self):
2091 """
2092 @see yac_cadd_interp_stack_config_hcsbb
2093 """
2094 _logger.debug(f"add_interp_stack_config_hcsbb interp_stack_id={self.interp_stack_id}")
2096
2097 def add_user_file(self, filename : str,
2098 on_missing_file : UserFileOnMissingFile =
2099 UserFileOnMissingFile.ERROR,
2100 on_success : UserFileOnSuccess = UserFileOnSuccess.CONT):
2101 """
2102 @see yac_cadd_interp_stack_config_user_file
2103 """
2104 _logger.debug(f"add_interp_stack_config_user_file interp_stack_id={self.interp_stack_id}")
2106 self.interp_stack_id,
2107 filename.encode(),
2108 UserFileOnMissingFile(on_missing_file).value,
2109 UserFileOnSuccess(on_success).on_success)
2110
2111 def add_fixed(self, value : _np.float64):
2112 """
2113 @see yac_cadd_interp_stack_config_fixed
2114 """
2115 _logger.debug(f"add_interp_stack_config_fixed interp_stack_id={self.interp_stack_id}")
2117
2118 def add_check(self, constructor_key : str, do_search_key : str):
2119 """
2120 @see yac_cadd_interp_stack_config_check
2121 """
2122 _logger.debug(f"add_interp_stack_config_check interp_stack_id={self.interp_stack_id}")
2124 constructor_key.encode(), do_search_key.encode())
2125
2126 def add_creep(self, creep_distance : int):
2127 """
2128 @see yac_cadd_interp_stack_config_creep
2129 """
2130 _logger.debug(f"add_interp_stack_config_creep interp_stack_id={self.interp_stack_id}")
2132 creep_distance)
2133
2134 def __del__(self):
2135 """
2136 @see yac_cfree_interp_stack_config
2137 """
2138 _logger.debug(f"free_interp_stack_config interp_stack_id={self.interp_stack_id}")
2140
2142 """
2143 @see yac_cget_version
2144 """
2145 return bytes.decode(yac_cget_version())
2146
2147
2148if Py_AtExit(yac_cfinalize) < 0:
2149 print(
2150 b"WARNING: %s\n",
2151 b"could not register yac_cfinalize with Py_AtExit()",
2152 )
2153
2154cdef yac_abort_func _prev_abort_func = yac_get_abort_handler()
2155
2156cdef void yac_python_abort(MPI_Comm comm, const char* msg,
2157 const char* source, int line) noexcept with gil:
2158 import traceback
2159 traceback.print_stack()
2160 _prev_abort_func(comm, msg, source, line)
2161
2162yac_set_abort_handler(yac_python_abort)
char const * grid_names[]
char const * component_names[]
Refers to YAC_ACTION_NONE, YAC_ACTION_REDUCTION etc.
Definition yac.pyx:525
Reduction type for average interpolation.
Definition yac.pyx:585
Calendar type for use in def_calendar.
Definition yac.pyx:548
__init__(self, str grid_name, x_vertices, y_vertices)
Definition yac.pyx:1441
def_points(self, x_points, y_points)
Definition yac.pyx:1453
Stores the component_id and provides further functionality.
Definition yac.pyx:1121
__init__(self, comp_id)
Definition yac.pyx:1125
size(self)
number of processes in this component
Definition yac.pyx:1140
comp_comm(self)
Definition yac.pyx:1129
rank(self)
process index in the component
Definition yac.pyx:1149
Normalization type for conservative interpolation.
Definition yac.pyx:615
A curvilinear stuctured 2d Grid.
Definition yac.pyx:1334
def_points_unstruct(self, Location location, x_vertices, y_vertices)
Definition yac.pyx:1370
def_points(self, Location location, x_vertices, y_vertices)
Definition yac.pyx:1354
__init__(self, str grid_name, x_vertices, y_vertices, cyclic=[False, False])
Definition yac.pyx:1339
Exchange type of a field.
Definition yac.pyx:515
Store the field_id.
Definition yac.pyx:1496
wait(self)
Definition yac.pyx:1545
datetime(self)
Definition yac.pyx:1787
grid_name(self)
Definition yac.pyx:1745
test(self)
Definition yac.pyx:1534
get_raw(self, buf, frac_mask=None, asyn=False)
Definition yac.pyx:1608
put_coro(self, buf, frac_mask=None)
Coroutine.
Definition yac.pyx:1680
get_coro(self, buf=None)
Coroutine.
Definition yac.pyx:1595
size(self)
The size of the corresponding points object.
Definition yac.pyx:1780
wait_coro(self)
Coroutine.
Definition yac.pyx:1556
get_raw_interp_weights_data(self)
Definition yac.pyx:1802
update(self)
Definition yac.pyx:1689
action(self)
Definition yac.pyx:1794
get(self, buf=None, asyn=False)
Definition yac.pyx:1564
exchange(cls, send_field, recv_field, send_buf, recv_buf=None, send_frac_mask=None)
Definition yac.pyx:1698
collection_size(self)
Definition yac.pyx:1773
create(cls, str field_name, Component comp, points, collection_size, str timestep, TimeUnit timeunit, masks=None)
Definition yac.pyx:1506
collection_size
Definition yac.pyx:1666
get_raw_interp_weights_data_csr(self)
Definition yac.pyx:1873
role(self)
Definition yac.pyx:1759
__init__(self, field_id, size=None)
Definition yac.pyx:1500
timestep(self)
Definition yac.pyx:1766
put(self, buf, frac_mask=None)
Definition yac.pyx:1654
component_name(self)
Definition yac.pyx:1752
Stores the grid_id and provides further functionality.
Definition yac.pyx:1164
nbr_corners(self)
Definition yac.pyx:1192
set_core_mask(self, is_core, Location location)
Definition yac.pyx:1205
nbr_cells(self)
Definition yac.pyx:1185
__init__(self, grid_id)
Definition yac.pyx:1170
set_global_index(self, global_index, Location location)
Definition yac.pyx:1174
nbr_edges(self)
Definition yac.pyx:1199
def_mask(self, Location location, is_valid, name=None)
Definition yac.pyx:1216
compute_grid_cell_areas(self, cell_areas=None)
Definition yac.pyx:1233
add_check(self, str constructor_key, str do_search_key)
Definition yac.pyx:2118
add_average(self, AverageReductionType reduction_type, partial_coverage)
Definition yac.pyx:1999
add_spmap(self, _np.float64 spread_distance, _np.float64 max_search_distance, SPMAPWeightType weight_type, SPMAPScaleType scale_type, _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:2052
add_user_file(self, str filename, UserFileOnMissingFile on_missing_file=UserFileOnMissingFile.ERROR, UserFileOnSuccess on_success=UserFileOnSuccess.CONT)
Definition yac.pyx:2100
add_conservative(self, int order, int enforced_conserv, int partial_coverage, ConservNormalizationType normalisation)
Definition yac.pyx:2037
add_creep(self, int creep_distance)
Definition yac.pyx:2126
add_rbf(self, int n=9, _np.float64 max_search_distance=0.0, _np.float64 scale=1.487973e+01)
Definition yac.pyx:2028
add_fixed(self, _np.float64 value)
Definition yac.pyx:2111
from_string_json(cls, str interp_stack_string)
Definition yac.pyx:1990
from_string_yaml(cls, str interp_stack_string)
Definition yac.pyx:1980
add_nnn(self, NNNReductionType reduction_type, int n, _np.float64 max_search_distance, _np.float64 scale)
Definition yac.pyx:2018
add_ncc(self, NCCReductionType reduction_type, partial_coverage)
Definition yac.pyx:2008
Location for points.
Definition yac.pyx:505
Stores the mask_id.
Definition yac.pyx:1157
__init__(self, mask_id)
Definition yac.pyx:1161
Reduction type for ncc interpolation.
Definition yac.pyx:595
Reduction type for nnn interpolation.
Definition yac.pyx:604
Stores the points_id and provides further functionality.
Definition yac.pyx:1243
set_mask(self, is_valid)
Definition yac.pyx:1257
__init__(self, points_id)
Definition yac.pyx:1247
size(self)
Definition yac.pyx:1251
Reduction type for the definition of interpolations.
Definition yac.pyx:536
A stuctured 2d Grid.
Definition yac.pyx:1268
def_points(self, Location location, x_vertices, y_vertices)
Definition yac.pyx:1297
__init__(self, str grid_name, x_vertices, y_vertices, cyclic=[False, False], north_pole=None)
Definition yac.pyx:1273
def_points_unstruct(self, Location location, x_vertices, y_vertices)
Definition yac.pyx:1320
Refers to YAC_SPMAP_NONE, YAC_SPMAP_SRCAREA YAC_SPMAP_INVTGTAREA, and YAC_SPMAP_FRACAREA.
Definition yac.pyx:631
Refers to YAC_SPMAP_AVG and YAC_SPMAP_DIST.
Definition yac.pyx:624
Refers to YAC_TIME_UNIT_MILLISECOND, YAC_TIME_UNIT_SECOND etc.
Definition yac.pyx:572
__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:1460
An unstuctured 2d Grid.
Definition yac.pyx:1403
__init__(self, str grid_name, num_vertices_per_cell, x_vertices, y_vertices, cell_to_vertex, use_ll_edges=False)
Definition yac.pyx:1408
Refers to YAC_FILE_MISSING_ERROR, YAC_FILE_MISSING_CONT.
Definition yac.pyx:641
Refers to YAC_FILE_SUCCESS_STOP, YAC_FILE_SUCCESS_CONT.
Definition yac.pyx:648
Handling of existing files, if weight file is to be written.
Definition yac.pyx:664
Initializies a YAC instance and provides further functionality.
Definition yac.pyx:682
read_config_yaml(self, str yaml_file)
Definition yac.pyx:1093
enddef(self)
Definition yac.pyx:896
def_comp(self, str comp_name)
Definition yac.pyx:740
predef_comp(self, str comp_name)
Definition yac.pyx:768
get_grid_metadata(self, str grid_name)
Definition yac.pyx:1060
instance_id
Definition yac.pyx:714
def_component_metadata(self, str comp_name, bytes metadata)
Definition yac.pyx:1025
sync_def(self)
Definition yac.pyx:824
def_field_metadata(self, str comp_name, str grid_name, str field_name, bytes metadata)
Definition yac.pyx:1042
def_grid_metadata(self, str grid_name, bytes metadata)
Definition yac.pyx:1033
start_datetime(self)
Definition yac.pyx:809
get_field_metadata(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1068
get_comps_comm(self, comp_names)
Definition yac.pyx:1078
cleanup(self)
Definition yac.pyx:731
get_field_names(self, str comp_name, str grid_name)
Definition yac.pyx:938
get_field_id(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:952
def_comps(self, comp_names=[])
Definition yac.pyx:750
set_grid_output_file(self, str gridname, str filename)
Definition yac.pyx:1113
from_id(cls, id)
Definition yac.pyx:722
get_component_metadata(self, str comp_name)
Definition yac.pyx:1052
def_datetime(self, start_datetime, end_datetime)
Definition yac.pyx:778
get_field_role(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:970
get_field_source(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:980
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, use_raw_exchange=False)
Definition yac.pyx:844
owned_instance
Definition yac.pyx:715
enable_field_frac_mask(self, str comp_name, str grid_name, str field_name, _np.float64 frac_mask_fallback_value)
Definition yac.pyx:1014
get_comp_grid_names(self, comp_name)
Definition yac.pyx:927
get_field_timestep(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:961
get_field_frac_mask_fallback_value(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:1004
end_datetime(self)
Definition yac.pyx:817
__del__(self)
Definition yac.pyx:728
__init__(self, comm=None, default_instance=False)
Definition yac.pyx:688
get_field_collection_size(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:995
set_config_output_file(self, str filename, ConfigOutputFormat fileformat, ConfigOutputSyncLoc sync_location, bool include_definitions=False)
Definition yac.pyx:1103
default_instance(cls)
Definition yac.pyx:718
__init__(self, grid_id)
Definition yac.pyx:1386
def_points(self, Location location, x_points, y_points)
Definition yac.pyx:1390
__get__(self, cls, owner)
Definition yac.pyx:679
enum callback_type type
version()
Definition yac.pyx:2141
get_calendar()
Definition yac.pyx:565
_prev_abort_func
Definition yac.pyx:2154
def_calendar(Calendar calendar)
Definition yac.pyx:559
char const * name
Definition toy_scrip.c:114
void yac_ccompute_grid_cell_areas(int grid_id, double *cell_areas)
Definition yac.c:4832
void yac_cadd_interp_stack_config_ncc(int interp_stack_config_id, int weight_type, int partial_coverage)
Definition yac.c:4906
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:1395
void yac_cpredef_comp_instance(int yac_instance_id, char const *name, int *comp_id)
Definition yac.c:825
char * yac_cget_start_datetime_instance(int yac_instance_id)
Definition yac.c:688
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:1201
void yac_cset_global_index(int const *global_index, int location, int grid_id)
Definition yac.c:4740
void yac_cset_grid_output_file_instance(int yac_instance_id, const char *gridname, const char *filename)
Definition yac.c:554
void yac_cget_(int const field_id, int const collection_size, double *recv_field, int *info, int *ierr)
Definition yac.c:2514
int yac_cget_nbr_grids_instance(int yac_instance_id)
Definition yac.c:4226
void yac_cfree_ext_couple_config(int ext_couple_config_id)
Definition yac.c:1434
const char * yac_cget_grid_metadata_instance(int yac_instance_id, const char *grid_name)
Definition yac.c:1382
char * yac_cget_end_datetime_instance(int yac_instance_id)
Definition yac.c:703
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:5039
void yac_cset_ext_couple_config_tgt_mask_name(int ext_couple_config_id, char const *tgt_mask_name)
Definition yac.c:1612
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:4600
void yac_cget_grid_names_instance(int yac_instance_id, int nbr_grids, const char **grid_names)
Definition yac.c:4318
void yac_cset_ext_couple_config_scale_factor(int ext_couple_config_id, double scale_factor)
Definition yac.c:1534
void yac_cset_ext_couple_config_weight_file_on_existing(int ext_couple_config_id, int weight_file_on_existing)
Definition yac.c:1485
void yac_cadd_interp_stack_config_creep(int interp_stack_config_id, int creep_distance)
Definition yac.c:5096
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:2856
void yac_cget_comp_rank_c2py(int comp_id, int *rank)
Definition yac.c:774
void yac_cget_comp_size_c2py(int comp_id, int *size)
Definition yac.c:767
int yac_cget_comp_nbr_grids_instance(int yac_instance_id, const char *comp_name)
Definition yac.c:4239
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:4639
void yac_csync_def_instance(int yac_instance_id)
Definition yac.c:4146
static void cleanup()
Definition yac.c:615
void yac_cget_interp_stack_config_from_string_json(char const *interp_stack_config, int *interp_stack_config_id)
Definition yac.c:5157
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:4720
void yac_cinit(void)
Definition yac.c:435
void yac_cget_raw_(int const field_id, int const collection_size, double *src_field_buffer, int *info, int *ierr)
Definition yac.c:2623
void yac_cfinalize()
Finalises YAC.
Definition yac.c:635
void yac_cadd_interp_stack_config_check(int interp_stack_config_id, char const *constructor_key, char const *do_search_key)
Definition yac.c:5084
void yac_cenddef_instance(int yac_instance_id)
Definition yac.c:4159
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:1587
void yac_cget_raw_async_(int const field_id, int const collection_size, double *src_field_buffer, int *info, int *ierr)
Definition yac.c:2680
int yac_cget_nbr_comps_instance(int yac_instance_id)
Definition yac.c:4213
int yac_cget_nbr_fields_instance(int yac_instance_id, const char *comp_name, const char *grid_name)
Definition yac.c:4267
void yac_cget_ext_couple_config(int *ext_couple_config_id)
Definition yac.c:1426
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:4660
void yac_cdef_grid_metadata_instance(int yac_instance_id, const char *grid_name, const char *metadata)
Definition yac.c:1339
void yac_cset_ext_couple_config_weight_file(int ext_couple_config_id, char const *weight_file)
Definition yac.c:1454
const char * yac_cget_component_metadata_instance(int yac_instance_id, const char *comp_name)
Definition yac.c:1369
void yac_cread_config_yaml_instance(int yac_instance_id, const char *yaml_filename)
Definition yac.c:481
void yac_cset_ext_couple_config_yaxt_exchanger_name(int ext_couple_config_id, char const *yaxt_exchanger_name)
Definition yac.c:1634
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:4482
void yac_cset_ext_couple_config_scale_summand(int ext_couple_config_id, double scale_summand)
Definition yac.c:1557
void yac_cget_comp_comm(int comp_id, MPI_Comm *comp_comm)
Definition yac.c:745
const char * yac_cget_field_datetime(int field_id)
Definition yac.c:2206
void yac_cdef_comp_instance(int yac_instance_id, char const *comp_name, int *comp_id)
Definition yac.c:896
void yac_cupdate(int field_id)
Definition yac.c:2226
void yac_cget_action(int field_id, int *action)
Definition yac.c:2163
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:3501
void yac_cdef_points_reg2d_rot(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, int *point_id)
Definition yac.c:1093
int yac_cget_collection_size_from_field_id(int field_id)
Definition yac.c:4466
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:4582
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:1698
void yac_cset_ext_couple_config_use_raw_exchange(int ext_couple_config_id, int use_raw_exchange)
Definition yac.c:1654
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:511
void yac_cdef_points_reg2d(int const grid_id, int const *nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
Definition yac.c:992
void yac_cinit_comm_instance(MPI_Comm comm, int *yac_instance_id)
Definition yac.c:397
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:1305
void yac_cget_interp_stack_config_from_string_yaml(char const *interp_stack_config, int *interp_stack_config_id)
Definition yac.c:5149
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:4957
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:4618
void yac_cdef_points_unstruct(int const grid_id, int const nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
Definition yac.c:1066
char * yac_cget_version(void)
Definition yac.c:721
int yac_cget_default_instance_id()
Definition yac.c:392
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:3612
void yac_cdef_component_metadata_instance(int yac_instance_id, const char *comp_name, const char *metadata)
Definition yac.c:1326
void yac_cdef_calendar(int calendar)
Definition yac.c:664
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:2692
void yac_cadd_interp_stack_config_rbf(int interp_stack_config_id, size_t n, double max_search_distance, double scale)
Definition yac.c:4945
int yac_cget_calendar()
Definition yac.c:681
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:2635
void yac_cput_(int const field_id, int const collection_size, double *send_field, int *info, int *ierr)
Definition yac.c:2836
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:4343
void yac_cget_async_(int const field_id, int const collection_size, double *recv_field, int *info, int *ierr)
Definition yac.c:2523
void yac_cadd_interp_stack_config_hcsbb(int interp_stack_config_id)
Definition yac.c:5030
void yac_cget_comps_comm_instance(int yac_instance_id, char const **comp_names, int num_comps, MPI_Comm *comps_comm)
Definition yac.c:785
void yac_cadd_interp_stack_config_fixed(int interp_stack_config_id, double value)
Definition yac.c:5074
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:4501
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:4555
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:4976
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:4682
void yac_cdef_points_curve2d(int const grid_id, int const *nbr_points, int const located, double const *x_points, double const *y_points, int *point_id)
Definition yac.c:1028
void yac_cset_ext_couple_config_mapping_side(int ext_couple_config_id, int mapping_side)
Definition yac.c:1511
void yac_ccleanup_instance(int yac_instance_id)
Clean-up a YAC instance (see Restarting YAC)
Definition yac.c:598
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:4512
void yac_cfree_interp_stack_config(int interp_stack_config_id)
Definition yac.c:4867
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:4924
size_t yac_cget_grid_size(int located, int grid_id)
Definition yac.c:4821
void yac_cinit_instance(int *yac_instance_id)
Definition yac.c:423
void yac_cget_interp_stack_config(int *interp_stack_config_id)
Definition yac.c:4853
void yac_cadd_interp_stack_config_average(int interp_stack_config_id, int reduction_type, int partial_coverage)
Definition yac.c:4887
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:1274
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:1353
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:4391
void yac_cdef_comps_instance(int yac_instance_id, char const **comp_names, int num_comps, int *comp_ids)
Definition yac.c:863
void yac_cget_comp_names_instance(int yac_instance_id, int nbr_comps, const char **comp_names)
Definition yac.c:4292
void yac_cinit_comm(MPI_Comm comm)
Definition yac.c:409
yac_abort_func yac_get_abort_handler(void)
void yac_set_abort_handler(yac_abort_func custom_abort)