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,129 @@
|
|
|
1
|
+
# Import Pyomo libraries
|
|
2
|
+
from pyomo.environ import (
|
|
3
|
+
Var,
|
|
4
|
+
Suffix,
|
|
5
|
+
units as pyunits,
|
|
6
|
+
)
|
|
7
|
+
from pyomo.common.config import ConfigBlock, ConfigValue, In
|
|
8
|
+
from idaes.core.util.tables import create_stream_table_dataframe
|
|
9
|
+
from idaes.core.util.exceptions import ConfigurationError
|
|
10
|
+
from idaes.models.unit_models.translator import TranslatorData
|
|
11
|
+
# Import IDAES cores
|
|
12
|
+
from idaes.core import (
|
|
13
|
+
declare_process_block_class,
|
|
14
|
+
UnitModelBlockData,
|
|
15
|
+
useDefault,
|
|
16
|
+
)
|
|
17
|
+
from idaes.core.util.config import is_physical_parameter_block
|
|
18
|
+
import idaes.core.util.scaling as iscale
|
|
19
|
+
import idaes.logger as idaeslog
|
|
20
|
+
from enum import Enum
|
|
21
|
+
|
|
22
|
+
# Set up logger
|
|
23
|
+
_log = idaeslog.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
class TranslatorType(Enum):
|
|
26
|
+
"""
|
|
27
|
+
Enum of supported translator types. This allows you to change what variables are translated across.
|
|
28
|
+
"""
|
|
29
|
+
pressure_enthalpy = "pressure_enthalpy"
|
|
30
|
+
pressure_vapor_fraction = "pressure_vapor_fraction"
|
|
31
|
+
pressure_temperature = "pressure_temperature"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# When using this file the name "GenericTranslator" is what is imported
|
|
35
|
+
@declare_process_block_class("GenericTranslator")
|
|
36
|
+
class GenericTranslatorData(TranslatorData):
|
|
37
|
+
"""
|
|
38
|
+
GenericTranslator.
|
|
39
|
+
|
|
40
|
+
This is used to translate between two different property packages, and supports dropping compounds that are not present.
|
|
41
|
+
|
|
42
|
+
For example, if you have a stream of water/milk, and it's almost all water, this allows you to translate the stream to a water-only stream.
|
|
43
|
+
|
|
44
|
+
It works by fixing the temperature and pressure, and flow of each component in the outlet stream to be the same as the inlet stream.
|
|
45
|
+
|
|
46
|
+
"""
|
|
47
|
+
CONFIG = TranslatorData.CONFIG()
|
|
48
|
+
|
|
49
|
+
CONFIG.declare(
|
|
50
|
+
"translator_type",
|
|
51
|
+
ConfigValue(
|
|
52
|
+
default=TranslatorType.pressure_enthalpy.value,
|
|
53
|
+
description="Translator type to use for translating properties",
|
|
54
|
+
doc="""
|
|
55
|
+
Depending on the property packages you are using and the phases that are present, it may make sense to use different translators.
|
|
56
|
+
This allows you to select what variables are translated across.
|
|
57
|
+
""",
|
|
58
|
+
),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def build(self):
|
|
63
|
+
self.CONFIG.outlet_state_defined = False # See constraint for flow
|
|
64
|
+
#self.CONFIG.has_phase_equilibrium = True # I don't think it matters if this is set, becuase in theory the phase equilibrium should
|
|
65
|
+
# already have been calculated in the inlet stream.
|
|
66
|
+
super().build()
|
|
67
|
+
|
|
68
|
+
# Pressure (= inlet pressure)
|
|
69
|
+
@self.Constraint(
|
|
70
|
+
self.flowsheet().time,
|
|
71
|
+
doc="Pressure balance",
|
|
72
|
+
)
|
|
73
|
+
def eq_outlet_pressure(b, t):
|
|
74
|
+
return b.properties_in[t].pressure == b.properties_out[t].pressure
|
|
75
|
+
|
|
76
|
+
# Flow
|
|
77
|
+
@self.Constraint(
|
|
78
|
+
self.flowsheet().time,
|
|
79
|
+
self.config.outlet_property_package.component_list,
|
|
80
|
+
doc="Mass balance for the outlet",
|
|
81
|
+
)
|
|
82
|
+
def eq_outlet_composition(b, t, c):
|
|
83
|
+
return 0 == sum(
|
|
84
|
+
b.properties_out[t].get_material_flow_terms(p, c)
|
|
85
|
+
- b.properties_in[t].get_material_flow_terms(p, c)
|
|
86
|
+
for p in b.properties_out[t].phase_list
|
|
87
|
+
if (p, c) in b.properties_out[t].phase_component_set
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if self.config.translator_type == TranslatorType.pressure_enthalpy.value:
|
|
91
|
+
# Enthalpy (= inlet enthalpy)
|
|
92
|
+
@self.Constraint(
|
|
93
|
+
self.flowsheet().time,
|
|
94
|
+
doc="Enthalpy balance",
|
|
95
|
+
)
|
|
96
|
+
def eq_outlet_enth_mol(b, t):
|
|
97
|
+
return (
|
|
98
|
+
b.properties_in[t].enth_mol == b.properties_out[t].enth_mol
|
|
99
|
+
)
|
|
100
|
+
elif self.config.translator_type == TranslatorType.pressure_vapor_fraction.value:
|
|
101
|
+
# Vapor fraction (= inlet vapor fraction)
|
|
102
|
+
# TODO: We might be able to make this smoother, by extending the vapor fraction
|
|
103
|
+
# below 0 and above 1 to make solving more reliable. See
|
|
104
|
+
# https://github.com/waikato-ahuora-smart-energy-systems/PropertyPackages/blob/8c6ee67b9d028ba0fdd1c937d9dcda821595b7d1/property_packages/helmholtz/helmholtz_extended.py#L104
|
|
105
|
+
@self.Constraint(
|
|
106
|
+
self.flowsheet().time,
|
|
107
|
+
doc="Vapor fraction balance",
|
|
108
|
+
)
|
|
109
|
+
def eq_outlet_vapor_frac(b, t):
|
|
110
|
+
return (
|
|
111
|
+
b.properties_in[t].vapor_frac == b.properties_out[t].vapor_frac
|
|
112
|
+
)
|
|
113
|
+
elif self.config.translator_type == TranslatorType.pressure_temperature.value:
|
|
114
|
+
# Temperature (= inlet temperature)
|
|
115
|
+
@self.Constraint(
|
|
116
|
+
self.flowsheet().time,
|
|
117
|
+
doc="Temperature balance",
|
|
118
|
+
)
|
|
119
|
+
def eq_outlet_temperature(b, t):
|
|
120
|
+
return (
|
|
121
|
+
b.properties_in[t].temperature == b.properties_out[t].temperature
|
|
122
|
+
)
|
|
123
|
+
else:
|
|
124
|
+
raise ConfigurationError(
|
|
125
|
+
f"Translator type {self.CONFIG.translator_type} is not supported."
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|