Salome HOME
IMP: Verima / New Plugin: Added a plugin for meshers quality testing (work done at...
[modules/smesh.git] / src / Tools / Verima / Stats / getStats.py
1 # -*- coding: utf-8 -*-
2
3 import os
4 import logging
5
6
7
8 # -----------------------------------------------------------------------------
9 # --- satistiques maillage
10
11 def getGroupesRef(fichierMed):
12       fichier=fichierMed.replace('.med','_groupesRef.res')
13       try:
14          text=open(fichier).read()
15       except:
16          return []
17       liste=text.split(",")
18       return liste
19
20
21 def getStatsMaillage(maillage,fichierStatMaillage):
22   """
23   """
24   logging.info('start')
25
26   OK = False
27   if maillage is not None:
28     mesures = maillage.GetMeshInfo()
29     txt=""
30     import SMESH
31     for i in range(len(mesures)):
32       txt += str(SMESH.EntityType._item(i))+ " " +str(mesures[SMESH.EntityType._item(i)]) + "\n"
33
34     from utiles import writeFile
35     writeFile(fichierStatMaillage,txt)
36
37
38
39 def getStatsGroupes(maillage,fichierMedResult):
40   """
41   """
42   logging.info('start')
43   fichierGroupe=fichierMedResult.replace('.med','_groupesRef.res')
44   lGroups=getGroupesRef(fichierGroupe)
45   if len(lGroups)==0: 
46     print "pas de Groupe de Reference "
47     try :
48       os.remove(fichierGroupe)
49       return
50     except :
51       return
52   lGroupsSMESH=maillage.GetGroups()
53   for groupe in lGroupsSMESH :
54      groupeName= groupe.GetName()
55      if groupeName not in lGroups : continue
56      extension='_'+groupeName+'.res'
57      fichierStatGroupe=fichierGroupe.replace('_groupesRef.res',extension)
58      getStatsStatSurGroupes(maillage,groupe,fichierStatGroupe)
59
60
61 def getStatsStatSurGroupes(maillage,groupe,fichierStatGroupe):
62   mesures = maillage.GetMeshInfo(groupe)
63   txt=""
64   import SMESH
65   for i in range(len(mesures)):
66       txt += str(SMESH.EntityType._item(i))+ " " +str(mesures[SMESH.EntityType._item(i)]) + "\n"
67   from utiles import writeFile
68   writeFile(fichierStatGroupe,txt)
69
70 def genHistogram(aMesh, aCriterion, nbIntervals, isLog, aFile,theStudy):
71   import SMESH,SALOMEDS
72   from salome.smesh import smeshBuilder
73   smesh = smeshBuilder.New(theStudy)
74   aFunctor = smesh.GetFunctor(aCriterion)
75   aFunctor.SetMesh(aMesh.GetMesh())
76   histogram = aFunctor.GetHistogram(nbIntervals,isLog)
77   f = open(aFile, 'w')
78   for tranche in histogram:
79     f.write(str(tranche.min) + " " + str(tranche.max) +  " " + str(tranche.nbEvents) + "\n")
80     pass
81   f.close()
82
83