Hi,

I wrote a OpenFOAM adaptor for Catalyst.

In the ParaView, the connection is made good and shows filtered flow field as written in the python script.

However, filename_%t and image_%t is not expanded as time marching but just write filename_0 and image_0.png.

As far as I know, %t should be replaced with current time as given in dataDescription->SetTimeData.

Any help would be appreciated.


FYI, python script is attached and snippet of my OpenFOAM Adaptor code for Catalyst is as follows:

// icoFoam.C

#ifdef USE_CATALYST
    Foam::HashTable<string> options = args.options();
    IStringStream is(options["scriptList"]);
    wordList scriptList = readList<word>(is);
    OFAdaptor::Initialize(scriptList, mesh);
#endif
    while (runTime.loop())
    {
        runTime.write();
#ifdef USE_CATALYST
        OFAdaptor::CoProcess(mesh, runTime);
#endif
    }
#ifdef USE_CATALYST
    OFAdaptor::Finalize();
#endif


// OFAdaptor.C

void CoProcess(Foam::fvMesh& mesh, Foam::Time& runTime)
{
       vtkNew<vtkCPDataDescription> dataDescription;
       dataDescription->AddInput("input");
       dataDescription->SetTimeData(runTime.value(), runTime.deltaTValue());
       if (runTime.end())
       {
           // assume that we want to all the pipelines to execute
           // if it is the last time step
           dataDescription->ForceOutputOn();
       }
       if (Processor->RequestDataDescription(dataDescription.GetPointer()) != 0)
       {
           Foam::polyMesh::readUpdateState meshState = mesh.readUpdate();

           if(meshState != Foam::polyMesh::UNCHANGED)
           {
               BuildVTKGrid(mesh);
           }
           UpdateVTKAttributes(mesh);
dataDescription->GetInputDescriptionByName("input")->SetGrid(multiBlockDataSet);
           Processor->CoProcess(dataDescription.GetPointer());
       }
}


--
SeongMo Yeon, Ph.D, Senior Engineer
Offshore Hydrodynamics Research
SAMSUNG HEAVY INDUSTRIES CO., LTD.
Central Research Institute
E-mail : seongmo.y...@gmail.com
Tel :
--------------------------------------------------------
Fluctuat nec mergitur

from paraview.simple import *
from paraview import coprocessing


#--------------------------------------------------------------
# Code generated from cpstate.py to create the CoProcessor.
# ParaView 5.4.0 64 bits

#--------------------------------------------------------------
# Global screenshot output options
imageFileNamePadding=0
rescale_lookuptable=False


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

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

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

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

      # Create a new 'Render View'
      renderView1 = CreateView('RenderView')
      renderView1.ViewSize = [559, 807]
      renderView1.AxesGrid = 'GridAxes3DActor'
      renderView1.CenterOfRotation = [0.05000000074505806, 0.05000000074505806, 0.004999999888241291]
      renderView1.StereoType = 0
      renderView1.CameraPosition = [-0.18085773971220812, 0.17695723422358023, 0.29044307779613565]
      renderView1.CameraFocalPoint = [0.05000000074505807, 0.05000000074505807, 0.004999999888241291]
      renderView1.CameraViewUp = [0.10924210608747086, 0.9380383648162762, -0.3288619594759789]
      renderView1.CameraParallelScale = 0.10233631305477851
      renderView1.Background = [0.32, 0.34, 0.43]

      # 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=559, height=807, cinema={})
      renderView1.ViewTime = datadescription.GetTime()

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

      # create a new 'OpenFOAMReader'
      # create a producer from a simulation input
      cavityfoam = coprocessor.CreateProducer(datadescription, 'input')

      # create a new 'Parallel MultiBlockDataSet Writer'
      parallelMultiBlockDataSetWriter1 = servermanager.writers.XMLMultiBlockDataWriter(Input=cavityfoam)

      # register the writer with coprocessor
      # and provide it with information such as the filename to use,
      # how frequently to write the data, etc.
      coprocessor.RegisterWriter(parallelMultiBlockDataSetWriter1, filename='filename_%t.vtm', freq=1, paddingamount=0)

      # create a new 'Stream Tracer'
      streamTracer1 = StreamTracer(Input=cavityfoam,
          SeedType='High Resolution Line Source')
      streamTracer1.Vectors = ['POINTS', 'U']
      streamTracer1.MaximumStreamlineLength = 0.10000000149011612

      # init the 'High Resolution Line Source' selected for 'SeedType'
      streamTracer1.SeedType.Point2 = [0.10000000149011612, 0.10000000149011612, 0.009999999776482582]
      streamTracer1.SeedType.Resolution = 20

      # create a new 'Tube'
      tube1 = Tube(Input=streamTracer1)
      tube1.Scalars = ['POINTS', 'p']
      tube1.Vectors = ['POINTS', 'Normals']
      tube1.Radius = 0.0009708686068188399

      # create a new 'Glyph'
      glyph1 = Glyph(Input=cavityfoam,
          GlyphType='Arrow')
      glyph1.Scalars = ['POINTS', 'p']
      glyph1.Vectors = ['POINTS', 'U']
      glyph1.ScaleFactor = 0.010000000149011612
      glyph1.GlyphTransform = 'Transform2'

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

      # get color transfer function/color map for 'p'
      pLUT = GetColorTransferFunction('p')
      pLUT.RGBPoints = [-4.3666672706604, 0.705882352941, 0.0156862745098, 0.149019607843, 0.2409207820892334, 0.865, 0.865, 0.865, 4.848508834838867, 0.23137254902, 0.298039215686, 0.752941176471]
      pLUT.ScalarRangeInitialized = 1.0

      # get opacity transfer function/opacity map for 'p'
      pPWF = GetOpacityTransferFunction('p')
      pPWF.Points = [-4.3666672706604, 0.0, 0.5, 0.0, 4.848508834838867, 1.0, 0.5, 0.0]
      pPWF.ScalarRangeInitialized = 1

      # get color transfer function/color map for 'GlyphScale'
      glyphScaleLUT = GetColorTransferFunction('GlyphScale')
      glyphScaleLUT.RGBPoints = [-4.3666672706604, 0.34902, 0.0, 0.129412, -4.136287868022919, 0.4, 0.00392157, 0.101961, -3.905908465385437, 0.470588, 0.0156863, 0.0901961, -3.6755290627479553, 0.54902, 0.027451, 0.0705882, -3.4451496601104736, 0.619608, 0.0627451, 0.0431373, -3.214770257472992, 0.690196, 0.12549, 0.0627451, -2.9843908548355103, 0.741176, 0.184314, 0.0745098, -2.7540114521980286, 0.788235, 0.266667, 0.0941176, -2.523632049560547, 0.811765, 0.345098, 0.113725, -2.293252646923065, 0.831373, 0.411765, 0.133333, -2.0628732442855835, 0.85098, 0.47451, 0.145098, -1.8324938416481018, 0.870588, 0.54902, 0.156863, -1.6021144390106201, 0.878431, 0.619608, 0.168627, -1.3717350363731384, 0.890196, 0.658824, 0.196078, -1.1413556337356567, 0.909804, 0.717647, 0.235294, -0.910976231098175, 0.929412, 0.776471, 0.278431, -0.7218623870611194, 0.94902, 0.823529, 0.321569, -0.5063839241862294, 0.968627, 0.87451, 0.407843, -0.27256726086139693, 0.980392, 0.917647, 0.509804, -0.03416143983602549, 0.988235, 0.956863, 0.643137, 0.08962602078914639, 0.992157, 0.964706, 0.713725, 0.23170560598373413, 0.988235, 0.980392, 0.870588, 0.2409207820892334, 1.0, 1.0, 1.0, 0.25013595819473267, 0.913725, 0.988235, 0.937255, 0.3922155433893204, 0.827451, 0.980392, 0.886275, 0.529752046763897, 0.764706, 0.980392, 0.866667, 0.6718777078390117, 0.658824, 0.980392, 0.843137, 0.832341569364071, 0.572549, 0.964706, 0.835294, 1.0478200322389606, 0.423529, 0.941176, 0.87451, 1.2174529939889904, 0.262745, 0.901961, 0.862745, 1.437520614564419, 0.0705882, 0.854902, 0.870588, 1.6392408195137982, 0.0509804, 0.8, 0.85098, 1.9143230414390562, 0.0235294, 0.709804, 0.831373, 2.2031543061137198, 0.0313725, 0.615686, 0.811765, 2.5447148084640503, 0.0313725, 0.537255, 0.788235, 2.775094211101532, 0.0392157, 0.466667, 0.768627, 3.0054736137390137, 0.0509804, 0.396078, 0.741176, 3.2358530163764954, 0.054902, 0.317647, 0.709804, 3.466232419013977, 0.054902, 0.243137, 0.678431, 3.6966118216514587, 0.0431373, 0.164706, 0.639216, 3.9269912242889404, 0.0313725, 0.0980392, 0.6, 4.157370626926422, 0.0392157, 0.0392157, 0.560784, 4.387750029563904, 0.105882, 0.0509804, 0.509804, 4.6181294322013855, 0.113725, 0.0235294, 0.45098, 4.848508834838867, 0.12549, 0.0, 0.380392]
      glyphScaleLUT.ColorSpace = 'Lab'
      glyphScaleLUT.NanColor = [0.250004, 0.0, 0.0]
      glyphScaleLUT.ScalarRangeInitialized = 1.0

      # get opacity transfer function/opacity map for 'GlyphScale'
      glyphScalePWF = GetOpacityTransferFunction('GlyphScale')
      glyphScalePWF.Points = [-4.3666672706604, 0.0, 0.5, 0.0, 4.848508834838867, 1.0, 0.5, 0.0]
      glyphScalePWF.ScalarRangeInitialized = 1

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

      # show data from glyph1
      glyph1Display = Show(glyph1, renderView1)
      # trace defaults for the display properties.
      glyph1Display.Representation = 'Surface'
      glyph1Display.ColorArrayName = ['POINTS', 'GlyphScale']
      glyph1Display.LookupTable = glyphScaleLUT
      glyph1Display.OSPRayScaleArray = 'GlyphScale'
      glyph1Display.OSPRayScaleFunction = 'PiecewiseFunction'
      glyph1Display.SelectOrientationVectors = 'GlyphVector'
      glyph1Display.ScaleFactor = 0.011547934124246241
      glyph1Display.SelectScaleArray = 'GlyphScale'
      glyph1Display.GlyphType = 'Arrow'
      glyph1Display.GlyphTableIndexArray = 'GlyphScale'
      glyph1Display.DataAxesGrid = 'GridAxesRepresentation'
      glyph1Display.PolarAxes = 'PolarAxesRepresentation'
      glyph1Display.GaussianRadius = 0.0057739670621231205
      glyph1Display.SetScaleArray = ['POINTS', 'GlyphScale']
      glyph1Display.ScaleTransferFunction = 'PiecewiseFunction'
      glyph1Display.OpacityArray = ['POINTS', 'GlyphScale']
      glyph1Display.OpacityTransferFunction = 'PiecewiseFunction'

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

      # show data from tube1
      tube1Display = Show(tube1, renderView1)
      # trace defaults for the display properties.
      tube1Display.Representation = 'Surface'
      tube1Display.ColorArrayName = ['POINTS', 'p']
      tube1Display.LookupTable = pLUT
      tube1Display.OSPRayScaleArray = 'p'
      tube1Display.OSPRayScaleFunction = 'PiecewiseFunction'
      tube1Display.SelectOrientationVectors = 'Normals'
      tube1Display.ScaleFactor = 0.009902804454031867
      tube1Display.SelectScaleArray = 'p'
      tube1Display.GlyphType = 'Arrow'
      tube1Display.GlyphTableIndexArray = 'p'
      tube1Display.DataAxesGrid = 'GridAxesRepresentation'
      tube1Display.PolarAxes = 'PolarAxesRepresentation'
      tube1Display.GaussianRadius = 0.0049514022270159335
      tube1Display.SetScaleArray = ['POINTS', 'p']
      tube1Display.ScaleTransferFunction = 'PiecewiseFunction'
      tube1Display.OpacityArray = ['POINTS', 'p']
      tube1Display.OpacityTransferFunction = 'PiecewiseFunction'

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

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

      # get color legend/bar for pLUT in view renderView1
      pLUTColorBar = GetScalarBar(pLUT, renderView1)
      pLUTColorBar.Title = 'p'
      pLUTColorBar.ComponentTitle = ''

      # get color legend/bar for glyphScaleLUT in view renderView1
      glyphScaleLUTColorBar = GetScalarBar(glyphScaleLUT, renderView1)
      glyphScaleLUTColorBar.WindowLocation = 'UpperRightCorner'
      glyphScaleLUTColorBar.Title = 'GlyphScale'
      glyphScaleLUTColorBar.ComponentTitle = ''

      # ----------------------------------------------------------------
      # finally, restore active source
      SetActiveSource(parallelMultiBlockDataSetWriter1)
      # ----------------------------------------------------------------
    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 = {'input': [1, 1, 1, 1, 1]}
  coprocessor.SetUpdateFrequencies(freqs)
  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(True, 1)

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

    # Live Visualization, if enabled.
    coprocessor.DoLiveVisualization(datadescription, "localhost", 22222)
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
https://paraview.org/mailman/listinfo/paraview

Reply via email to