From e10331eae5676f5b5d8732121a3aa196d46c6705 Mon Sep 17 00:00:00 2001 From: Gilles DAVID Date: Fri, 24 Mar 2017 13:48:58 +0100 Subject: [PATCH] Porting to Python 3 --- bin/mg-tetra_hpc.py | 136 +- .../GHS3DPRLPLUGIN/input/ghs3dprl_hypo.doc | 4 +- src/GHS3DPRLPlugin/GHS3DPRLPluginBuilder.py | 2 +- src/tools/facespoints2mesh.py | 60 +- src/tools/mesh2facespoints.py | 214 +-- src/tools/testMesh.py | 1558 ++++++++--------- src/tools/testMeshTest.py | 96 +- 7 files changed, 1042 insertions(+), 1028 deletions(-) diff --git a/bin/mg-tetra_hpc.py b/bin/mg-tetra_hpc.py index ca6f4ed..e20f654 100644 --- a/bin/mg-tetra_hpc.py +++ b/bin/mg-tetra_hpc.py @@ -3,21 +3,21 @@ # %% LICENSE_SALOME_CEA_BEGIN # Copyright (C) 2008-2016 CEA/DEN -# +# # 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 # %% LICENSE_END @@ -32,24 +32,26 @@ example linux usage: """ import os +import platform import sys import time -import platform + import argparse as AP -import pprint as PP #pretty print -import subprocess as SP #Popen -import multiprocessing as MP #cpu_count +import multiprocessing as MP # cpu_count +import pprint as PP # pretty print +import subprocess as SP # Popen + verbose = False OK = "ok" KO = "KO" -OKSYS = 0 #for linux -KOSYS = 1 #for linux +OKSYS = 0 # for linux +KOSYS = 1 # for linux + +NB_PROCS = MP.cpu_count() # current cpu number of proc +NAME_OS = platform.system() # 'Linux' or 'Windows' -NB_PROCS = MP.cpu_count() #current cpu number of proc -NAME_OS = platform.system() #'Linux' or 'Windows' - ########################################################################## # utilities @@ -57,10 +59,10 @@ NAME_OS = platform.system() #'Linux' or 'Windows' def okToSys(aResult, verbose=False): """to get windows or linux result of script""" - + def extendList(alist): """utility extend list of lists of string results with ok or KO""" - #bad: list(itertools.chain.from_list(alist)) iterate on str + # bad: list(itertools.chain.from_list(alist)) iterate on str res = [] if type(alist) != list: return [alist] @@ -71,19 +73,19 @@ def okToSys(aResult, verbose=False): else: res.extend(extendList(i)) return res - + resList = extendList(aResult) if resList == []: if verbose: print("WARNING: result no clear: []") return KOSYS - + rr = OK for ri in resList: if ri[0:2] != OK: - if verbose: print ri + if verbose: print(ri) rr = KO - if verbose: print("INFO: result: %s" % rr) + if verbose: print(("INFO: result: %s" % rr)) if rr == OK: return OKSYS else: @@ -116,22 +118,22 @@ class ArgRange(object): def exec_command(cmd, verbose=False): """Exec ONE command with popen""" - time.sleep(3) #wait for (MPI) flush files - if verbose: print("launch process:\n %s" % cmd) + time.sleep(3) # wait for (MPI) flush files + if verbose: print(("launch process:\n %s" % cmd)) try: - pipe = SP.Popen(cmd, shell=True, stdout=SP.PIPE, stderr=SP.PIPE ) + pipe = SP.Popen(cmd, shell=True, stdout=SP.PIPE, stderr=SP.PIPE) except Exception as e: result = KO + " ERROR: we have a problem popen on: %s" % PP.pformat(cmd) return result - + (out, error) = pipe.communicate() pipe.wait() - + print(out) print(error) - + result = OK + " INFO: seems final ok for: %s" % PP.pformat(cmd) - time.sleep(3) #wait for (MPI) flush files + time.sleep(3) # wait for (MPI) flush files return result @@ -158,7 +160,7 @@ def force_DISTENE_LICENSE_FILE(): #export PATH=/export/home/prerequisites_SALOME_780_LAURENT/openmpi-1.8.4/FROM_nothing/bin:$PATH #do not work prefer set before salome launch OPENMPI_INSTALL_DIR = "/export/home/prerequisites_SALOME_780_LAURENT/openmpi-1.8.4/FROM_nothing/bin" - sys.path.insert(0, OPENMPI_INSTALL_DIR) + sys.path.insert(0, OPENMPI_INSTALL_DIR) #INSTALL_DIR = /export/home/prerequisites_SALOME_780_LAURENT/openmpi-1.8.4/FROM_nothing for i in sys.path[0:10]: print "PATH",i """ @@ -168,18 +170,18 @@ def force_DISTENE_LICENSE_FILE(): ########################################################################## def launchMultithread(args): - if verbose: print("INFO: launchMultithread for %s" % NAME_OS) - + if verbose: print(("INFO: launchMultithread for %s" % NAME_OS)) + if NAME_OS == 'Linux': - #--out is ONE file: basename_tetra_hpc.mesh - outputMulti = os.path.splitext(args.inputFile)[0] + "_tetra_hpc.mesh" #only one file if Multithread + # --out is ONE file: basename_tetra_hpc.mesh + outputMulti = os.path.splitext(args.inputFile)[0] + "_tetra_hpc.mesh" # only one file if Multithread outputs = os.path.splitext(args.outputFiles)[0] - outputMultiAsMpi = os.path.splitext(args.outputFiles)[0] + ".000001.mesh" #create one output file named as only one from mpi + outputMultiAsMpi = os.path.splitext(args.outputFiles)[0] + ".000001.mesh" # create one output file named as only one from mpi cmd = "mg-tetra_hpc.exe --max_number_of_threads %i --in %s --gradation %s --max_size %s --min_size %s; cp %s %s; ls -alt %s*; " % \ (args.number, args.inputFile, args.gradation, args.max_size, args.min_size, outputMulti, outputMultiAsMpi, outputs) else: - return KO + " ERROR: unknown operating system: %s" % NAME_OS - + return KO + " ERROR: unknown operating system: %s" % NAME_OS + result = exec_command(cmd, verbose=True) return result @@ -187,11 +189,11 @@ def launchMultithread(args): ########################################################################## def launchMpi(args): - if verbose: print("INFO: launchMpi for %s" % NAME_OS) - - if NAME_OS == 'Linux': - cmd = "" - + if verbose: print(("INFO: launchMpi for %s" % NAME_OS)) + + if NAME_OS == 'Linux': + cmd = "" + """ compile libmeshgems_mpi.so: no needs COMPILDIR=os.getenv("MESHGEMSHOME") + "/stubs" TARGETDIR=os.getenv("MESHGEMSHOME") + "/lib/Linux_64" @@ -203,8 +205,8 @@ def launchMpi(args): cmd += "mpirun -n %i mg-tetra_hpc_mpi.exe --in %s --out %s --gradation %s --max_size %s --min_size %s; ls -alt %s*; " % \ (args.number, args.inputFile, args.outputFiles, args.gradation, args.max_size, args.min_size, outputs) else: - return KO + " ERROR: unknown operating system: %s" % NAME_OS - + return KO + " ERROR: unknown operating system: %s" % NAME_OS + result = exec_command(cmd, verbose=True) return result @@ -215,15 +217,15 @@ def launchMpi(args): if __name__ == '__main__': parser = AP.ArgumentParser(description='launch tetra_hpc.exe or tetra_hpc_mpi.exe mesh computation', argument_default=None) - #./mg-tetra_hpc.py -n 3 --in=/tmp/GHS3DPRL.mesh --out=/tmp/GHS3DPRL_out.mesh --gradation=1.05 --min_size=0.001 --max_size=1.1 --multithread no > /tmp/tetrahpc.log + # ./mg-tetra_hpc.py -n 3 --in=/tmp/GHS3DPRL.mesh --out=/tmp/GHS3DPRL_out.mesh --gradation=1.05 --min_size=0.001 --max_size=1.1 --multithread no > /tmp/tetrahpc.log parser.add_argument( - '-v', '--verbose', + '-v', '--verbose', help='set verbose, for debug', action='store_true', ) parser.add_argument( - '-n', '--number', + '-n', '--number', help='if multithread: number of threads, else distributed: number of processes MPI', choices=[ArgRange(1, 999999)], type=int, @@ -231,13 +233,13 @@ if __name__ == '__main__': default=1, ) parser.add_argument( - '-m', '--multithread', + '-m', '--multithread', help='launch tetra_hpc multithread instead tetra_hpc distributed (MPI)', choices=["no", "yes"], default='no', ) parser.add_argument( - '-g', '--gradation', + '-g', '--gradation', help='size ratio adjacent cell, default 0 is 1.05', type=float, choices=[ArgRange(0.0, 3.0)], @@ -245,7 +247,7 @@ if __name__ == '__main__': default='0' ) parser.add_argument( - '-si', '--min_size', + '-si', '--min_size', help='min size cell, default 0 is no constraint', type=float, choices=[ArgRange(0.0, 9e99)], @@ -253,7 +255,7 @@ if __name__ == '__main__': default='0' ) parser.add_argument( - '-sa', '--max_size', + '-sa', '--max_size', help='max size cell, default 0 is no constraint', type=float, choices=[ArgRange(0.0, 9e99)], @@ -261,20 +263,20 @@ if __name__ == '__main__': default='0' ) parser.add_argument( - '-i', '--inputFile', + '-i', '--inputFile', help='input file name', - #nargs='?', + # nargs='?', metavar='.../inputFile.mesh' ) parser.add_argument( - '-o', '--outputFiles', + '-o', '--outputFiles', help='output basename file(s) name', - #nargs='?', + # nargs='?', metavar='.../outputFile.mesh' ) """ parser.add_argument( - '-x', '--xoneargument', + '-x', '--xoneargument', nargs='?', metavar='0|1', choices=['0', '1'], @@ -282,39 +284,39 @@ if __name__ == '__main__': default='0' ) """ - - + + """ - args is Namespace, may use it as global to store + args is Namespace, may use it as global to store parameters, data, used arrays and results and other... """ args = parser.parse_args() - + verbose = args.verbose - if verbose: print("INFO: args:\n%s" % PP.pformat(args.__dict__)) + if verbose: print(("INFO: args:\n%s" % PP.pformat(args.__dict__))) - if len(sys.argv) == 1: #no args as --help + if len(sys.argv) == 1: # no args as --help parser.print_help() sys.exit(KOSYS) if args.inputFile == None: - print("\nERROR: Nothing to do: no input files\n\n%s\n" % PP.pformat(args)) + print(("\nERROR: Nothing to do: no input files\n\n%s\n" % PP.pformat(args))) parser.print_help() sys.exit(KOSYS) if args.outputFiles == None: tmp, _ = os.path.splitext(args.inputFile) args.outputFiles = tmp + "_out.mesh" - print("\nWARNING: Default ouput files: %s" % args.outputFiles) - + print(("\nWARNING: Default ouput files: %s" % args.outputFiles)) + force_DISTENE_LICENSE_FILE() - print("INFO: mg-tetra_hpc.py assume licence file set:\n DLIM8VAR=%s\n DISTENE_LICENSE_FILE=%s" % \ - (os.getenv("DLIM8VAR"), os.getenv("DISTENE_LICENSE_FILE"))) - - if args.multithread == "yes": + print(("INFO: mg-tetra_hpc.py assume licence file set:\n DLIM8VAR=%s\n DISTENE_LICENSE_FILE=%s" % \ + (os.getenv("DLIM8VAR"), os.getenv("DISTENE_LICENSE_FILE")))) + + if args.multithread == "yes": result = launchMultithread(args) else: result = launchMpi(args) sys.exit(okToSys(result, verbose=True)) - + diff --git a/doc/salome/gui/GHS3DPRLPLUGIN/input/ghs3dprl_hypo.doc b/doc/salome/gui/GHS3DPRLPLUGIN/input/ghs3dprl_hypo.doc index 90c9215..ba40414 100644 --- a/doc/salome/gui/GHS3DPRLPLUGIN/input/ghs3dprl_hypo.doc +++ b/doc/salome/gui/GHS3DPRLPLUGIN/input/ghs3dprl_hypo.doc @@ -388,9 +388,9 @@ status = m.Compute() # ---------- if os.access(results+".xml", os.F_OK): - print "Ok: tetra_hpc" + print("Ok: tetra_hpc") else: - print "KO: tetra_hpc" + print("KO: tetra_hpc") \endcode \n diff --git a/src/GHS3DPRLPlugin/GHS3DPRLPluginBuilder.py b/src/GHS3DPRLPlugin/GHS3DPRLPluginBuilder.py index c1f83c1..89f4d84 100644 --- a/src/GHS3DPRLPlugin/GHS3DPRLPluginBuilder.py +++ b/src/GHS3DPRLPlugin/GHS3DPRLPluginBuilder.py @@ -72,7 +72,7 @@ class GHS3DPRL_Algorithm(Mesh_Algorithm): # if it is @c 0 (default), the algorithm is assigned to the main shape def __init__(self, mesh, geom=0): Mesh_Algorithm.__init__(self) - if noGHS3DPRLPlugin: print "Warning: GHS3DPRLPlugin module unavailable" + if noGHS3DPRLPlugin: print("Warning: GHS3DPRLPlugin module unavailable") self.Create(mesh, geom, self.algoType, "libGHS3DPRLEngine.so") self.params = None pass diff --git a/src/tools/facespoints2mesh.py b/src/tools/facespoints2mesh.py index 8eeb7b1..c6ebe6a 100755 --- a/src/tools/facespoints2mesh.py +++ b/src/tools/facespoints2mesh.py @@ -18,7 +18,6 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # - """ these file is using in GHS3DPRL Plugin to convert input files .faces and .points of Tepal V1 @@ -30,38 +29,37 @@ example of use (when Tepal V2): mesh2facespoints.py DOMAIN """ -import os +import codecs import sys -file_fp='GHS3DPRL' -if len(sys.argv)==2: - file_fp=sys.argv[1] -f1=file_fp+'.points' -f2=file_fp+'.faces' -f3=file_fp+'.mesh' +file_fp = 'GHS3DPRL' +if len(sys.argv) == 2: + file_fp = sys.argv[1] + +f1 = file_fp + '.points' +f2 = file_fp + '.faces' +f3 = file_fp + '.mesh' -fs=open(f1, 'r') -ft=open(f3, 'w') -ft.write('MeshVersionFormatted 1\n') -ft.write('\nDimension\n3\n') -tmp=fs.readline() -nb=int(tmp) -ft.write('\nVertices\n') -ft.write(tmp) -for i in xrange(0,nb): - lig=fs.readline() - ft.write(lig) -fs.close() +with codecs.open(f3, 'w') as ft: + with codecs.open(f1, 'r') as fs: + ft.write('MeshVersionFormatted 1\n') + ft.write('\nDimension\n3\n') + tmp = fs.readline() + nb = int(tmp) + ft.write('\nVertices\n') + ft.write(tmp) + for i in range(nb): + lig = fs.readline() + ft.write(lig) + with codecs.open(f2, 'r') as fs: + lig = fs.readline() + nb = int(lig.split()[0]) + ft.write('\nTriangles\n' + lig.split()[0] + '\n') + for i in range(nb): + lig = fs.readline() + lig = lig.split() + ft.write(lig[1] + ' ' + lig[2] + ' ' + lig[3] + ' ' + lig[4] + '\n') + ft.write('\nEnd\n') -fs=open(f2, 'r') -lig=fs.readline() -nb=int(lig.split()[0]) -ft.write('\nTriangles\n'+lig.split()[0]+'\n') -for i in xrange(0,nb): - lig=fs.readline() - lig=lig.split() - ft.write(lig[1]+' '+lig[2]+' '+lig[3]+' '+lig[4]+'\n') -ft.write('\nEnd\n') -ft.close() -print 'facespoints2mesh creation of file '+f3 +print('facespoints2mesh creation of file ' + f3) diff --git a/src/tools/mesh2facespoints.py b/src/tools/mesh2facespoints.py index 0f9f5da..19f0853 100755 --- a/src/tools/mesh2facespoints.py +++ b/src/tools/mesh2facespoints.py @@ -18,7 +18,6 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # - """ these file is using in GHS3DPRL Plugin to convert output files .mesh of Tepal V2 @@ -30,106 +29,123 @@ example of use (when Tepal V2): mesh2facespoints.py DOMAIN """ +import codecs +import fileinput +import glob import os +import shutil import sys -import glob -import fileinput -import string - -file_m='GHS3DPRL' -if len(sys.argv)==2: - file_m=sys.argv[1] - -def find_cr_or_not(fs,tag): - """find number after tag with cr or sp""" - for line in fs: - if tag+'\n' in line: - #print tag+'' - res=fs.readline() - break - if tag+' ' in line: - #print 'vertices' - res=line.split()[1] - break - res=res.strip("\t\n ") - print tag+' '+res - return res + + +file_m = 'GHS3DPRL' +if len(sys.argv) == 2: + file_m = sys.argv[1] + + +def find_cr_or_not(fs, tag): + """find number after tag with cr or sp""" + for line in fs: + if tag + '\n' in line: + # print tag+'' + res = fs.readline() + break + if tag + ' ' in line: + # print 'vertices' + res = line.split()[1] + break + res = res.strip("\t\n ") + print(tag + ' ' + res) + return res + def m2fp(f1): - """convert .mesh file to .points and .faces and .noboite""" - print '\nconversion '+f1+' to .points and .faces and .noboite' - #fs=open(f1, 'r') - #fs=fileinput.FileInput(f1,mode='r') #mode not in v2.4.4 - fs=fileinput.FileInput(f1) - (shortname, extension)=os.path.splitext(f1) - f2=shortname+'.points' - print 'creating',f2 - fp=open(f2, 'w') - nb=find_cr_or_not(fs,'Vertices') - np=nb #for .noboite - fp.write(nb+'\n') - for i in xrange(0,int(nb)): - fp.write(fs.readline()) - fp.close() - - f2=shortname+'.faces' - print 'creating',f2 - ff=open(f2, 'w') - nb=find_cr_or_not(fs,'Triangles') - ff.write(nb+' 0\n') - for i in xrange(0,int(nb)): - ff.write('3 '+fs.readline().strip('\t\n ')+' 0 0 0\n') - ff.close() - - ne=find_cr_or_not(fs,'Tetrahedra') - f3=shortname+'.noboite' - fb=open(f3, 'w') - npfixe="0" - fb.write(ne+' '+np+' '+npfixe+' 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n') - for i in xrange(0,int(ne)): - lig=fs.readline().strip('\t\n ') - lig=lig.split() - fb.write(lig[0]+" "+lig[1]+" "+lig[2]+" "+lig[3]+" ") - fb.write('\n') - fs.close() - fs=fileinput.FileInput(shortname+'.points') - nb=fs.readline() #eqal to np - for i in xrange(0,int(nb)): - lig=fs.readline().strip('\t\n ') - lig=lig.split() - fb.write(lig[0]+" "+lig[1]+" "+lig[2]+" ") - fb.write('\n0\n') #subnumber - fs.close() - fb.close() - -def rename_tepal_v1(f1,imax): - """rename files as version v1 of tepal expect""" - (shortname, extension)=os.path.splitext(f1) - fs=os.path.splitext(shortname) - i=int(fs[1].strip('.')) - ff=fs[0]+'.'+str(imax)+'.'+string.zfill(str(i),len(str(imax))) - #noboite en ".32.02.noboite!" - mvcp='mv ' #ou 'cp ' - f2=shortname+'.points' ; f3=ff+os.path.splitext(f2)[1] - print f2,'->',f3 ; os.system(mvcp+f2+' '+f3) - f2=shortname+'.faces' ; f3=ff+os.path.splitext(f2)[1] - print f2,'->',f3 ; os.system(mvcp+f2+' '+f3) - f2=shortname+'.noboite' ; f3=ff+os.path.splitext(f2)[1] - print f2,'->',f3 ; os.system(mvcp+f2+' '+f3) - f2=shortname+'.glo' ; f3=ff+os.path.splitext(f2)[1] - print f2,'->',f3 ; os.system(mvcp+f2+' '+f3) - f2=shortname+'.msg' ; f3=ff+os.path.splitext(f2)[1] - print f2,'->',f3 ; os.system(mvcp+f2+' '+f3) - -def my_test(a): return int(os.path.basename(a).split('.')[1]) - -f0=file_m+'.?????.mesh' -#print f0 -fics=glob.glob(f0) -fics.sort(lambda a, b: cmp(my_test(b), my_test(a))) #tri ordre decroissant -print 'conversion of files:\n',fics - -imax=len(fics) + """convert .mesh file to .points and .faces and .noboite""" + print('\nconversion ' + f1 + ' to .points and .faces and .noboite') + # fs=open(f1, 'r') + # fs=fileinput.FileInput(f1,mode='r') #mode not in v2.4.4 + fs = fileinput.FileInput(f1) + shortname = os.path.splitext(f1)[0] + f2 = shortname + '.points' + print('creating', f2) + with codecs.open(f2, 'w') as fp: + nb = find_cr_or_not(fs, 'Vertices') + np = nb # for .noboite + fp.write(nb + '\n') + for _ in range(int(nb)): + fp.write(fs.readline()) + + f2 = shortname + '.faces' + print('creating', f2) + with codecs.open(f2, 'w') as ff: + nb = find_cr_or_not(fs, 'Triangles') + ff.write(nb + ' 0\n') + for _ in range(int(nb)): + ff.write('3 ' + fs.readline().strip('\t\n ') + ' 0 0 0\n') + + ne = find_cr_or_not(fs, 'Tetrahedra') + f3 = shortname + '.noboite' + with codecs.open(f3, 'w') as fb: + npfixe = "0" + fb.write(ne + ' ' + np + ' ' + npfixe + ' 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n') + for _ in range(int(ne)): + lig = fs.readline().strip('\t\n ') + lig = lig.split() + fb.write(lig[0] + " " + lig[1] + " " + lig[2] + " " + lig[3] + " ") + fb.write('\n') + fs.close() + fs = fileinput.FileInput(shortname + '.points') + nb = fs.readline() # eqal to np + for _ in range(int(nb)): + lig = fs.readline().strip('\t\n ') + lig = lig.split() + fb.write(lig[0] + " " + lig[1] + " " + lig[2] + " ") + fb.write('\n0\n') # subnumber + fs.close() + + +def rename_tepal_v1(f1, imax): + """rename files as version v1 of tepal expect""" + shortname = os.path.splitext(f1)[0] + fs = os.path.splitext(shortname) + i = int(fs[1].strip('.')) + ff = fs[0] + '.' + str(imax) + '.' + str(i).zfill(len(str(imax))) + # noboite en ".32.02.noboite!" + f2 = shortname + '.points' + f3 = ff + os.path.splitext(f2)[1] + print(f2, '->', f3) + shutil.move(f2, f3) + f2 = shortname + '.faces' + f3 = ff + os.path.splitext(f2)[1] + print(f2, '->', f3) + shutil.move(f2, f3) + f2 = shortname + '.noboite' + f3 = ff + os.path.splitext(f2)[1] + print(f2, '->', f3) + shutil.move(f2, f3) + f2 = shortname + '.glo' + f3 = ff + os.path.splitext(f2)[1] + print(f2, '->', f3) + shutil.move(f2, f3) + f2 = shortname + '.msg' + f3 = ff + os.path.splitext(f2)[1] + print(f2, '->', f3) + shutil.move(f2, f3) + + +def my_test(a): + return int(os.path.basename(a).split('.')[1]) + + +def cmp(a, b): + return (a > b) - (a < b) + +f0 = file_m + '.?????.mesh' +# print f0 +fics = glob.glob(f0) +fics.sort(lambda a, b: cmp(my_test(b), my_test(a))) # tri ordre decroissant +print('conversion of files:\n', fics) + +imax = len(fics) for f in fics: - m2fp(f) - rename_tepal_v1(f,imax) + m2fp(f) + rename_tepal_v1(f, imax) diff --git a/src/tools/testMesh.py b/src/tools/testMesh.py index cf3a206..9d04974 100644 --- a/src/tools/testMesh.py +++ b/src/tools/testMesh.py @@ -1,816 +1,812 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - -# %% LICENSE_SALOME_CEA_BEGIN -# Copyright (C) 2008-2016 CEA/DEN -# -# 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 -# %% LICENSE_END - - -""" -run coherency tests on one and some mesh. -initially used for test output(s) mg_tetra_hpc_mpi.exe - -WARNING: is for small meshes, obviously no optimisation. -WARNING: printing and .mesh indices are 1 to n when stored list python 0 to n-1 - -example linux usage: -- simple run: - ./testMesh.py --verbose --testall --files ./GHS3DPRL_out.000001.mesh ./GHS3DPRL_out.000002.mesh - ./testMesh.py -a -f /tmp/GHS3DPRL_out.00000?.mesh -""" - -import os -import sys -import platform -import argparse as AP -import pprint as PP #pretty print - -verbose = False - -OK = "ok" -KO = "KO" -OKSYS = 0 #for linux -KOSYS = 1 #for linux - - -######################################### -# utilities - -def okToSys(aResult, verbose=False): - """to get windows or linux result of script""" - + +# %% LICENSE_SALOME_CEA_BEGIN +# Copyright (C) 2008-2016 CEA/DEN +# +# 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 +# %% LICENSE_END + + +""" +run coherency tests on one and some mesh. +initially used for test output(s) mg_tetra_hpc_mpi.exe + +WARNING: is for small meshes, obviously no optimisation. +WARNING: printing and .mesh indices are 1 to n when stored list python 0 to n-1 + +example linux usage: +- simple run: + ./testMesh.py --verbose --testall --files ./GHS3DPRL_out.000001.mesh ./GHS3DPRL_out.000002.mesh + ./testMesh.py -a -f /tmp/GHS3DPRL_out.00000?.mesh +""" + +import os +import sys + +import argparse as AP +import pprint as PP # pretty print + + +verbose = False + +OK = "ok" +KO = "KO" +OKSYS = 0 # for linux +KOSYS = 1 # for linux + + +######################################### +# utilities + +def okToSys(aResult, verbose=False): + """to get windows or linux result of script""" + def extendList(alist): - """utility extend list of lists of string results with ok or KO""" - #bad: list(itertools.chain.from_list(alist)) iterate on str - res = [] - if type(alist) != list: - return [alist] - else: - for i in alist: - if type(i) == str: - res.append(i) - else: - res.extend(extendList(i)) - return res - - resList = extendList(aResult) - if resList == []: - if verbose: print("WARNING: result no clear: []") - return KOSYS - - rr = OK - for ri in resList: - if ri[0:2] != OK: - if verbose: print ri - rr = KO - - if verbose: print("INFO: result: %s" % rr) - if rr == OK: - return OKSYS - else: - return KOSYS - -def getDirAndName(datafile): - path, namefile = os.path.split(os.path.realpath(datafile)) - rootpath = os.getcwd() - return (path, rootpath, namefile) - -def resumeList(aList): - if len(aList) == 0: - return [] - if len(aList) < 3: - return aList - res = [aList[0], "...", aList[-1]] - return res - -def resumeLines(aList, ilines): - if verbose: print("INFO: resumeLines", ilines) - if len(aList) == 0: - return [] - if len(aList) < 3: - return aList - res = [] + """utility extend list of lists of string results with ok or KO""" + # bad: list(itertools.chain.from_list(alist)) iterate on str + res = [] + if type(alist) != list: + return [alist] + else: + for i in alist: + if type(i) == str: + res.append(i) + else: + res.extend(extendList(i)) + return res + + resList = extendList(aResult) + if resList == []: + if verbose: print("WARNING: result no clear: []") + return KOSYS + + rr = OK + for ri in resList: + if ri[0:2] != OK: + if verbose: print(ri) + rr = KO + + if verbose: print("INFO: result: %s" % rr) + if rr == OK: + return OKSYS + else: + return KOSYS + +def getDirAndName(datafile): + path, namefile = os.path.split(os.path.realpath(datafile)) + rootpath = os.getcwd() + return (path, rootpath, namefile) + +def resumeList(aList): + if len(aList) == 0: + return [] + if len(aList) < 3: + return aList + res = [aList[0], "...", aList[-1]] + return res + +def resumeLines(aList, ilines): + if verbose: print("INFO: resumeLines", ilines) + if len(aList) == 0: + return [] + if len(aList) < 3: + return aList + res = [] for i in ilines: - if i != None: # if not existing tetrahedra for example - resi = [ii.strip("\n") for ii in aList[i:i+4]] - resi.append("...") - res.append(resi) - return res - - -######################################### -class XXVert(object): - """Vertices, Nodes""" - def __init__(self, x, y, z, color=0, indexglobal=0): - self.x = x - self.y = y - self.z = z - self.color = color - self.indexglobal = indexglobal - - def compare(self, vb, args, withAll=True): - if self.x != vb.x: return False - if self.y != vb.y: return False - if self.z != vb.z: return False - if withAll: - if args.withColor: - if self.color != vb.color: return False - if args.withIndex: - if self.indexglobal != vb.indexglobal: return False - return True - - def __eq__(self, vb): - """equality test without color or indexglobal""" - #print "vertice equality" - if self.x != vb.x: return False - if self.y != vb.y: return False - if self.z != vb.z: return False - return True - - def __ne__(self, vb): - """inequality test without color or indexglobal""" - #print "vertice inequality" - if self.x == vb.x and self.y == vb.y and self.z != vb.z: - return True - return False - - def __repr__(self): - return "XXVert(%.4f %.4f %.4f (%i %i))" % \ - (self.x, self.y, self.z, self.color, self.indexglobal) - - def __str__(self): - return "(%s %s %s (%i %i))" % \ - (self.x, self.y, self.z, self.color, self.indexglobal) - - def dist(self, vb): - res = (self.x - vb.x)**2 + (self.y - vb.y)**2 + (self.z -vb.z)**2 - return res**.5 - - - -######################################### -class XXEdge(object): - """Edges, 2 Nodes""" - def __init__(self, a, b, color=0, indexglobal=0): - self.a = a - self.b = b - self.color = color - self.indexglobal = indexglobal - - def compare(self, eb, args): - res = self.a.compare(eb.a, args) and \ - self.b.compare(eb.b, args) - if res: - if args.withColor: - if self.color != eb.color: return False - if args.withIndex: - if self.indexglobal != eb.indexglobal: return False - return res - - def __repr__(self): - return "XXEdge(%i %i (%i %i))" % \ - (self.a, self.b, self.color, self.indexglobal) - - def __str__(self): - return "(%i %i (%i %i))" % \ - (self.a, self.b, self.color, self.indexglobal) - - def inTria(self, tria, args): - t = [tria.a, tria.b, tria.c] - if not self.a in t: return False - if not self.b in t: return False - return True - - def getVertices(self, mesh): - v1 = mesh.verts[self.a - 1] - v2 = mesh.verts[self.b - 1] - return [v1, v2] - - -######################################### -class XXTria(object): - """Triangles, Faces, 3 nodes""" - def __init__(self, a, b, c, color=0, indexglobal=0): - self.a = a - self.b = b - self.c = c - self.color = color - self.indexglobal = indexglobal - - def compare(self, trb, args): - res = self.a.compare(trb.a, args) and \ - self.b.compare(trb.b, args) and \ - self.c.compare(trb.c, args) - if res: - if args.withColor: - if self.color != trb.color: return False - if args.withIndex: - if self.indexglobal != trb.indexglobal: return False - return res - - def __repr__(self): - return "XXTria(%i %i %i (%i %i))" % \ - (self.a, self.b, self.c, self.color, self.indexglobal) - - def __str__(self): - return "(%i %i %i (%i %i))" % \ - (self.a, self.b, self.c, self.color, self.indexglobal) - - def inTetra(self, tetra, args): - t = [tetra.a, tetra.b, tetra.c, tetra.d] - if not self.a in t: return False - if not self.b in t: return False - if not self.c in t: return False - return True - - def getVertices(self, mesh): - v1 = mesh.verts[self.a - 1] - v2 = mesh.verts[self.b - 1] - v3 = mesh.verts[self.c - 1] - return [v1, v2, v3] - - - -######################################### -class XXTetra(object): - """Tetra, 4 nodes""" - def __init__(self, a, b, c, d, color=0, indexglobal=0): - self.a = a - self.b = b - self.c = c - self.d = d - self.color = color - self.indexglobal = indexglobal - - def compare(self, teb, args): - res = self.a.compare(teb.a, args) and \ - self.b.compare(teb.b, args) and \ - self.c.compare(teb.c, args) and \ - self.d.compare(teb.d, args) - if res: - if args.withColor: - if self.color != teb.color: return False - if args.withIndex: - if self.indexglobal != teb.indexglobal: return False - return res - - def __repr__(self): - return "XXTetra(%i %i %i %i (%i %i))" % \ - (self.a, self.b, self.c, self.d, self.color, self.indexglobal) - - def __str__(self): - return "(%i %i %i %i (%i %i))" % \ - (self.a, self.b, self.c, self.d, self.color, self.indexglobal) - - def getVertices(self, mesh): - v1 = mesh.verts[self.a - 1] - v2 = mesh.verts[self.b - 1] - v3 = mesh.verts[self.c - 1] - v4 = mesh.verts[self.d - 1] - return [v1, v2, v3, v4] - - -######################################### -class XXMesh(object): - """Mesh: vertices, edges, triangles, tetrahedra""" - def __init__(self): - self.nameFile = "" - self.verts = [] - self.edges = [] - self.trias = [] - self.tetras = [] - - def initFromFileMesh(self, fileName, args, withGlobal=True): - if not os.path.isfile(fileName): - raise Exception("ERROR: inexisting file '%s'" % fileName) - with open(fileName, "r") as f: - lines = f.readlines() - iverts, iedges, itrias, itetras = self.getIndexInMeshFile(lines) - self.verts = self.getMeshVerts(lines, iverts) - self.edges = self.getMeshEdges(lines, iedges) - self.trias = self.getMeshTrias(lines, itrias) - self.tetras = self.getMeshTetras(lines, itetras) - self.nameFile = fileName - if args.globalNumerotation == True and withGlobal==True: - self.initFromFileGlobal(fileName, args) - if verbose: - print("\nINFO: initFromFileMesh: read file: %s" % str(self)) - print(self.strResume()) - print(PP.pformat(resumeLines(lines, [iverts, iedges, itrias, itetras]))) - - def initFromFileGlobal(self, fileNameMeshOrGlobal, args): - shortname, extension = os.path.splitext(fileNameMeshOrGlobal) - if extension == ".mesh": - fileName = shortname + ".global" - elif extension == "global": - fileName = fileNameMeshOrGlobal - else: - raise Exception("ERROR: initFromFileGlobal: unexpected file '%s'" % fileName) - if not os.path.isfile(fileName): - raise Exception("ERROR: initFromFileGlobal: inexisting file '%s'" % fileName) - - with open(fileName, "r") as f: - lines = f.readlines() - nbverts, nbedges, nbtrias, nbtetras = [int(i) for i in lines[0].split()] - if verbose: - print("\nINFO: initFromFileGlobal: read file: %s" % str(self)) - print(" nbverts %i\n nbedges %i\n nbtrias %i\n nbtetras %i" % (nbverts, nbedges, nbtrias, nbtetras)) - if nbverts != len(self.verts): - raise Exception("ERROR: in file '%s' unexpected number of Vertices %i<>%i" % (fileName, nbverts, len(self.verts))) - if nbedges != len(self.edges): - raise Exception("ERROR: in file '%s' unexpected number of Edges %i<>%i" % (fileName, nbedges, len(self.edges))) - if nbtrias != len(self.trias): - raise Exception("ERROR: in file '%s' unexpected number of Triangles %i<>%i" % (fileName, nbtrias, len(self.trias))) - if nbtetras != len(self.tetras): - raise Exception("ERROR: in file '%s' unexpected number of Tetrahedra %i<>%i" % (fileName, nbtetras, len(self.tetras))) - i = 1 #begin index line 1 - for ii in range(nbverts): - self.verts[ii].indexglobal = long(lines[i]) - i +=1 - for ii in range(nbedges): - self.edges[ii].indexglobal = long(lines[i]) - i +=1 - for ii in range(nbtrias): - self.trias[ii].indexglobal = long(lines[i]) - i +=1 - for ii in range(nbtetras): - self.tetras[ii].indexglobal = long(lines[i]) - i +=1 - - - def __repr__(self): - return "XXMesh(nameFile='%s', nbverts=%i, nbedges=%i, nbtrias=%i, nbtetras=%i)" % \ - (self.nameFile, len(self.verts), len(self.edges), len(self.trias), len(self.tetras)) - - def strResume(self): - res = str(self) - contents = { - "Vertices": resumeList(self.verts), - "Edges": resumeList(self.edges), - "Triangles": resumeList(self.trias), - "Tetrahedra": resumeList(self.tetras), - } - res = res + "\n" + PP.pformat(contents) - return res - - def getIndexInMeshFile(self, lines): - res = [] - for s in ["Vertices", "Edges", "Triangles", "Tetrahedra"]: - try: - i = lines.index(s+"\n") - except: - i = None - res.append(i) - return res - - def getMeshVerts(self, lines, i): - res=[] - try: - idep = i+2 - ilen = int(lines[i+1]) - ifin = idep+ilen - for line in lines[idep:ifin]: - li = line.split(" ") - x, y, z, color = float(li[0]), float(li[1]), float(li[2]), int(li[3]) - res.append(XXVert(x, y, z, color)) - return res - except: - return res - - def getMeshEdges(self, lines, i): - res=[] - try: - idep = i+2 - ilen = int(lines[i+1]) - ifin = idep+ilen - for line in lines[idep:ifin]: - li = line.split(" ") - a, b, color = int(li[0]), int(li[1]), int(li[2]) - res.append(XXEdge(a, b, color)) - return res - except: - return res - - def getMeshTrias(self, lines, i): - res=[] - try: - idep = i+2 - ilen = int(lines[i+1]) - ifin = idep+ilen - for line in lines[idep:ifin]: - li = line.split(" ") - a, b, c, color = int(li[0]), int(li[1]), int(li[2]), int(li[3]) - res.append(XXTria(a, b, c, color)) - return res - except: - return res - - def getMeshTetras(self, lines, i): - res=[] - try: - idep = i+2 - ilen = int(lines[i+1]) - ifin = idep+ilen - for line in lines[idep:ifin]: - li = line.split(" ") - a, b, c, d, color = int(li[0]), int(li[1]), int(li[2]), int(li[3]), int(li[4]) - res.append(XXTetra(a, b, c, d, color)) - return res - except: - return res - - def haveVertsDistinct(self, args): - """stop a first KO""" - i = 0 - verts = self.verts - for v1 in verts[:-1]: - i += 1 - j = i - for v2 in verts[i:]: - j += 1 - if v1.compare(v2, args): - #printing indices 1 to n - print("ERROR: %s vert[%i] equal vert[%i]: v1=%s v2=%s" % (self.nameFile, i, j, v1, v2)) - return KO + " ERROR: %s some equal vertices" % self.nameFile #stop a first KO - return OK + " INFO: no equal vertices" - - def getVertices(self, elem): - """functionnal raccourci to XXElem.getVertices(XXMesh)""" - return elem.getVertices(self) - - def compareListOfVertices(self, v1s, v2s, ordered=False): - """not ordered for now""" - if ordered: - res = [i for i, j in zip(v1s, v2s) if i == j] - return len(res)==len(v1s) - else: - res = 0 - for i in v1s: - for j in v2s: - if i == j: - res += 1 - break - return res==len(v1s) - - - def getCommonVerts(self, mesh, args): - res = [] - for v1 in self.verts: - for v2 in mesh.verts: - if v1.compare(v2, args, withAll=False): - res.append((v1, v2)) - return res - - def getVertices(self, elem): - return elem.getVertices(self) - - def getCommonEdges(self, mesh, args): - res = [] - for e1 in self.edges: - v1s = self.getVertices(e1) - for e2 in mesh.edges: - v2s = mesh.getVertices(e2) - if self.compareListOfVertices(v1s, v2s): - res.append((e1, e2)) - return res - - def getCommonTriangles(self, mesh, args): - res = [] - for e1 in self.trias: - v1s = self.getVertices(e1) - for e2 in mesh.trias: - v2s = mesh.getVertices(e2) - if self.compareListOfVertices(v1s, v2s): - res.append((e1, e2)) - return res - - def getCommonTetras(self, mesh, args): - res = [] - for e1 in self.tetras: - v1s = self.getVertices(e1) - for e2 in mesh.tetras: - v2s = mesh.getVertices(e2) - if self.compareListOfVertices(v1s, v2s): - res.append((e1, e2)) - return res - - def areEdgesInTrias(self, args): - """stop a first KO""" - done = False - i = 0 - edges = self.edges - trias = self.trias - res = OK + " INFO: %s all edges in trias" % self.nameFile - for e in edges: - i += 1 - j = 0 - found = False - for t in trias: - j += 1 - if e.inTria(t, args): - #if verbose: print("INFO: %s edges[%i] in trias[%i]: edge=%s tria=%s" % (self.nameFile, i, j, e, t)) - found = True - break - if not found: - print("ERROR: %s edges[%i] not in trias: edge=%s" % (self.nameFile, i, e)) - if verbose and not done: - print("Triangles:\n%s" % PP.pformat(self.trias)) - done = True - res = KO+" ERROR: %s some edges not in trias" % (self.nameFile) - return res - - - def areTriasInTetras(self, args): - """no stop a first KO""" - done = False - i = 0 - trias = self.trias + if i != None: # if not existing tetrahedra for example + resi = [ii.strip("\n") for ii in aList[i:i + 4]] + resi.append("...") + res.append(resi) + return res + + +######################################### +class XXVert: + """Vertices, Nodes""" + def __init__(self, x, y, z, color=0, indexglobal=0): + self.x = x + self.y = y + self.z = z + self.color = color + self.indexglobal = indexglobal + + def compare(self, vb, args, withAll=True): + if self.x != vb.x: return False + if self.y != vb.y: return False + if self.z != vb.z: return False + if withAll: + if args.withColor: + if self.color != vb.color: return False + if args.withIndex: + if self.indexglobal != vb.indexglobal: return False + return True + + def __eq__(self, vb): + """equality test without color or indexglobal""" + # print "vertice equality" + if self.x != vb.x: return False + if self.y != vb.y: return False + if self.z != vb.z: return False + return True + + def __ne__(self, vb): + """inequality test without color or indexglobal""" + # print "vertice inequality" + if self.x == vb.x and self.y == vb.y and self.z != vb.z: + return True + return False + + def __repr__(self): + return "XXVert(%.4f %.4f %.4f (%i %i))" % \ + (self.x, self.y, self.z, self.color, self.indexglobal) + + def __str__(self): + return "(%s %s %s (%i %i))" % \ + (self.x, self.y, self.z, self.color, self.indexglobal) + + def dist(self, vb): + res = (self.x - vb.x) ** 2 + (self.y - vb.y) ** 2 + (self.z - vb.z) ** 2 + return res ** .5 + + +######################################### +class XXEdge: + """Edges, 2 Nodes""" + def __init__(self, a, b, color=0, indexglobal=0): + self.a = a + self.b = b + self.color = color + self.indexglobal = indexglobal + + def compare(self, eb, args): + res = self.a.compare(eb.a, args) and \ + self.b.compare(eb.b, args) + if res: + if args.withColor: + if self.color != eb.color: return False + if args.withIndex: + if self.indexglobal != eb.indexglobal: return False + return res + + def __repr__(self): + return "XXEdge(%i %i (%i %i))" % \ + (self.a, self.b, self.color, self.indexglobal) + + def __str__(self): + return "(%i %i (%i %i))" % \ + (self.a, self.b, self.color, self.indexglobal) + + def inTria(self, tria, args): + t = [tria.a, tria.b, tria.c] + if not self.a in t: return False + if not self.b in t: return False + return True + + def getVertices(self, mesh): + v1 = mesh.verts[self.a - 1] + v2 = mesh.verts[self.b - 1] + return [v1, v2] + + +######################################### +class XXTria: + """Triangles, Faces, 3 nodes""" + def __init__(self, a, b, c, color=0, indexglobal=0): + self.a = a + self.b = b + self.c = c + self.color = color + self.indexglobal = indexglobal + + def compare(self, trb, args): + res = self.a.compare(trb.a, args) and \ + self.b.compare(trb.b, args) and \ + self.c.compare(trb.c, args) + if res: + if args.withColor: + if self.color != trb.color: return False + if args.withIndex: + if self.indexglobal != trb.indexglobal: return False + return res + + def __repr__(self): + return "XXTria(%i %i %i (%i %i))" % \ + (self.a, self.b, self.c, self.color, self.indexglobal) + + def __str__(self): + return "(%i %i %i (%i %i))" % \ + (self.a, self.b, self.c, self.color, self.indexglobal) + + def inTetra(self, tetra, args): + t = [tetra.a, tetra.b, tetra.c, tetra.d] + if not self.a in t: return False + if not self.b in t: return False + if not self.c in t: return False + return True + + def getVertices(self, mesh): + v1 = mesh.verts[self.a - 1] + v2 = mesh.verts[self.b - 1] + v3 = mesh.verts[self.c - 1] + return [v1, v2, v3] + + +######################################### +class XXTetra: + """Tetra, 4 nodes""" + def __init__(self, a, b, c, d, color=0, indexglobal=0): + self.a = a + self.b = b + self.c = c + self.d = d + self.color = color + self.indexglobal = indexglobal + + def compare(self, teb, args): + res = self.a.compare(teb.a, args) and \ + self.b.compare(teb.b, args) and \ + self.c.compare(teb.c, args) and \ + self.d.compare(teb.d, args) + if res: + if args.withColor: + if self.color != teb.color: return False + if args.withIndex: + if self.indexglobal != teb.indexglobal: return False + return res + + def __repr__(self): + return "XXTetra(%i %i %i %i (%i %i))" % \ + (self.a, self.b, self.c, self.d, self.color, self.indexglobal) + + def __str__(self): + return "(%i %i %i %i (%i %i))" % \ + (self.a, self.b, self.c, self.d, self.color, self.indexglobal) + + def getVertices(self, mesh): + v1 = mesh.verts[self.a - 1] + v2 = mesh.verts[self.b - 1] + v3 = mesh.verts[self.c - 1] + v4 = mesh.verts[self.d - 1] + return [v1, v2, v3, v4] + + +######################################### +class XXMesh: + """Mesh: vertices, edges, triangles, tetrahedra""" + def __init__(self): + self.nameFile = "" + self.verts = [] + self.edges = [] + self.trias = [] + self.tetras = [] + + def initFromFileMesh(self, fileName, args, withGlobal=True): + if not os.path.isfile(fileName): + raise Exception("ERROR: inexisting file '%s'" % fileName) + with open(fileName, "r") as f: + lines = f.readlines() + iverts, iedges, itrias, itetras = self.getIndexInMeshFile(lines) + self.verts = self.getMeshVerts(lines, iverts) + self.edges = self.getMeshEdges(lines, iedges) + self.trias = self.getMeshTrias(lines, itrias) + self.tetras = self.getMeshTetras(lines, itetras) + self.nameFile = fileName + if args.globalNumerotation == True and withGlobal == True: + self.initFromFileGlobal(fileName, args) + if verbose: + print("\nINFO: initFromFileMesh: read file: %s" % str(self)) + print(self.strResume()) + print(PP.pformat(resumeLines(lines, [iverts, iedges, itrias, itetras]))) + + def initFromFileGlobal(self, fileNameMeshOrGlobal, args): + shortname, extension = os.path.splitext(fileNameMeshOrGlobal) + if extension == ".mesh": + fileName = shortname + ".global" + elif extension == "global": + fileName = fileNameMeshOrGlobal + else: + raise Exception("ERROR: initFromFileGlobal: unexpected file '%s'" % fileName) + if not os.path.isfile(fileName): + raise Exception("ERROR: initFromFileGlobal: inexisting file '%s'" % fileName) + + with open(fileName, "r") as f: + lines = f.readlines() + nbverts, nbedges, nbtrias, nbtetras = [int(i) for i in lines[0].split()] + if verbose: + print("\nINFO: initFromFileGlobal: read file: %s" % str(self)) + print(" nbverts %i\n nbedges %i\n nbtrias %i\n nbtetras %i" % (nbverts, nbedges, nbtrias, nbtetras)) + if nbverts != len(self.verts): + raise Exception("ERROR: in file '%s' unexpected number of Vertices %i<>%i" % (fileName, nbverts, len(self.verts))) + if nbedges != len(self.edges): + raise Exception("ERROR: in file '%s' unexpected number of Edges %i<>%i" % (fileName, nbedges, len(self.edges))) + if nbtrias != len(self.trias): + raise Exception("ERROR: in file '%s' unexpected number of Triangles %i<>%i" % (fileName, nbtrias, len(self.trias))) + if nbtetras != len(self.tetras): + raise Exception("ERROR: in file '%s' unexpected number of Tetrahedra %i<>%i" % (fileName, nbtetras, len(self.tetras))) + i = 1 # begin index line 1 + for ii in range(nbverts): + self.verts[ii].indexglobal = int(lines[i]) + i += 1 + for ii in range(nbedges): + self.edges[ii].indexglobal = int(lines[i]) + i += 1 + for ii in range(nbtrias): + self.trias[ii].indexglobal = int(lines[i]) + i += 1 + for ii in range(nbtetras): + self.tetras[ii].indexglobal = int(lines[i]) + i += 1 + + + def __repr__(self): + return "XXMesh(nameFile='%s', nbverts=%i, nbedges=%i, nbtrias=%i, nbtetras=%i)" % \ + (self.nameFile, len(self.verts), len(self.edges), len(self.trias), len(self.tetras)) + + def strResume(self): + res = str(self) + contents = { + "Vertices": resumeList(self.verts), + "Edges": resumeList(self.edges), + "Triangles": resumeList(self.trias), + "Tetrahedra": resumeList(self.tetras), + } + res = res + "\n" + PP.pformat(contents) + return res + + def getIndexInMeshFile(self, lines): + res = [] + for s in ["Vertices", "Edges", "Triangles", "Tetrahedra"]: + try: + i = lines.index(s + "\n") + except: + i = None + res.append(i) + return res + + def getMeshVerts(self, lines, i): + res = [] + try: + idep = i + 2 + ilen = int(lines[i + 1]) + ifin = idep + ilen + for line in lines[idep:ifin]: + li = line.split(" ") + x, y, z, color = float(li[0]), float(li[1]), float(li[2]), int(li[3]) + res.append(XXVert(x, y, z, color)) + return res + except: + return res + + def getMeshEdges(self, lines, i): + res = [] + try: + idep = i + 2 + ilen = int(lines[i + 1]) + ifin = idep + ilen + for line in lines[idep:ifin]: + li = line.split(" ") + a, b, color = int(li[0]), int(li[1]), int(li[2]) + res.append(XXEdge(a, b, color)) + return res + except: + return res + + def getMeshTrias(self, lines, i): + res = [] + try: + idep = i + 2 + ilen = int(lines[i + 1]) + ifin = idep + ilen + for line in lines[idep:ifin]: + li = line.split(" ") + a, b, c, color = int(li[0]), int(li[1]), int(li[2]), int(li[3]) + res.append(XXTria(a, b, c, color)) + return res + except: + return res + + def getMeshTetras(self, lines, i): + res = [] + try: + idep = i + 2 + ilen = int(lines[i + 1]) + ifin = idep + ilen + for line in lines[idep:ifin]: + li = line.split(" ") + a, b, c, d, color = int(li[0]), int(li[1]), int(li[2]), int(li[3]), int(li[4]) + res.append(XXTetra(a, b, c, d, color)) + return res + except: + return res + + def haveVertsDistinct(self, args): + """stop a first KO""" + i = 0 + verts = self.verts + for v1 in verts[:-1]: + i += 1 + j = i + for v2 in verts[i:]: + j += 1 + if v1.compare(v2, args): + # printing indices 1 to n + print("ERROR: %s vert[%i] equal vert[%i]: v1=%s v2=%s" % (self.nameFile, i, j, v1, v2)) + return KO + " ERROR: %s some equal vertices" % self.nameFile # stop a first KO + return OK + " INFO: no equal vertices" + + def getVertices(self, elem): + """functionnal raccourci to XXElem.getVertices(XXMesh)""" + return elem.getVertices(self) + + def compareListOfVertices(self, v1s, v2s, ordered=False): + """not ordered for now""" + if ordered: + res = [i for i, j in zip(v1s, v2s) if i == j] + return len(res) == len(v1s) + else: + res = 0 + for i in v1s: + for j in v2s: + if i == j: + res += 1 + break + return res == len(v1s) + + + def getCommonVerts(self, mesh, args): + res = [] + for v1 in self.verts: + for v2 in mesh.verts: + if v1.compare(v2, args, withAll=False): + res.append((v1, v2)) + return res + + def getCommonEdges(self, mesh, args): + res = [] + for e1 in self.edges: + v1s = self.getVertices(e1) + for e2 in mesh.edges: + v2s = mesh.getVertices(e2) + if self.compareListOfVertices(v1s, v2s): + res.append((e1, e2)) + return res + + def getCommonTriangles(self, mesh, args): + res = [] + for e1 in self.trias: + v1s = self.getVertices(e1) + for e2 in mesh.trias: + v2s = mesh.getVertices(e2) + if self.compareListOfVertices(v1s, v2s): + res.append((e1, e2)) + return res + + def getCommonTetras(self, mesh, args): + res = [] + for e1 in self.tetras: + v1s = self.getVertices(e1) + for e2 in mesh.tetras: + v2s = mesh.getVertices(e2) + if self.compareListOfVertices(v1s, v2s): + res.append((e1, e2)) + return res + + def areEdgesInTrias(self, args): + """stop a first KO""" + done = False + i = 0 + edges = self.edges + trias = self.trias + res = OK + " INFO: %s all edges in trias" % self.nameFile + for e in edges: + i += 1 + j = 0 + found = False + for t in trias: + j += 1 + if e.inTria(t, args): + # if verbose: print("INFO: %s edges[%i] in trias[%i]: edge=%s tria=%s" % (self.nameFile, i, j, e, t)) + found = True + break + if not found: + print("ERROR: %s edges[%i] not in trias: edge=%s" % (self.nameFile, i, e)) + if verbose and not done: + print("Triangles:\n%s" % PP.pformat(self.trias)) + done = True + res = KO + " ERROR: %s some edges not in trias" % (self.nameFile) + return res + + + def areTriasInTetras(self, args): + """no stop a first KO""" + done = False + i = 0 + trias = self.trias tetras = self.tetras - if tetras == []: #supposed skin without tetrahedra - res = OK +" WARNING: %s no tetrahedra in mesh" % (self.nameFile) - return res - res = OK + " INFO: %s all trias in tetras" % self.nameFile - for t in trias: - i += 1 - j = 0 - found = False - for h in tetras: - j += 1 - if t.inTetra(h, args): - #if verbose: print("INFO: %s trias[%i] in tetras[%i]: tria=%s tetra=%s" % (self.nameFile, i, j, t, h)) - found = True - break - if not found: - if verbose: print("ERROR: %s trias[%i] not in tetras: tria=%s" % (self.nameFile, i, t)) - if verbose and not done: - print("INFO: Tetrahedra:\n%s" % PP.pformat(self.tetras)) - done = True - res = KO+" ERROR: %s some trias not in tetras" % (self.nameFile) - return res - - def testIntersection(self, mesh, args): - """intersection coherency between self and mesh""" - - def storeAndInfoIntersection(): - """used as macro: avoid duplicate code""" - #store info in args to use later... - args.intersections[title+name] = commons - if commons == []: - res.append(OK + " INFO: no %s" % title+name) - else: - res.append(OK + " INFO: existing %s" % title+name) - return - - res=[] - name = "%s<->%s" % (self.nameFile, mesh.nameFile) - - title = "Vertices intersection: " - commons = self.getCommonVerts(mesh, args) - storeAndInfoIntersection() - - title = "Edges intersection: " - commons = self.getCommonEdges(mesh, args) - storeAndInfoIntersection() - - title = "Triangles intersection: " - commons = self.getCommonTriangles(mesh, args) - storeAndInfoIntersection() - - title = "Tetrahedra intersection: " - commons = self.getCommonTetras(mesh, args) - storeAndInfoIntersection() - - return res - - def testIndexGlobal(self, mesh, args): - """global index coherency between self and mesh""" - - def storeAndInfoIndexGlobal(): - """used as macro: avoid duplicate code""" - #store info in args to use later... - args.indexglobal[title+name] = problems - if verbose: print("\nINFO: %s\n%s" % (title+name, PP.pformat(problems))) - if problems == []: - res.append(OK + " INFO: coherent %s" % title+name) - else: - res.append(KO + " ERROR: some problems %s" % title+name) - return - - def testIndexGlobal(): - """used as macro: avoid duplicate code""" - nameElem = title.split(' ')[0] - #something like 'Vertices intersection: /tmp/GHS3DPRL_out.000002.mesh<->/tmp/GHS3DPRL_out.000003.mesh' - commonsTitle = nameElem + " intersection: "+ name - #if verbose: print "testIndexGlobal",title,commonsTitle - try: - intersection = args.intersections[commonsTitle] - except: - intersection = [] - problems = [] - for ii, jj in intersection: - if ii.indexglobal != jj.indexglobal: - problems.append((ii, jj)) - return problems - - res=[] - name = "%s<->%s" % (self.nameFile, mesh.nameFile) - - title = "Vertices indexglobal: " - problems = testIndexGlobal() - storeAndInfoIndexGlobal() - - title = "Edges indexglobal: " - problems = testIndexGlobal() - storeAndInfoIndexGlobal() - - title = "Triangles indexglobal: " - problems = testIndexGlobal() - storeAndInfoIndexGlobal() - - title = "Tetrahedra indexglobal: " - problems = testIndexGlobal() - storeAndInfoIndexGlobal() - - return res - - -######################################### -# tests - + if tetras == []: # supposed skin without tetrahedra + res = OK + " WARNING: %s no tetrahedra in mesh" % (self.nameFile) + return res + res = OK + " INFO: %s all trias in tetras" % self.nameFile + for t in trias: + i += 1 + j = 0 + found = False + for h in tetras: + j += 1 + if t.inTetra(h, args): + # if verbose: print("INFO: %s trias[%i] in tetras[%i]: tria=%s tetra=%s" % (self.nameFile, i, j, t, h)) + found = True + break + if not found: + if verbose: print("ERROR: %s trias[%i] not in tetras: tria=%s" % (self.nameFile, i, t)) + if verbose and not done: + print("INFO: Tetrahedra:\n%s" % PP.pformat(self.tetras)) + done = True + res = KO + " ERROR: %s some trias not in tetras" % (self.nameFile) + return res + + def testIntersection(self, mesh, args): + """intersection coherency between self and mesh""" + + def storeAndInfoIntersection(): + """used as macro: avoid duplicate code""" + # store info in args to use later... + args.intersections[title + name] = commons + if commons == []: + res.append(OK + " INFO: no %s" % title + name) + else: + res.append(OK + " INFO: existing %s" % title + name) + return + + res = [] + name = "%s<->%s" % (self.nameFile, mesh.nameFile) + + title = "Vertices intersection: " + commons = self.getCommonVerts(mesh, args) + storeAndInfoIntersection() + + title = "Edges intersection: " + commons = self.getCommonEdges(mesh, args) + storeAndInfoIntersection() + + title = "Triangles intersection: " + commons = self.getCommonTriangles(mesh, args) + storeAndInfoIntersection() + + title = "Tetrahedra intersection: " + commons = self.getCommonTetras(mesh, args) + storeAndInfoIntersection() + + return res + + def testIndexGlobal(self, mesh, args): + """global index coherency between self and mesh""" + + def storeAndInfoIndexGlobal(): + """used as macro: avoid duplicate code""" + # store info in args to use later... + args.indexglobal[title + name] = problems + if verbose: print("\nINFO: %s\n%s" % (title + name, PP.pformat(problems))) + if problems == []: + res.append(OK + " INFO: coherent %s" % title + name) + else: + res.append(KO + " ERROR: some problems %s" % title + name) + return + + def testIndexGlobal(): + """used as macro: avoid duplicate code""" + nameElem = title.split(' ')[0] + # something like 'Vertices intersection: /tmp/GHS3DPRL_out.000002.mesh<->/tmp/GHS3DPRL_out.000003.mesh' + commonsTitle = nameElem + " intersection: " + name + # if verbose: print "testIndexGlobal",title,commonsTitle + try: + intersection = args.intersections[commonsTitle] + except: + intersection = [] + problems = [] + for ii, jj in intersection: + if ii.indexglobal != jj.indexglobal: + problems.append((ii, jj)) + return problems + + res = [] + name = "%s<->%s" % (self.nameFile, mesh.nameFile) + + title = "Vertices indexglobal: " + problems = testIndexGlobal() + storeAndInfoIndexGlobal() + + title = "Edges indexglobal: " + problems = testIndexGlobal() + storeAndInfoIndexGlobal() + + title = "Triangles indexglobal: " + problems = testIndexGlobal() + storeAndInfoIndexGlobal() + + title = "Tetrahedra indexglobal: " + problems = testIndexGlobal() + storeAndInfoIndexGlobal() + + return res + + +######################################### +# tests + def testAll(args): - """test all on meshes from tetra_hpc_mpi""" - res = [] + """test all on meshes from tetra_hpc_mpi""" + res = [] if verbose: print("\n*****testAll*****\n") args.skinMesh = None if args.skinInputFile != None: args.skinMesh = XXMesh() - #a priori no global numerotation file.global for input tetra_hpc_mpi mesh + # a priori no global numerotation file.global for input tetra_hpc_mpi mesh args.skinMesh.initFromFileMesh(args.skinInputFile, args, withGlobal=False) res.append(testStandaloneMesh(args.skinMesh, args)) - print("\nINFO: testAll skin input file:\n%s" % (PP.pformat(args.skinMesh))) - - meshes = [] - for fileName in args.files: - xxmesh = XXMesh() - xxmesh.initFromFileMesh(fileName, args) - meshes.append(xxmesh) - print("\nINFO: testAll ouput files:\n%s\n" % (PP.pformat(meshes))) - #test coherence of one by one meshes - for mesh in meshes: - res.append(testStandaloneMesh(mesh, args)) - #test coherence of intersections an global numerotation of tetra_hpc_mpi output meshes + print("\nINFO: testAll skin input file:\n%s" % (PP.pformat(args.skinMesh))) + + meshes = [] + for fileName in args.files: + xxmesh = XXMesh() + xxmesh.initFromFileMesh(fileName, args) + meshes.append(xxmesh) + print("\nINFO: testAll ouput files:\n%s\n" % (PP.pformat(meshes))) + # test coherence of one by one meshes + for mesh in meshes: + res.append(testStandaloneMesh(mesh, args)) + # test coherence of intersections an global numerotation of tetra_hpc_mpi output meshes res.append(testParallelMesh(meshes, args)) - res.append(testParallelMeshAndSkin(meshes, args)) - res.append(testParallelMeshAndSkinColor(meshes, args)) - return res + res.append(testParallelMeshAndSkin(meshes, args)) + res.append(testParallelMeshAndSkinColor(meshes, args)) + return res + - def testStandaloneMesh(mesh, args): - """test coherence of one mesh alone""" - if verbose: print("\nINFO: testStandaloneMesh:\n%s" % PP.pformat(mesh)) - res = [] - res.append(mesh.haveVertsDistinct(args)) - res.append(mesh.areEdgesInTrias(args)) - res.append(mesh.areTriasInTetras(args)) - return res - - -def testParallelMesh(meshes, args): - """test intersection and overriding in tetra_hpc_mpi outputs GHS3DPRL_out.00000?.mesh""" - i = 0 - res = [] - args.intersections = {} - args.indexglobal = {} - for m1 in meshes[:-1]: - i += 1 - for m2 in meshes[i:]: - res.append(m1.testIntersection(m2, args)) - res.append(m1.testIndexGlobal(m2, args)) - if verbose: - print("\nINFO: intersections\n%s" % PP.pformat(args.intersections)) - print("\nINFO: indexglobal\n%s" % PP.pformat(args.indexglobal)) - return res - -def testParallelMeshAndSkin(meshes, args): - """test coherency between input skin and tetra_hpc_mpi outputs GHS3DPRL_out.00000?.mesh""" - res = [] + """test coherence of one mesh alone""" + if verbose: print("\nINFO: testStandaloneMesh:\n%s" % PP.pformat(mesh)) + res = [] + res.append(mesh.haveVertsDistinct(args)) + res.append(mesh.areEdgesInTrias(args)) + res.append(mesh.areTriasInTetras(args)) + return res + + +def testParallelMesh(meshes, args): + """test intersection and overriding in tetra_hpc_mpi outputs GHS3DPRL_out.00000?.mesh""" + i = 0 + res = [] + args.intersections = {} + args.indexglobal = {} + for m1 in meshes[:-1]: + i += 1 + for m2 in meshes[i:]: + res.append(m1.testIntersection(m2, args)) + res.append(m1.testIndexGlobal(m2, args)) + if verbose: + print("\nINFO: intersections\n%s" % PP.pformat(args.intersections)) + print("\nINFO: indexglobal\n%s" % PP.pformat(args.indexglobal)) + return res + +def testParallelMeshAndSkin(meshes, args): + """test coherency between input skin and tetra_hpc_mpi outputs GHS3DPRL_out.00000?.mesh""" + res = [] if args.skinMesh == None: print("INFO: no skin Mesh for testing intersectionsSkin\n") res = OK + "INFO: no skin Mesh for testing intersectionsSkin" return res - nbtriasskin = len(args.skinMesh.trias) - for m1 in meshes: - res.append(args.skinMesh.testIntersection(m1, args)) + nbtriasskin = len(args.skinMesh.trias) + for m1 in meshes: + res.append(args.skinMesh.testIntersection(m1, args)) res.append(args.skinMesh.testIndexGlobal(m1, args)) - - #test total Triangles in output parallel meshes vs input skin mesh + + # test total Triangles in output parallel meshes vs input skin mesh if True: - kk = {} + kk = {} nbtriaspara = 0 - for k in args.intersections.keys(): + for k in list(args.intersections.keys()): if args.skinMesh.nameFile in k: ll = len(args.intersections[k]) - if "Triangles intersection" in k: + if "Triangles intersection" in k: nbtriaspara += ll - kk[k] = len(args.intersections[k]) - print("INFO: skin intersections\n%s\n" % PP.pformat(kk)) + kk[k] = len(args.intersections[k]) + print("INFO: skin intersections\n%s\n" % PP.pformat(kk)) if nbtriaspara < nbtriasskin: - res.append(KO + " ERROR: problem all skin triangles not in parallel meshes: %i<->%i" % (nbtriasskin, nbtriaspara)) - return res + res.append(KO + " ERROR: problem all skin triangles not in parallel meshes: %i<->%i" % (nbtriasskin, nbtriaspara)) + return res -def testParallelMeshAndSkinColor(meshes, args): +def testParallelMeshAndSkinColor(meshes, args): """test coherency between color input skin and tetra_hpc_mpi outputs GHS3DPRL_out.00000?.mesh""" res = [] - if args.color == True: + if args.color == True: res.append(KO + " ERROR: test color TODO!!!") else: res.append(OK + " WARNING: test color not done") - return res - -if __name__ == '__main__': - parser = AP.ArgumentParser(description='launch test(s) on tetra_hpc_mpi mesh(es)', argument_default=None) - parser.add_argument( - '-a', '--testAll', - help='test all on all meshes', - action='store_true', - ) - parser.add_argument( - '-v', '--verbose', - help='set verbose, for deep debug', - action='store_true', - ) - parser.add_argument( - '-g', '--globalNumerotation', - help='read and set files .global, if associated', - action='store_true', - ) - parser.add_argument( - '-c', '--color', - help='read and test with color', - action='store_true', - ) - parser.add_argument( - '-f', '--files', - help='launch test(s) on file(s)', - nargs='*', - metavar='.../file.mesh' - ) - parser.add_argument( - '-s', '--skinInputFile', - help='launch test(s) on tetra_hpc_mpi input file', - nargs='?', - metavar='.../skinInputFile.mesh' - ) - """ - parser.add_argument( - '-x', '--xoneargument', - nargs='?', - metavar='0|1', - choices=['0', '1'], - help='one argument, for example', - default='0' - ) - """ - - + return res + +if __name__ == '__main__': + parser = AP.ArgumentParser(description='launch test(s) on tetra_hpc_mpi mesh(es)', argument_default=None) + parser.add_argument( + '-a', '--testAll', + help='test all on all meshes', + action='store_true', + ) + parser.add_argument( + '-v', '--verbose', + help='set verbose, for deep debug', + action='store_true', + ) + parser.add_argument( + '-g', '--globalNumerotation', + help='read and set files .global, if associated', + action='store_true', + ) + parser.add_argument( + '-c', '--color', + help='read and test with color', + action='store_true', + ) + parser.add_argument( + '-f', '--files', + help='launch test(s) on file(s)', + nargs='*', + metavar='.../file.mesh' + ) + parser.add_argument( + '-s', '--skinInputFile', + help='launch test(s) on tetra_hpc_mpi input file', + nargs='?', + metavar='.../skinInputFile.mesh' + ) + """ + parser.add_argument( + '-x', '--xoneargument', + nargs='?', + metavar='0|1', + choices=['0', '1'], + help='one argument, for example', + default='0' + ) + """ + + """ - args is Namespace, use it as global to store + args is Namespace, use it as global to store parameters, data, used arrays and results and other... - """ + """ args = parser.parse_args() - - verbose = args.verbose - if verbose: print("INFO: args:\n%s" % PP.pformat(args)) - - if len(sys.argv) == 1: #no args as --help - parser.print_help() - sys.exit(KOSYS) - - if args.files == None: - print("\nERROR: Nothing to do: no files\n%s" % PP.pformat(args)) - parser.print_help() - sys.exit(KOSYS) - - if args.testAll: - result = testAll(args) - else: - result = KO - print("\nERROR: Nothing to do:\n%s" % PP.pformat(args)) - sys.exit(okToSys(result, verbose=True)) - + + verbose = args.verbose + if verbose: print("INFO: args:\n%s" % PP.pformat(args)) + + if len(sys.argv) == 1: # no args as --help + parser.print_help() + sys.exit(KOSYS) + + if args.files == None: + print("\nERROR: Nothing to do: no files\n%s" % PP.pformat(args)) + parser.print_help() + sys.exit(KOSYS) + + if args.testAll: + result = testAll(args) + else: + result = KO + print("\nERROR: Nothing to do:\n%s" % PP.pformat(args)) + sys.exit(okToSys(result, verbose=True)) + diff --git a/src/tools/testMeshTest.py b/src/tools/testMeshTest.py index 4930a55..33288a0 100644 --- a/src/tools/testMeshTest.py +++ b/src/tools/testMeshTest.py @@ -3,74 +3,76 @@ # %% LICENSE_SALOME_CEA_BEGIN # Copyright (C) 2008-2016 CEA/DEN -# +# # 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 # %% LICENSE_END import unittest + import testMesh as TM -from argparse import Namespace - + + verbose = False + class TestCase(unittest.TestCase): - def test_010(self): - self.failUnlessEqual(TM.okToSys([]), TM.KOSYS) - self.failUnlessEqual(TM.okToSys([[]]), TM.KOSYS) - - res = TM.OK + " blah blah 0" - self.failUnlessEqual(TM.okToSys([[res]]), TM.OKSYS) - self.failUnlessEqual(TM.okToSys(res), TM.OKSYS) - res = [res] - self.failUnlessEqual(TM.okToSys(res), TM.OKSYS) - res.append(TM.OK + " blah blah 1") - self.failUnlessEqual(TM.okToSys(res), TM.OKSYS) - res.append([TM.OK + " blah blah 2"]) - self.failUnlessEqual(TM.okToSys(res), TM.OKSYS) - res.append([TM.KO + " blah blah 3"]) - self.failUnlessEqual(TM.okToSys(res), TM.KOSYS) - self.failUnlessEqual(TM.okToSys([]), TM.KOSYS) - res = [[[res]],[TM.OK + " blah blah 4"],[]] - self.failUnlessEqual(TM.okToSys(res), TM.KOSYS) - - def test_030(self): - a = TM.XXVert(1, 1, 1) - b = TM.XXVert(2, 2, 2) - c = TM.XXVert(1., 1., 1., 3, 4) - self.failUnlessEqual(a==c, True) - - from argparse import Namespace - args = Namespace(withColor=True, withIndex=True) - self.failUnlessEqual(a.compare(c, args, withAll=True), False) - self.failUnlessEqual(a.compare(c, args, withAll=False), True) - - args = Namespace(withColor=False, withIndex=False) - self.failUnlessEqual(a.compare(c, args, withAll=True), True) - - self.failUnlessEqual(a==b, False) - self.failUnlessEqual(a.dist(b), 3**.5) - - self.failUnlessEqual(str(c), '(1.0 1.0 1.0 (3 4))') - self.failUnlessEqual(c.__repr__(), 'XXVert(1.0000 1.0000 1.0000 (3 4))') + def test_010(self): + self.assertEqual(TM.okToSys([]), TM.KOSYS) + self.assertEqual(TM.okToSys([[]]), TM.KOSYS) + + res = TM.OK + " blah blah 0" + self.assertEqual(TM.okToSys([[res]]), TM.OKSYS) + self.assertEqual(TM.okToSys(res), TM.OKSYS) + res = [res] + self.assertEqual(TM.okToSys(res), TM.OKSYS) + res.append(TM.OK + " blah blah 1") + self.assertEqual(TM.okToSys(res), TM.OKSYS) + res.append([TM.OK + " blah blah 2"]) + self.assertEqual(TM.okToSys(res), TM.OKSYS) + res.append([TM.KO + " blah blah 3"]) + self.assertEqual(TM.okToSys(res), TM.KOSYS) + self.assertEqual(TM.okToSys([]), TM.KOSYS) + res = [[[res]], [TM.OK + " blah blah 4"], []] + self.assertEqual(TM.okToSys(res), TM.KOSYS) + + def test_030(self): + a = TM.XXVert(1, 1, 1) + b = TM.XXVert(2, 2, 2) + c = TM.XXVert(1., 1., 1., 3, 4) + self.assertEqual(a == c, True) + + from argparse import Namespace + args = Namespace(withColor=True, withIndex=True) + self.assertEqual(a.compare(c, args, withAll=True), False) + self.assertEqual(a.compare(c, args, withAll=False), True) + + args = Namespace(withColor=False, withIndex=False) + self.assertEqual(a.compare(c, args, withAll=True), True) + + self.assertEqual(a == b, False) + self.assertEqual(a.dist(b), 3 ** .5) + + self.assertEqual(str(c), '(1.0 1.0 1.0 (3 4))') + self.assertEqual(c.__repr__(), 'XXVert(1.0000 1.0000 1.0000 (3 4))') if __name__ == '__main__': - verbose = False - unittest.main() - pass + verbose = False + unittest.main() + pass -- 2.30.2