def getNF(self, bname, *, sname=None): """Get the number of feed stage for the specified RadFrac block and feed stream or Get the all feed stream for the specified RadFrac block in a list-type. :param bname: Block name. :param sname: Feed stream name. :return: if sname is None, return a feed stream list for specified block. if sname is specified, return the NF of specified block and feed stream. """ ## 檢查bname是否為RadFrac if self.master.BlockType(bname) != 'RadFrac': raise UDE.AspenPlus_BlockTypeError( bname + ' is not a RadFrac,' + 'please check the name you type!!') ## 對sname進行檢查並處理 if sname is None: pass elif type(sname) is str: ## 把sname轉換成大寫,因為Aspen裡面的名稱都大寫 sname = sname.upper() ## 檢查輸入的物流名稱是否在檔案當中,如無回傳錯誤 if sname not in self.master.StreamsList(): raise UDE.AspenPlus_StreamTypeError( "Cannot Find " + sname + " in the AspenFile. " + "Please Check the name you type!!") else: raise TypeError("sname must be a 'String'!!!") ## 指定塔的進料物流 物件 obj = self.aspen.Tree.Elements("Data").Elements("Blocks").Elements( bname).Elements("Input").Elements("FEED_STAGE") ## 列出指定塔的進料物流有哪些 nlist = [] for e in obj.Elements: nlist.append(e.Name) if sname is None: # 沒輸入sname就回傳進料物流列表 return nlist elif sname is not None: # 有輸入sname且為特定塔的進料物流的話,輸出進料板 if sname not in nlist: raise UDE.AspenPlus_StreamTypeError( sname + " is not a feed stream" + " for " + bname + ". " + "Please Check the name you type!!") return obj.Elements(sname).Value
def setNF(self, bname, sname, set_value): """Set the number of feed stage for the specified RadFrac block and feed stream. :param bname: Block name. :param sname: Feed stream name. :param set_value: feed stage you want to specify. :return: None """ ## 檢查輸入的資料型態正確與否 if type(set_value) != int: raise TypeError("set_value must be a 'Integer'!!!") ## 檢查set_value 是否為正整數 if set_value < 0: raise ValueError("set_value must be a 'Positive' number!!!") ## 對sname進行檢查並處理 if sname is None: pass elif type(sname) is str: ## 把sname轉換成大寫,因為Aspen裡面的名稱都大寫 sname = sname.upper() ## 檢查輸入的物流名稱是否在檔案當中,如無回傳錯誤 if sname not in self.master.StreamsList(): raise UDE.AspenPlus_StreamTypeError( "Cannot Find " + sname + " in the AspenFile. " + "Please Check the name you type!!") else: raise TypeError("sname must be a 'String'!!!") ## 指定塔的進料物流 物件 obj = self.aspen.Tree.Elements("Data").Elements("Blocks").Elements( bname).Elements("Input").Elements("FEED_STAGE") ## 列出指定塔的進料物流有哪些 nlist = [] for e in obj.Elements: nlist.append(e.Name) # 有輸入sname且為特定塔的進料物流的話,輸出進料板 if sname not in nlist: raise UDE.AspenPlus_StreamTypeError( sname + " is not a feed stream" + " for " + bname + ". " + "Please Check the name you type!!") obj.Elements(sname).Value = set_value # 輸入超過總板數會報有用的錯誤
def wrapper(self, *args, **kwargs): # Inner function for this decorator def name_up_and_arg_change(name, args): """將name變大寫並且回傳回args""" name = name.upper() args = list(args) # 要把args第一個參數(name)變成大寫 args[0] = name # 但是args是tuple不能修改,所以要先 args = tuple(args) # 變成list,修改過後再轉回tuple return name, args if Type == 'stream': sname = args[0] ## 先檢查輸入的資料型態正確與否 if type(sname) != str: raise TypeError("sname must be a 'String'!!!") # 把sname變大寫並回傳回args sname, args = name_up_and_arg_change(sname, args) ## 檢查輸入的物流名稱是否在檔案當中,如無回傳錯誤 if sname not in self.master.StreamsList(): raise UDE.AspenPlus_StreamTypeError("Cannot Find " + sname + " in the AspenFile. " + "Please Check the name you type!!") elif Type == 'block': bname = args[0] ## 先檢查輸入的資料型態正確與否 if type(bname) != str: raise TypeError("bname must be a 'String'!!!") # 把bname變大寫並回傳回args bname, args = name_up_and_arg_change(bname, args) ## 檢查輸入的物流名稱是否在檔案當中,如無回傳錯誤 if bname not in self.master.BlocksList(): raise UDE.AspenPlus_BlockTypeError("Cannot Find " + bname + " in the AspenFile. " + "Please Check the name you type!!") else: raise TypeError('No Match Value for Type, ' + 'Please Check the value you type !!!') return func(self, *args, **kwargs)