Salome HOME
Copyright update 2021
[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
21 import logging
22 import SMESH
23
24 # -----------------------------------------------------------------------------
25 # --- statistiques maillage
26
27 def getStatsMaillageFissure(maillage, referencesMaillageFissure, maillageFissureParams):
28   """
29   TODO: a completer
30   """
31   logging.debug('start')
32
33   nomRep = '.'
34   if 'nomRep' in maillageFissureParams:
35     nomRep = maillageFissureParams['nomRep']
36   
37   nomFicFissure     = maillageFissureParams['nomFicFissure']
38   fichierStatMaillageFissure = nomRep + '/' + nomFicFissure + '.res'
39   fichierNewRef = nomRep + '/' + nomFicFissure + '.new'
40   logging.debug("fichierStatMaillageFissure=%s", fichierStatMaillageFissure)
41
42   OK = False
43   if maillage is not None:
44     mesures = maillage.GetMeshInfo()
45     d= {}
46     for key, value in mesures.items():
47       logging.debug( "key: %s value: %s", key, value)
48       d[str(key)] = value
49     logging.debug("dico mesures %s", d)      
50
51     f = open(fichierStatMaillageFissure, 'w')
52     f2 = open(fichierNewRef, 'w')
53     OK = True
54     for key in ('Entity_Quad_Pyramid', 'Entity_Quad_Hexa', 'Entity_Quad_Quadrangle'):
55       if d[key] != referencesMaillageFissure[key]:
56         logging.info("Ecart: %s reference: %s calcul: %s", key, referencesMaillageFissure[key], d[key])
57         f.write("Ecart: " + key + " reference: " + str(referencesMaillageFissure[key]) + " calcul: " + str(d[key]) + '\n')
58         OK = False
59       else:
60         logging.info("Valeur_OK: %s reference: %s calcul: %s", key, referencesMaillageFissure[key], d[key])
61         f.write("Valeur_OK: " + key + " reference: " + str(referencesMaillageFissure[key]) + " calcul: " + str(d[key]) + '\n')
62       f2.write(key + " = " + str(d[key]) + ",\n")
63     tolerance = 0.05
64     for key in ('Entity_Quad_Penta', 'Entity_Quad_Tetra', 'Entity_Quad_Triangle', 'Entity_Quad_Edge', 'Entity_Node'):
65       if (d[key] < (1.0 - tolerance)*referencesMaillageFissure[key]) \
66       or (d[key] > (1.0 + tolerance)*referencesMaillageFissure[key]):
67         logging.info("Ecart: %s reference: %s calcul: %s", key, referencesMaillageFissure[key], d[key])
68         f.write("Ecart: " + key + " reference: " + str(referencesMaillageFissure[key]) + " calcul: " + str(d[key]) + '\n')
69         OK = False
70       else:
71         logging.info("Valeur_OK: %s reference: %s calcul: %s", key, referencesMaillageFissure[key], d[key])
72         f.write("Valeur_OK: " + key + " reference: " + str(referencesMaillageFissure[key]) + " calcul: " + str(d[key]) + '\n')
73       f2.write(key + " = " + str(d[key]) + ",\n")
74     f.close()
75     f2.close()
76   return OK