File: adios2-doc-write.py

package info (click to toggle)
adios2 2.10.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 33,764 kB
  • sloc: cpp: 175,964; ansic: 160,510; f90: 14,630; yacc: 12,668; python: 7,275; perl: 7,126; sh: 2,825; lisp: 1,106; xml: 1,049; makefile: 579; lex: 557
file content (34 lines) | stat: -rw-r--r-- 960 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from mpi4py import MPI
import numpy as np
from adios2 import Stream

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()

nx = 10
shape = [size * nx]
start = [rank * nx]
count = [nx]

temperature = np.zeros(nx, dtype=np.double)
pressure = np.ones(nx, dtype=np.double)
delta_time = 0.01
physical_time = 0.0
nsteps = 5

with Stream("cfd.bp", "w", comm) as s:
    # NSteps from application
    for _ in s.steps(nsteps):
        if rank == 0 and s.current_step() == 0:
            # write a Python integer
            s.write("nproc", size)

        # write a Python floating point value
        s.write("physical_time", physical_time)
        # temperature and pressure are numpy arrays
        s.write("temperature", temperature, shape, start, count)
        s.write_attribute("temperature/unit", "K")
        s.write("pressure", pressure, shape, start, count)
        s.write_attribute("pressure/unit", "Pa")
        physical_time += delta_time