def run(): A = np.mat([[0, 0, 1], [500**2, 500, 1], [1000**2, 1000, 1]]) x = np.array([0, 1.01, 3]) c = la.solve(A, x) power_curve = lambda q: c[0] * q**2 + c[1] * q + c[2] p1 = PressureReservoir(p=0.2) p2 = PressureReservoir(p=0) fan = PowerCurveFan(fcn=power_curve) c1 = Connector() c2 = Connector() c1.connect(p1.node, fan.input) c2.connect(fan.output, p2.node) fan.update_properties() system = IncompressibleSystem([p1, p2, fan]) system.solve(verbose=1) for c in system.connectors(): print(c.flow_rate) print(fan.dp, fan.flow_rate)
def run(): p1 = PressureReservoir(p=(1.11)) p2 = PressureReservoir(p=0.) c = Connector(k_ent=1.324) c.connect(p1.node, p2.node) system = IncompressibleSystem([p1, p2]) system.solve(toler=1e-14, verbose=1) for connector in system.connectors(): print(connector.flow_rate)
def run(): p1 = PressureReservoir(p=0.) p2 = PressureReservoir(p=0.) fan = ConstantDeliveryFan(flow_rate=500.) c1 = Connector() c2 = Connector() c1.connect(p1.node, fan.input) c2.connect(fan.output, p2.node) system = IncompressibleSystem([p1, p2, fan]) system.solve(verbose=1) for connector in system.connectors(): print(connector.flow_rate) for node in system.nodes(): print(node.p, type(node))
def run(): p1 = PressureReservoir(p=1.43) p2 = PressureReservoir(p=0) c1 = Connector() c2 = Connector() valve = ResistorValve(r=0.001) c1.connect(p1.node, valve.input) c2.connect(valve.output, p2.node) system = IncompressibleSystem([p1, p2, valve]) system.solve(verbose=1) print(valve.flow_rate, valve.output.p - valve.input.p) for node in system.nodes(): print(node.p, type(node.block)) for connector in system.connectors(): print(connector.flow_rate)
def run(): p1 = PressureReservoir(p=0) p2 = PressureReservoir(p=0) p3 = PressureReservoir(p=0) fan = Fan(dp=4.3) s = PerfectSplitter(num_outputs=2) c1 = ProcterAndGambleConnector(diameter=4) c2 = ProcterAndGambleConnector(diameter=5) c3 = ProcterAndGambleConnector(diameter=6) c4 = ProcterAndGambleConnector(diameter=2) c1.connect(p1.node, s.input) c2.connect(s.outputs[0], p2.node) c3.connect(s.outputs[1], fan.input) c4.connect(fan.output, p3.node) system = IncompressibleSystem([p1, p2, p3, s, fan]) system.solve() for c in c1, c2, c3, c4: print(c.flow_rate) print()
def run(): patm = [PressureReservoir(p=0.) for _ in range(4)] fan = Fan(dp=0) valves = [ResistorValve(r=0) for _ in range(3)] joint = PerfectJunction(num_nodes=4) conns = [Connector(length=25, diameter=1 + i) for i in range(8)] conns[0].connect(patm[0].node, valves[0].input) conns[1].connect(patm[1].node, valves[1].input) conns[2].connect(patm[2].node, valves[2].input) conns[3].connect(valves[0].output, joint.nodes[0]) conns[4].connect(valves[1].output, joint.nodes[1]) conns[5].connect(valves[2].output, joint.nodes[2]) conns[6].connect(joint.nodes[3], fan.input) conns[7].connect(fan.output, patm[3].node) system = IncompressibleSystem(patm + [fan] + valves + [joint]) optimizer = Optimizer(system=system) optimizer.init_objective_function(blocks=[fan], var='dp') for i, v in enumerate(valves): optimizer.add_property_constraint(v, 'Resistance', 'ineq', 0.) optimizer.add_solution_constraint(v, 'Flow rate', 'eq', 130 + 12 * i) optimizer.optimize(guess=[1, 0, 0, 0]) print('Objectives') print(fan.dp) print('Constraints') print(valves[0].r) print(valves[1].r) print(valves[2].r) print(valves[0].flow_rate) print(valves[1].flow_rate) print(valves[2].flow_rate) print(system.status)
def run(): p = [PressureReservoir(p=0.) for i in range(5)] j = PerfectJunction(num_nodes=5) f = [Fan(dp=1), Fan(dp=1), Fan(dp=1)] v = [ResistorValve(r=0.), ResistorValve(r=0.)] c = [Connector(diameter=6, length=25) for i in range(10)] #c = [LinearResistanceConnector(r=0.01) for i in range(10)] c[0].connect(p[0].node, v[0].input) c[1].connect(p[1].node, v[1].input) c[2].connect(v[0].output, f[0].input) c[3].connect(v[1].output, j.nodes[0]) c[4].connect(f[0].output, j.nodes[1]) c[5].connect(p[2].node, f[1].output) c[6].connect(f[1].input, j.nodes[2]) c[7].connect(j.nodes[3], p[3].node) c[8].connect(j.nodes[4], f[2].input) c[9].connect(f[2].output, p[4].node) system = IncompressibleSystem(p + [j] + f + v) system.assign_node_ids() # system.solve(verbose=1, method='gmres') # iters, error = system.solve(max_iters=200, toler=1e-9) def obj(x): return x[0]**2 + x[1]**2 + x[2]**2 def h1(x): callback(x) return v[0].input.connector.flow_rate - 450 def h2(x): callback(x) return v[1].input.connector.flow_rate - 340 def h3(x): return x[3] def h4(x): return x[4] def h5(x): return 2 - abs(x[0] - x[1]) def h6(x): return 2 - abs(x[1] - x[2]) def callback(x): f[0].dp = x[0] f[1].dp = x[1] f[2].dp = x[2] v[0].r = x[3] v[1].r = x[4] system.solve(verbose=1, method='lgmres', maxiter=1000) constr = [ { 'type': 'eq', 'fun': h1 }, { 'type': 'eq', 'fun': h2 }, { 'type': 'ineq', 'fun': h3 }, { 'type': 'ineq', 'fun': h4 }, { 'type': 'ineq', 'fun': h5 }, { 'type': 'ineq', 'fun': h6 }, ] print( opt.minimize(obj, [f[0].dp, f[1].dp, f[2].dp, 0, 0], constraints=constr)) print('Objectives') print(f[0].dp) print(f[1].dp) print(f[2].dp) print('Constraints') print(v[0].input.connector.flow_rate) print(v[1].input.connector.flow_rate)
def run(): patm = [PressureReservoir(p=0.) for _ in range(4)] fan = Fan(dp=0) valves = [ResistorValve(r=0) for _ in range(3)] joint = PerfectJunction(num_nodes=4) conns = [Connector(length=25) for _ in range(8)] conns[0].connect(patm[0].node, valves[0].input) conns[1].connect(patm[1].node, valves[1].input) conns[2].connect(patm[2].node, valves[2].input) conns[3].connect(valves[0].output, joint.nodes[0]) conns[4].connect(valves[1].output, joint.nodes[1]) conns[5].connect(valves[2].output, joint.nodes[2]) conns[6].connect(joint.nodes[3], fan.input) conns[7].connect(fan.output, patm[3].node) system = IncompressibleSystem(patm + [fan] + valves + [joint]) #system.solve(verbose=1) # iters, error = system.solve(max_iters=200, toler=1e-9) def obj(x): return x[0]**2 def h1(x): callback(x) return valves[0].input.connector.flow_rate - 300 def h2(x): callback(x) return valves[1].input.connector.flow_rate - 400 def h3(x): callback(x) return valves[2].input.connector.flow_rate - 600 def h4(x): return x[1] def h5(x): return x[2] def h6(x): return x[3] def callback(x): dp, r1, r2, r3 = x fan.dp = dp valves[0].r = r1 valves[1].r = r2 valves[2].r = r3 system.solve(verbose=1, method='bicgstab', maxiter=5000, toler=1e-11) constr = [{ 'type': 'eq', 'fun': h1 }, { 'type': 'eq', 'fun': h2 }, { 'type': 'eq', 'fun': h3 }, { 'type': 'ineq', 'fun': h4 }, { 'type': 'ineq', 'fun': h5 }, { 'type': 'ineq', 'fun': h6 }] try: print(opt.minimize(obj, [0.01, 0, .0, .0], constraints=constr)) except: pass print('Objectives') print(fan.dp) print('Constraints') print(valves[0].r) print(valves[1].r) print(valves[2].r) print(valves[0].input.connector.flow_rate) print(valves[1].input.connector.flow_rate) print(valves[2].input.connector.flow_rate)