def ConservativeLaw(self, flux_variables, output_variable): if output_variable == self.variable: v1 = Variable(hidden='True') b1 = WeightedSum(flux_variables, v1, [1] * len(flux_variables), -self.friction) b2 = ODE(v1, self.variable, [1], [self.SCx, self.mass]) return [b1, b2] else: v1 = Variable(hidden='True') b1 = ODE(self.variable, v1, [self.SCx, self.mass], [1]) b2 = WeightedSum([v1] + flux_variables, output_variable, [1] + [-1] * len(flux_variables), self.friction) return [b1, b2]
def partial_dynamic_system(self, ieq, variable): """ returns dynamical system blocks associated to output variable """ if ieq == 0: # Soc determination # soc=1-UI/CP v1 = Variable('UI', hidden=True) # UI v2 = Variable('UI/CP', hidden=True) # UI/CP v3 = Variable('soc0-UI/CP', hidden=True) # soc0-UI/CP b1 = Product(self.u, self.variables[0], v1) b2 = ODE(v1, v2, [1], [1, self.c]) b3 = WeightedSum([v2], v3, [-1], self.initial_soc) b4 = Saturation(v3, self.soc, 0, 1) b5 = WeightedSum([self.soc], self.u, [self.u_max - self.u_min], self.u_min) blocks = [b1, b2, b3, b4, b5] # U2-U1=U+Ri1 # U=soc(Umax-Umin)+Umin if variable == self.physical_nodes[0].variable: print('Bat0#1') # U1 is output # U1=-U-Ri1+U2 blocks.append( WeightedSum([ self.u, self.variables[0], self.physical_nodes[1].variable ], variable, [-1, -self.r, 1])) elif variable == self.physical_nodes[1].variable: print('Bat0#2') # U2 is output # U2=U1+Ri1+U blocks.append( WeightedSum([ self.physical_nodes[0].variable, self.variables[0], self.u ], variable, [1, self.r, 1])) elif variable == self.variables[0]: print('Bat0#3') # i1 is output # i1=(-U1+U2-U)/R blocks.append( WeightedSum([ self.physical_nodes[0].variable, self.physical_nodes[1].variable, self.u ], variable, [-1 / self.r, 1 / self.r, -1 / self.r])) return blocks
def __init__(self, node1, wmin, wmax, Tmax_map, fuel_flow_map, name='Thermal engine'): occurence_matrix = np.array([[0, 1]]) command = Variable('Requested engine throttle') self.wmin = wmin self.wmax = wmax self.Tmax = Tmax_map self.fuel_flow_map = fuel_flow_map self.max_torque = Variable('max torque') self.throttle = Variable('Engine throttle') PhysicalBlock.__init__(self, [node1], [0], occurence_matrix, [command], name)
def PartialDynamicSystem(self, ieq, variable): """ returns dynamical system blocks associated to output variable """ if ieq == 0: if variable == self.physical_nodes[0].variable: print('1') # U1 is output # U1=i1/pC+U2 Uc = Variable(hidden=True) block1 = ODE(self.variables[0], Uc, [1], [0, self.C]) sub1 = Sum([self.physical_nodes[1].variable, Uc], variable) return [block1, sub1] elif variable == self.physical_nodes[1].variable: print('2') # U2 is output # U2=U1-i1/pC Uc = Variable(hidden=True) block1 = ODE(self.variables[0], Uc, [-1], [0, self.C]) sum1 = Sum([self.physical_nodes[0].variable, Uc], variable) return [block1, sum1] # elif variable==self.variables[0]: # print('3') # # i1 is output # # i1=pC(U1-U2) # ic=Variable(hidden=True) # subs1=Subtraction(self.physical_nodes[0].variable,self.physical_nodes[1].variable,ic) # block1=ODE(ic,variable,[0,self.C],[1]) # return [block1,subs1] elif ieq == 1: # i1=-i2 if variable == self.variables[0]: # i1 as output # print('Bat1#0') return [Gain(self.variables[1], self.variables[0], -1)] elif variable == self.variables[1]: # i2 as output # print('Bat1#1') return [Gain(self.variables[0], self.variables[1], -1)]
def __init__(self, node1, node2, u_min, u_max, c, initial_soc, r, name='Battery'): # 1st eq: U2=signal, U1=0 occurrence_matrix = np.array([[1, 1, 1, 0], [0, 1, 0, 1]]) # occurrence_matrix=np.array([[1,1,1,0]]) # 1st eq: U2=signal, U1=0 PhysicalBlock.__init__(self, [node1, node2], [0, 1], occurrence_matrix, [], name) self.u_max = u_max self.u_min = u_min self.c = c self.r = r self.initial_soc = initial_soc self.soc = Variable('Battery SoC', [initial_soc]) self.u = Variable('Battery voltage')
def PartialDynamicSystem(self, ieq, variable): """ returns dynamical system blocks associated to output variable """ if ieq == 0: # C1=-f*Tmax*sign(w1-w2) if variable == self.variables[0]: ut = Variable('unsigned clutch friction torque', hidden=True) b1 = Gain(self.commands[0], ut, self.Tmax) dw = Variable('Delta rotationnal speed', hidden=True) sdw = Variable('Sign of delta rotationnal speed') b2 = WeightedSum([ self.physical_nodes[0].variable, self.physical_nodes[1].variable ], dw, [-1, 1]) b3 = Sign(dw, sdw) b4 = Product(ut, sdw, variable) return [b1, b2, b3, b4] elif ieq == 1: # C1=-C2 if variable == self.variables[0]: return [Gain(self.variables[1], variable, -1)] if variable == self.variables[1]: return [Gain(self.variables[0], variable, -1)]
def partial_dynamic_system(self, ieq, variable): """ returns dynamical system blocks associated to output variable """ if ieq == 0: # if variable==self.physical_nodes[0].variable: # print('1') # # U1 is output # # U1=i1/pC+U2 # Uc=Variable(hidden=True) # block1=ODE(self.variables[0],Uc,[1],[0,self.C]) # sub1=Sum([self.physical_nodes[1].variable,Uc],variable) # return [block1,sub1] # elif variable==self.physical_nodes[1].variable: # print('2') # # U2 is output # # U2=U1-i1/pC # Uc=Variable(hidden=True) # block1=ODE(self.variables[0],Uc,[-1],[0,self.C]) # sum1=Sum([self.physical_nodes[0].variable,Uc],variable) # return [block1,sum1] if variable == self.variables[0]: # i1=(u1-u2)/Lp print('3') # i1 is output # i1=pC(U1-U2) uc = Variable(hidden=True) subs1 = Subtraction( self.physical_nodes[0].variable, self.physical_nodes[1].variable, uc) block1 = ODE(uc, variable, [1], [0, self.L]) return [block1, subs1] elif ieq == 1: # i1=-i2 if variable == self.variables[0]: # i1 as output return [Gain(self.variables[1], self.variables[0], -1)] elif variable == self.variables[1]: # i2 as output return [Gain(self.variables[0], self.variables[1], -1)]
def __init__(self, node1, Tmax, name='Brake'): occurence_matrix = np.array([[0, 1]]) command = Variable('Brake command') self.Tmax = Tmax PhysicalBlock.__init__(self, [node1], [0], occurence_matrix, [command], name)
def __init__(self, node1, node2, Tmax, name='Clutch'): occurence_matrix = np.array([[0, 1, 0, 0], [0, 1, 0, 1]]) command = Variable('Clutch command') self.Tmax = Tmax PhysicalBlock.__init__(self, [node1, node2], [0, 1], occurence_matrix, [command], name)