Salome HOME
3305bac0fe6d9dfc6e57239aeeb51a0dc7a30270
[modules/smesh.git] / src / Tools / blocFissure / gmu / getStatsMaillageFissure.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2021  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 """Statistiques maillage"""
21
22 import os
23 import logging
24 import SMESH
25
26
27 def getStatsMaillageFissure(maillage, referencesMaillageFissure, maillageFissureParams):
28   """"Statistiques maillage"""
29
30   logging.debug('start')
31
32   if 'nomRep' in maillageFissureParams:
33     nomRep = maillageFissureParams['nomRep']
34   else:
35     nomRep = os.path.curdir
36
37   nomFicFissure     = maillageFissureParams['nomFicFissure']
38   fichierStatMaillageFissure = os.path.join(nomRep, "{}.res".format(nomFicFissure))
39   fichierNewRef = os.path.join(nomRep, "{}.new".format(nomFicFissure))
40   logging.debug("fichierStatMaillageFissure=%s", fichierStatMaillageFissure)
41
42   ok_maillage = False
43   if maillage is not None:
44     mesures = maillage.GetMeshInfo()
45     d_resu = dict()
46     for key, value in mesures.items():
47       logging.debug( "key: %s value: %s", key, value)
48       d_resu[str(key)] = value
49     logging.debug("dico mesures %s", d_resu)
50
51     text_2 = ""
52     ok_maillage = True
53     with open(fichierStatMaillageFissure, "w") as fic_stat :
54
55       # Le nombre d'arêtes, de quadrangles ou d'hexaèdres doit être rigoureusement identique
56       for key in ('Entity_Quad_Edge', 'Entity_Quad_Quadrangle', 'Entity_Quad_Hexa'):
57         if d_resu[key] != referencesMaillageFissure[key]:
58           text = "Ecart"
59           ok_maillage = False
60         else:
61           text = "Valeur_OK"
62         text += ": {} reference: {} calcul: {}".format(key,referencesMaillageFissure[key],d_resu[key])
63         logging.info(text)
64         fic_stat.write(text+"\n")
65         text_2 += "                                          {} = {}, \\\n".format(key,d_resu[key])
66
67       # Le nombre de noeuds, de triangles, de tétraèdres ou de pyramides peut varier du fait des algorithmes. On tolère 5% d'écart.
68       tolerance = 0.05
69       for key in ('Entity_Node', 'Entity_Quad_Triangle', 'Entity_Quad_Tetra', 'Entity_Quad_Pyramid', 'Entity_Quad_Penta'):
70         if d_resu[key] == referencesMaillageFissure[key]:
71           text = "Valeur_OK"
72         elif (d_resu[key] < (1.0 - tolerance)*referencesMaillageFissure[key]) \
73           or (d_resu[key] > (1.0 + tolerance)*referencesMaillageFissure[key]):
74           text = "Ecart de plus de {}%".format(tolerance*100.)
75           ok_maillage = False
76         else:
77           text = "Valeur_OK à moins de {}%".format(tolerance*100.)
78         text += ": {} reference: {} calcul: {}".format(key,referencesMaillageFissure[key],d_resu[key])
79         logging.info(text)
80         fic_stat.write(text+"\n")
81         text_2 += "                                          {} = {}, \\\n".format(key,d_resu[key])
82
83     if ok_maillage:
84       text = "Calcul cohérent avec la référence."
85     else:
86       text = "Calcul différent de la référence.\n"
87       text += "Voir le fichier {}\n".format(fichierStatMaillageFissure)
88       text += "La nouvelle référence est disponible dans le fichier :\n{}\n".format(fichierNewRef)
89       text += "Il faut l'insérer pour créer le dictionnaire 'referencesMaillageFissure' dans le paramétrage du cas."
90 #     Résultats de référence pour intégration dans le python du cas pour une mise à jour
91       with open(fichierNewRef, "w") as fic_info :
92         fic_info.write(text_2[:-4]+" \\")
93
94     print (text)
95
96   return ok_maillage