Salome HOME
Découpage de construitFissureGenerale
[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   """"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       for key in ('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       tolerance = 0.05
65       for key in ('Entity_Node', 'Entity_Quad_Edge', 'Entity_Quad_Triangle', 'Entity_Quad_Tetra', 'Entity_Quad_Pyramid', 'Entity_Quad_Penta'):
66         if (d_resu[key] < (1.0 - tolerance)*referencesMaillageFissure[key]) \
67         or (d_resu[key] > (1.0 + tolerance)*referencesMaillageFissure[key]):
68           text = "Ecart"
69           ok_maillage = False
70         else:
71           text = "Valeur_OK"
72         text += ": {} reference: {} calcul: {}".format(key,referencesMaillageFissure[key],d_resu[key])
73         logging.info(text)
74         fic_stat.write(text+"\n")
75         text_2 += "                                          {} = {}, \\\n".format(key,d_resu[key])
76
77     if ok_maillage:
78       text = "Calcul cohérent avec la référence."
79     else:
80       text = "Calcul différent de la référence.\n"
81       text += "Voir le fichier {}\n".format(fichierStatMaillageFissure)
82       text += "La nouvelle référence est disponible dans le fichier :\n{}\n".format(fichierNewRef)
83       text += "Il faut l'insérer pour créer le dictionnaire 'referencesMaillageFissure' dans le paramétrage du cas."
84 #     Résultats de référence pour intégration dans le python du cas pour une mise à jour
85       with open(fichierNewRef, "w") as fic_info :
86         fic_info.write(text_2[:-4]+" \\")
87
88     print (text)
89
90   return ok_maillage