Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding initial support for v2 solvers #1384

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a36deb1
Adding initial support for v2 solvers
Mar 22, 2024
f515d80
Cleaning up and using isinstance ot detect legacy solver interface
Mar 25, 2024
38a9a94
Correcting solve config
Mar 29, 2024
d9287c2
Fixing leak of options
Mar 29, 2024
eb20e86
Fixing or skipping failing tests
Mar 31, 2024
7f5fe40
Fixing use of pytest skip
Apr 1, 2024
258e2c0
Fixing presolve issues in apps and core
Apr 1, 2024
532d23b
Switch Block to ConcreteModel in solve_indexed_blocks
mrmundt Apr 2, 2024
923df9e
Resolve CI failures from new version (1.20.4) of spellchecker (#1389)
lbianchi-lbl Apr 4, 2024
4e6a0f0
Fix target for 'fv' (flowsheet visualizer) reference (#1391)
dangunter Apr 4, 2024
f8ccdec
Updating black and rerunning it on all files (#1388)
ksbeattie Apr 4, 2024
8c37ddf
Merge branch 'main' into scaling_v2
Apr 10, 2024
61c938e
Merge branch 'scaling_v2' of https://github.com/andrewlee94/idaes-pse…
Apr 10, 2024
c8f2f7c
Merge branch 'scaling_v2' of https://github.com/IDAES/idaes-pse into …
Apr 10, 2024
637b7fb
Cleaning up
Apr 10, 2024
075edf7
Updating Pyomo tag
Apr 10, 2024
4d73ced
Trying @jsiirola's branch fix
Apr 11, 2024
f312c00
Trying @jsiirola's branch fix again
Apr 11, 2024
c3a7010
Trying @jsiirola's branch fix again
Apr 11, 2024
b5ddcf8
Bumping Pyomo tag
Apr 11, 2024
40d3dc7
Fixing spurious DoF in Gibbs reactor model (#1393)
Apr 11, 2024
45c8ff0
Update parameter sweep tool to support indexed vars (#1387)
Apr 11, 2024
3a1d54a
Adding attributes to hold units used by MSContactor (#1396)
Apr 16, 2024
b3d55b7
Crossflow hx (#1382)
dallan-keylogic Apr 22, 2024
5cf975f
bug fix: catch AttributeError in set_scaling_from_default (#1400)
jasonmbray-p66 Apr 25, 2024
2e89daf
Renaming Block classes
May 2, 2024
75b71e8
Fixing instances of _General
May 2, 2024
4424c53
Fixing other _Data classes
May 3, 2024
bc2f6c0
Add parallel constraint/variable check to `report_numerical_issues` (…
Robbybp May 3, 2024
7eed1cc
Some clean up
May 3, 2024
6fe724a
Address many unexpected warnings in pytest (#1403)
May 6, 2024
3e0a27c
bumping Pyomo tag
May 7, 2024
5f685b2
Merge branch 'main' into renaming_components
May 7, 2024
2c43633
Merging main
May 7, 2024
50956cd
Fixing conflict
May 7, 2024
97d2f05
Renaming components (#1402)
May 8, 2024
5d2f94c
Update the Pyomo tag to the 6.7.2 release (#1406)
blnicho May 9, 2024
8094e8d
Fixing conflict
May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pylint/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ disable=no-self-argument,
arguments-differ,
abstract-method,
arguments-renamed,
unused-argument, # w have cases where a general high level method passes arguments that simpler methods do not need
unused-argument, # we have cases where a general high level method passes arguments that simpler methods do not need
redefined-outer-name,
anomalous-backslash-in-string,
unspecified-encoding,
Expand All @@ -29,6 +29,7 @@ disable=no-self-argument,
too-many-lines,
use-implicit-booleaness-not-comparison, # implicit booleaness can be hard to follow
consider-using-f-string, # should fix, but a lot of effort
no-member, # Triggers many false positives from Pyomo due to diamond structure

[IMPORTS]
ignored-modules=cvalsim,almsim
Expand Down
2 changes: 1 addition & 1 deletion docs/reference_guides/core/var_like_expr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ In these cases, it is possible that a user might mistake the `Expression` for a
.. autoclass:: IndexedVarLikeExpression
:members:

.. autoclass:: _GeneralVarLikeExpressionData
.. autoclass:: VarLikeExpressionData
:members:

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
Heater1D
========

.. index::
pair: idaes.models_extra.power_generation.unit_models.heater_1D;Heater1D

.. module:: idaes.models_extra.power_generation.unit_models.heater_1D

This model is for a gas trim heater modeled as gas being blown perpendicularly across banks of hollow tubes,
which are heated by resistive heating. Note that the ``finite_elements`` option in the control
volume config should be set to an integer factor of ``number_passes`` in order for the
discretization equations to make sense as a cross-flow heat exchanger.

Example
-------

.. code-block:: python

import pyomo.environ as pyo

from idaes.core import FlowsheetBlock
import idaes.core.util.scaling as iscale
from idaes.models.properties.modular_properties import GenericParameterBlock
from idaes.models_extra.power_generation.properties.natural_gas_PR import (
get_prop,
EosType,
)
from idaes.models_extra.power_generation.unit_models import Heater1D
from idaes.core.util.model_statistics import degrees_of_freedom

optarg = {
"constr_viol_tol": 1e-8,
"nlp_scaling_method": "user-scaling",
"linear_solver": "ma57",
"OF_ma57_automatic_scaling": "yes",
"max_iter": 350,
"tol": 1e-8,
"halt_on_ampl_error": "no",
}

m = pyo.ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)
m.fs.h2_side_prop_params = GenericParameterBlock(
**get_prop(["H2", "H2O", "Ar", "N2"], {"Vap"}, eos=EosType.IDEAL),
doc="H2O + H2 gas property parameters",
)
m.fs.heater = Heater1D(
property_package=m.fs.h2_side_prop_params,
has_holdup=True,
dynamic=False,
has_fluid_holdup=False,
has_pressure_change=pressure_drop,
finite_elements=4,
tube_arrangement="in-line",
transformation_method="dae.finite_difference",
transformation_scheme="BACKWARD",
)

heater = m.fs.heater

heater.inlet.flow_mol.fix(5102.5)
heater.inlet.temperature.fix(938.83)
heater.inlet.pressure.fix(1.2e5)
heater.inlet.mole_frac_comp[0, "H2"].fix(0.57375)
heater.inlet.mole_frac_comp[0, "H2O"].fix(0.42517)
heater.inlet.mole_frac_comp[0, "Ar"].fix(0.00086358)
heater.inlet.mole_frac_comp[0, "N2"].fix(0.00021589)

heater.di_tube.fix(0.0525018)
heater.thickness_tube.fix(0.0039116)
heater.pitch_x.fix(0.1)
heater.pitch_y.fix(0.1)
heater.length_tube_seg.fix(10)
heater.number_passes.fix(1)
heater.rfouling = 0.0001
heater.fcorrection_htc_shell.fix(1)
heater.cp_wall = 502.4
if pressure_drop:
heater.fcorrection_dp_shell.fix(1)

heater.number_columns_per_pass.fix(40)
heater.number_rows_per_pass.fix(40)
heater.electric_heat_duty.fix(3.6504e06)

pp = m.fs.h2_side_prop_params
pp.set_default_scaling("enth_mol_phase", 1e-3)
pp.set_default_scaling("pressure", 1e-5)
pp.set_default_scaling("temperature", 1e-2)
pp.set_default_scaling("flow_mol", 1e-3)

_mf_scale = {
"H2": 1,
"H2O": 1,
"N2": 10,
"Ar": 10,
}
for comp, s in _mf_scale.items():
pp.set_default_scaling("mole_frac_comp", s, index=comp)
pp.set_default_scaling("mole_frac_phase_comp", s, index=("Vap", comp))
pp.set_default_scaling("flow_mol_phase_comp", s * 1e-3, index=("Vap", comp))

shell = heater.control_volume
iscale.set_scaling_factor(shell.area, 1e-1)
iscale.set_scaling_factor(shell.heat, 1e-6)
iscale.set_scaling_factor(shell.enthalpy_flow_dx, 1e-7)
iscale.set_scaling_factor(heater.heat_holdup, 1e-8)

iscale.calculate_scaling_factors(m)

initializer = m.fs.heat_exchanger.default_initializer(
solver="ipopt",
solver_options=optarg
)
initializer.initialize(m.fs.heat_exchanger)




Heater Geometry
---------------
=========================== =========== =============================================================================================
Variable Index Sets Doc
=========================== =========== =============================================================================================
``number_columns_per_pass`` None Number of columns of tube per pass
``number_rows_per_pass`` None Number of rows of tube per pass
``number_passes`` None Number of tube banks of ``nrow_tube * ncol_inlet`` tubes
``pitch_x`` None Distance between tubes parallel to flow, measured from center-of-tube to center-of-tube
``pitch_y`` None Distance between tubes perpendicular to flow, measured from center-of-tube to center-of-tube
``length_tube_seg`` None Length of tube segment perpendicular to flow in each pass
``area_flow_shell`` None Reference to flow area on control volume
``length_flow_shell`` None Reference to flow length on control volume
``area_flow_shell_min`` None Minimum flow area on shell side
``di_tube`` None Inner diameter of tubes
``thickness_tube`` None Thickness of tube wall.
=========================== =========== =============================================================================================

============================ =========== ===========================================================================
Expression Index Sets Doc
============================ =========== ===========================================================================
``nrow_tube`` None Total number of rows of tube
``do_tube`` None Outer diameter of tube (equal to ``di_tube+2*thickness_tube``)
``pitch_x_to_do`` None Ratio of ``pitch_x`` to ``do_tube``
``pitch_y_to_do`` None Ratio of ``pitch_y`` to ``do_tube``
``area_wall_seg`` None Total cross-sectional area of tube per pass
``total_heat_transfer_area`` None Total heat transfer area, as measured on outer surface of tubes
============================ =========== ===========================================================================

=========================== =========== =================================================================================================
Constraint Index Sets Doc
=========================== =========== =================================================================================================
``length_flow_shell_eqn`` None Constrains flow length from control volume to equal value implied by geometry
``area_flow_shell_eqn`` None Constrains flow cross-sectional area from control volume to equal value implied by geometry
``area_flow_shell_min_eqn`` None Constraints ``area_flow_shell_min`` to equal value determined by geometry
=========================== =========== =================================================================================================

Performance Equations
-----------------------

================================== ============ =================================================================================
Variable Index Sets Doc
================================== ============ =================================================================================
``electric_heat_duty`` time Electric heat duty supplied to entire heater unit
``fcorrection_htc_shell`` time, length Correction factor for convective heat transfer
``conv_heat_transfer_coeff_shell`` time, length Convective heat transfer coefficient
``temp_wall_shell`` time, length Wall temperature of tube
``temp_wall_center`` time, length Temperature at center of tube wall
``v_shell`` time, length Flow velocity through minimum area
``N_Re_shell`` time, length Reynolds number
``N_Nu_shell`` time, length Nusselt number
================================== ============ =================================================================================

=========================== =========== =================================================================================
Parameter Index Sets Doc
=========================== =========== =================================================================================
``therm_cond_wall`` None Thermal conductivity of tube wall
``density_wall`` None Mass density of tube wall metal
``cp_wall`` None Tube wall heat capacity (mass basis)
``rfouling_shell`` None Fouling resistance on shell side
``f_arrangement`` None Adjustment factor depending on ``tube_arrangement`` in config
=========================== =========== =================================================================================

====================================== ============ =================================================================================
Constraint Index Sets Doc
====================================== ============ =================================================================================
``v_shell_eqn`` time, length Calculates velocity of flow through shell using ``area_flow_shell_min``
``N_Re_shell_eqn`` time, length Calculates the Reynolds number
``conv_heat_transfer_coeff_shell_eqn`` time, length Calculates the convective heat transfer coefficient
``N_Nu_shell_eqn`` time, length Calculate the Nusselt number
``heat_shell_eqn`` time, length Calculates heat transfer per unit length
``temp_wall_shell_eqn`` time, length Calculate the wall temperature of the outer tube
``temp_wall_center_eqn`` time, length Overall energy balance on tube metal
====================================== ============ =================================================================================

====================================== ============ ===================================================================================
Expression Index Sets Doc
====================================== ============ ===================================================================================
``total_heat_transfer_coeff_shell`` time Returns ``conv_heat_transfer_coeff_shell``. Could be extended to include radiation.
====================================== ============ ===================================================================================

Pressure Change Equations
-------------------------

=========================== ============ =================================================================================
Parameter Index Sets Doc
=========================== ============ =================================================================================
``fcorrection_dp_shell`` None Correction factor for pressure drop
=========================== ============ =================================================================================

=========================== ============ =================================================================================
Variable Index Sets Doc
=========================== ============ =================================================================================
``fcorrection_dp_shell`` None Correction factor for pressure drop
``friction_factor_shell`` time, length Friction factor
=========================== ============ =================================================================================

================================== ============ =================================================================================
Constraint Index Sets Doc
================================== ============ =================================================================================
``friction_factor_shell_eqn`` time, length Calculates the friction factor
``deltaP_shell_eqn`` time, length Sets ``deltaP_shell`` based on the friction factor and physical properties
================================== ============ =================================================================================


Holdup Equations
----------------

Created when ``has_holdup=True`` in the config.

=========================== ============ =================================================================================
Variable Index Sets Doc
=========================== ============ =================================================================================
``heat_holdup`` time, length Energy holdup per unit length of flow path
=========================== ============ =================================================================================

=========================== ============ =================================================================================
Constraint Index Sets Doc
=========================== ============ =================================================================================
``heat_holdup_eqn`` time, length Defines heat holdup in terms of geometry and physical properties
=========================== ============ =================================================================================

Dynamic Equations
-----------------

Created when ``dynamic=True`` in the config.

=========================== ============ =================================================================================
Derivative Variable Index Sets Doc
=========================== ============ =================================================================================
``heat_accumulation`` time, length Energy accumulation in tube wall per unit length of shell flow path per unit time
=========================== ============ =================================================================================


Initialization
--------------

A simple initialization method that first initializes the control volume without heat transfer,
then adds heat transfer in and solves it again, then finally solves the entire model.


Heater1D Class
--------------

.. autoclass:: Heater1D
:members:

Heater1DData Class
------------------

.. autoclass:: Heater1DData
:members:

Heater1DInitializer Class
-------------------------

.. autoclass:: Heater1DInitializer
:members:
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ Unit Models
waterpipe
boiler_heat_exchanger_3streams
feedwater_heater_0D_dynamic
cross_flow_heat_exchanger_1D
heater_1D
6 changes: 3 additions & 3 deletions idaes/apps/caprese/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""
import enum
from pyomo.environ import SolverFactory
from pyomo.core.base.var import _GeneralVarData
from pyomo.core.base.var import VarData


class ControlInitOption(enum.Enum):
Expand Down Expand Up @@ -94,7 +94,7 @@ def validate_list_of_vardata(varlist):
if not isinstance(varlist, list):
raise TypeError("Not a list of VarData")
for var in varlist:
if not isinstance(var, _GeneralVarData):
if not isinstance(var, VarData):
raise TypeError("Not a list of VarData")
return varlist

Expand All @@ -107,7 +107,7 @@ def validate_list_of_vardata_value_tuples(varvaluelist):
raise TypeError("Item in list is not a tuple")
if not len(item) == 2:
raise ValueError("Tuple in list does not have correct length")
if not isinstance(item[0], _GeneralVarData):
if not isinstance(item[0], VarData):
raise TypeError("First entry is not a VarData")
item = (item[0], float(item[1]))
return varvaluelist
Expand Down
13 changes: 1 addition & 12 deletions idaes/apps/caprese/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@
""" Block-like object meant for controller models.
"""

import idaes.logger as idaeslog
from idaes.apps.caprese.util import initialize_by_element_in_range
from idaes.apps.caprese.common.config import (
ControlPenaltyType,
)
from idaes.apps.caprese.common.config import VariableCategory as VC
from idaes.apps.caprese.categorize import (
categorize_dae_variables,
CATEGORY_TYPE_MAP,
)
Comment on lines -17 to -26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these are all unused imports being removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - I generally clean these up as I find them.


from idaes.apps.caprese.nmpc_var import (
NmpcVar,
DiffVar,
AlgVar,
InputVar,
Expand All @@ -35,22 +29,17 @@
)
from idaes.apps.caprese.dynamic_block import (
_DynamicBlockData,
IndexedDynamicBlock,
DynamicBlock,
)
from idaes.core.util.model_statistics import degrees_of_freedom

from pyomo.environ import (
Objective,
check_optimal_termination,
Constraint,
Block,
)
from pyomo.core.base.block import _BlockData
from pyomo.common.collections import ComponentMap
from pyomo.core.base.range import remainder
from pyomo.dae.set_utils import deactivate_model_at
from pyomo.dae.flatten import flatten_dae_components
from pyomo.core.base.indexed_component import UnindexedComponent_set


Expand Down
Loading
Loading