YAC 3.13.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_coupling1.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# Copyright (c) 2025 The YAC Authors
4#
5# SPDX-License-Identifier: BSD-3-Clause
6
7
11
12import yac
13import numpy as np
14
15try:
16 from mpi4py import MPI
17except:
18 pass
19
20yac.def_calendar(yac.Calendar.PROLEPTIC_GREGORIAN)
21
22yac_instance = yac.YAC()
23assert yac_instance.size == 4
24yac_instance.def_datetime("2020-01-01T00:00:00",
25 "2020-01-02T00:00:00")
26
27rank = yac_instance.rank
28
29if rank < 2:
30 comp = yac_instance.def_comp("comp_A")
31 grid = yac.Reg2dGrid("grid_A",
32 np.linspace(0, 2*np.pi, 180, endpoint=False),
33 np.linspace(-np.pi/2, np.pi/2, 90),
34 cyclic=[True,False])
35 points = grid.def_points(yac.Location.CELL,
36 np.pi/180 + np.linspace(0, 2*np.pi, 180, endpoint=False),
37 np.pi/90 + np.linspace(-np.pi/2, np.pi/2, 89, endpoint=False))
38 field = yac.Field.create("field_A", comp, points,
39 collection_size=3,
40 timestep="1", timeunit=yac.TimeUnit.MINUTE)
41 yac_instance.enddef()
42 t = 0
43 while field.action != yac.Action.OUT_OF_BOUND:
44 field.put(t + np.stack([1*np.ones(points.size),
45 2*np.ones(points.size),
46 3*np.ones(points.size)]
47 )
48 )
49 t += 1
50else:
51 comp = yac_instance.def_comp("comp_B")
53 "grid_B",
54 [3],
55 np.deg2rad([0.0, 1.0, 0.0]),
56 np.deg2rad([0.0, 0.0, 1.0]),
57 [0, 1, 2],
58 )
59 points = grid.def_points(yac.Location.CELL,
60 np.deg2rad([1/3]),
61 np.deg2rad([1/3])
62 )
63 field = yac.Field.create("field_B", comp, points,
64 collection_size = 2,
65 timestep="1", timeunit=yac.TimeUnit.HOUR)
66
67 interp_stack = yac.InterpolationStack()
68 interp_stack.add_nnn()
69
70 yac_instance.def_couple("comp_A", "grid_A", "field_A",
71 "comp_B", "grid_B", "field_B",
72 coupling_timestep="1", timeunit=yac.TimeUnit.HOUR,
73 time_reduction=yac.Reduction.TIME_NONE,
74 interp_stack=interp_stack,
75 collection_selection=[2,1])
76 yac_instance.enddef()
77 t = 0
78 while field.action != yac.Action.OUT_OF_BOUND:
79 data, info = field.get()
80 assert np.allclose(data,
81 60*t + np.stack([3*np.ones(points.size),
82 2*np.ones(points.size)]
83 )
84 )
85 t += 1
create(cls, str field_name, Component comp, points, collection_size, str timestep, TimeUnit timeunit, masks=None)
Definition yac.pyx:1570
A stuctured 2d Grid.
Definition yac.pyx:1332
An unstuctured 2d Grid.
Definition yac.pyx:1467
Initializies a YAC instance and provides further functionality.
Definition yac.pyx:693
def_calendar(Calendar calendar)
Definition yac.pyx:570