BioSTEAMDevelopmentGroup / biosteam

The Biorefinery Simulation and Techno-Economic Analysis Modules; Life Cycle Assessment; Chemical Process Simulation Under Uncertainty
Other
176 stars 35 forks source link

Small error in `BoilerTurbogenerator` design cause negative work/cost #151

Closed yalinli2 closed 1 year ago

yalinli2 commented 1 year ago

@emilypl2 and I ran into a problem when running the lactic acid module with biosteam's BoilerTurbogenerator. Essentially a very small negative value (to 10-15) was calculated for H_electricity: https://github.com/BioSTEAMDevelopmentGroup/biosteam/blob/e2db47535d594f9010e6a3094737b817c837ff44/biosteam/facilities/_boiler_turbogenerator.py#L334

which led to negative work and error in decorated cost calculation: https://github.com/BioSTEAMDevelopmentGroup/biosteam/blob/e2db47535d594f9010e6a3094737b817c837ff44/biosteam/units/decorators/_cost.py#L152

I locally inserted a line H_electricity = 0 if abs(H_electricity)<1e-6 else H_electricity to temporarily fix it for now, but not sure if it's good for a permanent fix, thanks!

yoelcortes commented 1 year ago

@yalinli2,

The temporary fix confuses the solver. I added some code to handle this special case. I am not able to test it, but I believe it should fix your issue:

https://github.com/BioSTEAMDevelopmentGroup/biosteam/blob/a00a85602270f74791855c63248e41005ffe3be4/biosteam/facilities/_boiler_turbogenerator.py#L355

Thanks,

yalinli2 commented 1 year ago

lol I know my two-second fix would be problematic, I think your fix works, thank you!

@emilypl2 I didn't test all the way through, feel free to reopen this issue and follow up if you run into future problems!