1 # -*- coding: utf-8 -*-
15 import MEDLoader as ml
16 import MEDCoupling as mc
18 # Get current study id
20 theStudy = salome.myStudy
21 theStudyId = salome.myStudyId
23 class BadParamsError(ValueError):
24 """Bad parameters exception"""
28 def assignStrickler(nomCas, input_file_name, output_file_name="", med_field_name='BOTTOM FRICTION', verbose=False):
30 assignStrickler creates the scalar field associated with the mesh of the calculation case that
31 represents the Strickler coefficient of the land cover.
34 nomCas: Calculation Case Name in module HYDRO
35 input_file_name: med file name corresponding to the HYDRO case
36 output_file_name: med file name with the Strickler coefficient; default is the same as fichierMaillage
37 med_field_name: name of the field of the Strickler coefficient
38 default value is 'BOTTOM FRICTION'.
47 print "nomCas:", nomCas
48 print "input_file_name:", input_file_name
49 print "output_file_name:", output_file_name
50 print "med_field_name:", med_field_name
53 # 1.1. Check calculation case
54 doc = HYDROPy.HYDROData_Document.Document(theStudyId)
55 case = doc.FindObjectByName(nomCas)
57 raise BadParamsError("Calculation case '%s' not found" % nomCas)
59 # 1.2. Check input MED file
60 if not os.path.exists(input_file_name):
61 raise BadParamsError("Input file '%s' not exists" % input_file_name)
64 # 2.1. If output MED file is not defined, it is equal to the input file
65 if not output_file_name:
66 output_file_name = input_file_name
68 # 2.2. Copy input file to the output path, if the output path is different from the input path
69 if output_file_name != input_file_name:
71 shutil.copyfile(input_file_name, output_file_name)
75 meshMEDFileRead = ml.MEDFileMesh.New(output_file_name)
77 # 4. Gets the information about the nodes
79 nbnodes = meshMEDFileRead.getNumberOfNodes()
81 print "Number of nodes: %d" % nbnodes
83 coords = meshMEDFileRead.getCoords()
84 #print "coords =\n", coords
86 # 5. Calculation of the Strickler coefficient
88 x_coords = coords[:, 0]
89 y_coords = coords[:, 1]
90 #print "x_coords =\n", x_coords
91 #print "y_coords =\n", y_coords
92 values = case.GetStricklerCoefficientForPoints(x_coords, y_coords, 0.0, True)
96 coeff = mc.DataArrayDouble(np.asfarray(values, dtype='float'))
97 coeff.setInfoOnComponents(["Strickler [SI]"])
98 #print "coeff =\n", coeff
100 print ".. Ecriture du Strickler sous le nom '"+med_field_name+"'"
101 fieldOnNodes = ml.MEDCouplingFieldDouble(ml.ON_NODES)
102 fieldOnNodes.setName(med_field_name)
103 fieldOnNodes.setMesh(meshMEDFileRead.getMeshAtLevel(0))
104 fieldOnNodes.setArray(coeff)
105 # Ces valeurs d'instants sont mises pour assurer la lecture par TELEMAC
107 # numero d'itération : 0
108 # pas de numero d'ordre (-1)
109 fieldOnNodes.setTime(0.0, 0, -1)
111 fMEDFile_ch_d = ml.MEDFileField1TS()
112 fMEDFile_ch_d.setFieldNoProfileSBT(fieldOnNodes)
113 fMEDFile_ch_d.write(output_file_name, 0)