Salome HOME
Porting to ParaView 5.8
[modules/paravis.git] / src / Plugins / MEDReader / plugin / Test / TestDataAnalysis.py
1 # -*- coding: iso-8859-1 -*-
2 # Script de visualisation rosette et contrainte normale/tangeantielle
3
4 # Donnees utilisateur
5 #
6 # MEDFILE : Fichier de resultat MED
7 # MAILLAGE : Nom du maillage
8 # GROUPE_FACE : Liste  groupes de face de post-traitement
9 # COEFF_T1T2 : facteur scale rosette
10 # COEFF_TN : facteur scale normale/cisaillement
11 #
12 # T1 : Nom du champ SIRO_ELEM_T1
13 # T2 : Nom du champ SIRO_ELEM_T2
14 # T  : Nom du champ SIRO_ELEM_SIGT
15 # N  : Nom du champ SIRO_ELEM_SIGN
16 #
17 # ROSETTE : True/False
18
19 from paraview.simple import *
20
21 import os
22 dataRoot = os.getenv('PARAVIEW_DATA_ROOT', "")
23 MEDFILE = dataRoot+'/rosette_am.med'
24 MAILLAGE='mail'
25 GROUPE_FACE = ['SURF_AM',]
26 COEFF_T1T2 = 0.00003
27 COEFF_TN = 0.003
28
29 T='RESUNL__SIRO_ELEM_TANGENT_Vector'
30 N='RESUNL__SIRO_ELEM_NORMAL_Vector'
31 T1 = 'RESUNL__SIRO_ELEM_T1_Vector'
32 T2 = 'RESUNL__SIRO_ELEM_T2_Vector'
33
34 ROSETTE = True
35
36 # Fin données utilisateurs
37
38
39
40 #%==================== Importing MED file====================%
41
42 print ("**** Importing MED file")
43
44 myResult0 = MEDReader(FileName=MEDFILE)
45 if myResult0 is None : raise "Erreur de fichier MED"
46
47 # Imposition GenerateVectors à faire
48 myResult0.GenerateVectors=1
49
50 NB_ORDRE = myResult0.GetPropertyValue('TimestepValues')
51
52 #extraction groupes et visualisation du maillage
53 listeg=[]
54 for g in GROUPE_FACE :
55     listeg.append('GRP_'+g)
56
57 myResult = ExtractGroup()
58 myResult.AllGroups=listeg
59 #myResult.Groups = listeg
60
61
62 CellCenters1 = CellCenters()
63 if len(NB_ORDRE) > 1 :
64     animation = GetAnimationScene()
65     #animation.AnimationTime = NB_ORDRE[2]
66 view2 = GetRenderView()
67
68
69 #%====================Displaying rosette====================%
70
71 if ROSETTE : 
72      CMAX = 0.0
73      T_MAX = 0.0
74      print ("****  Displaying rosette")
75
76      view2.Background=[1.0,1.0,1.0]
77      SetActiveSource(myResult)
78      Display0 = Show()
79      Display0.Texture=[]
80      Display0.Representation = 'Wireframe'
81      Display0.AmbientColor=[0.0,0.0,0.0]
82  
83      SetActiveSource(CellCenters1)
84      Glyph1 = Glyph()
85      Glyph1.OrientationArray = ['POINTS', T1]
86      Glyph1.GlyphType ='Line'
87      Glyph1.GlyphMode = 'All Points'
88
89      pd1 = Glyph1.PointData
90
91      for i in range(len(pd1)):
92            if pd1.values()[i-1].GetName()== T1 :
93                     NUM = i-1
94                     NB_CMP = pd1.values()[i-1].GetNumberOfComponents()
95                     NOM_CMP = pd1.values()[i-1].GetComponentName(NB_CMP)
96                     RANGE_CMP = pd1.values()[i-1].GetRange(NB_CMP-1)
97                     MAX_CMP = max(abs(RANGE_CMP[0]),abs(RANGE_CMP[1]))
98                     if RANGE_CMP[0] < 0.0 :
99                          C_MAX = -RANGE_CMP[0]
100                     else :
101                          C_MAX = 0.
102                     if RANGE_CMP[1] > 0.0 :
103                          T_MAX = RANGE_CMP[1]
104                     else :
105                          T_MAX = 0.
106  
107      Render()
108
109      Glyph1.ScaleArray = ['POINTS', T1]
110      Glyph1.VectorScaleMode = 'Scale by Magnitude'
111      Glyph1.ScaleFactor = COEFF_T1T2
112
113      Display1=Show()
114
115      PVLookupTable1 = GetLookupTableForArray( T1, NB_CMP, VectorMode = 'Component',VectorComponent=NB_CMP-1, NumberOfTableValues=2, RGBPoints=[-MAX_CMP, 0.0, 0.0, 1.0, MAX_CMP, 1.0, 0.0, 0.0], AutomaticRescaleRangeMode=-1, ScalarRangeInitialized = 1.0)
116      
117      scalarbar1 = CreateScalarBar(Title =T1, ComponentTitle = NOM_CMP, LookupTable=PVLookupTable1, TitleFontSize=12 , LabelFontSize=12, TitleColor=[0.0,0.0,0.0],LabelColor=[0.0,0.0,0.0])
118
119      view2.Representations.append(scalarbar1)
120      Display1.ColorArrayName = T1
121      Display1.LookupTable = PVLookupTable1
122      Display1.Representation = 'Surface'
123
124      SetActiveSource(CellCenters1)
125      Glyph2 = Glyph()
126      Glyph2.OrientationArray = ['POINTS', T2]
127      Glyph2.GlyphType ='Line'
128      Glyph2.ScaleArray = ['POINTS', T2]
129      Glyph2.VectorScaleMode = 'Scale by Magnitude'
130      Glyph2.ScaleFactor = COEFF_T1T2
131
132      Glyph2.GlyphMode = 'All Points'
133
134      pd2 = Glyph2.PointData
135
136      for i in range(len(pd2)):
137             if pd2.values()[i-1].GetName()== T2 :
138                     NB_CMP = pd2.values()[i-1].GetNumberOfComponents()
139                     NOM_CMP = pd2.values()[i-1].GetComponentName(NB_CMP-1)
140                     RANGE_CMP = pd2.values()[i-1].GetRange(NB_CMP-1)
141                     MAX_CMP = max(abs(RANGE_CMP[0]),abs(RANGE_CMP[1]))
142                     if RANGE_CMP[0] < 0.0 :
143                          C_MAX = max(C_MAX,-RANGE_CMP[0])
144                     if RANGE_CMP[1] > 0.0 : 
145                          T_MAX = max(T_MAX,RANGE_CMP[1])
146
147      Display2=Show()
148
149      PVLookupTable2 = GetLookupTableForArray( T2, NB_CMP, VectorMode = 'Component',VectorComponent=NB_CMP-1, NumberOfTableValues=2, RGBPoints=[-MAX_CMP, 0.0, 0.0, 1.0, MAX_CMP, 1.0, 0.0, 0.0], AutomaticRescaleRangeMode=-1)
150      scalarbar2 = CreateScalarBar(Title =T2, ComponentTitle = NOM_CMP, LookupTable=PVLookupTable2, TitleFontSize=12 , LabelFontSize=12,TitleColor=[0.0,0.0,0.0],LabelColor=[0.0,0.0,0.0])
151      #view2.Representations.append(scalarbar2)
152      Display2.ColorArrayName = T2
153      Display2.LookupTable = PVLookupTable2
154      Display2.Representation = 'Surface'
155
156      Text2 = Text()
157      Texte = 'COMPRESSION MAX = '+str(C_MAX)+' MPa \nTRACTION MAX = '+str(T_MAX)+' Mpa'
158      Text2.Text = Texte
159      DisplayT = Show()
160      DisplayT.FontSize = 12
161      DisplayT.Color=[0.0, 0.0, 0.0]
162
163      Render()
164      view2.CameraPosition = [-524.450475200065, -34.2470779418945, 572.968383789062]
165      view2.CameraFocalPoint = [9.7492516040802, -34.2470779418945, 572.968383789062]
166      view2.CameraViewUp = [0.0, 0.0, 1.0]
167      ResetCamera()
168
169      import sys
170      try:
171        baselineIndex = sys.argv.index('-B')+1
172        baselinePath = sys.argv[baselineIndex]
173      except:
174        print ("Could not get baseline directory. Test failed.")
175      baseline_file = os.path.join(baselinePath, "TestDataAnalysis.png")
176      from paraview.vtk.test import Testing
177      from paraview.vtk.util.misc import vtkGetTempDir
178      Testing.VTK_TEMP_DIR = vtkGetTempDir()
179      Testing.compareImage(view2.GetRenderWindow(), baseline_file, threshold=10)
180      Testing.interact()