Skip to content

Commit

Permalink
finally get PO-alg optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Aug 2, 2024
1 parent 8aeee1c commit d446cb8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
6 changes: 5 additions & 1 deletion benchmark/haber_bosch_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ def create_system_haber_bosch_process(alg='sequential modular'):
phase='g'
)
preheater = bst.HXutility(ins=feed, T=450 + 273.15)
reactor = bst.
reactor = bst.ReactivePhaseStage(
ins=preheater-0, T=450 + 273.15, P=300e5,
reaction=bst.Reaction('N2 + H2 -> NH4', reactant='N2', X=0.15, correct_atomic_balance=True),
)

makeup_butanol = bst.Stream('makeup_butanol', Butanol=1)
makeup_butanol.T = makeup_butanol.bubble_point_at_P().T
recycle_butanol = bst.Stream('recycle_butanol')
Expand Down
1 change: 1 addition & 0 deletions benchmark/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def benchmark(self):
time.tic()
f()
net_time += time.toc()
print('material error', sum([abs(i.mass_balance_error()) for i in stages]))
new_temperatures = np.array([i.T for i in streams])
new_flows = np.array([i.mol for i in streams])
dF = np.abs(flows - new_flows)
Expand Down
7 changes: 3 additions & 4 deletions biosteam/_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ def _solve_material_flows(self, composition_sensitive):
A, objs = dictionaries2array(A)
values = solve(A, np.array(b).T).T
values[values < 0] = 0
for obj, value in zip(objs, values):
obj._update_material_flows(value)
for obj, value in zip(objs, values): obj._update_material_flows(value)
for i in nodes:
if hasattr(i, '_update_auxiliaries'): i._update_auxiliaries()
return values
Expand Down Expand Up @@ -2381,7 +2380,7 @@ def stage_configuration(self, aggregated=False):
self.path, stages, nodes, streams, stream_ref, connections, aggregated
)
return conf

failure = 0
def run_phenomena(self):
"""Decouple and linearize material, equilibrium, summation, enthalpy,
and reaction phenomena and iteratively solve them."""
Expand All @@ -2395,7 +2394,7 @@ def run_phenomena(self):
i.run()
conf.solve_energy_departures()
conf.solve_material_flows()
except NotImplementedError as error:
except (NotImplementedError, UnboundLocalError) as error:
raise error
except:
for i in path: i.run()
Expand Down
2 changes: 1 addition & 1 deletion biosteam/_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _begin_equations(self, composition_sensitive):
for i in dct:
if i.source and not getattr(i.source, 'composition_sensitive', False): break
else:
dependent_streams.append(i.imol)
dependent_streams.extend([i.imol for i in dct])
equations.append(eq)
dependent_streams = set(dependent_streams)
for i in inlets:
Expand Down
7 changes: 2 additions & 5 deletions biosteam/units/distillation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,15 +1520,12 @@ def _update_net_flow_parameters(self):
)
self.B = phi / (1 - phi)

def _create_material_balance_equations(self):
def _create_material_balance_equations(self, composition_sensitive):
top, bottom = self.outs
B = self.B
K = self.K
inlets = self.ins
fresh_inlets = [i for i in inlets if i.isfeed() and not i.material_equations]
process_inlets = [i for i in inlets if not i.isfeed()]
fresh_inlets, process_inlets, equations = self._begin_equations(composition_sensitive)
top, bottom, *_ = self.outs
equations = []
ones = np.ones(self.chemicals.size)
minus_ones = -ones
zeros = np.zeros(self.chemicals.size)
Expand Down
2 changes: 1 addition & 1 deletion biosteam/units/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _run(self):
if self.T is None:
self.reaction.adiabatic_reaction(outlet, Q=self.Q)
else:
self.reaction(outlet, Q=self.Q)
self.reaction(outlet)
outlet.T = self.T

def _create_material_balance_equations(self, composition_sensitive=False):
Expand Down

0 comments on commit d446cb8

Please sign in to comment.