source: CPL/oasis3-mct/branches/OASIS3-MCT_5.0_branch/pyoasis/examples/4-orange/python/sender-orange.py @ 6331

Last change on this file since 6331 was 6331, checked in by aclsce, 17 months ago

Moved oasis-mct_5.0 in oasis3-mct/branches directory.

File size: 1.0 KB
Line 
1#!/usr/bin/env python3
2
3import pyoasis
4from pyoasis import OASIS
5import numpy
6
7from mpi4py import MPI
8
9comm = MPI.COMM_WORLD
10
11component_name = "sender-orange"
12
13comp = pyoasis.Component(component_name, True, comm)
14
15local_comm_rank = comp.localcomm.rank
16local_comm_size = comp.localcomm.size
17
18coupled = True
19if local_comm_size > 3:
20    if local_comm_rank >= local_comm_size - 2:
21        coupled = False
22
23print(comp, flush=True)
24
25comp.create_couplcomm(coupled)
26
27if coupled:
28    comm_rank = comp.couplcomm.rank
29    comm_size = comp.couplcomm.size
30
31    n_points = 16
32    extent = int(n_points / comm_size)
33    offset = comm_rank * extent
34
35    offsets = [offset]
36    extents = [extent]
37
38    partition = pyoasis.OrangePartition(offsets, extents)
39    print(partition, flush=True)
40
41    variable = pyoasis.Var("FSENDOCN", partition, OASIS.OUT)
42    print(variable, flush=True)
43
44comp.enddef()
45
46if coupled:
47    date = int(0)
48
49    field = pyoasis.asarray(numpy.zeros(extent))
50    for i in range(extent):
51        field[i] = offset + i
52
53    variable.put(date, field)
54
55del comp
Note: See TracBrowser for help on using the repository browser.