X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FTools%2FblocFissure%2Fgmu%2FgetStatsMaillageFissure.py;h=2f1a6813d2c4be4aeb0dedb24713c3390a021b52;hp=cf06fb33cb15450398f9137c27c44d8796a083d3;hb=6e356afaff4f01d88f76e5cde2cbfcadebe47c50;hpb=5260bd00bd51567f6137d5ea7ae0564464c4290a diff --git a/src/Tools/blocFissure/gmu/getStatsMaillageFissure.py b/src/Tools/blocFissure/gmu/getStatsMaillageFissure.py index cf06fb33c..2f1a6813d 100644 --- a/src/Tools/blocFissure/gmu/getStatsMaillageFissure.py +++ b/src/Tools/blocFissure/gmu/getStatsMaillageFissure.py @@ -1,58 +1,94 @@ # -*- coding: utf-8 -*- +# Copyright (C) 2014-2021 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +"""Statistiques maillage""" +import os import logging -import SMESH - -# ----------------------------------------------------------------------------- -# --- statistiques maillage def getStatsMaillageFissure(maillage, referencesMaillageFissure, maillageFissureParams): - """ - TODO: a completer - """ + """"Statistiques maillage""" + logging.debug('start') - nomRep = '.' if 'nomRep' in maillageFissureParams: nomRep = maillageFissureParams['nomRep'] - + else: + nomRep = os.path.curdir + nomFicFissure = maillageFissureParams['nomFicFissure'] - fichierStatMaillageFissure = nomRep + '/' + nomFicFissure + '.res' - fichierNewRef = nomRep + '/' + nomFicFissure + '.new' + fichierStatMaillageFissure = os.path.join(nomRep, "{}.res".format(nomFicFissure)) + fichierNewRef = os.path.join(nomRep, "{}.new".format(nomFicFissure)) logging.debug("fichierStatMaillageFissure=%s", fichierStatMaillageFissure) - OK = False + ok_maillage = False if maillage is not None: mesures = maillage.GetMeshInfo() - d= {} + d_resu = dict() for key, value in mesures.items(): logging.debug( "key: %s value: %s", key, value) - d[str(key)] = value - logging.debug("dico mesures %s", d) - - f = open(fichierStatMaillageFissure, 'w') - f2 = open(fichierNewRef, 'w') - OK = True - for key in ('Entity_Quad_Pyramid', 'Entity_Quad_Hexa', 'Entity_Quad_Quadrangle'): - if d[key] != referencesMaillageFissure[key]: - logging.info("Ecart: %s reference: %s calcul: %s", key, referencesMaillageFissure[key], d[key]) - f.write("Ecart: " + key + " reference: " + str(referencesMaillageFissure[key]) + " calcul: " + str(d[key]) + '\n') - OK = False - else: - logging.info("Valeur_OK: %s reference: %s calcul: %s", key, referencesMaillageFissure[key], d[key]) - f.write("Valeur_OK: " + key + " reference: " + str(referencesMaillageFissure[key]) + " calcul: " + str(d[key]) + '\n') - f2.write(key + " = " + str(d[key]) + ",\n") - tolerance = 0.05 - for key in ('Entity_Quad_Penta', 'Entity_Quad_Tetra', 'Entity_Quad_Triangle', 'Entity_Quad_Edge', 'Entity_Node'): - if (d[key] < (1.0 - tolerance)*referencesMaillageFissure[key]) \ - or (d[key] > (1.0 + tolerance)*referencesMaillageFissure[key]): - logging.info("Ecart: %s reference: %s calcul: %s", key, referencesMaillageFissure[key], d[key]) - f.write("Ecart: " + key + " reference: " + str(referencesMaillageFissure[key]) + " calcul: " + str(d[key]) + '\n') - OK = False - else: - logging.info("Valeur_OK: %s reference: %s calcul: %s", key, referencesMaillageFissure[key], d[key]) - f.write("Valeur_OK: " + key + " reference: " + str(referencesMaillageFissure[key]) + " calcul: " + str(d[key]) + '\n') - f2.write(key + " = " + str(d[key]) + ",\n") - f.close() - f2.close() - return OK + d_resu[str(key)] = value + logging.debug("dico mesures %s", d_resu) + + text_2 = "" + ok_maillage = True + with open(fichierStatMaillageFissure, "w") as fic_stat : + + # Le nombre de quadrangles ou d'hexaèdres doit être rigoureusement identique + for key in ('Entity_Quad_Quadrangle', 'Entity_Quad_Hexa'): + if d_resu[key] != referencesMaillageFissure[key]: + text = "Ecart" + ok_maillage = False + else: + text = "Valeur_OK" + text += ": {} reference: {} calcul: {}".format(key,referencesMaillageFissure[key],d_resu[key]) + logging.info(text) + fic_stat.write(text+"\n") + text_2 += " {} = {}, \\\n".format(key,d_resu[key]) + + # Le nombre de noeuds, d'arêtes, de triangles, de tétraèdres ou de pyramides peut varier du fait des algorithmes. On tolère 5% d'écart. + tolerance = 0.05 + for key in ('Entity_Node', 'Entity_Quad_Edge', 'Entity_Quad_Triangle', 'Entity_Quad_Tetra', 'Entity_Quad_Pyramid', 'Entity_Quad_Penta'): + if d_resu[key] == referencesMaillageFissure[key]: + text = "Valeur_OK" + elif (d_resu[key] < (1.0 - tolerance)*referencesMaillageFissure[key]) \ + or (d_resu[key] > (1.0 + tolerance)*referencesMaillageFissure[key]): + text = "Ecart de plus de {}%".format(tolerance*100.) + ok_maillage = False + else: + text = "Valeur_OK à moins de {}%".format(tolerance*100.) + text += ": {} reference: {} calcul: {}".format(key,referencesMaillageFissure[key],d_resu[key]) + logging.info(text) + fic_stat.write(text+"\n") + text_2 += " {} = {}, \\\n".format(key,d_resu[key]) + + if ok_maillage: + text = "Calcul cohérent avec la référence." + else: + text = "Calcul différent de la référence.\n" + text += "Voir le fichier {}\n".format(fichierStatMaillageFissure) + text += "La nouvelle référence est disponible dans le fichier :\n{}\n".format(fichierNewRef) + text += "Il faut l'insérer pour créer le dictionnaire 'referencesMaillageFissure' dans le paramétrage du cas." +# Résultats de référence pour intégration dans le python du cas pour une mise à jour + with open(fichierNewRef, "w") as fic_info : + fic_info.write(text_2[:-4]+" \\") + + print (text) + + return ok_maillage