CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   [OpenFOAM] Python Script not working Attribute Error (https://www.cfd-online.com/Forums/paraview/218826-python-script-not-working-attribute-error.html)

Oguzhan90 July 5, 2019 04:56

Python Script not working Attribute Error
 
Hello,


I’m working with OpenFoam for simulations and using paraView to postprocess them.
What we do is extracting 3 csv data files and as we test a lot of different simulations in the same time, we worked on automatize them.


So I used the Trace method to build the python script.


The point is that when I use the Python Shell or even Pvpython/PvBatch (in order to postprocess from the command tab), I have the following error :


/home/calculopenfoam/OpenFOAM/ThirdParty-4.1/platforms/linux64Gcc/ParaView-5.0.1/lib/paraview-5.0/site-packages/paraview/servermanager.py", line 302, in setattr
“to add this attribute.”)
AttributeError: Attribute PartArrayStatus does not exist. This class does not allow addition of new attributes to avoid mistakes due to typos. Use add_attribute() if you really want to add this attribute.


I searched a lot but did not found any answers.
I let you my script. Note that when I # the not working lines on my scripts, it works with the Python Shell but I got a proxy error using pvpython/pybatch.
My final goal is to use only pvpython/pvbatch


I copy past my script below.


What should I do ?

Thanks a lot


#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

# get animation scene
animationScene1 = GetAnimationScene()

animationScene1.GoToLast()

# get active source.
simuOpenFOAM = GetActiveSource()

# Properties modified on simuOpenFOAM
simuOpenFOAM.PartArrayStatus = ['internalMesh', '1', 'wall - group', '0', 'inlet - patch', '1', 'outlet_Air - patch', '1', 'outlet_Water - patch', '1', 'walls - patch', '1']
simuOpenFOAM.MeshParts = ['internalMesh', 'wall - group', 'inlet - patch', 'outlet_Air - patch', 'outlet_Water - patch', 'walls - patch']
simuOpenFOAM.VolFieldArrayStatus = ['T.air', '0', 'T.particles', '0', 'alpha.air', '1', 'alpha.air_0', '0', 'alpha.particles', '0', 'alpha.particles_0', '0', 'alphat.air', '0', 'dgdt', '0', 'k.air', '0', 'k.air_0', '0', 'nut.air', '0', 'omega.air', '0', 'omega.air_0', '0', 'p', '0', 'p_0', '0', 'p_rgh', '0', 'p_rgh_0', '0', 'U', '0', 'U.air', '1', 'U.air_0', '0', 'U.particles', '1', 'U.particles_0', '0', 'Ur', '0']
simuOpenFOAM.VolumeFields = ['alpha.air', 'U.air', 'U.particles']

# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
# uncomment following to set a specific view size
# renderView1.ViewSize = [1560, 832]

# show data in view
simuOpenFOAMDisplay = Show(simuOpenFOAM, renderView1)
# trace defaults for the display properties.
simuOpenFOAMDisplay.CubeAxesVisibility = 0
simuOpenFOAMDisplay.Representation = 'Surface'
simuOpenFOAMDisplay.AmbientColor = [1.0, 1.0, 1.0]
simuOpenFOAMDisplay.ColorArrayName = [None, '']
simuOpenFOAMDisplay.DiffuseColor = [1.0, 1.0, 1.0]
simuOpenFOAMDisplay.LookupTable = None
simuOpenFOAMDisplay.MapScalars = 1
simuOpenFOAMDisplay.InterpolateScalarsBeforeMappin g = 1
simuOpenFOAMDisplay.Opacity = 1.0
simuOpenFOAMDisplay.PointSize = 2.0
simuOpenFOAMDisplay.LineWidth = 1.0
simuOpenFOAMDisplay.Interpolation = 'Gouraud'
simuOpenFOAMDisplay.Specular = 0.0
simuOpenFOAMDisplay.SpecularColor = [1.0, 1.0, 1.0]
simuOpenFOAMDisplay.SpecularPower = 100.0
simuOpenFOAMDisplay.Ambient = 0.0
simuOpenFOAMDisplay.Diffuse = 1.0
simuOpenFOAMDisplay.EdgeColor = [0.0, 0.0, 0.5]
simuOpenFOAMDisplay.BackfaceRepresentation = 'Follow Frontface'
simuOpenFOAMDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
simuOpenFOAMDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
simuOpenFOAMDisplay.BackfaceOpacity = 1.0
simuOpenFOAMDisplay.Position = [0.0, 0.0, 0.0]
simuOpenFOAMDisplay.Scale = [1.0, 1.0, 1.0]
simuOpenFOAMDisplay.Orientation = [0.0, 0.0, 0.0]
simuOpenFOAMDisplay.Origin = [0.0, 0.0, 0.0]
simuOpenFOAMDisplay.Pickable = 1
simuOpenFOAMDisplay.Texture = None
simuOpenFOAMDisplay.Triangulate = 0
simuOpenFOAMDisplay.NonlinearSubdivisionLevel = 1
simuOpenFOAMDisplay.GlyphType = 'Arrow'
simuOpenFOAMDisplay.CubeAxesColor = [1.0, 1.0, 1.0]
simuOpenFOAMDisplay.CubeAxesCornerOffset = 0.0
simuOpenFOAMDisplay.CubeAxesFlyMode = 'Closest Triad'
simuOpenFOAMDisplay.CubeAxesInertia = 1
simuOpenFOAMDisplay.CubeAxesTickLocation = 'Inside'
simuOpenFOAMDisplay.CubeAxesXAxisMinorTickVisibili ty = 1
simuOpenFOAMDisplay.CubeAxesXAxisTickVisibility = 1
simuOpenFOAMDisplay.CubeAxesXAxisVisibility = 1
simuOpenFOAMDisplay.CubeAxesXGridLines = 0
simuOpenFOAMDisplay.CubeAxesXTitle = 'X-Axis'
simuOpenFOAMDisplay.CubeAxesUseDefaultXTitle = 1
simuOpenFOAMDisplay.CubeAxesYAxisMinorTickVisibili ty = 1
simuOpenFOAMDisplay.CubeAxesYAxisTickVisibility = 1
simuOpenFOAMDisplay.CubeAxesYAxisVisibility = 1
simuOpenFOAMDisplay.CubeAxesYGridLines = 0
simuOpenFOAMDisplay.CubeAxesYTitle = 'Y-Axis'
simuOpenFOAMDisplay.CubeAxesUseDefaultYTitle = 1
simuOpenFOAMDisplay.CubeAxesZAxisMinorTickVisibili ty = 1
simuOpenFOAMDisplay.CubeAxesZAxisTickVisibility = 1
simuOpenFOAMDisplay.CubeAxesZAxisVisibility = 1
simuOpenFOAMDisplay.CubeAxesZGridLines = 0
simuOpenFOAMDisplay.CubeAxesZTitle = 'Z-Axis'
simuOpenFOAMDisplay.CubeAxesUseDefaultZTitle = 1
simuOpenFOAMDisplay.CubeAxesGridLineLocation = 'All Faces'
simuOpenFOAMDisplay.CustomBounds = [0.0, 1.0, 0.0, 1.0, 0.0, 1.0]
simuOpenFOAMDisplay.CustomBoundsActive = [0, 0, 0]
simuOpenFOAMDisplay.OriginalBoundsRangeActive = [0, 0, 0]
simuOpenFOAMDisplay.CustomRange = [0.0, 1.0, 0.0, 1.0, 0.0, 1.0]
simuOpenFOAMDisplay.CustomRangeActive = [0, 0, 0]
simuOpenFOAMDisplay.UseAxesOrigin = 0
simuOpenFOAMDisplay.AxesOrigin = [0.0, 0.0, 0.0]
simuOpenFOAMDisplay.CubeAxesXLabelFormat = '%-#6.3g'
simuOpenFOAMDisplay.CubeAxesYLabelFormat = '%-#6.3g'
simuOpenFOAMDisplay.CubeAxesZLabelFormat = '%-#6.3g'
simuOpenFOAMDisplay.StickyAxes = 0
simuOpenFOAMDisplay.CenterStickyAxes = 0
simuOpenFOAMDisplay.SelectionCellLabelBold = 0
simuOpenFOAMDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
simuOpenFOAMDisplay.SelectionCellLabelFontFamily = 'Arial'
simuOpenFOAMDisplay.SelectionCellLabelFontSize = 18
simuOpenFOAMDisplay.SelectionCellLabelItalic = 0
simuOpenFOAMDisplay.SelectionCellLabelJustificatio n = 'Left'
simuOpenFOAMDisplay.SelectionCellLabelOpacity = 1.0
simuOpenFOAMDisplay.SelectionCellLabelShadow = 0
simuOpenFOAMDisplay.SelectionPointLabelBold = 0
simuOpenFOAMDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
simuOpenFOAMDisplay.SelectionPointLabelFontFamily = 'Arial'
simuOpenFOAMDisplay.SelectionPointLabelFontSize = 18
simuOpenFOAMDisplay.SelectionPointLabelItalic = 0
simuOpenFOAMDisplay.SelectionPointLabelJustificati on = 'Left'
simuOpenFOAMDisplay.SelectionPointLabelOpacity = 1.0
simuOpenFOAMDisplay.SelectionPointLabelShadow = 0

# init the 'Arrow' selected for 'GlyphType'
simuOpenFOAMDisplay.GlyphType.TipResolution = 6
simuOpenFOAMDisplay.GlyphType.TipRadius = 0.1
simuOpenFOAMDisplay.GlyphType.TipLength = 0.35
simuOpenFOAMDisplay.GlyphType.ShaftResolution = 6
simuOpenFOAMDisplay.GlyphType.ShaftRadius = 0.03
simuOpenFOAMDisplay.GlyphType.Invert = 0

# reset view to fit data
renderView1.ResetCamera()

# set scalar coloring
ColorBy(simuOpenFOAMDisplay, ('FIELD', 'vtkBlockColors'))

# show color bar/color legend
simuOpenFOAMDisplay.SetScalarBarVisibility(renderV iew1, True)

# get color transfer function/color map for 'vtkBlockColors'
vtkBlockColorsLUT = GetColorTransferFunction('vtkBlockColors')
vtkBlockColorsLUT.LockDataRange = 0
vtkBlockColorsLUT.InterpretValuesAsCategories = 1
vtkBlockColorsLUT.ShowCategoricalColorsinDataRange Only = 0
vtkBlockColorsLUT.RescaleOnVisibilityChange = 0
vtkBlockColorsLUT.EnableOpacityMapping = 0
vtkBlockColorsLUT.RGBPoints = [0.0, 0.231373, 0.298039, 0.752941, 0.5, 0.865003, 0.865003, 0.865003, 1.0, 0.705882, 0.0156863, 0.14902]
vtkBlockColorsLUT.UseLogScale = 0
vtkBlockColorsLUT.ColorSpace = 'Diverging'
vtkBlockColorsLUT.UseBelowRangeColor = 0
vtkBlockColorsLUT.BelowRangeColor = [0.0, 0.0, 0.0]
vtkBlockColorsLUT.UseAboveRangeColor = 0
vtkBlockColorsLUT.AboveRangeColor = [1.0, 1.0, 1.0]
vtkBlockColorsLUT.NanColor = [1.0, 1.0, 0.0]
vtkBlockColorsLUT.Discretize = 1
vtkBlockColorsLUT.NumberOfTableValues = 256
vtkBlockColorsLUT.ScalarRangeInitialized = 0.0
vtkBlockColorsLUT.HSVWrap = 0
vtkBlockColorsLUT.VectorComponent = 0
vtkBlockColorsLUT.VectorMode = 'Magnitude'
vtkBlockColorsLUT.AllowDuplicateScalars = 1
vtkBlockColorsLUT.Annotations = ['0', '0', '1', '1', '2', '2', '3', '3', '4', '4', '5', '5', '6', '6', '7', '7', '8', '8', '9', '9', '10', '10', '11', '11']
vtkBlockColorsLUT.ActiveAnnotatedValues = ['0', '1', '2', '3', '4']
vtkBlockColorsLUT.IndexedColors = [1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.63, 0.63, 1.0, 0.67, 0.5, 0.33, 1.0, 0.5, 0.75, 0.53, 0.35, 0.7, 1.0, 0.75, 0.5]

# get opacity transfer function/opacity map for 'vtkBlockColors'
vtkBlockColorsPWF = GetOpacityTransferFunction('vtkBlockColors')
vtkBlockColorsPWF.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
vtkBlockColorsPWF.AllowDuplicateScalars = 1
vtkBlockColorsPWF.ScalarRangeInitialized = 0

# set active view
SetActiveView(None)

# Create a new 'SpreadSheet View'
spreadSheetView1 = CreateView('SpreadSheetView')
spreadSheetView1.UseCache = 0
spreadSheetView1.ViewSize = [400, 400]
spreadSheetView1.CellFontSize = 9
spreadSheetView1.HeaderFontSize = 9
spreadSheetView1.SelectionOnly = 0
spreadSheetView1.ColumnToSort = None
spreadSheetView1.SelectedComponent = -1
spreadSheetView1.InvertOrder = 0
spreadSheetView1.BlockSize = 1024L

# get layout
viewLayout2 = GetLayout()

# place view in the layout
viewLayout2.AssignView(0, spreadSheetView1)

# show data in view
simuOpenFOAMDisplay_1 = Show(simuOpenFOAM, spreadSheetView1)
# trace defaults for the display properties.
simuOpenFOAMDisplay_1.FieldAssociation = 'Point Data'
simuOpenFOAMDisplay_1.CompositeDataSetIndex = 2

# save data
SaveData('/home/calculopenfoam/Bureau/simu/a.csv', proxy=simuOpenFOAM, Precision=5,
UseScientificNotation=0,
WriteAllTimeSteps=0,
FieldAssociation='Cells')

#### saving camera placements for all active views

# current camera placement for renderView1
renderView1.CameraPosition = [-0.020548243075609207, -0.015000000596046448, 0.7837419423292586]
renderView1.CameraFocalPoint = [-0.020548243075609207, -0.015000000596046448, -0.04500000178813934]
renderView1.CameraParallelScale = 0.21449419861287156

#### uncomment the following to render all views
# RenderAllViews()
# alternatively, if you want to write images, you can use SaveScreenshot(...).


All times are GMT -4. The time now is 21:03.