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