def dumpVtk(filename, grid, scalars, vectors, D, structured="auto"): """ Write data to file. If structured="yes" then structured gird will be used; if structure="no" then unstructured grid will be used; if structured="auto" then structured grid will be used if "grid" form a cubic lattice (see listR.listFormCubicLattice for info on cubic lattice). """ # setup grid structured = structured.lower(); if structured == "yes": use_structured_grid = True; if structured == "no": use_structured_grid = False; if structured == "auto": form_lattice_D = listFormCubicLatticeD(grid); use_structured_grid = form_lattice_D["answer"]; if use_structured_grid == False: # unstructured grid; simple grid_cmd = "UnstructuredGrid(grid)"; else: # structured grid; more labor [grid, permutation] = tracedSort(grid); # sort it so x changes 1st, y changes 2nd, etc scalars = [applyOrderList(permutation, x) for x in scalars]; vectors = [applyOrderList(permutation, x) for x in vectors]; grid_cmd = "StructuredGrid("+str(form_lattice_D["dim"])+", "+str(grid)+")"; # fill in objects object_strings = []; scalars_keys = D["scalar"].keys(); for ii in range(len(scalars_keys)): object_strings.append("Scalars(scalars["+str(ii)+"], name='"+scalars_keys[ii]+"')"); vectors_keys = D["vector"].keys(); for ii in range(len(vectors_keys)): object_strings.append("Vectors(vectors["+str(ii)+"], name='"+vectors_keys[ii]+"')"); # call VtkData exec("VtkData("+grid_cmd+", PointData("+','.join(object_strings)+")).tofile(filename)");
def preExePost(argValueList, preFncs=[], exeFile="", postFncs=[], order=[], sleepTime=0): # exeFile="" to do nothing """ Execute exeFile with a choice of arguments specified in argNameList. argValueList is a nested list, elements from each sublist consist a "choice" of arguments. order is applied before this choice of arguments is used. For each possible combination of values of arguments, preFncs are executed first, then exeFile is executed, then postFncs are executed. preFnc is used to do some possible clean work between each run, it has one parameter: a list of choice of parameters. postFun is similar, only executed after each run. Note that exeFile is a string that contains the executable file, and the string can contain other arguments, as long as these arguments are positioned in front of those automatically generated arguments list of the form argNameList. The list argValueList is very free, for example, the list [["1 2","3 4"],...] will use "1 2" or "3 4" as the first generated parameter. This is especially useful if a program reads argument for a loop to generate one file. """ for valueCmb in listR.outer( map(listR.toList, listR.toList(argValueList) )): # take a perticular list of possible combination of values valueCmb = list(listR.FL(valueCmb)) # execute preFnc if preFncs != []: for pre_func in listR.toList(preFncs): pre_func(valueCmb) # execute exeFile with given choice of arguments if exeFile != "": runCommand( exeFile + " " + listR.listToStr(listR.applyOrderList(order, valueCmb)), os.path.dirname(exeFile), sleepTime) # execute postFnc if postFncs != []: for post_func in listR.toList(postFncs): post_func(valueCmb)
def preExePost(argValueList, preFncs=[], exeFile="", postFncs=[], order=[], sleepTime=0): # exeFile="" to do nothing """ Execute exeFile with a choice of arguments specified in argNameList. argValueList is a nested list, elements from each sublist consist a "choice" of arguments. order is applied before this choice of arguments is used. For each possible combination of values of arguments, preFncs are executed first, then exeFile is executed, then postFncs are executed. preFnc is used to do some possible clean work between each run, it has one parameter: a list of choice of parameters. postFun is similar, only executed after each run. Note that exeFile is a string that contains the executable file, and the string can contain other arguments, as long as these arguments are positioned in front of those automatically generated arguments list of the form argNameList. The list argValueList is very free, for example, the list [["1 2","3 4"],...] will use "1 2" or "3 4" as the first generated parameter. This is especially useful if a program reads argument for a loop to generate one file. """ for valueCmb in listR.outer(map(listR.toList, listR.toList(argValueList))): # take a perticular list of possible combination of values valueCmb = list(listR.FL(valueCmb)) # execute preFnc if preFncs!=[]: for pre_func in listR.toList(preFncs): pre_func(valueCmb) # execute exeFile with given choice of arguments if exeFile!="": runCommand(exeFile + " " + listR.listToStr(listR.applyOrderList(order,valueCmb)), path.dirname(exeFile), sleepTime) # execute postFnc if postFncs!=[]: for post_func in listR.toList(postFncs): post_func(valueCmb)