Salome HOME
Copyright update 2022
[modules/smesh.git] / src / Tools / Verima / Stats / getCritere.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2014-2022  EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import sys,os
22 import salome
23 from .getStats import getGroupesRef
24 from .Type_Maille import dicoDimENtite
25
26 def getCritere(dim,NomMesh,acritere):
27   import SMESH
28   from salome.smesh import smeshBuilder
29   smesh = smeshBuilder.New()
30   import numpy
31 #  print dim,NomMesh,acritere
32   if dim == 2 :
33     NumElt=NomMesh.GetElementsByType(SMESH.FACE)
34   if dim == 3 :
35     NumElt=NomMesh.GetElementsByType(SMESH.VOLUME)
36   
37   critere=[]
38   if acritere =="Ratio" :
39     for i in range(len(NumElt)):
40       critere.append (NomMesh.GetAspectRatio(NumElt[i]))
41
42   if acritere =="Length" :
43     for i in range(len(NumElt)):
44       critere.append (NomMesh.GetMaxElementLength(NumElt[i]))
45       
46   crit= numpy.array(critere)
47   max=crit.max()
48   min=crit.min()
49   moyenne=crit.mean()
50   M=numpy.median(crit)
51   Q1=numpy.percentile(crit,25)
52   Q3=numpy.percentile(crit,75)
53   
54   return [max,min,Q1,M,Q3,moyenne]
55
56 def getCritereGroupe(NomMesh,NomGr,acritere):
57   import SMESH
58   from salome.smesh import smeshBuilder
59   smesh = smeshBuilder.New()
60   import numpy
61     
62   # on ne traite que les mailles 2D et 3D
63   NumElt = NomGr.GetListOfID()
64   type_gr=NomMesh.GetElementGeomType(NumElt[0])
65
66 #  print "critere",acritere
67 #  print "type groupe",type_gr
68 #  print dicoDimENtite[str(type_gr)]
69
70   if dicoDimENtite[str(type_gr)]==0 :
71      return [0,0,0,0,0,0]
72
73   critere=[]
74   if acritere =="Ratio" :
75     for i in range(len(NumElt)):
76       critere.append (NomMesh.GetAspectRatio(NumElt[i]))
77
78   if acritere =="Length" :
79     for i in range(len(NumElt)):
80       critere.append (NomMesh.GetMaxElementLength(NumElt[i]))
81       
82   crit= numpy.array(critere)
83   max=crit.max()
84   min=crit.min()
85   moyenne=crit.mean()
86   M=numpy.median(crit)
87   Q1=numpy.percentile(crit,25)
88   Q3=numpy.percentile(crit,75)
89   
90   return [max,min,Q1,M,Q3,moyenne]
91
92 def getObjectsGroupe(Mesh,liste):
93   import SMESH
94   from salome.smesh import smeshBuilder
95   dico={}
96   lGroups=Mesh.GetGroups()
97   for g in lGroups :
98       name = g.GetName() 
99       for n in liste :
100           if name == n :  dico[name]=g
101   return dico
102
103 def getStatsCritere(dim,Mesh,fichierMedResult):
104   fichierStatRatio=fichierMedResult.replace('.med','.ratio')
105   max,min,Q1,M,Q3,moyenne = getCritere(dim,Mesh,"Ratio")
106   f = open(fichierStatRatio, 'w')
107   f.write(str(max)+","+str(min)+","+str(Q1)+","+str(M)+","+str(Q3)+","+str(moyenne))
108   f.close()
109
110   fichierStatRatio=fichierMedResult.replace('.med','.taille')
111   max,min,Q1,M,Q3,moyenne = getCritere(dim,Mesh,"Length")
112   f = open(fichierStatRatio, 'w')
113   f.write(str(max)+","+str(min)+","+str(Q1)+","+str(M)+","+str(Q3)+","+str(moyenne))
114   f.close()
115
116   liste=getGroupesRef(fichierMedResult)
117   dicoGroupe=getObjectsGroupe(Mesh,liste)
118   for groupe in liste :
119       max,min,Q1,M,Q3,moyenne=getCritereGroupe(Mesh,dicoGroupe[groupe],"Ratio")
120       extension="_"+groupe+'_Ratio.res'
121       fichier=fichierMedResult.replace('.med',extension)
122       f = open(fichier, 'w')
123       f.write(str(max)+","+str(min)+","+str(Q1)+","+str(M)+","+str(Q3)+","+str(moyenne))
124       f.close()
125       max,min,Q1,M,Q3,moyenne=getCritereGroupe(Mesh,dicoGroupe[groupe],"Length")
126       extension="_"+groupe+'_Taille.res'
127       fichier=fichierMedResult.replace('.med',extension)
128       f = open(fichier, 'w')
129       f.write(str(max)+","+str(min)+","+str(Q1)+","+str(M)+","+str(Q3)+","+str(moyenne))
130       f.close()
131