
#--------------------------------------------------------------

# Global timestep output options
timeStepToStartOutputAt=0
forceOutputAtFirstCall=False

# Global screenshot output options
imageFileNamePadding=0
rescale_lookuptable=False

# Whether or not to request specific arrays from the adaptor.
requestSpecificArrays=False

# a root directory under which all Catalyst output goes
rootDirectory=''

# makes a cinema D index table
make_cinema_table=False

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

from paraview.simple import *
from paraview import coprocessing

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

def CreateCoProcessor():
  def _CreatePipeline(coprocessor, datadescription):
    class Pipeline:
      # state file generated using paraview version 5.6.0

      # ----------------------------------------------------------------
      # setup views used in the visualization
      # ----------------------------------------------------------------

      # trace generated using paraview version 5.6.0
      #
      # To ensure correct image size when batch processing, please search 
      # for and uncomment the line `# renderView*.ViewSize = [*,*]`

      #### disable automatic camera reset on 'Show'
      paraview.simple._DisableFirstRenderCameraReset()

      # Create a new 'Render View'
      renderView1 = CreateView('RenderView')
      renderView1.ViewSize = [1205, 757]
      renderView1.AxesGrid = 'GridAxes3DActor'
      renderView1.CenterOfRotation = [0.0, 0.0, -0.10000000894069672]
      renderView1.StereoType = 0
      renderView1.CameraPosition = [0.0, 0.0, 8.75285643298775]
      renderView1.CameraFocalPoint = [0.0, 0.0, -0.10000000894069672]
      renderView1.CameraParallelScale = 2.29128785072962
      renderView1.Background = [0.32, 0.34, 0.43]

      # init the 'GridAxes3DActor' selected for 'AxesGrid'
      renderView1.AxesGrid.XTitleFontFile = ''
      renderView1.AxesGrid.YTitleFontFile = ''
      renderView1.AxesGrid.ZTitleFontFile = ''
      renderView1.AxesGrid.XLabelFontFile = ''
      renderView1.AxesGrid.YLabelFontFile = ''
      renderView1.AxesGrid.ZLabelFontFile = ''

      # register the view with coprocessor
      # and provide it with information such as the filename to use,
      # how frequently to write the images, etc.
      coprocessor.RegisterView(renderView1,
          filename='image_%t.png', freq=1, fittoscreen=0, magnification=1, width=1205, height=757, cinema={})
      renderView1.ViewTime = datadescription.GetTime()

      # ----------------------------------------------------------------
      # restore active view
      SetActiveView(renderView1)
      # ----------------------------------------------------------------

      # ----------------------------------------------------------------
      # setup the data processing pipelines
      # ----------------------------------------------------------------

      # create a new 'EnSight Reader'
      # create a producer from a simulation input
      rESULTScase = coprocessor.CreateProducer(datadescription, 'RESULTS.case')

      # ----------------------------------------------------------------
      # setup the visualization in view 'renderView1'
      # ----------------------------------------------------------------

      # show data from rESULTScase
      rESULTScaseDisplay = Show(rESULTScase, renderView1)

      # get color transfer function/color map for 'TempC'
      tempCLUT = GetColorTransferFunction('TempC')
      tempCLUT.RGBPoints = [-3.056058631045744e-05, 0.231373, 0.298039, 0.752941, 0.2460471474660153, 0.865003, 0.865003, 0.865003, 0.49212485551834106, 0.705882, 0.0156863, 0.14902]
      tempCLUT.ScalarRangeInitialized = 1.0

      # get opacity transfer function/opacity map for 'TempC'
      tempCPWF = GetOpacityTransferFunction('TempC')
      tempCPWF.Points = [-3.056058631045744e-05, 0.0, 0.5, 0.0, 0.49212485551834106, 1.0, 0.5, 0.0]
      tempCPWF.ScalarRangeInitialized = 1

      # trace defaults for the display properties.
      rESULTScaseDisplay.Representation = 'Surface'
      rESULTScaseDisplay.ColorArrayName = ['CELLS', 'TempC']
      rESULTScaseDisplay.LookupTable = tempCLUT
      rESULTScaseDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
      rESULTScaseDisplay.SelectOrientationVectors = 'None'
      rESULTScaseDisplay.ScaleFactor = 0.4
      rESULTScaseDisplay.SelectScaleArray = 'None'
      rESULTScaseDisplay.GlyphType = 'Arrow'
      rESULTScaseDisplay.GlyphTableIndexArray = 'None'
      rESULTScaseDisplay.GaussianRadius = 0.02
      rESULTScaseDisplay.SetScaleArray = [None, '']
      rESULTScaseDisplay.ScaleTransferFunction = 'PiecewiseFunction'
      rESULTScaseDisplay.OpacityArray = [None, '']
      rESULTScaseDisplay.OpacityTransferFunction = 'PiecewiseFunction'
      rESULTScaseDisplay.DataAxesGrid = 'GridAxesRepresentation'
      rESULTScaseDisplay.SelectionCellLabelFontFile = ''
      rESULTScaseDisplay.SelectionPointLabelFontFile = ''
      rESULTScaseDisplay.PolarAxes = 'PolarAxesRepresentation'
      rESULTScaseDisplay.ScalarOpacityFunction = tempCPWF
      rESULTScaseDisplay.ScalarOpacityUnitDistance = 0.08367903615550028

      # init the 'GridAxesRepresentation' selected for 'DataAxesGrid'
      rESULTScaseDisplay.DataAxesGrid.XTitleFontFile = ''
      rESULTScaseDisplay.DataAxesGrid.YTitleFontFile = ''
      rESULTScaseDisplay.DataAxesGrid.ZTitleFontFile = ''
      rESULTScaseDisplay.DataAxesGrid.XLabelFontFile = ''
      rESULTScaseDisplay.DataAxesGrid.YLabelFontFile = ''
      rESULTScaseDisplay.DataAxesGrid.ZLabelFontFile = ''

      # init the 'PolarAxesRepresentation' selected for 'PolarAxes'
      rESULTScaseDisplay.PolarAxes.PolarAxisTitleFontFile = ''
      rESULTScaseDisplay.PolarAxes.PolarAxisLabelFontFile = ''
      rESULTScaseDisplay.PolarAxes.LastRadialAxisTextFontFile = ''
      rESULTScaseDisplay.PolarAxes.SecondaryRadialAxesTextFontFile = ''

      # setup the color legend parameters for each legend in this view

      # get color legend/bar for tempCLUT in view renderView1
      tempCLUTColorBar = GetScalarBar(tempCLUT, renderView1)
      tempCLUTColorBar.WindowLocation = 'AnyLocation'
      tempCLUTColorBar.Position = [0.7593052109181142, 0.297225891677675]
      tempCLUTColorBar.Title = 'TempC'
      tempCLUTColorBar.ComponentTitle = ''
      tempCLUTColorBar.TitleFontFile = ''
      tempCLUTColorBar.LabelFontFile = ''
      tempCLUTColorBar.ScalarBarLength = 0.32999999999999996

      # set color bar visibility
      tempCLUTColorBar.Visibility = 1

      # show color legend
      rESULTScaseDisplay.SetScalarBarVisibility(renderView1, True)

      # ----------------------------------------------------------------
      # setup color maps and opacity mapes used in the visualization
      # note: the Get..() functions create a new object, if needed
      # ----------------------------------------------------------------

      # ----------------------------------------------------------------
      # finally, restore active source
      SetActiveSource(rESULTScase)
      # ----------------------------------------------------------------
    return Pipeline()

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

  coprocessor = CoProcessor()
  # these are the frequencies at which the coprocessor updates.
  freqs = {'RESULTS.case': [1]}
  coprocessor.SetUpdateFrequencies(freqs)
  if requestSpecificArrays:
    arrays = [['CourantNb', 1], ['Density', 1], ['FourierNb', 1], ['Input_thermal_flux', 1], ['Pressure', 1], ['SpecHeat', 1], ['Stress', 1], ['TempC', 1], ['Temperature', 1], ['total_pressure', 1], ['Velocity', 1], ['volume_zone_id', 1], ['Yplus', 1]]
    coprocessor.SetRequestedArrays('RESULTS.case', arrays)
  coprocessor.SetInitialOutputOptions(timeStepToStartOutputAt,forceOutputAtFirstCall)

  if rootDirectory:
      coprocessor.SetRootDirectory(rootDirectory)

  if make_cinema_table:
      coprocessor.EnableCinemaDTable()

  return coprocessor


#--------------------------------------------------------------
# Global variable 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 and the update frequency
coprocessor.EnableLiveVisualization(False, 1)

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

def RequestDataDescription(datadescription):
    "Callback to populate the request for current timestep"
    global coprocessor

    # 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=rescale_lookuptable,
        image_quality=0, padding_amount=imageFileNamePadding)

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