7from yac
import YAC, Curve2dGrid, Location, Field, TimeUnit
8from itertools
import product
17 return clat * np.cos(lon), clat * np.sin(lon), slat
22 lon = np.arctan2(y, x)
28 e[np.ix_(plane_dims, plane_dims)] = np.array([[np.cos(theta), -np.sin(theta)],
29 [np.sin(theta), np.cos(theta)]])
33MPI.COMM_WORLD.Barrier()
37comp = yac.def_comp(my_comp_name)
39size = comp.comp_comm.size
40rank = comp.comp_comm.rank
45 print(
"toy_multi_curve2d: ", m)
49fac = int(np.sqrt(size))
52msg(f
"decomposition: {fac} x {size//fac}")
55size2d = [fac, size//fac]
56rank2d = [rank % fac, rank//fac]
57chunk2d = [math.ceil(dim2d[0]/size2d[0]), math.ceil(dim2d[1]/size2d[1])]
58slice2d = [slice(rank2d[0]*chunk2d[0], (rank2d[0]+1)*chunk2d[0]+1),
59 slice(rank2d[1]*chunk2d[1], (rank2d[1]+1)*chunk2d[1]+1)]
61x = np.linspace(-.5, .5, dim2d[0])
62y = np.linspace(-.5, .5, dim2d[1])
65vx, vy = np.meshgrid(x, y)
67r =
rotmat(-.45*np.pi, [0, 2], 3)
@rotmat(0.1*np.pi, [0, 1], 3)
68v_xyz = np.stack(lonlat2xyz(vx, vy), axis=-1)
70c_xyz = 0.25*(v_xyz[:-1, :-1, :]+v_xyz[1:, :-1, :]+v_xyz[:-1, 1:, :]+v_xyz[1:, 1:, :])
71vx, vy =
xyz2lonlat(v_xyz[..., 0], v_xyz[..., 1], v_xyz[..., 2])
72cx, cy =
xyz2lonlat(c_xyz[..., 0], c_xyz[..., 1], c_xyz[..., 2])
76corner_idx = np.arange(math.prod(dim2d)).reshape(dim2d)[slice2d[0], slice2d[1]]
77grid.set_global_index(corner_idx.T.flatten(), Location.CORNER)
79cell_idx = np.arange(math.prod([d-1
for d
in dim2d])).reshape([d-1
for d
in dim2d])[
80 slice(rank2d[0]*chunk2d[0], (rank2d[0]+1)*chunk2d[0]),
81 slice(rank2d[1]*chunk2d[1], (rank2d[1]+1)*chunk2d[1])]
82grid.set_global_index(cell_idx.T.flatten(), Location.CELL)
84points_cell = grid.def_points(Location.CELL, cx, cy)
85points_vertex = grid.def_points(Location.CORNER, vx, vy)
87interpolations = [(
"conserv", Location.CELL),
88 (
"2nd_conserv", Location.CELL),
89 (
"avg", Location.CORNER),
90 (
"hcsbb", Location.CELL),
91 (
"rbf", Location.CELL)]
93MPI.COMM_WORLD.Barrier()
94MPI.COMM_WORLD.Barrier()
96field = {f
"{interp[0]}_{comp_name}_field_out":
97 Field.create(f
"{interp[0]}_{comp_name}_field_out", comp,
98 points_vertex
if interp[1] == Location.CORNER
else points_cell,
99 1,
"2", TimeUnit.SECOND)
100 for comp_name, interp
in product(yac.component_names, interpolations)}
102MPI.COMM_WORLD.Barrier()
103MPI.COMM_WORLD.Barrier()
105MPI.COMM_WORLD.Barrier()
109 return (np.sin(8*lon)*np.cos(12*lat)).flatten()
115MPI.COMM_WORLD.Barrier()
116for interp
in interpolations:
117 field[f
"{interp[0]}_{my_comp_name}_field_out"].put(data_vertex
if interp[1] == Location.CORNER
else data_cell)
119for comp_name, interp
in product(yac.component_names, interpolations):
120 if comp_name == my_comp_name:
122 data = field[f
"{interp[0]}_{comp_name}_field_out"].get()
123MPI.COMM_WORLD.Barrier()
A curvilinear stuctured 2d Grid.
Initializies a YAC instance and provides further functionality.
rotmat(theta, plane_dims, d=2)