ahuora-builder 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ahuora_builder/__init__.py +0 -0
- ahuora_builder/arc_manager.py +33 -0
- ahuora_builder/build_state.py +57 -0
- ahuora_builder/custom/PIDController.py +494 -0
- ahuora_builder/custom/PySMOModel.py +178 -0
- ahuora_builder/custom/SimpleEffectivenessHX_DH.py +727 -0
- ahuora_builder/custom/__init__.py +0 -0
- ahuora_builder/custom/add_initial_dynamics.py +35 -0
- ahuora_builder/custom/custom_compressor.py +107 -0
- ahuora_builder/custom/custom_cooler.py +33 -0
- ahuora_builder/custom/custom_heat_exchanger.py +183 -0
- ahuora_builder/custom/custom_heat_exchanger_1d.py +258 -0
- ahuora_builder/custom/custom_heater.py +41 -0
- ahuora_builder/custom/custom_pressure_changer.py +34 -0
- ahuora_builder/custom/custom_pump.py +107 -0
- ahuora_builder/custom/custom_separator.py +371 -0
- ahuora_builder/custom/custom_tank.py +133 -0
- ahuora_builder/custom/custom_turbine.py +132 -0
- ahuora_builder/custom/custom_valve.py +300 -0
- ahuora_builder/custom/custom_variable.py +29 -0
- ahuora_builder/custom/direct_steam_injection.py +371 -0
- ahuora_builder/custom/energy/__init__.py +0 -0
- ahuora_builder/custom/energy/acBus.py +280 -0
- ahuora_builder/custom/energy/ac_property_package.py +279 -0
- ahuora_builder/custom/energy/battery.py +170 -0
- ahuora_builder/custom/energy/bus.py +182 -0
- ahuora_builder/custom/energy/energy_mixer.py +195 -0
- ahuora_builder/custom/energy/energy_splitter.py +228 -0
- ahuora_builder/custom/energy/grid.py +173 -0
- ahuora_builder/custom/energy/hydro.py +169 -0
- ahuora_builder/custom/energy/link.py +137 -0
- ahuora_builder/custom/energy/load.py +155 -0
- ahuora_builder/custom/energy/mainDistributionBoard.py +257 -0
- ahuora_builder/custom/energy/power_property_package.py +253 -0
- ahuora_builder/custom/energy/solar.py +176 -0
- ahuora_builder/custom/energy/storage.py +230 -0
- ahuora_builder/custom/energy/storage_wrapper +0 -0
- ahuora_builder/custom/energy/tests/__init__.py +0 -0
- ahuora_builder/custom/energy/tests/test_bus.py +44 -0
- ahuora_builder/custom/energy/tests/test_energy_mixer.py +46 -0
- ahuora_builder/custom/energy/tests/test_mdb.py +49 -0
- ahuora_builder/custom/energy/transformer.py +187 -0
- ahuora_builder/custom/energy/transformer_property_package.py +267 -0
- ahuora_builder/custom/energy/transmissionLine.py +228 -0
- ahuora_builder/custom/energy/wind.py +206 -0
- ahuora_builder/custom/hda_ideal_VLE.py +1341 -0
- ahuora_builder/custom/hda_reaction.py +182 -0
- ahuora_builder/custom/heat_exchanger_1d_wrapper.py +31 -0
- ahuora_builder/custom/integration_block.py +106 -0
- ahuora_builder/custom/inverted.py +81 -0
- ahuora_builder/custom/performance_curves.py +1 -0
- ahuora_builder/custom/reactions/__init__.py +0 -0
- ahuora_builder/custom/reactions/hda_stoich.py +10 -0
- ahuora_builder/custom/simple_separator.py +680 -0
- ahuora_builder/custom/tests/__init__.py +0 -0
- ahuora_builder/custom/tests/test_SimpleEffectivenessHX_DH.py +91 -0
- ahuora_builder/custom/tests/test_custom_tank.py +70 -0
- ahuora_builder/custom/tests/test_direct_steam_injection.py +41 -0
- ahuora_builder/custom/tests/test_simple_separator.py +46 -0
- ahuora_builder/custom/tests/test_waterpipe.py +46 -0
- ahuora_builder/custom/thermal_utility_systems/desuperheater.py +624 -0
- ahuora_builder/custom/thermal_utility_systems/header.py +889 -0
- ahuora_builder/custom/thermal_utility_systems/simple_heat_pump.py +567 -0
- ahuora_builder/custom/thermal_utility_systems/steam_header.py +353 -0
- ahuora_builder/custom/thermal_utility_systems/steam_user.py +944 -0
- ahuora_builder/custom/thermal_utility_systems/temp.py +349 -0
- ahuora_builder/custom/thermal_utility_systems/tests/test_desuperheater.py +142 -0
- ahuora_builder/custom/thermal_utility_systems/tests/test_header.py +998 -0
- ahuora_builder/custom/thermal_utility_systems/tests/test_ntu_hx.py +129 -0
- ahuora_builder/custom/thermal_utility_systems/tests/test_simple_heat_pump.py +120 -0
- ahuora_builder/custom/thermal_utility_systems/tests/test_steam_header.py +703 -0
- ahuora_builder/custom/thermal_utility_systems/tests/test_steam_user.py +277 -0
- ahuora_builder/custom/thermal_utility_systems/tests/test_waterpipe.py +36 -0
- ahuora_builder/custom/thermal_utility_systems/tests/test_willans_turbine.py +253 -0
- ahuora_builder/custom/thermal_utility_systems/willans_turbine.py +804 -0
- ahuora_builder/custom/translator.py +129 -0
- ahuora_builder/custom/updated_pressure_changer.py +1404 -0
- ahuora_builder/custom/valve_wrapper.py +38 -0
- ahuora_builder/custom/water_tank_with_units.py +456 -0
- ahuora_builder/diagnostics/__init__.py +0 -0
- ahuora_builder/diagnostics/infeasibilities.py +40 -0
- ahuora_builder/diagnostics/tests/__init__.py +0 -0
- ahuora_builder/diagnostics/tests/test_infeasibilities.py +28 -0
- ahuora_builder/flowsheet_manager.py +542 -0
- ahuora_builder/flowsheet_manager_type.py +20 -0
- ahuora_builder/generate_python_file.py +440 -0
- ahuora_builder/methods/BlockContext.py +84 -0
- ahuora_builder/methods/__init__.py +0 -0
- ahuora_builder/methods/adapter.py +355 -0
- ahuora_builder/methods/adapter_library.py +549 -0
- ahuora_builder/methods/adapter_methods.py +80 -0
- ahuora_builder/methods/expression_parsing.py +105 -0
- ahuora_builder/methods/load_unit_model.py +147 -0
- ahuora_builder/methods/slice_manipulation.py +7 -0
- ahuora_builder/methods/tests/__init__.py +0 -0
- ahuora_builder/methods/tests/test_expression_parsing.py +15 -0
- ahuora_builder/methods/units_handler.py +129 -0
- ahuora_builder/ml_wizard.py +101 -0
- ahuora_builder/port_manager.py +20 -0
- ahuora_builder/properties_manager.py +44 -0
- ahuora_builder/property_package_manager.py +78 -0
- ahuora_builder/solver.py +38 -0
- ahuora_builder/tear_manager.py +98 -0
- ahuora_builder/tests/__init__.py +0 -0
- ahuora_builder/tests/test_generate_python_file/__init__.py +0 -0
- ahuora_builder/tests/test_generate_python_file/configurations/compressor_generated.py +63 -0
- ahuora_builder/tests/test_generate_python_file/configurations/heat_exchanger_generated.py +70 -0
- ahuora_builder/tests/test_generate_python_file/configurations/pump_generated.py +84 -0
- ahuora_builder/tests/test_generate_python_file/configurations/recycle_generated.py +73 -0
- ahuora_builder/tests/test_generate_python_file/test_generate_python_file.py +108 -0
- ahuora_builder/tests/test_solver/__init__.py +0 -0
- ahuora_builder/tests/test_solver/configurations/BT_PR.json +59 -0
- ahuora_builder/tests/test_solver/configurations/BT_PR_solved.json +59 -0
- ahuora_builder/tests/test_solver/configurations/bus.json +99 -0
- ahuora_builder/tests/test_solver/configurations/bus_solved.json +50 -0
- ahuora_builder/tests/test_solver/configurations/compound_separator.json +377 -0
- ahuora_builder/tests/test_solver/configurations/compound_separator_solved.json +374 -0
- ahuora_builder/tests/test_solver/configurations/compressor.json +38 -0
- ahuora_builder/tests/test_solver/configurations/compressor_solved.json +68 -0
- ahuora_builder/tests/test_solver/configurations/constraints.json +44 -0
- ahuora_builder/tests/test_solver/configurations/constraints_solved.json +59 -0
- ahuora_builder/tests/test_solver/configurations/control.json +39 -0
- ahuora_builder/tests/test_solver/configurations/control_solved.json +68 -0
- ahuora_builder/tests/test_solver/configurations/dynamic_tank.json +733 -0
- ahuora_builder/tests/test_solver/configurations/dynamic_tank_solved.json +846 -0
- ahuora_builder/tests/test_solver/configurations/elimination.json +39 -0
- ahuora_builder/tests/test_solver/configurations/elimination_solved.json +68 -0
- ahuora_builder/tests/test_solver/configurations/expressions.json +68 -0
- ahuora_builder/tests/test_solver/configurations/expressions_solved.json +104 -0
- ahuora_builder/tests/test_solver/configurations/header.json +1192 -0
- ahuora_builder/tests/test_solver/configurations/header_solved.json +761 -0
- ahuora_builder/tests/test_solver/configurations/heat_exchanger.json +63 -0
- ahuora_builder/tests/test_solver/configurations/heat_exchanger_solved.json +104 -0
- ahuora_builder/tests/test_solver/configurations/heat_pump.json +137 -0
- ahuora_builder/tests/test_solver/configurations/heat_pump_solved.json +104 -0
- ahuora_builder/tests/test_solver/configurations/machine_learning.json +2156 -0
- ahuora_builder/tests/test_solver/configurations/machine_learning_solved.json +266 -0
- ahuora_builder/tests/test_solver/configurations/mass_flow_tear.json +77 -0
- ahuora_builder/tests/test_solver/configurations/mass_flow_tear_solved.json +68 -0
- ahuora_builder/tests/test_solver/configurations/milk_heater.json +521 -0
- ahuora_builder/tests/test_solver/configurations/milk_heater_solved.json +311 -0
- ahuora_builder/tests/test_solver/configurations/mixer.json +44 -0
- ahuora_builder/tests/test_solver/configurations/mixer_solved.json +86 -0
- ahuora_builder/tests/test_solver/configurations/optimization.json +62 -0
- ahuora_builder/tests/test_solver/configurations/optimization_solved.json +59 -0
- ahuora_builder/tests/test_solver/configurations/propane_heat_pump.json +167 -0
- ahuora_builder/tests/test_solver/configurations/propane_heat_pump_solved.json +158 -0
- ahuora_builder/tests/test_solver/configurations/propane_recycle.json +141 -0
- ahuora_builder/tests/test_solver/configurations/propane_recycle_solved.json +104 -0
- ahuora_builder/tests/test_solver/configurations/pump.json +64 -0
- ahuora_builder/tests/test_solver/configurations/pump_solved.json +59 -0
- ahuora_builder/tests/test_solver/configurations/pump_unit_conversions.json +63 -0
- ahuora_builder/tests/test_solver/configurations/recycle.json +49 -0
- ahuora_builder/tests/test_solver/configurations/recycle_solved.json +50 -0
- ahuora_builder/tests/test_solver/configurations/sb_vapor_frac.json +29 -0
- ahuora_builder/tests/test_solver/configurations/sb_vapor_frac_solved.json +29 -0
- ahuora_builder/tests/test_solver/configurations/solar.json +67 -0
- ahuora_builder/tests/test_solver/configurations/solar_solved.json +50 -0
- ahuora_builder/tests/test_solver/configurations/vapor_frac_target.json +67 -0
- ahuora_builder/tests/test_solver/configurations/vapor_frac_target_solved.json +68 -0
- ahuora_builder/tests/test_solver/test_solve_models.py +250 -0
- ahuora_builder/timing.py +65 -0
- ahuora_builder/types/__init__.py +1 -0
- ahuora_builder/unit_model_manager.py +48 -0
- ahuora_builder-0.1.0.dist-info/METADATA +14 -0
- ahuora_builder-0.1.0.dist-info/RECORD +167 -0
- ahuora_builder-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import pyomo.environ as pe# Pyomo environment
|
|
2
|
+
from idaes.core import FlowsheetBlock, StateBlock
|
|
3
|
+
from idaes.models.unit_models import HeatExchanger
|
|
4
|
+
from idaes.models.properties.general_helmholtz import (
|
|
5
|
+
HelmholtzParameterBlock,
|
|
6
|
+
PhaseType,
|
|
7
|
+
StateVars,
|
|
8
|
+
)
|
|
9
|
+
from idaes.models.unit_models.heat_exchanger import HX0DInitializer
|
|
10
|
+
from idaes.models.unit_models.heat_exchanger import delta_temperature_lmtd_callback
|
|
11
|
+
from idaes.models.properties import iapws95
|
|
12
|
+
from ahuora_builder.custom.SimpleEffectivenessHX_DH import HeatExchangerEffectiveness
|
|
13
|
+
# from milk_props_full_config import MilkParameterBlock
|
|
14
|
+
from idaes.core.util.model_statistics import degrees_of_freedom
|
|
15
|
+
import idaes.logger as idaeslog
|
|
16
|
+
from idaes.core.util import DiagnosticsToolbox
|
|
17
|
+
from multiprocessing import freeze_support
|
|
18
|
+
from property_packages.build_package import build_package
|
|
19
|
+
|
|
20
|
+
#--------------------------------------------------------------
|
|
21
|
+
#Only works with smooth temperature need the Ahuora smooth helmhotlz, the Ahuora smooth Helmholtz does not work on windows
|
|
22
|
+
#--------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
if __name__ == '__main__':
|
|
25
|
+
freeze_support()
|
|
26
|
+
# Create an empty flowsheet and steam property parameter block.
|
|
27
|
+
model = pe.ConcreteModel()
|
|
28
|
+
model.fs = FlowsheetBlock(dynamic=False)
|
|
29
|
+
model.fs.properties = build_package("helmholtz",["water"],["Liq","Vap"]) #HelmholtzParameterBlock(pure_component="h2o",state_vars=StateVars.PH,phase_presentation=PhaseType.MIX)
|
|
30
|
+
dt = DiagnosticsToolbox(model)
|
|
31
|
+
# Add a Heater model to the flowsheet.
|
|
32
|
+
model.fs.heat_exchanger = HeatExchangerEffectiveness(
|
|
33
|
+
hot_side_name="shell",
|
|
34
|
+
cold_side_name="tube",
|
|
35
|
+
shell={"property_package": model.fs.properties},
|
|
36
|
+
tube={"property_package": model.fs.properties},
|
|
37
|
+
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
model.fs.heat_exchanger.effectiveness.fix(1)
|
|
41
|
+
model.fs.heat_exchanger.shell_inlet.flow_mol.fix(10)
|
|
42
|
+
P_hot = 270280
|
|
43
|
+
T_hot = 200 + 273
|
|
44
|
+
h = model.fs.properties.htpx(T=T_hot*pe.units.K, p= P_hot*pe.units.Pa)
|
|
45
|
+
print(h)
|
|
46
|
+
model.fs.heat_exchanger.shell_inlet.pressure.fix(P_hot)
|
|
47
|
+
model.fs.heat_exchanger.shell_inlet.enth_mol.fix(h)
|
|
48
|
+
|
|
49
|
+
P_cold = 101325
|
|
50
|
+
T_cold = 50 + 273
|
|
51
|
+
model.fs.heat_exchanger.tube_inlet.flow_mol.fix(5)
|
|
52
|
+
model.fs.heat_exchanger.tube_inlet.pressure.fix(P_cold)
|
|
53
|
+
|
|
54
|
+
h = model.fs.properties.htpx(T=T_cold*pe.units.K, p= P_cold*pe.units.Pa)
|
|
55
|
+
print(h)
|
|
56
|
+
model.fs.heat_exchanger.tube_inlet.enth_mol.fix(h)
|
|
57
|
+
# Perform degrees of freedom analysis
|
|
58
|
+
dof = degrees_of_freedom(model)
|
|
59
|
+
print("Degrees of Freedom:", dof)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# Initialize the model
|
|
63
|
+
# initializer = HX0DInitializer()
|
|
64
|
+
# initializer.initialize(model.fs.heat_exchanger)
|
|
65
|
+
model.fs.heat_exchanger.initialize(outlvl=idaeslog.INFO_HIGH)
|
|
66
|
+
model.fs.heat_exchanger.report()
|
|
67
|
+
|
|
68
|
+
# Solve the models
|
|
69
|
+
solver = pe.SolverFactory('ipopt')
|
|
70
|
+
results = solver.solve(model, tee=True)
|
|
71
|
+
|
|
72
|
+
# Display the results
|
|
73
|
+
model.fs.heat_exchanger.report()
|
|
74
|
+
print("Hot inlet enthalpy theory: ", model.fs.properties.htpx(p= P_hot*pe.units.Pa, T= T_hot*pe.units.K), "J/mol")
|
|
75
|
+
print("Cold inlet enthalpy theory: ", model.fs.properties.htpx(p= P_cold*pe.units.Pa, T= T_cold*pe.units.K), "J/mol")
|
|
76
|
+
print("Hot inlet enthalpy: ", pe.value(model.fs.heat_exchanger.hot_side.properties_in[0].enth_mol), "J/mol")
|
|
77
|
+
print("Cold inlet enthalpy: ", pe.value(model.fs.heat_exchanger.cold_side.properties_in[0].enth_mol), "J/mol")
|
|
78
|
+
print("Hot outlet enthalpy_max: ", pe.value(model.fs.heat_exchanger.properties_hotside[0].enth_mol), "J/mol")
|
|
79
|
+
print("Cold outlet enthalpy_max: ", pe.value(model.fs.heat_exchanger.properties_coldside[0].enth_mol), "J/mol")
|
|
80
|
+
print("dH_hot: ", pe.value(model.fs.heat_exchanger.delta_h_hot_qmax[0]), "J/mol")
|
|
81
|
+
print("dH_cold: ", pe.value(model.fs.heat_exchanger.delta_h_cold_qmax[0]), "J/mol")
|
|
82
|
+
print("Duty: ", pe.value(model.fs.heat_exchanger.heat_duty[0])/1e3, "kW")
|
|
83
|
+
print("Qmax: ", pe.value(model.fs.heat_exchanger.Qmax[0])/1e3, "kW")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
eff = pe.value(model.fs.heat_exchanger.effectiveness[0])
|
|
87
|
+
eff_apparent = pe.value(model.fs.heat_exchanger.heat_duty[0]/model.fs.heat_exchanger.Qmax[0])
|
|
88
|
+
print("Effectiveness set: ", eff)
|
|
89
|
+
print("Effectiveness apparent: ", eff_apparent)
|
|
90
|
+
|
|
91
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from ..custom_tank import DynamicTank
|
|
2
|
+
import pytest
|
|
3
|
+
import pyomo.environ as pyo
|
|
4
|
+
from pyomo.network import Arc
|
|
5
|
+
from idaes.core import FlowsheetBlock, MaterialBalanceType
|
|
6
|
+
from idaes.models.unit_models import Heater, Valve
|
|
7
|
+
from idaes.models.properties import iapws95
|
|
8
|
+
from idaes.core.util.initialization import propagate_state
|
|
9
|
+
from idaes.core.util.model_statistics import degrees_of_freedom
|
|
10
|
+
# need to pip install ahuora_compounds@git+https://github.com/waikato-ahuora-smart-energy-systems/PropertyPackages.git@v0.0.25
|
|
11
|
+
from property_packages.build_package import build_package
|
|
12
|
+
|
|
13
|
+
def test_dynamic_tank():
|
|
14
|
+
m = pyo.ConcreteModel()
|
|
15
|
+
m.fs = FlowsheetBlock(dynamic=True,time_set=[0,1,2,3],time_units=pyo.units.s)
|
|
16
|
+
m.fs.water = build_package("helmholtz", ["water"],["Liq","Vap"])
|
|
17
|
+
m.fs.tank = DynamicTank(property_package=m.fs.water, tank_type="vertical_cylindrical_tank", has_holdup=True,
|
|
18
|
+
has_heat_transfer=True, dynamic=True)
|
|
19
|
+
|
|
20
|
+
m.discretizer = pyo.TransformationFactory("dae.finite_difference")
|
|
21
|
+
m.discretizer.apply_to(m, nfe=3, wrt=m.fs.time, scheme="BACKWARD")
|
|
22
|
+
|
|
23
|
+
# Initialisation - doen't really matter
|
|
24
|
+
m.fs.tank.control_volume.material_holdup[:,:,:].fix(0.5)
|
|
25
|
+
m.fs.tank.control_volume.material_holdup[:,:,:].unfix()
|
|
26
|
+
|
|
27
|
+
# Setting the required properties
|
|
28
|
+
|
|
29
|
+
#Inlet state - all timesteps
|
|
30
|
+
m.fs.tank.inlet.flow_mol.fix(100)
|
|
31
|
+
m.fs.tank.inlet.enth_mol.fix(m.fs.water.htpx(300 * pyo.units.K,101325* pyo.units.Pa)) # around 5 deg c
|
|
32
|
+
m.fs.tank.inlet.pressure.fix(101325)
|
|
33
|
+
|
|
34
|
+
#Tank properties
|
|
35
|
+
m.fs.tank.tank_diameter.fix(0.5) # m
|
|
36
|
+
m.fs.tank.heat_duty.fix(0) # W
|
|
37
|
+
m.fs.tank.outlet.flow_mol.fix(10)
|
|
38
|
+
|
|
39
|
+
#Initial conditions
|
|
40
|
+
m.fs.tank.initial_temperature.fix(300)
|
|
41
|
+
m.fs.tank.initial_pressure.fix(101325)
|
|
42
|
+
m.fs.tank.initial_holdup.fix(1000)
|
|
43
|
+
|
|
44
|
+
assert degrees_of_freedom(m.fs) == 0
|
|
45
|
+
|
|
46
|
+
m.fs.tank.initialize()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
opt = pyo.SolverFactory("ipopt")
|
|
50
|
+
results = opt.solve(m, tee=False)
|
|
51
|
+
#m.fs.tank.display()
|
|
52
|
+
|
|
53
|
+
b = m.fs.tank
|
|
54
|
+
|
|
55
|
+
assert results.solver.termination_condition == pyo.TerminationCondition.optimal
|
|
56
|
+
|
|
57
|
+
# print("Enthalpy Liquid: Enthalpy Vap: Material Holdup Liquid: Material Holdup Vap")
|
|
58
|
+
# for t in m.fs.time:
|
|
59
|
+
# print(m.fs.tank.enthalpy[t,"Liq"].value, m.fs.tank.enthalpy[t,"Vap"].value, pyo.value(m.fs.tank.material_phase_holdup[t,"Liq"]), pyo.value(m.fs.tank.material_phase_holdup[t,"Vap"]))
|
|
60
|
+
|
|
61
|
+
# for t in m.fs.time:
|
|
62
|
+
# print(m.fs.tank.outlet.enth_mol[t].value, m.fs.tank.outlet.flow_mol[t].value, pyo.value(m.fs.tank.control_volume.properties_out[t].temperature), pyo.value(m.fs.tank.control_volume.properties_in[t].temperature))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
assert pyo.value(b.outlet.enth_mol[0]) == pytest.approx(pyo.value(b.inlet.enth_mol[0]), rel=1e-1)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
test_dynamic_tank()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from ..direct_steam_injection import Dsi
|
|
2
|
+
import pytest
|
|
3
|
+
import pyomo.environ as pyo
|
|
4
|
+
from pyomo.network import Arc
|
|
5
|
+
from idaes.core import FlowsheetBlock, MaterialBalanceType
|
|
6
|
+
from idaes.models.unit_models import Heater, Valve
|
|
7
|
+
from idaes.models.properties import iapws95
|
|
8
|
+
from idaes.core.util.initialization import propagate_state
|
|
9
|
+
from idaes.core.util.model_statistics import degrees_of_freedom
|
|
10
|
+
# need to pip install ahuora_compounds@git+https://github.com/waikato-ahuora-smart-energy-systems/PropertyPackages.git@v0.0.25
|
|
11
|
+
from property_packages.build_package import build_package
|
|
12
|
+
|
|
13
|
+
def test_dsi():
|
|
14
|
+
m = pyo.ConcreteModel()
|
|
15
|
+
m.fs = FlowsheetBlock(dynamic=False)
|
|
16
|
+
m.fs.steam_properties = build_package("helmholtz", ["water"],["Liq","Vap"])
|
|
17
|
+
m.fs.milk_properties = build_package("milk", ["water","milk_solid"],["Liq","Vap"])
|
|
18
|
+
m.fs.dsi = Dsi(property_package=m.fs.milk_properties,steam_property_package=m.fs.steam_properties)
|
|
19
|
+
|
|
20
|
+
m.fs.dsi.inlet.flow_mol.fix(1)
|
|
21
|
+
m.fs.dsi.properties_milk_in[0].constrain_component(m.fs.dsi.properties_milk_in[0].temperature, 300 * pyo.units.K)
|
|
22
|
+
m.fs.dsi.inlet.pressure.fix(101325)
|
|
23
|
+
m.fs.dsi.inlet.mole_frac_comp[0,"water"].fix(0.9)
|
|
24
|
+
m.fs.dsi.inlet.mole_frac_comp[0,"milk_solid"].fix(0.1)
|
|
25
|
+
|
|
26
|
+
m.fs.dsi.steam_inlet.flow_mol.fix(1)
|
|
27
|
+
m.fs.dsi.properties_steam_in[0].constrain_component(m.fs.dsi.properties_steam_in[0].temperature, 400 * pyo.units.K)
|
|
28
|
+
m.fs.dsi.steam_inlet.pressure.fix(101325)
|
|
29
|
+
|
|
30
|
+
m.fs.dsi.initialize()
|
|
31
|
+
assert degrees_of_freedom(m.fs.dsi.properties_milk_in) == 0
|
|
32
|
+
assert degrees_of_freedom(m.fs.dsi.properties_steam_in) == 0
|
|
33
|
+
assert degrees_of_freedom(m.fs) == 0
|
|
34
|
+
|
|
35
|
+
opt = pyo.SolverFactory("ipopt")
|
|
36
|
+
results = opt.solve(m, tee=True)
|
|
37
|
+
|
|
38
|
+
assert results.solver.termination_condition == pyo.TerminationCondition.optimal
|
|
39
|
+
assert degrees_of_freedom(m.fs) == 0
|
|
40
|
+
|
|
41
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pyomo.environ import ConcreteModel, SolverFactory, value
|
|
3
|
+
from idaes.core import FlowsheetBlock
|
|
4
|
+
from idaes.models.properties.iapws95 import Iapws95ParameterBlock
|
|
5
|
+
from idaes.core.util.model_statistics import degrees_of_freedom
|
|
6
|
+
from ahuora_builder.custom.simple_separator import SimpleSeparator
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_simple_separator_iapws95():
|
|
10
|
+
m = ConcreteModel()
|
|
11
|
+
m.fs = FlowsheetBlock(dynamic=False)
|
|
12
|
+
|
|
13
|
+
# Property package: IAPWS95 (pure water/steam)
|
|
14
|
+
m.fs.properties = Iapws95ParameterBlock()
|
|
15
|
+
|
|
16
|
+
# Add SimpleSeparator with 2 outlets
|
|
17
|
+
m.fs.sep = SimpleSeparator(
|
|
18
|
+
property_package=m.fs.properties,
|
|
19
|
+
num_outlets=2,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
# Fix inlet state
|
|
23
|
+
m.fs.sep.inlet.flow_mol[0].fix(100.0) # mol/s
|
|
24
|
+
m.fs.sep.inlet.enth_mol[0].fix(50000.0) # J/mol (example enthalpy)
|
|
25
|
+
m.fs.sep.inlet.pressure[0].fix(101325.0) # Pa
|
|
26
|
+
|
|
27
|
+
# Fix split fractions
|
|
28
|
+
m.fs.sep.outlet_1.flow_mol[0].fix(70.0) # mol/s
|
|
29
|
+
|
|
30
|
+
# Model should be fully specified
|
|
31
|
+
assert degrees_of_freedom(m) == 0
|
|
32
|
+
|
|
33
|
+
# Initialize and solve
|
|
34
|
+
m.fs.sep.initialize()
|
|
35
|
+
solver = SolverFactory("ipopt")
|
|
36
|
+
results = solver.solve(m, tee=False)
|
|
37
|
+
assert results.solver.termination_condition == "optimal"
|
|
38
|
+
|
|
39
|
+
# Check material balance
|
|
40
|
+
inlet_flow = value(m.fs.sep.inlet.flow_mol[0])
|
|
41
|
+
out1_flow = value(m.fs.sep.outlet_1.flow_mol[0])
|
|
42
|
+
out2_flow = value(m.fs.sep.outlet_2.flow_mol[0])
|
|
43
|
+
|
|
44
|
+
assert abs(inlet_flow - (out1_flow + out2_flow)) <= 1e-6
|
|
45
|
+
assert abs(out1_flow - 0.7 * inlet_flow) <= 1e-6
|
|
46
|
+
assert abs(out2_flow - 0.3 * inlet_flow) <= 1e-6
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import pyomo.environ as pyo
|
|
3
|
+
from idaes.core import FlowsheetBlock
|
|
4
|
+
from idaes.models.properties import iapws95
|
|
5
|
+
from idaes.models_extra.power_generation.unit_models.waterpipe import WaterPipe
|
|
6
|
+
from idaes.core.util.model_statistics import degrees_of_freedom
|
|
7
|
+
from idaes.core.util.testing import initialization_tester
|
|
8
|
+
from idaes.core.solvers import get_solver
|
|
9
|
+
|
|
10
|
+
solver = get_solver()
|
|
11
|
+
|
|
12
|
+
def test_waterpipe_simple():
|
|
13
|
+
'''
|
|
14
|
+
Simple test for the WaterPipe unit model
|
|
15
|
+
'''
|
|
16
|
+
m = pyo.ConcreteModel()
|
|
17
|
+
m.fs = FlowsheetBlock(dynamic=False)
|
|
18
|
+
m.fs.properties = iapws95.Iapws95ParameterBlock()
|
|
19
|
+
m.fs.pipe = WaterPipe(
|
|
20
|
+
dynamic=False,
|
|
21
|
+
property_package=m.fs.properties,
|
|
22
|
+
has_holdup=True,
|
|
23
|
+
has_heat_transfer=False,
|
|
24
|
+
has_pressure_change=True,
|
|
25
|
+
water_phase="Liq",
|
|
26
|
+
contraction_expansion_at_end="None",
|
|
27
|
+
)
|
|
28
|
+
m.fs.pipe.diameter.fix(0.04)
|
|
29
|
+
m.fs.pipe.length.fix(40)
|
|
30
|
+
m.fs.pipe.number_of_pipes.fix(100)
|
|
31
|
+
m.fs.pipe.elevation_change.fix(25)
|
|
32
|
+
m.fs.pipe.fcorrection_dp.fix(1.0)
|
|
33
|
+
|
|
34
|
+
state_args = {"flow_mol": 10000, "pressure": 1.3e7, "enth_mol": 18000}
|
|
35
|
+
initialization_tester(m, dof=3, state_args=state_args, unit=m.fs.pipe)
|
|
36
|
+
m.fs.pipe.inlet.enth_mol.fix()
|
|
37
|
+
m.fs.pipe.inlet.flow_mol.fix()
|
|
38
|
+
m.fs.pipe.inlet.pressure.fix()
|
|
39
|
+
assert degrees_of_freedom(m) == 0
|
|
40
|
+
|
|
41
|
+
results = solver.solve(m, tee=True)
|
|
42
|
+
assert pyo.check_optimal_termination(results)
|
|
43
|
+
# Output for debugging
|
|
44
|
+
print("Outlet pressure:", pyo.value(m.fs.pipe.outlet.pressure[0]))
|
|
45
|
+
print("Pressure drop:", pyo.value(m.fs.pipe.deltaP[0]))
|
|
46
|
+
print("Outlet enthalpy:", pyo.value(m.fs.pipe.outlet.enth_mol[0]))
|