File: gridwriter.py

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (104 lines) | stat: -rw-r--r-- 4,205 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
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
103
104
from paraview.simple import *

from paraview import coprocessing

# the frequency to output everything
outputfrequency = 5

#--------------------------------------------------------------
# Code generated from cpstate.py to create the CoProcessor.


# ----------------------- CoProcessor definition -----------------------

def CreateCoProcessor():
  def _CreatePipeline(coprocessor, datadescription):
    class Pipeline:
      adaptorinput = coprocessor.CreateProducer( datadescription, "input" )
      grid = adaptorinput.GetClientSideObject().GetOutputDataObject(0)
      filename = None
      if  grid.IsA('vtkImageData') or grid.IsA('vtkUniformGrid'):
        writer = servermanager.writers.XMLPImageDataWriter(Input=adaptorinput)
        filename = 'filename_%t.pvti'
      elif  grid.IsA('vtkRectilinearGrid'):
        writer = servermanager.writers.XMLPRectilinearGridWriter(Input=adaptorinput)
        filename = 'filename_%t.pvtr'
      elif  grid.IsA('vtkStructuredGrid'):
        writer = servermanager.writers.XMLPStructuredGridWriter(Input=adaptorinput)
        filename = 'filename_%t.pvts'
      elif  grid.IsA('vtkPolyData'):
        writer = servermanager.writers.XMLPPolyDataWriter(Input=adaptorinput)
        filename = 'filename_%t.pvtp'
      elif  grid.IsA('vtkUnstructuredGrid'):
        writer = servermanager.writers.XMLPUnstructuredGridWriter(Input=adaptorinput)
        filename = 'filename_%t.pvtu'
      elif  grid.IsA('vtkUniformGridAMR'):
        writer = servermanager.writers.XMLHierarchicalBoxDataWriter(Input=adaptorinput)
        filename = 'filename_%t.vthb'
      elif  grid.IsA('vtkMultiBlockDataSet'):
        writer = servermanager.writers.XMLMultiBlockDataWriter(Input=adaptorinput)
        filename = 'filename_%t.vtm'
      else:
        print "Don't know how to create a writer for a ", grid.GetClassName()

      if filename:
        coprocessor.RegisterWriter(writer, filename, freq=outputfrequency)

    return Pipeline()

  class CoProcessor(coprocessing.CoProcessor):
    def CreatePipeline(self, datadescription):
      self.Pipeline = _CreatePipeline(self, datadescription)

  coprocessor = CoProcessor()
  freqs = {'input': [outputfrequency]}
  coprocessor.SetUpdateFrequencies(freqs)
  return coprocessor

#--------------------------------------------------------------
# Global variables that will hold the pipeline for each timestep
# Creating the CoProcessor object, doesn't actually create the ParaView pipeline.
# It will be automatically setup when coprocessor.UpdateProducers() is called the
# first time.
coprocessor = CreateCoProcessor()

#--------------------------------------------------------------
# Enable Live-Visualizaton with ParaView
coprocessor.EnableLiveVisualization(False)


# ---------------------- Data Selection method ----------------------

def RequestDataDescription(datadescription):
    "Callback to populate the request for current timestep"
    global coprocessor
    if datadescription.GetForceOutput() == True:
        # We are just going to request all fields and meshes from the simulation
        # code/adaptor.
        for i in range(datadescription.GetNumberOfInputDescriptions()):
            datadescription.GetInputDescription(i).AllFieldsOn()
            datadescription.GetInputDescription(i).GenerateMeshOn()
        return

    # setup requests for all inputs based on the requirements of the
    # pipeline.
    coprocessor.LoadRequestedData(datadescription)

# ------------------------ Processing method ------------------------

def DoCoProcessing(datadescription):
    "Callback to do co-processing for current timestep"
    global coprocessor

    # Update the coprocessor by providing it the newly generated simulation data.
    # If the pipeline hasn't been setup yet, this will setup the pipeline.
    coprocessor.UpdateProducers(datadescription)

    # Write output data, if appropriate.
    coprocessor.WriteData(datadescription);

    # Write image capture (Last arg: rescale lookup table), if appropriate.
    coprocessor.WriteImages(datadescription, rescale_lookuptable=False)

    # Live Visualization, if enabled.
    coprocessor.DoLiveVisualization(datadescription, "localhost", 22222)