File: catalyst_adaptor.py

package info (click to toggle)
paraview 5.13.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 544,220 kB
  • sloc: cpp: 3,374,605; ansic: 1,332,409; python: 150,381; xml: 122,166; sql: 65,887; sh: 7,317; javascript: 5,262; yacc: 4,417; java: 3,977; perl: 2,363; lex: 1,929; f90: 1,397; makefile: 170; objc: 153; tcl: 59; pascal: 50; fortran: 29
file content (102 lines) | stat: -rw-r--r-- 3,853 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import os
import glob
import sys
import catalyst
import catalyst_conduit
from mpi4py import MPI


def initialize():
    # initialize ParaView Catalyst V2.
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()

    node = catalyst_conduit.Node()
    count = 0
    for i in sys.argv[1:]:
        node['catalyst/scripts/script'+str(count)] = i
        count = count + 1
        if rank == 0:
            print('Using Catalyst script', i)
    node['catalyst_load/implementation'] = 'paraview'
    # if we know the location of libcatalyst-paraview.so and want to pass that along via
    # Python we would do that like:
    # node['catalyst_load/search_paths/paraview'] = </full/path/to/libcatalyst-paraview.so>

    catalyst.initialize(node)

def finalize():
    # finalize ParaView Catalyst V2.
    node = catalyst_conduit.Node()
    catalyst.finalize(node)

def coprocess(time, timeStep, grid, attributes):
    # do the actual in situ analysis and visualization.
    node = catalyst_conduit.Node()

    node['catalyst/state/timestep'] = timeStep
    node['catalyst/state/time'] = time

    node['catalyst/state/pipelines/0'] = 'script0'

    # the Catalyst channel is "input"
    node['catalyst/channels/input/type'] = 'mesh'

    mesh = node['catalyst/channels/input/data']

    mesh['coordsets/coords/type'] = 'uniform'

    mesh['coordsets/coords/dims/i'] = grid.XEndPoint - grid.XStartPoint + 1
    mesh['coordsets/coords/dims/j'] = grid.NumberOfYPoints
    mesh['coordsets/coords/dims/k'] = grid.NumberOfZPoints

    mesh['coordsets/coords/origin/x'] = grid.XStartPoint * grid.Spacing[0]
    mesh['coordsets/coords/origin/y'] = 0.0
    mesh['coordsets/coords/origin/z'] = 0.0

    mesh['coordsets/coords/spacing/dx'] = grid.Spacing[0]
    mesh['coordsets/coords/spacing/dy'] = grid.Spacing[1]
    mesh['coordsets/coords/spacing/dz'] = grid.Spacing[2]

    mesh['topologies/mesh/type'] = 'uniform'
    mesh['topologies/mesh/coordset'] = 'coords'

    fields = mesh['fields']

    # velocity is point-data.
    # velocity is stored in interlaced form.
    fields['velocitydeepcopy/association'] = 'vertex'
    fields['velocitydeepcopy/topology'] = 'mesh'
    fields['velocitydeepcopy/volume_dependent'] = 'false'
    # flatten creates a deep copy of the array so we need to deep copy
    # this data into the Conduit Node.
    fields['velocitydeepcopy/values/x'] = attributes.Velocity.flatten()[0::3]
    fields['velocitydeepcopy/values/y'] = attributes.Velocity.flatten()[1::3]
    fields['velocitydeepcopy/values/z'] = attributes.Velocity.flatten()[2::3]

    # pressure is cell-data.
    fields['pressure/association'] = 'element'
    fields['pressure/topology'] = 'mesh'
    fields['pressure/volume_dependent'] = 'false'
    # pressure is zero-copied into Catalyst because the simulation
    # stores the data the same way that Conduit expects it and it is scalar.
    fields['pressure/values'].set_external(attributes.Pressure)

    # zero-copied numpy arrays don't seem to work yet
    # for non-flat, non-scalar arrays. it should look something like
    # the following though.
    fields['velocityzerocopy/association'] = 'vertex'
    fields['velocityzerocopy/topology'] = 'mesh'
    fields['velocityzerocopy/volume_dependent'] = 'false'
    # we can also use reshape to get do a zero-copy into Conduit.
    fields['velocityzerocopy/values/x'].set_external(attributes.Velocity.reshape(-1)[0::3])
    fields['velocityzerocopy/values/y'].set_external(attributes.Velocity.reshape(-1)[1::3])
    fields['velocityzerocopy/values/z'].set_external(attributes.Velocity.reshape(-1)[2::3])

    # can look at
    # https://github.com/LLNL/conduit/blob/50a5dbe8e975c1914187cf4ef3279b61f7753085/src/tests/conduit/python/t_python_conduit_node.py#L671
    # for other examples on how to do zero-copy using set_external.

    catalyst.execute(node)

    return