source: CPL/oasis3-mct_5.0/pyoasis/examples/6-apple_and_orange/python/receiver-orange.py @ 6328

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

First import of oasis3-mct_5.0 (from oasis git server, branch OASIS3-MCT_5.0)

File size: 890 bytes
Line 
1#!/usr/bin/env python3
2
3import pyoasis
4from pyoasis import OASIS
5import numpy
6from mpi4py import MPI
7
8comm = MPI.COMM_WORLD
9
10component_name = "receiver"
11
12comp = pyoasis.Component(component_name, True, comm)
13print(comp)
14
15comm_rank = comp.localcomm.rank
16comm_size = comp.localcomm.size
17
18n_points = 16
19extent = int(n_points/comm_size)
20offset = comm_rank*extent
21
22offsets = [offset]
23extents = [extent]
24
25partition = pyoasis.OrangePartition(offsets, extents)
26print(partition)
27
28variable = pyoasis.Var("FRECVATM", partition, OASIS.IN)
29print(variable)
30
31comp.enddef()
32
33date = int(0)
34field = pyoasis.asarray(numpy.zeros(extent))
35
36variable.get(date, field)
37
38expected_field = pyoasis.asarray(numpy.zeros(extent))
39for i in range(extent):
40    expected_field[i] = offset + i
41
42epsilon = 1e-8
43error = numpy.abs(field-expected_field).sum()
44if error < epsilon:
45    print("Data received successfully")
46
47del comp
Note: See TracBrowser for help on using the repository browser.