def testBool(self): g=FoamFileGenerator({'a':True}) self.assertEqual(str(g),"a yes;\n") g=FoamFileGenerator({'a':False}) self.assertEqual(str(g),"a no;\n") g=FoamFileGenerator({'a':BoolProxy(True)}) self.assertEqual(str(g),"a yes;\n") g=FoamFileGenerator({'a':BoolProxy(True,textual="on")}) self.assertEqual(str(g),"a yes;\n")
def p_word(self, p): '''word : NAME | UNIFORM | NONUNIFORM | MERGE | OVERWRITE | DEFAULT | WARN | PROTECT | ERROR''' if p[1] in BoolProxy.TrueStrings + BoolProxy.FalseStrings: p[0] = BoolProxy(textual=p[1]) else: p[0] = p[1]
def __init__(self,basename,solver, parameterfile, arguments, parameters={}, noMeshCreate=False, **kwargs): self.__parameterfile=parameterfile self.__noMeshCreate=noMeshCreate para={} if type(arguments)==list: if len(arguments) % 2 !=0: error("Length of arguments should be an even number. Is",len(arguments), ":",arguments) # make all string arguments that could be boolean boolean values from PyFoam.Basics.DataStructures import BoolProxy for k,v in dict(zip(arguments[::2],arguments[1::2])).items(): try: try: para[k]=BoolProxy(textual=v).val except TypeError: para[k]=int(v) except ValueError: try: para[k]=float(v) except ValueError: try: para[k]=eval(v) except (SyntaxError,NameError): para[k]="'"+v+"'" elif type(arguments)==dict: para=arguments else: error("Type of arguments is ",type(arguments),"Should be 'dict' or 'list':",arguments) self.__parametervalues=para parameters.update(self.__parametervalues) print_("Parameter file",self.__parameterfile) print_("Parameter values",self.__parametervalues) SolverJob.__init__(self,basename,solver, parameters=parameters, **kwargs)