YetAnotherCoupler 3.5.2
Loading...
Searching...
No Matches
yac.pyx
Go to the documentation of this file.
1# Copyright (c) 2024 The YAC Authors
2#
3# SPDX-License-Identifier: BSD-3-Clause
4
5import cython
6from enum import Enum
7import numpy as _np
8import logging
9from types import coroutine
10
11from libc.stdlib cimport malloc, free
12
13cdef import from "<mpi.h>" nogil:
14 ctypedef struct _mpi_comm_t
15 ctypedef _mpi_comm_t* MPI_Comm
16 int MPI_Comm_c2f(MPI_Comm)
17 MPI_Comm MPI_Comm_f2c(int)
18
19cdef extern from "Python.h":
20 int Py_AtExit(void (*)())
21
22cdef extern from "yac.h":
23 cdef const int _LOCATION_CELL "YAC_LOCATION_CELL"
24 cdef const int _LOCATION_CORNER "YAC_LOCATION_CORNER"
25 cdef const int _LOCATION_EDGE "YAC_LOCATION_EDGE"
26
27 cdef const int _EXCHANGE_TYPE_NONE "YAC_EXCHANGE_TYPE_NONE"
28 cdef const int _EXCHANGE_TYPE_SOURCE "YAC_EXCHANGE_TYPE_SOURCE"
29 cdef const int _EXCHANGE_TYPE_TARGET "YAC_EXCHANGE_TYPE_TARGET"
30
31 cdef const int _ACTION_NONE "YAC_ACTION_NONE"
32 cdef const int _ACTION_REDUCTION "YAC_ACTION_REDUCTION"
33 cdef const int _ACTION_COUPLING "YAC_ACTION_COUPLING"
34 cdef const int _ACTION_GET_FOR_RESTART "YAC_ACTION_GET_FOR_RESTART"
35 cdef const int _ACTION_PUT_FOR_RESTART "YAC_ACTION_PUT_FOR_RESTART"
36 cdef const int _ACTION_OUT_OF_BOUND "YAC_ACTION_OUT_OF_BOUND"
37
38 cdef const int _REDUCTION_TIME_NONE "YAC_REDUCTION_TIME_NONE"
39 cdef const int _REDUCTION_TIME_ACCUMULATE "YAC_REDUCTION_TIME_ACCUMULATE"
40 cdef const int _REDUCTION_TIME_AVERAGE "YAC_REDUCTION_TIME_AVERAGE"
41 cdef const int _REDUCTION_TIME_MINIMUM "YAC_REDUCTION_TIME_MINIMUM"
42 cdef const int _REDUCTION_TIME_MAXIMUM "YAC_REDUCTION_TIME_MAXIMUM"
43
44 cdef const int _CALENDAR_NOT_SET "YAC_CALENDAR_NOT_SET"
45 cdef const int _PROLEPTIC_GREGORIAN "YAC_PROLEPTIC_GREGORIAN"
46 cdef const int _YEAR_OF_365_DAYS "YAC_YEAR_OF_365_DAYS"
47 cdef const int _YEAR_OF_360_DAYS "YAC_YEAR_OF_365_DAYS"
48
49 cdef const int _TIME_UNIT_MILLISECOND "YAC_TIME_UNIT_MILLISECOND"
50 cdef const int _TIME_UNIT_SECOND "YAC_TIME_UNIT_SECOND"
51 cdef const int _TIME_UNIT_MINUTE "YAC_TIME_UNIT_MINUTE"
52 cdef const int _TIME_UNIT_HOUR "YAC_TIME_UNIT_HOUR"
53 cdef const int _TIME_UNIT_DAY "YAC_TIME_UNIT_DAY"
54 cdef const int _TIME_UNIT_MONTH "YAC_TIME_UNIT_MONTH"
55 cdef const int _TIME_UNIT_YEAR "YAC_TIME_UNIT_YEAR"
56 cdef const int _TIME_UNIT_ISO_FORMAT "YAC_TIME_UNIT_ISO_FORMAT"
57
58 cdef const int _AVG_ARITHMETIC "YAC_AVG_ARITHMETIC"
59 cdef const int _AVG_DIST "YAC_AVG_DIST"
60 cdef const int _AVG_BARY "YAC_AVG_BARY"
61
62 cdef const int _NCC_AVG "YAC_NCC_AVG"
63 cdef const int _NCC_DIST "YAC_NCC_DIST"
64
65 cdef const int _NNN_AVG "YAC_NNN_AVG"
66 cdef const int _NNN_DIST "YAC_NNN_DIST"
67 cdef const int _NNN_GAUSS "YAC_NNN_GAUSS"
68 cdef const int _NNN_RBF "YAC_NNN_RBF"
69
70 cdef const int _CONSERV_DESTAREA "YAC_CONSERV_DESTAREA"
71 cdef const int _CONSERV_FRACAREA "YAC_CONSERV_FRACAREA"
72
73 cdef const int _SPMAP_AVG "YAC_SPMAP_AVG"
74 cdef const int _SPMAP_DIST "YAC_SPMAP_DIST"
75
76 cdef const int _SPMAP_NONE "YAC_SPMAP_NONE"
77 cdef const int _SPMAP_SRCAREA "YAC_SPMAP_SRCAREA"
78 cdef const int _SPMAP_INVTGTAREA "YAC_SPMAP_INVTGTAREA"
79 cdef const int _SPMAP_FRACAREA "YAC_SPMAP_FRACAREA"
80
81 cdef const int _CONFIG_OUTPUT_FORMAT_YAML "YAC_CONFIG_OUTPUT_FORMAT_YAML"
82 cdef const int _CONFIG_OUTPUT_FORMAT_JSON "YAC_CONFIG_OUTPUT_FORMAT_JSON"
83
84 cdef const int _CONFIG_OUTPUT_SYNC_LOC_DEF_COMP "YAC_CONFIG_OUTPUT_SYNC_LOC_DEF_COMP"
85 cdef const int _CONFIG_OUTPUT_SYNC_LOC_SYNC_DEF "YAC_CONFIG_OUTPUT_SYNC_LOC_SYNC_DEF"
86 cdef const int _CONFIG_OUTPUT_SYNC_LOC_ENDDEF "YAC_CONFIG_OUTPUT_SYNC_LOC_ENDDEF"
87
88 void yac_cinit ()
89 void yac_cinit_instance ( int * yac_instance_id )
90 void yac_cinit_comm (MPI_Comm comm )
91 void yac_cinit_comm_instance (MPI_Comm comm, int * yac_instance_id )
93 void yac_ccleanup_instance (int yac_instance_id)
94 void yac_cdef_comp_instance ( int yac_instance_id,
95 const char * comp_name,
96 int * comp_id )
97 void yac_cdef_comps_instance ( int yac_instance_id,
98 const char ** comp_names,
99 int num_comps,
100 int * comp_ids )
101 void yac_cpredef_comp_instance ( int yac_instance_id,
102 const char * comp_name,
103 int * comp_id )
104 void yac_cget_comp_comm ( int comp_id, MPI_Comm* comp_comm )
105 void yac_cdef_datetime_instance ( int yac_instance_id,
106 const char * start_datetime,
107 const char * end_datetime )
108 void yac_cget_comps_comm_instance( int yac_instance_id,
109 const char ** comp_names,
110 int num_comps,
111 MPI_Comm * comps_comm)
112 void yac_cdef_calendar ( int calendar )
113 int yac_cget_calendar ( )
114 void yac_cenddef_instance ( int yac_instance_id )
115 int yac_cget_nbr_comps_instance ( int yac_instance_id )
116 int yac_cget_nbr_grids_instance ( int yac_instance_id )
117 int yac_cget_comp_nbr_grids_instance ( int yac_instance_id, const char* comp_name )
118 int yac_cget_nbr_fields_instance ( int yac_instance_id, const char * comp_name,
119 const char* grid_name)
120 void yac_cget_comp_names_instance ( int yac_instance_id, int nbr_comps,
121 const char ** comp_names )
122 void yac_cget_grid_names_instance ( int yac_instance_id, int nbr_grids,
123 const char ** grid_names )
124 void yac_cget_comp_grid_names_instance ( int yac_instance_id, const char* comp_name,
125 int nbr_grids, const char ** grid_names )
126 void yac_cget_field_names_instance ( int yac_instance_id, const char* comp_name,
127 const char* grid_name,
128 int nbr_fields, const char ** field_names )
129 int yac_cget_field_id_instance ( int yac_instance_id, const char* comp_name,
130 const char* grid_name,
131 const char * field_name )
132 const char* yac_cget_field_timestep_instance ( int yac_instance_id, const char* comp_name,
133 const char* grid_name,
134 const char * field_name )
135 int yac_cget_field_role_instance ( int yac_instance_id, const char* comp_name,
136 const char* grid_name, const char* field_name )
137 void yac_cget_field_source_instance ( int yac_instance_id, const char* tgt_comp_name,
138 const char* tgt_grid_name, const char* tgt_field_name,
139 const char** src_comp_name, const char** src_grid_name,
140 const char** src_field_name)
141 void yac_cenable_field_frac_mask_instance ( int yac_instance_id,
142 const char* comp_name,
143 const char* grid_name,
144 const char * field_name,
145 double frac_mask_fallback_value)
146 int yac_cget_field_collection_size_instance ( int yac_instance_id,
147 const char* comp_name,
148 const char* grid_name,
149 const char * field_name )
150 double yac_cget_field_frac_mask_fallback_value_instance ( int yac_instance_id,
151 const char* comp_name,
152 const char* grid_name,
153 const char * field_name )
154 void yac_cdef_component_metadata_instance ( int yac_instance_id,
155 const char* comp_name,
156 const char* metadata)
157 void yac_cdef_grid_metadata_instance ( int yac_instance_id,
158 const char* grid_name,
159 const char* metadata)
160 void yac_cdef_field_metadata_instance ( int yac_instance_id,
161 const char* comp_name,
162 const char* grid_name,
163 const char* field_name,
164 const char* metadata)
165 const char* yac_cget_component_metadata_instance(int yac_instance_id,
166 const char* comp_name)
167 const char* yac_cget_grid_metadata_instance(int yac_instance_id,
168 const char* grid_name)
169 const char* yac_cget_field_metadata_instance(int yac_instance_id,
170 const char* comp_name,
171 const char* grid_name,
172 const char* field_name)
173 char * yac_cget_start_datetime_instance ( int yac_instance_id )
174 char * yac_cget_end_datetime_instance ( int yac_instance_id )
175 char * yac_cget_version ()
176 void yac_cdef_grid_reg2d ( const char * grid_name,
177 int nbr_vertices[2],
178 int cyclic[2],
179 double *x_vertices,
180 double *y_vertices,
181 int *grid_id)
182 void yac_cdef_points_reg2d ( const int grid_id,
183 int nbr_points[2],
184 const int location,
185 const double *x_points,
186 const double *y_points,
187 int *point_id )
188 void yac_cdef_grid_curve2d ( const char * grid_name,
189 int nbr_vertices[2],
190 int cyclic[2],
191 double *x_vertices,
192 double *y_vertices,
193 int *grid_id)
194 void yac_cdef_points_curve2d ( const int grid_id,
195 int nbr_points[2],
196 const int location,
197 const double *x_points,
198 const double *y_points,
199 int *point_id )
200 void yac_cdef_grid_cloud ( const char * grid_name,
201 int nbr_points,
202 double *x_points,
203 double *y_points,
204 int *grid_id)
205 void yac_cdef_grid_unstruct ( const char * grid_name,
206 int nbr_vertices,
207 int nbr_cells,
208 int *num_vertices_per_cell,
209 double *x_vertices,
210 double *y_vertices,
211 int *cell_to_vertex,
212 int *grid_id)
213 void yac_cdef_grid_unstruct_ll ( const char * grid_name,
214 int nbr_vertices,
215 int nbr_cells,
216 int *num_vertices_per_cell,
217 double *x_vertices,
218 double *y_vertices,
219 int *cell_to_vertex,
220 int *grid_id)
221 void yac_cdef_grid_unstruct_edge ( const char * grid_name,
222 int nbr_vertices,
223 int nbr_cells,
224 int nbr_edges,
225 int *num_edges_per_cell,
226 double *x_vertices,
227 double *y_vertices,
228 int *cell_to_edge,
229 int *edge_to_vertex,
230 int *grid_id)
231 void yac_cdef_grid_unstruct_edge_ll ( const char * grid_name,
232 int nbr_vertices,
233 int nbr_cells,
234 int nbr_edges,
235 int *num_edges_per_cell,
236 double *x_vertices,
237 double *y_vertices,
238 int *cell_to_edge,
239 int *edge_to_vertex,
240 int *grid_id)
241 void yac_cdef_points_unstruct ( const int grid_id,
242 const int nbr_points,
243 const int location,
244 const double *x_points,
245 const double *y_points,
246 int *point_id )
247 void yac_cset_global_index ( const int * global_index,
248 int location,
249 int grid_id)
250 void yac_cdef_field ( const char * field_name,
251 const int component_id,
252 const int * point_ids,
253 const int num_pointsets,
254 int collection_size,
255 const char* timestep,
256 int timeunit,
257 int * field_id )
258 void yac_cdef_field_mask ( const char * field_name,
259 const int component_id,
260 const int * point_ids,
261 const int * mask_ids,
262 const int num_pointsets,
263 int collection_size,
264 const char* timestep,
265 int timeunit,
266 int * field_id )
267 void yac_csync_def_instance ( int yac_instance_id )
268 void yac_cget_ext_couple_config(int * ext_couple_config_id)
269 void yac_cset_ext_couple_config_weight_file(int ext_couple_config_id,
270 const char * weight_file)
271 void yac_cset_ext_couple_config_mapping_side(int ext_couple_config_id,
272 int mapping_side)
273 void yac_cset_ext_couple_config_scale_factor(int ext_couple_config_id,
274 double scale_factor)
275 void yac_cset_ext_couple_config_scale_summand(int ext_couple_config_id,
276 double scale_summand)
278 int ext_couple_config_id, size_t num_src_mask_names,
279 const char * const * src_mask_names)
281 int ext_couple_config_id, const char * tgt_mask_name)
283 int ext_couple_config_id, const char * yaxt_exchanger_name)
284 void yac_cfree_ext_couple_config(int ext_couple_config_id)
285 void yac_cdef_couple_custom_instance(int yac_instance_id,
286 const char * src_comp_name,
287 const char * src_grid_name,
288 const char * src_field_name,
289 const char * tgt_comp_name,
290 const char * tgt_grid_name,
291 const char * tgt_field_name,
292 const char * coupling_timestep,
293 int time_unit, int time_reduction,
294 int interp_stack_config_id,
295 int src_lag, int tgt_lag,
296 int ext_couple_config_id)
297 void yac_cget_ ( const int field_id,
298 const int collection_size,
299 double *recv_field,
300 int *info,
301 int *ierror ) nogil
302 void yac_cget_async_ ( const int field_id,
303 const int collection_size,
304 double *recv_field,
305 int *info,
306 int *ierror )
307 void yac_cput_ ( const int field_id,
308 const int collection_size,
309 double * send_field,
310 int *info,
311 int *ierror ) nogil
312 void yac_cput_frac_ ( const int field_id,
313 const int collection_size,
314 double *send_field,
315 double *send_frac_mask,
316 int *info,
317 int *ierr ) nogil
318 void yac_cexchange_ ( const int send_field_id,
319 const int recv_field_id,
320 const int collection_size,
321 double *send_field ,
322 double *recv_field,
323 int *send_info,
324 int *recv_info,
325 int *ierror ) nogil
326 void yac_cexchange_frac_ ( const int send_field_id,
327 const int recv_field_id,
328 const int collection_size,
329 double *send_field,
330 double *send_frac_mask,
331 double *recv_field,
332 int *send_info,
333 int *recv_info,
334 int *ierror ) nogil
335 void yac_ctest ( int field_id, int * flag )
336 void yac_cwait ( int field_id ) nogil
337 void yac_cupdate( int field_id )
338 const char* yac_cget_field_name_from_field_id ( int field_id )
339 const char* yac_cget_component_name_from_field_id ( int field_id )
340 const char* yac_cget_grid_name_from_field_id ( int field_id )
341 int yac_cget_role_from_field_id ( int field_id )
342 const char* yac_cget_timestep_from_field_id ( int field_id )
343 size_t yac_cget_grid_size ( int location, int grid_id )
344 size_t yac_cget_points_size ( int points_id )
345 int yac_cget_collection_size_from_field_id ( const int field_id )
346 const char* yac_cget_field_datetime(int field_id)
347 void yac_cget_interp_stack_config(int * interp_stack_config_id)
349 int interp_stack_config_id, int reduction_type, int partial_coverage)
351 int interp_stack_config_id, int weight_type, int partial_coverage)
352 void yac_cadd_interp_stack_config_nnn(int interp_stack_config_id, int type,
353 unsigned int n,
354 double max_search_distance,
355 double scale)
357 int interp_stack_config_id, int order, int enforced_conserv,
358 int partial_coverage, int normalisation)
360 int interp_stack_config_id, double spread_distance,
361 double max_search_distance, int weight_type, int scale_type,
362 double src_sphere_radius, char * src_filename,
363 char * src_varname, int src_min_global_id,
364 double tgt_sphere_radius, char * tgt_filename,
365 char * tgt_varname, int tgt_min_global_id)
366 void yac_cadd_interp_stack_config_hcsbb(int interp_stack_config_id)
368 int interp_stack_config_id, char * filename)
370 int interp_stack_config_id, double value)
372 int interp_stack_config_id, char * constructor_key, char * do_search_key)
374 int interp_stack_config_id, int creep_distance)
375 void yac_cget_interp_stack_config_from_string_yaml(char * interp_stack_config,
376 int * interp_stack_config_id)
377 void yac_cget_interp_stack_config_from_string_json(char * interp_stack_config,
378 int * interp_stack_config_id)
379 void yac_cfree_interp_stack_config(int interp_stack_config_id)
380 void yac_cset_core_mask ( const int * is_core,
381 int location,
382 int grid_id)
383 void yac_cset_mask ( const int * is_valid,
384 int points_id )
385 void yac_cdef_mask_named ( const int grid_id,
386 const int nbr_points,
387 const int location,
388 const int * is_valid,
389 const char * name,
390 int *mask_id )
391 void yac_cfinalize()
392 ctypedef void (*yac_abort_func)(MPI_Comm comm, const char *msg,
393 const char *source, int line) except *
394 void yac_set_abort_handler(yac_abort_func custom_abort)
395 yac_abort_func yac_get_abort_handler()
396 void yac_cread_config_yaml_instance( int yac_instance_id,
397 const char * yaml_file)
398 void yac_cget_action( int field_id, int* action)
399 void yac_cset_config_output_file_instance( int yac_instance_id,
400 const char * filename,
401 int fileformat,
402 int sync_location,
403 int include_definitions);
404 void yac_ccompute_grid_cell_areas(int grid_id, double* cell_areas);
405
406# helper functions for py interface (not in yac_interface.h)
407cdef extern void yac_cget_comp_size_c2py(int comp_id, int* size)
408cdef extern void yac_cget_comp_rank_c2py(int comp_id, int* rank)
409
410_logger = logging.getLogger("yac")
411_logger.addHandler(logging.NullHandler())
412
413class Location(Enum):
414 """
415 Location for points
416
417 Refers to @ref YAC_LOCATION_CELL, @ref YAC_LOCATION_CORNER and @ref YAC_LOCATION_EDGE
418 """
419 CELL = _LOCATION_CELL
420 CORNER = _LOCATION_CORNER
421 EDGE = _LOCATION_EDGE
422
423class ExchangeType(Enum):
424 """
425 Exchange type of a field
426
427 Refers to @ref YAC_EXCHANGE_TYPE_NONE, @ref YAC_EXCHANGE_TYPE_SOURCE and @ref YAC_EXCHANGE_TYPE_TARGET
428 """
429 NONE = _EXCHANGE_TYPE_NONE
430 SOURCE = _EXCHANGE_TYPE_SOURCE
431 TARGET = _EXCHANGE_TYPE_TARGET
432
433class Action(Enum):
434 """
435 Refers to @ref YAC_ACTION_NONE, @ref YAC_ACTION_REDUCTION etc.
436 """
437 NONE = _ACTION_NONE
438 REDUCTION = _ACTION_REDUCTION
439 COUPLING = _ACTION_COUPLING
440 GET_FOR_RESTART = _ACTION_GET_FOR_RESTART
441 PUT_FOR_RESTART = _ACTION_PUT_FOR_RESTART
442 OUT_OF_BOUND = _ACTION_OUT_OF_BOUND
443
444class Reduction(Enum):
445 """
446 Reduction type for the definition of interpolations
447
448 Refers to @ref YAC_REDUCTION_TIME_NONE, @ref YAC_REDUCTION_TIME_ACCUMULATE etc.
449 """
450 TIME_NONE = _REDUCTION_TIME_NONE
451 TIME_ACCUMULATE = _REDUCTION_TIME_ACCUMULATE
452 TIME_AVERAGE = _REDUCTION_TIME_AVERAGE
453 TIME_MINIMUM = _REDUCTION_TIME_MINIMUM
454 TIME_MAXIMUM = _REDUCTION_TIME_MAXIMUM
455
456class Calendar(Enum):
457 """
458 Calendar type for use in def_calendar
459
460 Refers to @ref YAC_CALENDAR_NOT_SET, @ref YAC_PROLEPTIC_GREGORIAN etc.
461 """
462 CALENDAR_NOT_SET = _CALENDAR_NOT_SET
463 PROLEPTIC_GREGORIAN = _PROLEPTIC_GREGORIAN
464 YEAR_OF_365_DAYS = _YEAR_OF_365_DAYS
465 YEAR_OF_360_DAYS = _YEAR_OF_360_DAYS
466
467def def_calendar(calendar : Calendar):
468 """
469 @see yac_cdef_calendar
470 """
471 yac_cdef_calendar(Calendar(calendar).value)
472
474 """
475 @see yac_cget_calendar
476 """
478
479
480class TimeUnit(Enum):
481 """
482 Refers to @ref YAC_TIME_UNIT_MILLISECOND, @ref YAC_TIME_UNIT_SECOND etc.
483 """
484 MILLISECOND = _TIME_UNIT_MILLISECOND
485 SECOND = _TIME_UNIT_SECOND
486 MINUTE = _TIME_UNIT_MINUTE
487 HOUR = _TIME_UNIT_HOUR
488 DAY = _TIME_UNIT_DAY
489 MONTH = _TIME_UNIT_MONTH
490 YEAR = _TIME_UNIT_YEAR
491 ISO_FORMAT = _TIME_UNIT_ISO_FORMAT
492
494 """
495 Reduction type for average interpolation
496
497 Refers to @ref YAC_AVG_ARITHMETIC, @ref YAC_AVG_DIST and @ref YAC_AVG_BARY
498 """
499 AVG_ARITHMETIC = _AVG_ARITHMETIC
500 AVG_DIST = _AVG_DIST
501 AVG_BARY = _AVG_BARY
502
504 """
505 Reduction type for ncc interpolation
506
507 Refers to @ref YAC_NCC_AVG and @ref YAC_NCC_DIST
508 """
509 AVG = _NCC_AVG
510 DIST = _NCC_DIST
511
513 """
514 Reduction type for nnn interpolation
515
516 Refers to @ref YAC_NNN_AVG, @ref YAC_NNN_DIST etc.
517 """
518 AVG = _NNN_AVG
519 DIST = _NNN_DIST
520 GAUSS = _NNN_GAUSS
521 RBF = _NNN_RBF
522
524 """
525 Normalization type for conservative interpolation
526
527 Refers to @ref YAC_CONSERV_DESTAREA and @ref YAC_CONSERV_FRACAREA
528 """
529 DESTAREA = _CONSERV_DESTAREA
530 FRACAREA = _CONSERV_FRACAREA
531
532class SPMAPWeightType(Enum):
533 """
534 Refers to @ref YAC_SPMAP_AVG and @ref YAC_SPMAP_DIST
535 """
536 AVG = _SPMAP_AVG
537 DIST = _SPMAP_DIST
538
539class SPMAPScaleType(Enum):
540 """
541 Refers to @ref YAC_SPMAP_NONE, YAC_SPMAP_SRCAREA
542 YAC_SPMAP_INVTGTAREA, and @ref YAC_SPMAP_FRACAREA
543 """
544 NONE = _SPMAP_NONE
545 SRCAREA = _SPMAP_SRCAREA
546 INVTGTAREA = _SPMAP_INVTGTAREA
547 FRACAREA = _SPMAP_FRACAREA
548
550 YAML = _CONFIG_OUTPUT_FORMAT_YAML
551 JSON = _CONFIG_OUTPUT_FORMAT_JSON
552
554 DEF_COMP = _CONFIG_OUTPUT_SYNC_LOC_DEF_COMP # after component definition
555 SYNC_DEF = _CONFIG_OUTPUT_SYNC_LOC_SYNC_DEF # after synchronization of definition
556 ENDDEF = _CONFIG_OUTPUT_SYNC_LOC_ENDDEF # after end of definitions
557
558class YAC:
559 """
560 Initializies a YAC instance and provides further functionality
561
562 The destructor finalizes the YAC instance by calling yac_cfinalize_instance
563 """
564 def __init__(self, comm = None, default_instance = False):
565 """
566 @see yac_cinit_instance
567 """
568 cdef int instance_id
569 cdef MPI_Comm c_comm
570 if comm is None:
571 if default_instance:
572 _logger.debug("init")
573 yac_cinit()
574 instance_id = yac_cget_default_instance_id()
575 else:
576 _logger.debug("init_instance")
577 yac_cinit_instance(&instance_id)
578 else:
579 from mpi4py import MPI
580 if type(comm) is MPI.Intracomm:
581 comm = MPI.Comm.py2f(comm)
582 if default_instance:
583 _logger.debug("init_comm")
584 yac_cinit_comm(MPI_Comm_f2c(comm))
585 instance_id = yac_cget_default_instance_id()
586 else:
587 _logger.debug("init_comm_instance")
588 yac_cinit_comm_instance(MPI_Comm_f2c(comm), &instance_id)
589 _logger.debug(f"instance_id={instance_id}")
590 self.instance_id = instance_id
591 self.owned_instance = True
592
593 @classmethod
594 @property
598 @classmethod
599 def from_id(cls, id):
600 yac = cls.__new__(cls)
601 yac.instance_id = id
602 yac.owned_instance = False
603 return yac
604
605 def __del__(self):
606 self.cleanup()
607
608 def cleanup(self):
609 """
610 @see yac_ccleanup_instance
611 """
612 if self.owned_instance:
613 _logger.debug(f"cleanup instance_id={self.instance_id}")
615 self.owned_instance = False
616
617 def def_comp(self, comp_name : str):
618 """
619 @see yac_cdef_comp_instance
620 """
621 cdef int comp_id
622 _logger.debug(f"def_comp: comp_name={comp_name}")
623 yac_cdef_comp_instance(self.instance_id, comp_name.encode(), &comp_id)
624 _logger.debug(f"comp_id={comp_id}")
625 return Component(comp_id)
626
627 def def_comps(self, comp_names = []):
628 """
629 @see yac_cdef_comps_instance
630 """
631 cdef int comp_len = len(comp_names)
632 cdef const char **c_comp_names = <const char **>malloc(comp_len * sizeof(const char *))
633 cdef int *c_comp_ids = <int*>malloc(comp_len * sizeof(int))
634 _logger.debug(f"def_comps: comp_names={comp_names}")
635 byte_comp_names = [c.encode() for c in comp_names]
636 for i in range(comp_len):
637 c_comp_names[i] = byte_comp_names[i]
638 yac_cdef_comps_instance(self.instance_id, c_comp_names, comp_len, c_comp_ids)
639 comp_list = [Component(c_comp_ids[i]) for i in range(comp_len) ]
640 free(c_comp_names)
641 free(c_comp_ids)
642 _logger.debug("comp_list={comp_list}")
643 return comp_list
644
645 def predef_comp(self, comp_name :str):
646 """
647 @see yac_cpredef_comp_instance
648 """
649 cdef int comp_id
650 _logger.debug(f"predef_comp: comp_name={comp_name}")
651 yac_cpredef_comp_instance(self.instance_id, comp_name.encode(), &comp_id)
652 _logger.debug("comp_id={comp_id}")
653 return Component(comp_id)
654
655 def def_datetime(self, start_datetime, end_datetime):
656 """
657 @see yac_cdef_datetime_instance
658
659 The parameters can be given either as a string in iso8601
660 format or as datetime objects
661 """
662 try:
663 import datetime
664 if(type(start_datetime) is datetime.datetime):
665 start_datetime = start_datetime.isoformat()
666 except:
667 pass
668 if start_datetime is not None:
669 _logger.debug(f"def_datetime start: {start_datetime}")
670 yac_cdef_datetime_instance ( self.instance_id,
671 start_datetime.encode(),
672 NULL)
673
674 try:
675 if(type(end_datetime) is datetime.datetime):
676 end_datetime = end_datetime.isoformat()
677 except:
678 pass
679 if end_datetime is not None:
680 _logger.debug(f"def_datetime end: {end_datetime}")
681 yac_cdef_datetime_instance ( self.instance_id,
682 NULL,
683 end_datetime.encode())
684
685 @property
686 def start_datetime(self):
687 """
688 @see yac_cget_start_datetime_instance (`datetime.datetime`, read-only).
689 """
691 return bytes.decode(start)
692
693 @property
694 def end_datetime(self):
695 """
696 @see yac_cget_end_datetime_instance (`datetime.datetime`, read-only).
697 """
699 return bytes.decode(end)
700
701 def sync_def(self):
702 """
703 @see yac_csync_def_instance
704 """
705 _logger.debug("sync_def")
707
708 def def_couple(self,
709 src_comp : str, src_grid : str, src_field,
710 tgt_comp : str, tgt_grid : str, tgt_field,
711 coupling_timestep : str, timeunit : TimeUnit,
712 time_reduction : Reduction,
713 interp_stack, src_lag = 0, tgt_lag = 0,
714 weight_file = None, mapping_on_source = 1,
715 scale_factor = 1.0, scale_summand = 0.0,
716 src_masks_names = None, tgt_mask_name = None,
717 yaxt_exchanger_name = None):
718 """
719 @see yac_cdef_couple_instance
720 """
721 cdef char * weight_file_ptr
722 if weight_file is None:
723 weight_file_ptr = NULL
724 else:
725 weight_file_bytes = weight_file.encode()
726 weight_file_ptr = weight_file_bytes
727 cdef const char ** src_mask_names_ptr = NULL
728 cdef const char * tgt_mask_name_ptr = NULL
729 cdef const char * yaxt_exchanger_name_ptr = NULL
730 cdef int couple_config_id
731 yac_cget_ext_couple_config(&couple_config_id)
733 weight_file_ptr)
735 mapping_on_source)
737 scale_factor)
739 scale_summand)
740 if src_masks_names is not None:
741 if type(src_masks_names) is str:
742 src_masks = [src_masks_names]
743 src_masks_enc = [s.encode() for s in src_masks_names]
744 src_mask_names_ptr = <const char **>malloc(len(src_masks_enc) * sizeof(char*))
745 for i in range(len(src_masks_enc)):
746 src_mask_names_ptr[i] = src_masks_enc[i]
748 len(src_masks_enc),
749 src_mask_names_ptr)
750 free(src_mask_names_ptr)
751 if tgt_mask_name is not None:
752 yac_cset_ext_couple_config_tgt_mask_name(couple_config_id, tgt_mask_name.encode())
753 if yaxt_exchanger_name is not None:
754 yac_cset_ext_couple_config_yaxt_exchanger_name(couple_config_id, yaxt_exchanger_name.encode())
755 _logger.debug(f"def_couple {(src_comp.encode(), src_grid.encode(), src_field.encode())}, {(tgt_comp.encode(), tgt_grid.encode(), tgt_field.encode())}")
757 src_comp.encode(), src_grid.encode(), src_field.encode(),
758 tgt_comp.encode(), tgt_grid.encode(), tgt_field.encode(),
759 coupling_timestep.encode(), TimeUnit(timeunit).value,
760 Reduction(time_reduction).value,
761 interp_stack.interp_stack_id, src_lag, tgt_lag,
762 couple_config_id)
763 yac_cfree_ext_couple_config(couple_config_id)
764
765 def enddef(self):
766 """
767 @see yac_cenddef_instance
768 """
769 _logger.debug("enddef")
771
772 @property
774 """
775 @see yac_cget_comp_names
776 """
777 cdef int nbr_components = yac_cget_nbr_comps_instance(self.instance_id)
778 cdef const char **ret = <const char **>malloc(nbr_components * sizeof(const char *))
779 yac_cget_comp_names_instance(self.instance_id, nbr_components, ret)
780 comp_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_components) ]
781 free(ret)
782 return comp_list
783
784 @property
785 def grid_names(self):
786 """
787 @see yac_cget_grid_names
788 """
789 cdef int nbr_grids = yac_cget_nbr_grids_instance(self.instance_id)
790 cdef const char **ret = <const char **>malloc(nbr_grids * sizeof(const char *))
791 yac_cget_grid_names_instance(self.instance_id, nbr_grids, ret)
792 grid_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_grids) ]
793 free(ret)
794 return grid_list
795
796 def get_comp_grid_names(self, comp_name):
797 """
798 @see yac_cget_comp_grid_names
799 """
800 cdef int nbr_grids = yac_cget_comp_nbr_grids_instance(self.instance_id, comp_name.encode())
801 cdef const char **ret = <const char **>malloc(nbr_grids * sizeof(const char *))
802 yac_cget_comp_grid_names_instance(self.instance_id, comp_name.encode(), nbr_grids, ret)
803 grid_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_grids) ]
804 free(ret)
805 return grid_list
806
807 def get_field_names(self, comp_name : str, grid_name : str):
808 """
809 @see yac_cget_field_names
810 """
811 cdef int nbr_fields = yac_cget_nbr_fields_instance(self.instance_id,
812 comp_name.encode(),
813 grid_name.encode())
814 cdef const char **ret = <const char **>malloc(nbr_fields * sizeof(const char *))
815 yac_cget_field_names_instance(self.instance_id, comp_name.encode(),
816 grid_name.encode(), nbr_fields, ret)
817 field_list = [bytes(ret[i]).decode('UTF-8') for i in range(nbr_fields) ]
818 free(ret)
819 return field_list
820
821 def get_field_id(self, comp_name : str, grid_name : str, field_name : str):
822 """
823 @see yac_cget_field_id
824 """
825 return yac_cget_field_id_instance (self.instance_id,
826 comp_name.encode(),
827 grid_name.encode(),
828 field_name.encode())
829
830 def get_field_timestep(self, comp_name : str, grid_name : str, field_name : str):
831 """
832 @see yac_cget_field_timestep
833 """
835 comp_name.encode(),
836 grid_name.encode(),
837 field_name.encode()).decode('UTF-8')
838
839 def get_field_role(self, comp_name : str, grid_name : str, field_name : str):
840 """
841 @see yac_cget_field_role
842 """
843 return ExchangeType(yac_cget_field_role_instance (self.instance_id,
844 comp_name.encode(),
845 grid_name.encode(),
846 field_name.encode()))
847
848 def get_field_source(self, comp_name : str, grid_name : str,
849 field_name : str):
850 cdef const char* src_comp
851 cdef const char* src_grid
852 cdef const char* src_field
854 comp_name.encode(),
855 grid_name.encode(),
856 field_name.encode(),
857 &src_comp,
858 &src_grid,
859 &src_field)
860 return (src_comp.decode("UTF-8"),
861 src_grid.decode("UTF-8"),
862 src_field.decode("UTF-8"))
863
864 def get_field_collection_size(self, comp_name : str, grid_name : str, field_name : str):
865 """
866 @see yac_cget_field_collection_size
867 """
869 comp_name.encode(),
870 grid_name.encode(),
871 field_name.encode())
872
873 def get_field_frac_mask_fallback_value(self, comp_name : str, grid_name : str, field_name : str):
874 """
875 @see yac_cget_field_frac_mask_fallback_value
876 """
878 comp_name.encode(),
879 grid_name.encode(),
880 field_name.encode())
881
882 def enable_field_frac_mask(self, comp_name : str, grid_name : str, field_name : str,
883 frac_mask_fallback_value : _np.float64):
884 """
885 @see yac_cenable_field_frac_mask
886 """
887 _logger.debug(f"enable_field_frac_mask {(comp_name, grid_name, field_name)})")
889 comp_name.encode(),
890 grid_name.encode(),
891 field_name.encode(),
892 frac_mask_fallback_value)
893
894 def def_component_metadata(self, comp_name : str, metadata : bytes):
895 """
896 @see yac_cdef_component_metadata
897 """
898 _logger.debug(f"def_component_metadata comp_name={comp_name}")
900 comp_name.encode(), metadata)
901
902 def def_grid_metadata(self, grid_name : str, metadata : bytes):
903 """
904 @see yac_cdef_grid_metadata
905 """
906 _logger.debug(f"def_grid_metadata grid_name={grid_name}")
908 grid_name.encode(), metadata)
909
910 def def_field_metadata(self, comp_name : str, grid_name : str,
911 field_name : str,metadata : bytes):
912 """
913 @see yac_cdef_field_metadata
914 """
915 _logger.debug("def_field_metadata (comp_name, grid_name, field_name)="
916 f"{(comp_name, grid_name, field_name)}")
917 yac_cdef_field_metadata_instance(self.instance_id, comp_name.encode(),
918 grid_name.encode(), field_name.encode(),
919 metadata)
920
921 def get_component_metadata(self, comp_name : str):
922 """
923 @see yac_cget_component_metadata
924 """
925 cdef const char* metadata = yac_cget_component_metadata_instance(self.instance_id,
926 comp_name.encode())
927 return bytes(metadata).decode('UTF-8') if metadata != NULL else None
928
929 def get_grid_metadata(self, grid_name : str):
930 """
931 @see yac_cget_grid_metadata
932 """
933 cdef const char* metadata = yac_cget_grid_metadata_instance(self.instance_id,
934 grid_name.encode())
935 return bytes(metadata).decode('UTF-8') if metadata != NULL else None
936
937 def get_field_metadata(self, comp_name : str, grid_name : str, field_name :str):
938 """
939 @see yac_cget_field_metadata
940 """
941 cdef const char* metadata = yac_cget_field_metadata_instance(self.instance_id,
942 comp_name.encode(),
943 grid_name.encode(),
944 field_name.encode())
945 return bytes(metadata).decode('UTF-8') if metadata != NULL else None
946
947 def get_comps_comm(self, comp_names):
948 """
949 @see yac_cget_comps_comm
950 """
951 from mpi4py import MPI
952 cdef MPI_Comm comm
953 cptr = [c.encode() for c in comp_names]
954 cdef const char ** comp_names_c_ptr = <const char **>malloc(len(comp_names) * sizeof(const char *))
955 for i in range(len(comp_names)):
956 comp_names_c_ptr[i] = cptr[i]
957 yac_cget_comps_comm_instance(self.instance_id, comp_names_c_ptr, len(comp_names), &comm)
958 free(comp_names_c_ptr)
959 # convert to mpi4py communicator
960 return MPI.Comm.f2py(MPI_Comm_c2f(comm))
961
962 def read_config_yaml(self, yaml_file : str):
963 """
964 @see yac_cread_config_yaml_instance
965 """
966 _logger.debug(f"read_config_yaml yaml_file={yaml_file}")
967 yac_cread_config_yaml_instance(self.instance_id, yaml_file.encode())
968
969 def set_config_output_file(self, filename : str,
970 fileformat : ConfigOutputFormat,
971 sync_location : ConfigOutputSyncLoc,
972 include_definitions : bool = False):
973 """
974 @see yac_cset_config_output_file_instance
975 """
977 filename.encode(),
978 fileformat.value,
979 sync_location.value,
980 1 if include_definitions else 0)
981
983 """
984 Stores the component_id and provides further functionality
985 """
986 def __init__(self, comp_id):
987 self.comp_id = comp_id
988
989 @property
990 def comp_comm(self):
991 """
992 @see yac_cget_comp_comm (`MPI.Comm`, read-only)
993 """
994 from mpi4py import MPI
995 cdef MPI_Comm comm
996 yac_cget_comp_comm(self.comp_id, &comm)
997 # convert to mpi4py communicator
998 return MPI.Comm.f2py(MPI_Comm_c2f(comm))
999
1000 @property
1001 def size(self):
1002 """
1003 number of processes in this component
1004 """
1005 cdef int size
1006 yac_cget_comp_size_c2py(self.comp_id, &size)
1007 return size
1008
1009 @property
1010 def rank(self):
1011 """
1012 process index in the component
1013 """
1014 cdef int rank
1015 yac_cget_comp_rank_c2py(self.comp_id, &rank)
1016 return rank
1017
1018class Mask:
1019 """
1020 Stores the mask_id
1021 """
1022 def __init__(self, mask_id):
1023 self.mask_id = mask_id
1024
1025class Grid:
1026 """
1027 Stores the grid_id and provides further functionality
1028
1029 Base class for Reg2dGrid and UnstructuredGrid
1030 """
1031 def __init__(self, grid_id):
1032 _logger.debug(f"grid_id={grid_id}")
1033 self.grid_id = grid_id
1034
1035 def set_global_index(self, global_index, location : Location):
1036 """
1037 @see yac_cset_global_index
1038 """
1039 cdef const int[::1] global_index_view = _np.ascontiguousarray(global_index, dtype=_np.intc)
1040 assert len(global_index_view) == yac_cget_grid_size ( location.value, self.grid_id ), \
1041 "Wrong number of indices provided"
1042 _logger.debug(f"set_global_index grid_id={self.grid_id}")
1043 yac_cset_global_index(&global_index_view[0], location.value, self.grid_id)
1044
1045 @property
1046 def nbr_cells(self):
1047 """
1048 @see yac_cget_grid_size (`int`, read-only)
1049 """
1050 return yac_cget_grid_size ( Location.CELL.value, self.grid_id )
1051
1052 @property
1053 def nbr_corners(self):
1054 """
1055 @see yac_cget_grid_size (`int`, read-only)
1056 """
1057 return yac_cget_grid_size ( Location.CORNER.value, self.grid_id )
1058
1059 @property
1060 def nbr_edges(self):
1061 """
1062 @see yac_cget_grid_size (`int`, read-only)
1063 """
1064 return yac_cget_grid_size ( Location.EDGE.value, self.grid_id )
1065
1066 def set_core_mask(self, is_core, location : Location):
1067 """
1068 @see yac_cset_core_mask
1069 """
1070 cdef size_t len_is_core = len(is_core)
1071 assert(len_is_core == yac_cget_grid_size( location.value, self.grid_id ) )
1072 cdef const int[::1] np_mask = _np.ascontiguousarray(is_core, dtype=_np.intc)
1073 _logger.debug(f"set_core_mask grid_id={self.grid_id}")
1074 yac_cset_core_mask ( &np_mask[0], location.value, self.grid_id)
1075
1076 def def_mask(self, location : Location,
1077 is_valid, name = None):
1078 cdef int len_is_valid = len(is_valid)
1079 cdef const int[::1] np_mask = _np.ascontiguousarray(is_valid, dtype=_np.int32)
1080 cdef int mask_id
1081 cdef char* c_name = NULL
1082 if name is not None:
1083 name_enc = name.encode()
1084 c_name = name_enc
1085 _logger.debug(f"def_mask_named grid_id={self.grid_id}, name={name}")
1086 yac_cdef_mask_named ( self.grid_id,
1087 len_is_valid,
1088 location.value,
1089 &np_mask[0],
1090 c_name,
1091 &mask_id )
1092 return Mask(mask_id)
1093
1094 def compute_grid_cell_areas(self, cell_areas = None):
1095 """
1096 @see yac_ccompute_grid_cell_areas
1097 """
1098 if cell_areas is None:
1099 cell_areas = _np.empty(self.nbr_cells)
1100 cdef double[::1] np_cell_areas = _np.ascontiguousarray(cell_areas, dtype=_np.double)
1101 yac_ccompute_grid_cell_areas(self.grid_id, &np_cell_areas[0])
1102 return cell_areas
1103
1105 """
1106 Stores the points_id and provides further functionality
1107 """
1108 def __init__(self, points_id):
1109 self.points_id = points_id
1110
1111 @property
1112 def size(self):
1113 """
1114 @see yac_cget_points_size (`int`, read-only)
1115 """
1116 return yac_cget_points_size ( self.points_id )
1117
1118 def set_mask(self, is_valid):
1119 """
1120 @see yac_cset_mask
1121 """
1122 cdef size_t len_is_valid = len(is_valid)
1123 assert len_is_valid==self.size
1124 cdef const int[::1] np_mask = _np.ascontiguousarray(is_valid, dtype=_np.intc)
1125 _logger.debug(f"set_mask points_id={self.points_id}")
1126 yac_cset_mask ( &np_mask[0],
1127 self.points_id )
1128
1130 """
1131 A stuctured 2d Grid
1132 """
1133 def __init__(self, grid_name : str, x_vertices, y_vertices,
1134 cyclic = [False, False]):
1135 """
1136 @see yac_cdef_grid_reg2d
1137 """
1138 cdef int grid_id
1139 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1140 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1141 cdef int[2] cyclic_view = cyclic
1142 _logger.debug(f"def_grid_reg2d grid_name={grid_name}")
1143 yac_cdef_grid_reg2d(grid_name.encode(), [len(x),len(y)],
1144 cyclic_view, <double*>&x[0], <double*>&y[0], &grid_id)
1145 super().__init__(grid_id)
1146
1147 def def_points(self, location : Location,
1148 x_vertices, y_vertices):
1149 """
1150 @see yac_cdef_points_reg2d
1151 """
1152 cdef int points_id
1153 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1154 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1155 _logger.debug(f"def_points_reg2d grid_id={self.grid_id}")
1157 location.value, &x[0], &y[0], &points_id)
1158 _logger.debug(f"points_id={points_id}")
1159 return Points(points_id)
1160
1161 def def_points_unstruct(self, location : Location,
1162 x_vertices, y_vertices):
1163 """
1164 @see yac_cdef_points_unstruct
1165 """
1166 assert len(x_vertices) == len(y_vertices)
1167 cdef int points_id
1168 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1169 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1170 _logger.debug(f"def_points_unstruct grid_id={self.grid_id}")
1172 location.value, &x[0], &y[0], &points_id)
1173 _logger.debug(f"points_id={points_id}")
1174 return Points(points_id)
1175
1177 """
1178 A curvilinear stuctured 2d Grid
1179 """
1180 def __init__(self, grid_name : str, x_vertices, y_vertices,
1181 cyclic = [False, False]):
1182 """
1183 @see yac_cdef_grid_curve2d
1184 """
1185 cdef int grid_id
1186 cdef const double[::1] x = _np.ascontiguousarray(x_vertices.flatten(), dtype=_np.double)
1187 cdef const double[::1] y = _np.ascontiguousarray(y_vertices.flatten(), dtype=_np.double)
1188 cdef int[2] cyclic_view = cyclic
1189 _logger.debug(f"def_grid_curve2d grid_name={grid_name}")
1190 yac_cdef_grid_curve2d(grid_name.encode(),
1191 [_np.shape(x_vertices)[1], _np.shape(y_vertices)[0]],
1192 cyclic_view, <double*>&x[0], <double*>&y[0], &grid_id)
1193 super().__init__(grid_id)
1194
1195 def def_points(self, location : Location,
1196 x_vertices, y_vertices):
1197 """
1198 @see yac_cdef_points_curve2d
1199 """
1200 assert x_vertices.shape == y_vertices.shape
1201 cdef int points_id
1202 cdef const double[::1] x = _np.ascontiguousarray(x_vertices.flatten(), dtype=_np.double)
1203 cdef const double[::1] y = _np.ascontiguousarray(y_vertices.flatten(), dtype=_np.double)
1204 _logger.debug(f"def_points_curve2d grid_id={self.grid_id}")
1206 [_np.shape(x_vertices)[1], _np.shape(x_vertices)[0]],
1207 location.value, &x[0], &y[0], &points_id)
1208 _logger.debug(f"points_id={points_id}")
1209 return Points(points_id)
1210
1211 def def_points_unstruct(self, location : Location,
1212 x_vertices, y_vertices):
1213 """
1214 @see yac_cdef_points_unstruct
1215 """
1216 assert len(x_vertices) == len(y_vertices)
1217 cdef int points_id
1218 cdef const double[::1] x = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1219 cdef const double[::1] y = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1220 _logger.debug(f"def_points_unstruct grid_id={self.grid_id}")
1222 location.value, &x[0], &y[0], &points_id)
1223 _logger.debug(f"points_id={points_id}")
1224 return Points(points_id)
1225
1226
1228 def __init__(self, grid_id):
1229 super().__init__(grid_id)
1230
1231 def def_points(self, location : Location,
1232 x_points, y_points):
1233 """
1234 @see yac_cdef_points_unstruct
1235 """
1236 cdef int points_id
1237 cdef const double[::1] x_points_view = _np.ascontiguousarray(x_points, dtype=_np.double)
1238 cdef const double[::1] y_points_view = _np.ascontiguousarray(y_points, dtype=_np.double)
1239 _logger.debug(f"yac_cdef_points_unstruct grid_id={self.grid_id}")
1240 yac_cdef_points_unstruct(self.grid_idgrid_id, len(x_points_view), location.value,
1241 &x_points_view[0], &y_points_view[0], &points_id)
1242 _logger.debug(f"points_id={points_id}")
1243 return Points(points_id)
1244
1246 """
1247 An unstuctured 2d Grid
1248 """
1249 def __init__(self, grid_name : str, num_vertices_per_cell,
1250 x_vertices, y_vertices, cell_to_vertex, use_ll_edges=False):
1251 """
1252 @see yac_cdef_grid_unstruct and @see yac_cdef_grid_unstruct_ll
1253 """
1254 cdef int grid_id
1255 cdef const int[::1] num_vertices_per_cell_view = _np.ascontiguousarray(num_vertices_per_cell, dtype=_np.intc)
1256 cdef const double[::1] x_vertices_view = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1257 cdef const double[::1] y_vertices_view = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1258 cdef const int[::1] cell_to_vertex_view = _np.ascontiguousarray(cell_to_vertex, dtype=_np.intc)
1259 assert len(num_vertices_per_cell_view) > 0, \
1260 "UnstrucuredGrid needs at least one cell. Use CloudGrid if you dont need to define cells."
1261 if not use_ll_edges:
1262 _logger.debug(f"def_grid_unstruct grid_name={grid_name}")
1263 yac_cdef_grid_unstruct(grid_name.encode(), len(x_vertices_view),
1264 len(num_vertices_per_cell_view),
1265 <int*>&num_vertices_per_cell_view[0],
1266 <double*>&x_vertices_view[0],
1267 <double*>&y_vertices_view[0],
1268 <int*>&cell_to_vertex_view[0], &grid_id)
1269 else:
1270 _logger.debug(f"def_grid_unstruct_ll grid_name={grid_name}")
1271 yac_cdef_grid_unstruct_ll(grid_name.encode(), len(x_vertices_view),
1272 len(num_vertices_per_cell_view),
1273 <int*>&num_vertices_per_cell_view[0],
1274 <double*>&x_vertices_view[0],
1275 <double*>&y_vertices_view[0],
1276 <int*>&cell_to_vertex_view[0], &grid_id)
1277 super().__init__(grid_id)
1278
1280 """
1281 @see yac_cdef_grid_cloud
1282 """
1283 def __init__(self, grid_name : str, x_vertices, y_vertices):
1284 cdef int grid_id
1285 cdef const double[::1] x_vertices_view = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1286 cdef const double[::1] y_vertices_view = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1287 _logger.debug(f"def_grid_cloud grid_name={grid_name}")
1288 yac_cdef_grid_cloud (grid_name.encode(),
1289 len(x_vertices_view),
1290 <double*>&x_vertices_view[0],
1291 <double*>&y_vertices_view[0],
1292 &grid_id)
1293 super().__init__(grid_id)
1294
1295 def def_points(self, x_points, y_points):
1296 return super().def_points(Location.CORNER, x_points, y_points)
1297
1298
1300 def __init__(self, grid_name : str, num_edges_per_cell,
1301 x_vertices, y_vertices, cell_to_edge, edge_to_vertex,
1302 use_ll_edges=False):
1303 cdef int grid_id
1304 cdef const int[::1] num_edges_per_cell_view = _np.ascontiguousarray(num_edges_per_cell, dtype=_np.intc)
1305 cdef const double[::1] x_vertices_view = _np.ascontiguousarray(x_vertices, dtype=_np.double)
1306 cdef const double[::1] y_vertices_view = _np.ascontiguousarray(y_vertices, dtype=_np.double)
1307 cdef const int[::1] cell_to_edge_view = _np.ascontiguousarray(cell_to_edge, dtype=_np.intc)
1308 cdef const int[:, ::1] edge_to_vertex_view = _np.ascontiguousarray(edge_to_vertex, dtype=_np.intc)
1309 assert edge_to_vertex_view.shape[1] == 2, \
1310 "dimension 1 of edge_to_vertex must be 2"
1311 assert len(num_edges_per_cell_view) > 0, \
1312 "UnstrucuredGridEdge needs at least one cell. Use CloudGrid if you dont need to define cells."
1313 if not use_ll_edges:
1314 _logger.debug(f"def_grid_unstruct_edge grid_name={grid_name}")
1315 yac_cdef_grid_unstruct_edge(grid_name.encode(), len(x_vertices_view),
1316 len(num_edges_per_cell_view),
1317 edge_to_vertex_view.shape[0],
1318 <int*>&num_edges_per_cell_view[0],
1319 <double*>&x_vertices_view[0],
1320 <double*>&y_vertices_view[0],
1321 <int*>&cell_to_edge_view[0],
1322 <int*>&edge_to_vertex_view[0,0],
1323 &grid_id)
1324 else:
1325 _logger.debug(f"def_grid_unstruct_edge_ll grid_name={grid_name}")
1326 yac_cdef_grid_unstruct_edge_ll(grid_name.encode(), len(x_vertices_view),
1327 len(num_edges_per_cell_view),
1328 edge_to_vertex_view.shape[0],
1329 <int*>&num_edges_per_cell_view[0],
1330 <double*>&x_vertices_view[0],
1331 <double*>&y_vertices_view[0],
1332 <int*>&cell_to_edge_view[0],
1333 <int*>&edge_to_vertex_view[0,0],
1334 &grid_id)
1335 super().__init__(grid_id)
1336
1337
1338class Field:
1339 """
1340 Store the field_id
1341 """
1342 def __init__(self, field_id, size=None):
1343 self.field_id = field_id
1344 self._size = size
1345
1346 @classmethod
1347 def create(cls, field_name : str, comp : Component, points, collection_size,
1348 timestep : str, timeunit : TimeUnit, masks = None):
1349 """
1350 @see yac_cdef_field
1351 """
1352 from collections.abc import Iterable
1353 cdef int field_id
1354 if not isinstance(points, Iterable):
1355 points = [points]
1356 cdef const int[:] point_ids_array = _np.array([p.points_id for p in points], dtype=_np.intc)
1357 size = sum(p.size for p in points)
1358 cdef const int[:] mask_ids_array
1359 if masks is None:
1360 _logger.debug(f"def_field field_name={field_name}, comp_id={comp.comp_id}, point_ids={[p.points_id for p in points]}")
1361 yac_cdef_field(field_name.encode(), comp.comp_id,
1362 &point_ids_array[0], len(point_ids_array),
1363 collection_size, timestep.encode(), TimeUnit(timeunit).value, &field_id)
1364 else:
1365 if not isinstance(masks, Iterable):
1366 masks = [masks]
1367 mask_ids_array = _np.array([m.mask_id for m in masks], dtype=_np.intc)
1368 _logger.debug(f"def_field_mask field_name={field_name}, comp_id={comp.comp_id}, point_ids={[p.points_id for p in points]}")
1369 yac_cdef_field_mask(field_name.encode(), comp.comp_id,
1370 &point_ids_array[0], &mask_ids_array[0],
1371 len(point_ids_array),
1372 collection_size, timestep.encode(), TimeUnit(timeunit).value, &field_id)
1373 _logger.debug(f"field_id={field_id}")
1374 return Field(field_id, size)
1375
1376 def test(self):
1377 """
1378 @see yac_ctest
1379
1380 """
1381 cdef int flag
1382 _logger.debug(f"test field_id={self.field_id}")
1383 yac_ctest ( self.field_id, &flag )
1384 _logger.debug(f"flag={flag}")
1385 return flag
1386
1387 def wait(self):
1388 """
1389 @see yac_cwait
1390
1391 """
1392 cdef int field_id = self.field_id
1393 _logger.debug(f"wait field_id={field_id}")
1394 with cython.nogil:
1395 yac_cwait ( field_id )
1396
1397 @coroutine
1398 def wait_coro(self):
1399 """
1400 Coroutine. Blocks until the communication is completed.
1401 """
1402 while self.test() == 0:
1403 yield
1404
1405 @cython.boundscheck(False)
1406 def get(self, buf=None, asyn=False):
1407 """
1408 @see yac_cget_
1409
1410 @param[out] buf receive buffer, if `None` a numpy array of correct size is allocated
1411 @param[in] asyn if True the call returns immidiatly and must be completed
1412 with `test` or `wait`
1413 """
1414 cdef int info
1415 cdef int ierror
1416 buf_in = buf
1417 if buf is None:
1418 buf = _np.empty((self.collection_sizecollection_size, self.sizesize), dtype=_np.double)
1419 buf = _np.ascontiguousarray(buf.reshape(self.collection_sizecollection_size, self.sizesize), dtype=_np.double)
1420 if buf_in is not None and buf.base is None:
1421 _logger.warning("get: non-contiguous buffer passed to get. Reallocated memory.")
1422 cdef double[:,::1] buf_view = buf
1423 cdef int field_id = self.field_id
1424 cdef int collection_size = self.collection_sizecollection_size
1425 if asyn:
1426 _logger.debug(f"get_async_ field_id={self.field_id}")
1427 yac_cget_async_(field_id, collection_size, &buf_view[0,0], &info, &ierror)
1428 else:
1429 _logger.debug(f"get_ field_id={self.field_id}")
1430 with cython.nogil:
1431 yac_cget_(field_id, collection_size, &buf_view[0,0], &info, &ierror)
1432 if ierror != 0:
1433 raise RuntimeError("yac_cget returned error number " + str(ierror))
1434 _logger.debug(f"info={info}")
1435 return buf, Action(info)
1436
1437 async def get_coro(self, buf=None):
1438 """
1439 Coroutine. Executes a get operation.
1440
1441 @see yac_cget_async_
1442
1443 @param[out] buf receive buffer, if `None` a numpy array of correct size is allocated
1444 """
1445 buf, info = self.get(buf, asyn=True)
1446 await self.wait_coro()
1447 return buf, info
1448
1449 @cython.boundscheck(False)
1450 def put(self, buf, frac_mask = None):
1451 """
1452 @see yac_cput_
1453 """
1454 cdef int info
1455 cdef int ierror
1456 cdef const double[:,:,::1] buf_view = _np.ascontiguousarray(buf.reshape(-1,self.collection_sizecollection_size,self.sizesize), dtype=_np.double)
1457 cdef const double[:,:,::1] frac_mask_view
1458 cdef int field_id = self.field_id
1459 cdef int collection_size = self.collection_sizecollection_size
1460 if frac_mask is not None:
1461 frac_mask_view = _np.ascontiguousarray(
1462 frac_mask.reshape(-1,self.collection_sizecollection_size,self.sizesize), dtype=_np.double)
1463 _logger.debug(f"put_frac_ field_id={self.field_id}")
1464 with cython.nogil:
1465 yac_cput_frac_(field_id, collection_size, <double*>&buf_view[0,0,0],
1466 <double*>&frac_mask_view[0,0,0], &info, &ierror)
1467 else:
1468 _logger.debug(f"put_ field_id={self.field_id}")
1469 with cython.nogil:
1470 yac_cput_(field_id, collection_size, <double*>&buf_view[0,0,0], &info, &ierror)
1471 if ierror != 0:
1472 raise RuntimeError("yac_cput returned error number " + str(ierror))
1473 _logger.debug(f"info={info}")
1474 return Action(info)
1475
1476 async def put_coro(self, buf, frac_mask = None):
1477 """
1478 Coroutine. Executes a put operation.
1479
1480 @see yac_cput_
1481 """
1482 await self.wait_coro()
1483 return self.put(buf, frac_mask)
1484
1485 def update(self):
1486 """
1487 @see yac_cupdate
1488 """
1489 _logger.debug(f"update field_id={self.field_id}")
1490 yac_cupdate(self.field_id)
1491
1492 @classmethod
1493 @cython.boundscheck(False)
1494 def exchange(cls, send_field, recv_field, send_buf, recv_buf=None, send_frac_mask=None):
1495 """
1496 @see yac_cexchange_frac_
1497 """
1498 assert send_field.collection_size == recv_field.collection_size, "exchange can only be used with fields of the same collection_size"
1499 cdef int collection_size = send_field.collection_size
1500 cdef int send_info
1501 cdef int recv_info
1502 cdef int ierror
1503 cdef const double[:,:,::1] send_buf_view = _np.ascontiguousarray(send_buf.reshape(-1,collection_size,send_field.size), dtype=_np.double)
1504 cdef const double[:,:,::1] frac_mask_view
1505 if recv_buf is None:
1506 recv_buf = _np.empty((collection_size, recv_field.size), dtype=_np.double)
1507 recv_buf = _np.ascontiguousarray(recv_buf.reshape(collection_size, recv_field.size), dtype=_np.double)
1508 cdef double[:,::1] recv_buf_view = recv_buf
1509 cdef int send_field_id = send_field.field_id
1510 cdef int recv_field_id = recv_field.field_id
1511 if send_frac_mask is None:
1512 _logger.debug(f"exchange_ with send_field.field_id={send_field.field_id} and recv_field.field_id={recv_field.field_id}")
1513 with cython.nogil:
1514 yac_cexchange_(send_field_id, recv_field_id, collection_size,
1515 <double*>&send_buf_view[0,0,0],
1516 <double*>&recv_buf_view[0,0],
1517 &send_info, &recv_info, &ierror)
1518 else:
1519 _logger.debug(f"exchange_frac_ with send_field.field_id={send_field.field_id} and recv_field.field_id={recv_field.field_id}")
1520 frac_mask_view = _np.ascontiguousarray(
1521 send_frac_mask.reshape(-1,collection_size,send_field.size), dtype=_np.double)
1522 with cython.nogil:
1523 yac_cexchange_frac_(send_field_id, recv_field_id, collection_size,
1524 <double*>&send_buf_view[0,0,0],
1525 <double*>&frac_mask_view[0,0,0],
1526 <double*>&recv_buf_view[0,0],
1527 &send_info, &recv_info, &ierror)
1528 if ierror != 0:
1529 raise RuntimeError("yac_cexchange_frac_ returned error number " + str(ierror))
1530
1531 return recv_buf, send_info, recv_info
1532
1533 @property
1534 def name(self):
1535 """
1536 @see yac_cget_field_name_from_field_id
1537 """
1538 return bytes.decode(yac_cget_field_name_from_field_id ( self.field_id ))
1539
1540 @property
1541 def grid_name(self):
1542 """
1543 @see yac_cget_grid_name_from_field_id
1544 """
1545 return bytes.decode(yac_cget_grid_name_from_field_id ( self.field_id ))
1546
1547 @property
1549 """
1550 @see yac_cget_component_name_from_field_id
1551 """
1552 return bytes.decode(yac_cget_component_name_from_field_id ( self.field_id ))
1553
1554 @property
1555 def role(self):
1556 """
1557 @see yac_cget_role_from_field_id
1558 """
1559 return ExchangeType(yac_cget_role_from_field_id ( self.field_id ))
1560
1561 @property
1562 def timestep(self):
1563 """
1564 @see yac_cget_timestep_from_field_id
1565 """
1566 return bytes.decode(yac_cget_timestep_from_field_id ( self.field_id ))
1567
1568 @property
1570 """
1571 @see yac_cget_collection_size_from_field_id
1572 """
1574
1575 @property
1576 def size(self):
1577 """
1578 The size of the corresponding points object
1579 """
1580 return self._size
1581
1582 @property
1583 def datetime(self):
1584 """
1585 @see yac_cget_field_datetime
1586 """
1587 return bytes.decode(yac_cget_field_datetime(self.field_id))
1588
1589 @property
1590 def action(self):
1591 """
1592 @see yac_cget_action
1593 """
1594 cdef int action
1595 yac_cget_action(self.field_id, &action)
1596 return Action(action)
1597
1599 def __init__(self):
1600 """
1601 @see yac_cget_interp_stack_config
1602 """
1603 cdef int interp_stack_config_id
1604 _logger.debug(f"get_interp_stack_config")
1605 yac_cget_interp_stack_config(&interp_stack_config_id)
1606 _logger.debug(f"interp_stack_config_id={interp_stack_config_id}")
1607 self.interp_stack_id = interp_stack_config_id
1608
1609 @classmethod
1610 def from_string_yaml(cls, interp_stack_string : str):
1611 interp_stack = cls.__new__(cls)
1612 cdef int interp_stack_config_id
1613 _logger.debug(f"get_interp_stack_config_from_string_yaml: interp_stack_string={interp_stack_string}")
1614 yac_cget_interp_stack_config_from_string_yaml(interp_stack_string.encode(), &interp_stack_config_id)
1615 _logger.debug(f"interp_stack_config_id_from_string_yaml={interp_stack_config_id}")
1616 interp_stack.interp_stack_id = interp_stack_config_id
1617 return interp_stack
1618
1619 @classmethod
1620 def from_string_json(cls, interp_stack_string : str):
1621 interp_stack = cls.__new__(cls)
1622 cdef int interp_stack_config_id
1623 _logger.debug(f"get_interp_stack_config_from_string_json: interp_stack_string={interp_stack_string}")
1624 yac_cget_interp_stack_config_from_string_json(interp_stack_string.encode(), &interp_stack_config_id)
1625 _logger.debug(f"interp_stack_config_id_from_string_json={interp_stack_config_id}")
1626 interp_stack.interp_stack_id = interp_stack_config_id
1627 return interp_stack
1628
1629 def add_average(self, reduction_type : AverageReductionType, partial_coverage):
1630 """
1631 @see yac_cadd_interp_stack_config_average
1632 """
1633 _logger.debug(f"add_interp_stack_config_average interp_stack_id={self.interp_stack_id}")
1635 AverageReductionType(reduction_type).value,
1636 partial_coverage)
1637
1638 def add_ncc(self, reduction_type : NCCReductionType, partial_coverage):
1639 """
1640 @see yac_cadd_interp_stack_config_ncc
1641 """
1642 _logger.debug(f"add_interp_stack_config_ncc interp_stack_id={self.interp_stack_id}")
1644 NCCReductionType(reduction_type).value,
1645 partial_coverage)
1646
1647 def add_nnn(self, reduction_type : NNNReductionType, n : int,
1648 max_search_distance : _np.float64, scale : _np.float64):
1649 """
1650 @see yac_cadd_interp_stack_config_nnn
1651 """
1652 _logger.debug(f"add_interp_stack_config_nnn interp_stack_id={self.interp_stack_id}")
1654 NNNReductionType(reduction_type).value,
1655 n, max_search_distance, scale)
1656
1657 def add_conservative(self, order : int, enforced_conserv : int,
1658 partial_coverage : int, normalisation : ConservNormalizationType):
1659 """
1660 @see yac_cadd_interp_stack_config_conservative
1661 """
1662 _logger.debug(f"add_interp_stack_config_conservative interp_stack_id={self.interp_stack_id}")
1664 order, enforced_conserv,
1665 partial_coverage,
1666 ConservNormalizationType(normalisation).value)
1667
1668 def add_spmap(self, spread_distance : _np.float64, max_search_distance : _np.float64,
1669 weight_type : SPMAPWeightType, scale_type : SPMAPScaleType,
1670 src_sphere_radius : _np.float64 = 1.0, src_filename : str = None,
1671 src_varname : str = None, src_min_global_id : int = 0,
1672 tgt_sphere_radius : _np.float64 = 1.0, tgt_filename : str = None,
1673 tgt_varname : str = None, tgt_min_global_id : int = 0):
1674 """
1675 @see yac_cadd_interp_stack_config_spmap
1676 """
1677 _logger.debug(f"add_interp_stack_config_spmap interp_stack_id={self.interp_stack_id}")
1678 cdef char * src_filename_ptr
1679 if src_filename is None:
1680 src_filename_ptr = NULL
1681 else:
1682 src_filename_bytes = src_filename.encode()
1683 src_filename_ptr = src_filename_bytes
1684 cdef char * src_varname_ptr
1685 if src_varname is None:
1686 src_varname_ptr = NULL
1687 else:
1688 src_varname_bytes = src_varname.encode()
1689 src_varname_ptr = src_varname_bytes
1690 cdef char * tgt_filename_ptr
1691 if tgt_filename is None:
1692 tgt_filename_ptr = NULL
1693 else:
1694 tgt_filename_bytes = tgt_filename.encode()
1695 tgt_filename_ptr = tgt_filename_bytes
1696 cdef char * tgt_varname_ptr
1697 if tgt_varname is None:
1698 tgt_varname_ptr = NULL
1699 else:
1700 tgt_varname_bytes = tgt_varname.encode()
1701 tgt_varname_ptr = tgt_varname_bytes
1703 spread_distance, max_search_distance,
1704 SPMAPWeightType(weight_type).value,
1705 SPMAPScaleType(scale_type).value,
1706 src_sphere_radius, src_filename_ptr,
1707 src_varname_ptr, src_min_global_id,
1708 tgt_sphere_radius, tgt_filename_ptr,
1709 tgt_varname_ptr, tgt_min_global_id)
1710
1711 def add_hcsbb(self):
1712 """
1713 @see yac_cadd_interp_stack_config_hcsbb
1714 """
1715 _logger.debug(f"add_interp_stack_config_hcsbb interp_stack_id={self.interp_stack_id}")
1717
1718 def add_user_file(self, filename : str):
1719 """
1720 @see yac_cadd_interp_stack_config_user_file
1721 """
1722 _logger.debug(f"add_interp_stack_config_user_file interp_stack_id={self.interp_stack_id}")
1724 filename.encode())
1725
1726 def add_fixed(self, value : _np.float64):
1727 """
1728 @see yac_cadd_interp_stack_config_fixed
1729 """
1730 _logger.debug(f"add_interp_stack_config_fixed interp_stack_id={self.interp_stack_id}")
1732
1733 def add_check(self, constructor_key : str, do_search_key : str):
1734 """
1735 @see yac_cadd_interp_stack_config_check
1736 """
1737 _logger.debug(f"add_interp_stack_config_check interp_stack_id={self.interp_stack_id}")
1739 constructor_key.encode(), do_search_key.encode())
1740
1741 def add_creep(self, creep_distance : int):
1742 """
1743 @see yac_cadd_interp_stack_config_creep
1744 """
1745 _logger.debug(f"add_interp_stack_config_creep interp_stack_id={self.interp_stack_id}")
1747 creep_distance)
1748
1749 def __del__(self):
1750 """
1751 @see yac_cfree_interp_stack_config
1752 """
1753 _logger.debug(f"free_interp_stack_config interp_stack_id={self.interp_stack_id}")
1755
1757 """
1758 @see yac_cget_version
1759 """
1760 return bytes.decode(yac_cget_version())
1761
1762
1763if Py_AtExit(yac_cfinalize) < 0:
1764 print(
1765 b"WARNING: %s\n",
1766 b"could not register yac_cfinalize with Py_AtExit()",
1767 )
1768
1769cdef yac_abort_func _prev_abort_func = yac_get_abort_handler()
1770
1771cdef void yac_python_abort(MPI_Comm comm, const char* msg,
1772 const char* source, int line) noexcept with gil:
1773 import traceback
1774 traceback.print_stack()
1775 _prev_abort_func(comm, msg, source, line)
1776
1777yac_set_abort_handler(yac_python_abort)
Refers to YAC_ACTION_NONE, YAC_ACTION_REDUCTION etc.
Definition yac.pyx:433
Reduction type for average interpolation.
Definition yac.pyx:493
Calendar type for use in def_calendar.
Definition yac.pyx:456
__init__(self, str grid_name, x_vertices, y_vertices)
Definition yac.pyx:1283
def_points(self, x_points, y_points)
Definition yac.pyx:1295
Stores the component_id and provides further functionality.
Definition yac.pyx:982
__init__(self, comp_id)
Definition yac.pyx:986
size(self)
number of processes in this component
Definition yac.pyx:1001
comp_comm(self)
Definition yac.pyx:990
rank(self)
process index in the component
Definition yac.pyx:1010
Normalization type for conservative interpolation.
Definition yac.pyx:523
A curvilinear stuctured 2d Grid.
Definition yac.pyx:1176
def_points_unstruct(self, Location location, x_vertices, y_vertices)
Definition yac.pyx:1212
def_points(self, Location location, x_vertices, y_vertices)
Definition yac.pyx:1196
__init__(self, str grid_name, x_vertices, y_vertices, cyclic=[False, False])
Definition yac.pyx:1181
Exchange type of a field.
Definition yac.pyx:423
Store the field_id.
Definition yac.pyx:1338
wait(self)
Definition yac.pyx:1387
datetime(self)
Definition yac.pyx:1583
grid_name(self)
Definition yac.pyx:1541
test(self)
Definition yac.pyx:1376
put_coro(self, buf, frac_mask=None)
Coroutine.
Definition yac.pyx:1476
get_coro(self, buf=None)
Coroutine.
Definition yac.pyx:1437
size(self)
The size of the corresponding points object.
Definition yac.pyx:1576
wait_coro(self)
Coroutine.
Definition yac.pyx:1398
update(self)
Definition yac.pyx:1485
action(self)
Definition yac.pyx:1590
get(self, buf=None, asyn=False)
Definition yac.pyx:1406
exchange(cls, send_field, recv_field, send_buf, recv_buf=None, send_frac_mask=None)
Definition yac.pyx:1494
collection_size(self)
Definition yac.pyx:1569
create(cls, str field_name, Component comp, points, collection_size, str timestep, TimeUnit timeunit, masks=None)
Definition yac.pyx:1348
collection_size
Definition yac.pyx:1462
role(self)
Definition yac.pyx:1555
__init__(self, field_id, size=None)
Definition yac.pyx:1342
timestep(self)
Definition yac.pyx:1562
put(self, buf, frac_mask=None)
Definition yac.pyx:1450
component_name(self)
Definition yac.pyx:1548
name(self)
Definition yac.pyx:1534
Stores the grid_id and provides further functionality.
Definition yac.pyx:1025
nbr_corners(self)
Definition yac.pyx:1053
set_core_mask(self, is_core, Location location)
Definition yac.pyx:1066
nbr_cells(self)
Definition yac.pyx:1046
__init__(self, grid_id)
Definition yac.pyx:1031
set_global_index(self, global_index, Location location)
Definition yac.pyx:1035
nbr_edges(self)
Definition yac.pyx:1060
def_mask(self, Location location, is_valid, name=None)
Definition yac.pyx:1077
compute_grid_cell_areas(self, cell_areas=None)
Definition yac.pyx:1094
add_check(self, str constructor_key, str do_search_key)
Definition yac.pyx:1733
add_average(self, AverageReductionType reduction_type, partial_coverage)
Definition yac.pyx:1629
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:1673
add_conservative(self, int order, int enforced_conserv, int partial_coverage, ConservNormalizationType normalisation)
Definition yac.pyx:1658
add_creep(self, int creep_distance)
Definition yac.pyx:1741
add_fixed(self, _np.float64 value)
Definition yac.pyx:1726
from_string_json(cls, str interp_stack_string)
Definition yac.pyx:1620
from_string_yaml(cls, str interp_stack_string)
Definition yac.pyx:1610
add_nnn(self, NNNReductionType reduction_type, int n, _np.float64 max_search_distance, _np.float64 scale)
Definition yac.pyx:1648
add_user_file(self, str filename)
Definition yac.pyx:1718
add_ncc(self, NCCReductionType reduction_type, partial_coverage)
Definition yac.pyx:1638
Location for points.
Definition yac.pyx:413
Stores the mask_id.
Definition yac.pyx:1018
__init__(self, mask_id)
Definition yac.pyx:1022
Reduction type for ncc interpolation.
Definition yac.pyx:503
Reduction type for nnn interpolation.
Definition yac.pyx:512
Stores the points_id and provides further functionality.
Definition yac.pyx:1104
set_mask(self, is_valid)
Definition yac.pyx:1118
__init__(self, points_id)
Definition yac.pyx:1108
size(self)
Definition yac.pyx:1112
Reduction type for the definition of interpolations.
Definition yac.pyx:444
A stuctured 2d Grid.
Definition yac.pyx:1129
__init__(self, str grid_name, x_vertices, y_vertices, cyclic=[False, False])
Definition yac.pyx:1134
def_points(self, Location location, x_vertices, y_vertices)
Definition yac.pyx:1148
def_points_unstruct(self, Location location, x_vertices, y_vertices)
Definition yac.pyx:1162
Refers to YAC_SPMAP_NONE, YAC_SPMAP_SRCAREA YAC_SPMAP_INVTGTAREA, and YAC_SPMAP_FRACAREA.
Definition yac.pyx:539
Refers to YAC_SPMAP_AVG and YAC_SPMAP_DIST.
Definition yac.pyx:532
Refers to YAC_TIME_UNIT_MILLISECOND, YAC_TIME_UNIT_SECOND etc.
Definition yac.pyx:480
__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:1302
An unstuctured 2d Grid.
Definition yac.pyx:1245
__init__(self, str grid_name, num_vertices_per_cell, x_vertices, y_vertices, cell_to_vertex, use_ll_edges=False)
Definition yac.pyx:1250
Initializies a YAC instance and provides further functionality.
Definition yac.pyx:558
read_config_yaml(self, str yaml_file)
Definition yac.pyx:962
enddef(self)
Definition yac.pyx:765
def_comp(self, str comp_name)
Definition yac.pyx:617
predef_comp(self, str comp_name)
Definition yac.pyx:645
grid_names(self)
Definition yac.pyx:785
get_grid_metadata(self, str grid_name)
Definition yac.pyx:929
instance_id
Definition yac.pyx:590
def_component_metadata(self, str comp_name, bytes metadata)
Definition yac.pyx:894
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, mapping_on_source=1, scale_factor=1.0, scale_summand=0.0, src_masks_names=None, tgt_mask_name=None, yaxt_exchanger_name=None)
Definition yac.pyx:717
sync_def(self)
Definition yac.pyx:701
def_field_metadata(self, str comp_name, str grid_name, str field_name, bytes metadata)
Definition yac.pyx:911
def_grid_metadata(self, str grid_name, bytes metadata)
Definition yac.pyx:902
start_datetime(self)
Definition yac.pyx:686
get_field_metadata(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:937
get_comps_comm(self, comp_names)
Definition yac.pyx:947
cleanup(self)
Definition yac.pyx:608
get_field_names(self, str comp_name, str grid_name)
Definition yac.pyx:807
get_field_id(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:821
def_comps(self, comp_names=[])
Definition yac.pyx:627
from_id(cls, id)
Definition yac.pyx:599
get_component_metadata(self, str comp_name)
Definition yac.pyx:921
def_datetime(self, start_datetime, end_datetime)
Definition yac.pyx:655
get_field_role(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:839
get_field_source(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:849
owned_instance
Definition yac.pyx:591
enable_field_frac_mask(self, str comp_name, str grid_name, str field_name, _np.float64 frac_mask_fallback_value)
Definition yac.pyx:883
get_comp_grid_names(self, comp_name)
Definition yac.pyx:796
get_field_timestep(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:830
get_field_frac_mask_fallback_value(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:873
end_datetime(self)
Definition yac.pyx:694
__del__(self)
Definition yac.pyx:605
__init__(self, comm=None, default_instance=False)
Definition yac.pyx:564
component_names(self)
Definition yac.pyx:773
get_field_collection_size(self, str comp_name, str grid_name, str field_name)
Definition yac.pyx:864
set_config_output_file(self, str filename, ConfigOutputFormat fileformat, ConfigOutputSyncLoc sync_location, bool include_definitions=False)
Definition yac.pyx:972
default_instance(cls)
Definition yac.pyx:595
__init__(self, grid_id)
Definition yac.pyx:1228
def_points(self, Location location, x_points, y_points)
Definition yac.pyx:1232
enum callback_type type
version()
Definition yac.pyx:1756
get_calendar()
Definition yac.pyx:473
_prev_abort_func
Definition yac.pyx:1769
def_calendar(Calendar calendar)
Definition yac.pyx:467
void yac_ccompute_grid_cell_areas(int grid_id, double *cell_areas)
Definition yac.c:3646
void yac_cadd_interp_stack_config_ncc(int interp_stack_config_id, int weight_type, int partial_coverage)
Definition yac.c:3720
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:1337
void yac_cpredef_comp_instance(int yac_instance_id, char const *name, int *comp_id)
Definition yac.c:809
char * yac_cget_start_datetime_instance(int yac_instance_id)
Definition yac.c:672
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:1143
void yac_cset_global_index(int const *global_index, int location, int grid_id)
Definition yac.c:3554
void yac_cget_(int const field_id, int const collection_size, double *recv_field, int *info, int *ierr)
Definition yac.c:1989
int yac_cget_nbr_grids_instance(int yac_instance_id)
Definition yac.c:3060
void yac_cfree_ext_couple_config(int ext_couple_config_id)
Definition yac.c:1373
const char * yac_cget_grid_metadata_instance(int yac_instance_id, const char *grid_name)
Definition yac.c:1324
char * yac_cget_end_datetime_instance(int yac_instance_id)
Definition yac.c:687
void yac_cset_ext_couple_config_tgt_mask_name(int ext_couple_config_id, char const *tgt_mask_name)
Definition yac.c:1520
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:3434
void yac_cget_grid_names_instance(int yac_instance_id, int nbr_grids, const char **grid_names)
Definition yac.c:3152
void yac_cset_ext_couple_config_scale_factor(int ext_couple_config_id, double scale_factor)
Definition yac.c:1442
void yac_cadd_interp_stack_config_creep(int interp_stack_config_id, int creep_distance)
Definition yac.c:3874
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:2095
void yac_cget_comp_rank_c2py(int comp_id, int *rank)
Definition yac.c:758
void yac_cget_comp_size_c2py(int comp_id, int *size)
Definition yac.c:751
int yac_cget_comp_nbr_grids_instance(int yac_instance_id, const char *comp_name)
Definition yac.c:3073
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:3473
void yac_csync_def_instance(int yac_instance_id)
Definition yac.c:2980
static void cleanup()
Definition yac.c:599
void yac_cget_interp_stack_config_from_string_json(char const *interp_stack_config, int *interp_stack_config_id)
Definition yac.c:3935
void yac_cinit(void)
Definition yac.c:419
void yac_cfinalize()
Definition yac.c:619
void yac_cadd_interp_stack_config_check(int interp_stack_config_id, char const *constructor_key, char const *do_search_key)
Definition yac.c:3862
void yac_cenddef_instance(int yac_instance_id)
Definition yac.c:2993
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:1495
int yac_cget_nbr_comps_instance(int yac_instance_id)
Definition yac.c:3047
int yac_cget_nbr_fields_instance(int yac_instance_id, const char *comp_name, const char *grid_name)
Definition yac.c:3101
void yac_cget_ext_couple_config(int *ext_couple_config_id)
Definition yac.c:1365
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:3494
void yac_cdef_grid_metadata_instance(int yac_instance_id, const char *grid_name, const char *metadata)
Definition yac.c:1281
void yac_cset_ext_couple_config_weight_file(int ext_couple_config_id, char const *weight_file)
Definition yac.c:1393
const char * yac_cget_component_metadata_instance(int yac_instance_id, const char *comp_name)
Definition yac.c:1311
void yac_cread_config_yaml_instance(int yac_instance_id, const char *yaml_filename)
Definition yac.c:465
void yac_cset_ext_couple_config_yaxt_exchanger_name(int ext_couple_config_id, char const *yaxt_exchanger_name)
Definition yac.c:1542
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:3316
void yac_cset_ext_couple_config_scale_summand(int ext_couple_config_id, double scale_summand)
Definition yac.c:1465
void yac_cget_comp_comm(int comp_id, MPI_Comm *comp_comm)
Definition yac.c:729
const char * yac_cget_field_datetime(int field_id)
Definition yac.c:1810
void yac_cdef_comp_instance(int yac_instance_id, char const *comp_name, int *comp_id)
Definition yac.c:880
void yac_cupdate(int field_id)
Definition yac.c:1830
void yac_cget_action(int field_id, int *action)
Definition yac.c:1767
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:2686
int yac_cget_collection_size_from_field_id(int field_id)
Definition yac.c:3300
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:3416
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:1585
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:495
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:976
void yac_cinit_comm_instance(MPI_Comm comm, int *yac_instance_id)
Definition yac.c:381
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:1247
void yac_cget_interp_stack_config_from_string_yaml(char const *interp_stack_config, int *interp_stack_config_id)
Definition yac.c:3927
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:3759
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:3452
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:1050
char * yac_cget_version(void)
Definition yac.c:705
int yac_cget_default_instance_id()
Definition yac.c:376
void yac_cadd_interp_stack_config_user_file(int interp_stack_config_id, char const *filename)
Definition yac.c:3841
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:2719
void yac_cdef_component_metadata_instance(int yac_instance_id, const char *comp_name, const char *metadata)
Definition yac.c:1268
void yac_cdef_calendar(int calendar)
Definition yac.c:648
int yac_cget_calendar()
Definition yac.c:665
void yac_cput_(int const field_id, int const collection_size, double *send_field, int *info, int *ierr)
Definition yac.c:2074
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:3177
void yac_cget_async_(int const field_id, int const collection_size, double *recv_field, int *info, int *ierr)
Definition yac.c:1998
void yac_cadd_interp_stack_config_hcsbb(int interp_stack_config_id)
Definition yac.c:3832
void yac_cget_comps_comm_instance(int yac_instance_id, char const **comp_names, int num_comps, MPI_Comm *comps_comm)
Definition yac.c:769
void yac_cadd_interp_stack_config_fixed(int interp_stack_config_id, double value)
Definition yac.c:3852
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:3335
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:3389
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:3778
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:3516
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:1012
void yac_cset_ext_couple_config_mapping_side(int ext_couple_config_id, int mapping_side)
Definition yac.c:1419
void yac_ccleanup_instance(int yac_instance_id)
Definition yac.c:582
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:3346
void yac_cfree_interp_stack_config(int interp_stack_config_id)
Definition yac.c:3681
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:3738
size_t yac_cget_grid_size(int located, int grid_id)
Definition yac.c:3635
void yac_cinit_instance(int *yac_instance_id)
Definition yac.c:407
void yac_cget_interp_stack_config(int *interp_stack_config_id)
Definition yac.c:3667
void yac_cadd_interp_stack_config_average(int interp_stack_config_id, int reduction_type, int partial_coverage)
Definition yac.c:3701
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:1216
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:1295
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:3225
void yac_cdef_comps_instance(int yac_instance_id, char const **comp_names, int num_comps, int *comp_ids)
Definition yac.c:847
void yac_cget_comp_names_instance(int yac_instance_id, int nbr_comps, const char **comp_names)
Definition yac.c:3126
void yac_cinit_comm(MPI_Comm comm)
Definition yac.c:393
yac_abort_func yac_get_abort_handler(void)
void yac_set_abort_handler(yac_abort_func custom_abort)