Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / src / Tools / Verima / Stats / getStats.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-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 os
22 import logging
23
24 # -----------------------------------------------------------------------------
25 # --- satistiques maillage
26
27 def getGroupesRef(fichierMed):
28       fichier=fichierMed.replace('.med','_groupesRef.res')
29       try:
30          text=open(fichier).read()
31       except:
32          return []
33       liste=text.split(",")
34       return liste
35
36
37 def getStatsMaillage(maillage,fichierMed):
38   """
39   """
40   logging.info('start')
41
42   OK = False
43   fichier=fichierMed.replace('.med','.res')
44   if maillage is not None:
45     mesures = maillage.GetMeshInfo()
46     txt=""
47     import SMESH
48     for i in range(len(mesures)):
49       txt += str(SMESH.EntityType._item(i))+ " " +str(mesures[SMESH.EntityType._item(i)]) + "\n"
50
51     from .utiles import writeFile
52     writeFile(fichier,txt)
53
54
55 def getStatsGroupes(maillage,fichierMedResult):
56   """
57   """
58   logging.info('start')
59   fichierGroupe=fichierMedResult.replace('.med','_groupesRef.res')
60   lGroups=getGroupesRef(fichierGroupe)
61   if len(lGroups)==0: 
62     print("pas de Groupe de Reference ")
63     try :
64       os.remove(fichierGroupe)
65       return
66     except :
67       return
68   lGroupsSMESH=maillage.GetGroups()
69   for groupe in lGroupsSMESH :
70      groupeName= groupe.GetName()
71      if groupeName not in lGroups : continue
72      extension='_'+groupeName+'.res'
73      fichierStatGroupe=fichierGroupe.replace('_groupesRef.res',extension)
74      getStatsStatSurGroupes(maillage,groupe,fichierStatGroupe)
75
76
77 def getStatsStatSurGroupes(maillage,groupe,fichierStatGroupe):
78   mesures = maillage.GetMeshInfo(groupe)
79   txt=""
80   import SMESH
81   for i in range(len(mesures)):
82       txt += str(SMESH.EntityType._item(i))+ " " +str(mesures[SMESH.EntityType._item(i)]) + "\n"
83   from .utiles import writeFile
84   writeFile(fichierStatGroupe,txt)
85
86
87