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