From: asl Date: Tue, 11 Oct 2016 08:18:15 +0000 (+0300) Subject: generation of the interpolZ script X-Git-Tag: v1.6~18 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f0a15c050e758043b1e4e374f5685fb766855ece;p=modules%2Fhydrosolver.git generation of the interpolZ script --- diff --git a/src/salome_hydro/generate_interpolz.py b/src/salome_hydro/generate_interpolz.py new file mode 100644 index 0000000..8879667 --- /dev/null +++ b/src/salome_hydro/generate_interpolz.py @@ -0,0 +1,44 @@ + +def replace( lines, pattern, subst ): + for i in range( 0, len( lines ) ): + line = lines[i] + if pattern in lines[i]: + if isinstance( subst, list ): + del lines[i] + for s in subst: + new_line = line.replace( pattern, repr(s) ) + lines.insert( i, new_line ) + elif isinstance( subst, dict ): + del lines[i] + name = pattern[1:-1] + lines.insert( i, "%s = {}\n" % name ) + keys = subst.keys() + keys.sort() + i = i+1 + for k in keys: + v = subst[k] + lines.insert( i, "%s[%s] = %s\n" % (name, repr(k), repr(v) ) ) + i = i+1 + else: + new_line = line.replace( pattern, repr(subst) ) + lines[i] = new_line + + +def generate( path, calc_case, med_file, med_groups_regions, z_undef, interp ): + f = open( path, "w" ) + tf = open( "interpolz.template", "r" ) + templ = tf.readlines() + + replace( templ, "", calc_case ) + replace( templ, "", med_file ) + replace( templ, "", med_groups_regions ) + replace( templ, "", z_undef ) + replace( templ, "", interp ) + + for line in templ: + f.write( line ) + f.close() + + + +generate( "test_interpolz.py", "case_1", "mesh.med", {"group_1":"reg_1", "group_2":"reg_2"}, -9999, "linear" ) diff --git a/src/salome_hydro/interpolz.template b/src/salome_hydro/interpolz.template new file mode 100644 index 0000000..1596f43 --- /dev/null +++ b/src/salome_hydro/interpolz.template @@ -0,0 +1,21 @@ +”””Z interpolation with HYDRO””” + +from salome.hydrotools.interpolZ import interpolZ + +# Calculation case name in HYDRO +caseName = + +# MED file 2D(x,y) of the case produced by SMESH +medFile = + +# Dictionary [med group name] = region name + + +# Value to use for Z when the node is not in a region (used to detect problems) +zUndef = + +# Interpolation method +interpolMethod = + +# Z interpolation on the bathymetry/altimetry on the mesh nodes +statZ = interpolZ(caseName, medFile, dictGroupRegion, zUndef,interpolMethod)