Coverage for backend/ahuora-builder/src/ahuora_builder/custom/custom_pump.py: 93%

30 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-07-22 05:22 +0000

1# Import Pyomo libraries 

2from pyomo.environ import ( 

3 Var, 

4 Suffix, 

5 units as pyunits, 

6) 

7from pyomo.common.config import ConfigBlock, ConfigValue, In 

8from idaes.core.util.tables import create_stream_table_dataframe 

9from idaes.core.util.exceptions import ConfigurationError 

10# Import IDAES cores 

11from idaes.core import ( 

12 declare_process_block_class, 

13 UnitModelBlockData, 

14 useDefault, 

15) 

16from idaes.core.util.config import is_physical_parameter_block 

17import idaes.core.util.scaling as iscale 

18import idaes.logger as idaeslog 

19 

20from ..custom.updated_pressure_changer import ( 

21 

22 PumpData, 

23) 

24 

25 

26 

27 

28# When using this file the name "CustomCompressor" is what is imported 

29@declare_process_block_class("CustomPump") 

30class CustomPumpData(PumpData): 

31 """ 

32 Zero order Load model 

33 """ 

34 

35 # CONFIG are options for the unit model, this simple model only has the mandatory config options 

36 CONFIG = PumpData.CONFIG() 

37 

38 CONFIG.declare( 

39 "power_property_package", 

40 ConfigValue( 

41 default=useDefault, 

42 domain=is_physical_parameter_block, 

43 description="Property package to use for power", 

44 doc="""Power Property parameter object used to define power calculations, 

45 **default** - useDefault. 

46 **Valid values:** { 

47 **useDefault** - use default package from parent model or flowsheet, 

48 **PhysicalParameterObject** - a PhysicalParameterBlock object.}""", 

49 ), 

50 ) 

51 CONFIG.declare( 

52 "power_property_package_args", 

53 ConfigBlock( 

54 implicit=True, 

55 description="Arguments to use for constructing power property packages", 

56 doc="""A ConfigBlock with arguments to be passed to a property block(s) 

57 and used when constructing these, 

58 **default** - None.  

59 **Valid values:** { 

60 see property package for documentation.}""", 

61 ), 

62 ) 

63 

64 def build(self): 

65 # build always starts by calling super().build() 

66 # This triggers a lot of boilerplate in the background for you 

67 super().build() 

68 

69 # This creates blank scaling factors, which are populated later 

70 self.scaling_factor = Suffix(direction=Suffix.EXPORT) 

71 

72 

73 # Add state blocks for inlet, outlet, and waste 

74 # These include the state variables and any other properties on demand 

75 

76 tmp_dict = dict(**self.config.property_package_args) 

77 tmp_dict["parameters"] = self.config.property_package 

78 tmp_dict["defined_state"] = True # inlet block is an inlet 

79 # Add inlet block 

80 # self.properties_in = self.config.property_package.state_block_class( 

81 # self.flowsheet().config.time, doc="Material properties of inlet", **tmp_dict 

82 # ) 

83 

84 

85 # Add outlet and waste block 

86 tmp_dict["defined_state"] = False # outlet and waste block is not an inlet 

87 self.power_properties_out = self.config.power_property_package.state_block_class( 

88 self.flowsheet().config.time, 

89 doc="Material properties of outlet", 

90 **tmp_dict 

91 ) 

92 

93 

94 # Add ports - oftentimes users interact with these rather than the state blocks 

95 self.add_port(name="power_outlet", block=self.power_properties_out) 

96 

97 # Add constraints 

98 # Usually unit models use a control volume to do the mass, energy, and momentum 

99 # balances, however, they will be explicitly written out in this example 

100 @self.Constraint( 

101 self.flowsheet().time, 

102 doc="Power out", 

103 ) 

104 def eq_power_out(b, t): 

105 return ( 

106 self.power_properties_out[t].power == self.work_mechanical[t] * -1 

107 ) 

108 

109 

110 @staticmethod 

111 def ahuora_metadata(): 

112 from ahuora_unit_ops.json_config import ( 

113 JsonAdapterArgConfig, 

114 JsonFrontendConfig, 

115 JsonGraphicObjectConfig, 

116 JsonIdaesAdapterConfig, 

117 JsonPortConfig, 

118 JsonPropertyConfig, 

119 JsonPropertySetGroupConfig, 

120 JsonUnitOpConfig, 

121 ) 

122 

123 return JsonUnitOpConfig( 

124 key='pump', 

125 objectType='pump', 

126 enumMember='Pump', 

127 displayType='Pump', 

128 displayName='Pump', 

129 categoryPath=['chemical', 'pressure_changer'], 

130 ports={ 

131 'inlet': JsonPortConfig( 

132 displayName='Inlet', 

133 type='inlet', 

134 streamType='stream', 

135 many=False, 

136 default=1, 

137 minimum=1, 

138 makeStream=True, 

139 streamOffset=0.75, 

140 streamName='S', 

141 ), 

142 'outlet': JsonPortConfig( 

143 displayName='Outlet', 

144 type='outlet', 

145 streamType='stream', 

146 many=False, 

147 default=1, 

148 minimum=1, 

149 makeStream=True, 

150 streamOffset=0.75, 

151 streamName='S', 

152 ), 

153 'power_outlet': JsonPortConfig( 

154 displayName='Power Stream', 

155 type='outlet', 

156 streamType='energy_stream', 

157 many=False, 

158 default=1, 

159 minimum=1, 

160 makeStream=False, 

161 streamOffset=0.75, 

162 streamName='PS', 

163 ), 

164 }, 

165 propertyPackagePorts={ 

166 '': ['inlet', 'outlet'], 

167 }, 

168 graphicObject=JsonGraphicObjectConfig( 

169 kind='unitop_graphic', 

170 ), 

171 indexSets=[], 

172 properties={ 

173 'efficiency_pump': JsonPropertyConfig( 

174 propertySetGroup='default', 

175 displayName='Efficiency', 

176 indexSets=None, 

177 sumToOne=False, 

178 value=None, 

179 unit=None, 

180 unitType='ratio', 

181 description=None, 

182 type='numeric', 

183 many=False, 

184 default=1, 

185 options={}, 

186 hasTimeIndex=True, 

187 ), 

188 'deltaP': JsonPropertyConfig( 

189 propertySetGroup='default', 

190 displayName='Pressure Increase', 

191 indexSets=None, 

192 sumToOne=False, 

193 value=None, 

194 unit=None, 

195 unitType='pressure', 

196 description=None, 

197 type='numeric', 

198 many=False, 

199 default=1, 

200 options={}, 

201 hasTimeIndex=True, 

202 ), 

203 'ratioP': JsonPropertyConfig( 

204 propertySetGroup='default', 

205 displayName='Pressure Ratio', 

206 indexSets=None, 

207 sumToOne=False, 

208 value=None, 

209 unit=None, 

210 unitType='ratio', 

211 description=None, 

212 type='numeric', 

213 many=False, 

214 default=1, 

215 options={}, 

216 hasTimeIndex=True, 

217 ), 

218 'work_mechanical': JsonPropertyConfig( 

219 propertySetGroup='default', 

220 displayName='Mechanical Work', 

221 indexSets=None, 

222 sumToOne=False, 

223 value=None, 

224 unit=None, 

225 unitType='heatflow', 

226 description=None, 

227 type='numeric', 

228 many=False, 

229 default=1, 

230 options={}, 

231 hasTimeIndex=True, 

232 ), 

233 }, 

234 propertySetGroups={ 

235 'default': JsonPropertySetGroupConfig( 

236 type='stateVars', 

237 displayName='Properties', 

238 stateVars=['efficiency_pump', 'work_mechanical'], 

239 toggle=None, 

240 ), 

241 }, 

242 keyProperties=['work_mechanical', 'efficiency_pump', 'deltaP', 'ratioP'], 

243 splitterFractionName=None, 

244 idaesAdapter=JsonIdaesAdapterConfig( 

245 constructor='ahuora_builder.custom.custom_pump.CustomPump', 

246 args={ 

247 'property_package': JsonAdapterArgConfig( 

248 kind='property_package', 

249 label=None, 

250 ), 

251 'dynamic': JsonAdapterArgConfig( 

252 kind='constant', 

253 value=False, 

254 ), 

255 'power_property_package': JsonAdapterArgConfig( 

256 kind='constant_schema', 

257 schema='PowerPPArgSchema', 

258 ), 

259 }, 

260 ports=None, 

261 properties=None, 

262 ), 

263 frontend=JsonFrontendConfig( 

264 showInPanel=True, 

265 variant=None, 

266 ), 

267 )