-
Notifications
You must be signed in to change notification settings - Fork 297
Replies: 2 comments · 11 replies
-
|
Can you please provide the entire stack trace, not just the final error message? While theoretically the Gibbs reactor should work for multiphase systems, it has not been tested. IDAES (or, more precisely, the modular property framework) uses the term "equation of state" more broadly than is traditional in the thermodynamic literature. For example, the |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Here's my property package code. I adapted much of it from the natural gas property example. |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
You first need to uncomment Next, there's an error in This is incorrect, but it is incorrect in Observe: However, the main problem isn't either of those things, but a bug in the The fix is straightforward, but testing, etc. adds additional overhead. I've opened an issue #1615 , but I make no promises about when it will be fixed. Feel free to attempt a fix yourself and open a PR. |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Thank you for your helpful comment. I appreciate the clarification, and I'll do my best to address the main problem regarding the incorrect component summation in elemental_flow_in. I'll look into a fix and see if I can open a PR soon. |
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
|
Hello, Following up on a previous question I posted—thanks again for your helpful advice. Based on your suggestion, I approached the issue in the IDAES Gibbs Reactor more intuitively and modified parts of the code accordingly. In the process, I noticed some overlap with ControlVolume0D, so I made a few changes there as well. These adjustments helped me avoid the earlier "invalid phase" errors. However, I’m now encountering a different issue—specifically, numerical problems that arise even scaling. I’ll include the relevant debug output below to show what I’ve found so far. It’s been difficult to identify the root cause of this behavior. If you have any suggestions on how to resolve or further debug this, I’d really appreciate your help. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Beta Was this translation helpful? Give feedback.
All reactions
-
Without your exact code, it's hard to diagnose what might be going wrong. Your solve starting out with a primal infeasibility of If you've set scaling factors for constraints using the |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Thank you always for your helpful responses. I apologize for the delayed reply; I had some other matters to attend to. Personally, I believe that the previous issues were caused by the code looping over all possible combinations of phases and components, rather than just the valid ones. Therefore, I went through the relevant sections and modified the code to restrict these loops to valid phase-component combinations. The codes I updated include the ControlVolume0D, Gibbs reactor, and the generic property package. Due to the large amount of code, I am only including the parts that have been changed, as shown below.
|
Beta Was this translation helpful? Give feedback.
All reactions
-
|
Other than these changes, the rest of the code is written the same as in the code examples I previously shared (it is essentially the original natural_gas_property code with only solid phases added). Just in case, I am attaching the remaining code sections as well. Additionally, I applied the scaling advice you provided, but the results are still not coming out as expected. If it seems like the problem could be resolved just by improving the scaling, I’ll try working on that a bit more. Since I’m still not fully experienced with this, there’s a chance I just haven’t applied the scaling properly yet. import copy
import enum
import pyomo.environ as pyo
from pyomo.environ import units as pyunits
from idaes.core import SolidPhase, Component, PhaseType
from idaes.models.properties.modular_properties.state_definitions import FTPx
from idaes.models.properties.modular_properties.eos.ideal import Ideal
from idaes.models.properties.modular_properties.pure import RPP4
from idaes.models.properties.modular_properties.base.generic_reaction import ConcentrationForm
from idaes.models.properties.modular_properties.reactions.dh_rxn import constant_dh_rxn
from idaes.models.properties.modular_properties.reactions.rate_constant import arrhenius
from idaes.models.properties.modular_properties.reactions.rate_forms import power_law_rate
from idaes.core.util.exceptions import ConfigurationError
# Import Python libraries
import copy
import enum
# Import Pyomo units
import pyomo.environ as pyo
from pyomo.environ import units as pyunits
# Import IDAES cores
from idaes.core import SolidPhase, Component, PhaseType
from idaes.models.properties.modular_properties.state_definitions import FTPx
from idaes.models.properties.modular_properties.eos.ideal import Ideal
from idaes.models.properties.modular_properties.pure import RPP4, NIST
from idaes.models.properties.modular_properties.base.generic_reaction import (
ConcentrationForm,
)
from idaes.models.properties.modular_properties.reactions.dh_rxn import constant_dh_rxn
from idaes.models.properties.modular_properties.reactions.rate_constant import arrhenius
from idaes.models.properties.modular_properties.reactions.rate_forms import (
power_law_rate,
)
from idaes.core.util.exceptions import ConfigurationError
# Custom Cp + enthalpy handler (NIST-like)
class SolidNIST:
@staticmethod
def build_parameters(c):
# 기존 컴포넌트가 있으면 삭제
if hasattr(c, "enth_mol_form_ref"):
c.del_component("enth_mol_form_ref")
if hasattr(c, "dens_mol"):
c.del_component("dens_mol")
c.enth_mol_form_ref = pyo.Var(
initialize=0,
units=pyunits.J / pyunits.mol,
doc="Standard state molar heat of formation at reference T",
)
val, units = c.config.parameter_data["enth_mol_form_ref"]
c.enth_mol_form_ref.fix(val * units)
#RPP4.build_parameters(c) # Use Shomate coefficients
c.dens_mol = pyo.Var(
initialize=70000,
units=pyunits.mol / pyunits.m**3,
doc="Solid molar density"
)
dens_val, dens_unit = c.config.parameter_data["dens_mol"]
c.dens_mol.fix(dens_val * dens_unit)
@staticmethod
def return_expression(b, c, T):
t = T / 1000
coeff = c.config.parameter_data["cp_mol_ig_comp_coeff"]
cp = (
coeff["A"]
+ coeff["B"] * t
+ coeff["C"] * t**2
+ coeff["D"] * t**3
+ coeff["E"] / t**2
) * pyunits.J / pyunits.mol / pyunits.K
return cp
@staticmethod
def return_enth_mol_expression(b, c, T):
t = T / 1000
coeff = c.config.parameter_data["cp_mol_ig_comp_coeff"]
h = (
coeff["A"] * t
+ coeff["B"] * t**2 / 2
+ coeff["C"] * t**3 / 3
+ coeff["D"] * t**4 / 4
- coeff["E"] / t
+ coeff["F"]
) * 1000 # kJ/mol → J/mol
return c.enth_mol_form_ref + h
@staticmethod
def return_entr_mol_expression(b, c, T):
t = T / 1000
coeff = c.config.parameter_data["cp_mol_ig_comp_coeff"]
s = (
coeff["A"] * pyo.log(t)
+ coeff["B"] * t
+ coeff["C"] * t**2 / 2
+ coeff["D"] * t**3 / 3
- coeff["E"] / (2 * t**2)
+ coeff["G"]
) * pyunits.J / pyunits.mol / pyunits.K
return s
@staticmethod
def return_dens_mol_expression(b, c):
return c.dens_mol#################################################################################
# The Institute for the Design of Advanced Energy Systems Integrated Platform
# Framework (IDAES IP) was produced under the DOE Institute for the
# Design of Advanced Energy Systems (IDAES).
#
# Copyright (c) 2018-2024 by the software owners: The Regents of the
# University of California, through Lawrence Berkeley National Laboratory,
# National Technology & Engineering Solutions of Sandia, LLC, Carnegie Mellon
# University, West Virginia University Research Corporation, et al.
# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md
# for full copyright and license information.
#################################################################################
"""
Natural gas property package for the vapor phase using Peng-Robinson equation
of state.
"""
# TODO: Missing docstrings
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
# Import Python libraries
import logging
import copy
import enum
# Import Pyomo units
import pyomo.environ as pyo
from pyomo.environ import units as pyunits
# Import IDAES cores
from idaes.core import VaporPhase, SolidPhase, Component, PhaseType
from idaes.models.properties.modular_properties.state_definitions import FTPx
from idaes.models.properties.modular_properties.eos.ceos import Cubic, CubicType
from idaes.models.properties.modular_properties.eos.ideal import Ideal
from idaes.models.properties.modular_properties.phase_equil.forms import (
log_fugacity,
)
from idaes.models.properties.modular_properties.phase_equil import SmoothVLE
from idaes.models.properties.modular_properties.pure import (
NIST,
RPP4,
RPP5,
ChapmanEnskogLennardJones,
Eucken,
)
from idaes.models.properties.modular_properties.base.generic_reaction import (
ConcentrationForm,
)
from idaes.models.properties.modular_properties.transport_properties import (
ViscosityWilke,
ThermalConductivityWMS,
NoMethod,
)
from idaes.models.properties.modular_properties.transport_properties.viscosity_wilke import (
wilke_phi_ij_callback,
)
from idaes.models.properties.modular_properties.reactions.dh_rxn import constant_dh_rxn
from idaes.models.properties.modular_properties.reactions.rate_constant import arrhenius
from idaes.models.properties.modular_properties.reactions.rate_forms import (
power_law_rate,
)
from idaes.core.util.exceptions import ConfigurationError
# Set up logger
_log = logging.getLogger(__name__)
class EosType(enum.Enum):
PR = 1
IDEAL = 2
# Property Sources
# Source: NIST webbook
# Properties: Heat capacity coefficients for all species except ethane,
# propane, and butane. Reference enthalpies and entropies for all species.
# Source: The Properties of Gases and Liquids (1987)
# 4th edition, Chemical Engineering Series - Robert C. Reid
# Properties: Critical temperatures and pressures. Omega.
# Heat capacity coefficients for ethane, propane, and butane.
_phase_dicts_ideal = {
"Vap": {
"type": VaporPhase,
"equation_of_state": Ideal,
"visc_d_phase": ViscosityWilke,
"transport_property_options": {
"viscosity_phi_ij_callback": wilke_phi_ij_callback,
},
"therm_cond_phase": ThermalConductivityWMS,
},
"Sol": {
"type": SolidPhase,
"equation_of_state": Ideal,
},
}
_component_params = {
"H2": {
"type": Component,
"valid_phase_types": [PhaseType.vaporPhase],
"elemental_composition": {"H": 2},
"enth_mol_ig_comp": NIST,
"entr_mol_ig_comp": NIST,
"cp_mol_ig_comp": NIST,
"visc_d_phase_comp": {"Vap": ChapmanEnskogLennardJones},
"therm_cond_phase_comp": {"Vap": Eucken},
"parameter_data": {
"mw": (0.0020159, pyunits.kg / pyunits.mol),
"pressure_crit": (13e5, pyunits.Pa),
"temperature_crit": (33.2, pyunits.K),
"omega": -0.218,
"cp_mol_ig_comp_coeff": {
"A": 33.066178,
"B": -11.363417,
"C": 11.432816,
"D": -2.772874,
"E": -0.158558,
"F": -9.980797,
"G": 172.707974,
"H": 0.0,
},
"lennard_jones_sigma": (2.826, pyunits.angstrom),
"lennard_jones_epsilon_reduced": (59.7, pyunits.K),
"f_int_eucken": 1,
},
},
"CO": {
"type": Component,
"valid_phase_types": [PhaseType.vaporPhase],
"elemental_composition": {"C": 1, "O": 1},
"enth_mol_ig_comp": NIST,
"entr_mol_ig_comp": NIST,
"cp_mol_ig_comp": NIST,
"visc_d_phase_comp": {"Vap": ChapmanEnskogLennardJones},
"therm_cond_phase_comp": {"Vap": Eucken},
"parameter_data": {
"mw": (0.0280101, pyunits.kg / pyunits.mol),
"pressure_crit": (35e5, pyunits.Pa),
"temperature_crit": (132.9, pyunits.K),
"omega": 0.066,
"cp_mol_ig_comp_coeff": {
"A": 25.56759,
"B": 6.09613,
"C": 4.054656,
"D": -2.671301,
"E": 0.131021,
"F": -118.0089,
"G": 227.3665,
"H": -110.5271,
},
"lennard_jones_sigma": (3.690, pyunits.angstrom),
"lennard_jones_epsilon_reduced": (91.7, pyunits.K),
"f_int_eucken": 1,
},
},
"H2O": {
"type": Component,
"valid_phase_types": [PhaseType.vaporPhase],
"elemental_composition": {"H": 2, "O": 1},
"enth_mol_ig_comp": NIST,
"entr_mol_ig_comp": NIST,
"cp_mol_ig_comp": NIST,
"pressure_sat_comp": NIST,
"parameter_data": {
"mw": (0.01801528, pyunits.kg / pyunits.mol),
"pressure_crit": (221.2e5, pyunits.Pa),
"temperature_crit": (647.3, pyunits.K),
"omega": 0.344,
"cp_mol_ig_comp_coeff": {
"A": 30.092,
"B": 6.832514,
"C": 6.793435,
"D": -2.53448,
"E": 0.082139,
"F": -250.881,
"G": 223.3967,
"H": -241.8264,
},
"pressure_sat_comp_coeff": { # NIST <- Stull 1947
"A": 4.6543,
"B": 1435.264,
"C": -64.848,
},
"lennard_jones_sigma": (2.641, pyunits.angstrom),
"lennard_jones_epsilon_reduced": (809.1, pyunits.K),
"f_int_eucken": 1,
},
},
"CO2": {
"type": Component,
"valid_phase_types": [PhaseType.vaporPhase],
"visc_d_phase_comp": {"Vap": ChapmanEnskogLennardJones},
"therm_cond_phase_comp": {"Vap": Eucken},
"elemental_composition": {"C": 1, "O": 2},
"enth_mol_ig_comp": NIST,
"entr_mol_ig_comp": NIST,
"cp_mol_ig_comp": NIST,
"parameter_data": {
"mw": (0.04401, pyunits.kg / pyunits.mol),
"pressure_crit": (73.8e5, pyunits.Pa),
"temperature_crit": (304.1, pyunits.K),
"omega": 0.239,
"cp_mol_ig_comp_coeff": {
"A": 24.99735,
"B": 55.18696,
"C": -33.69137,
"D": 7.948387,
"E": -0.136638,
"F": -403.6075,
"G": 228.2431,
"H": -393.5224,
},
"lennard_jones_sigma": (3.941, pyunits.angstrom),
"lennard_jones_epsilon_reduced": (195.2, pyunits.K),
"f_int_eucken": 1,
},
},
"O2": {
"type": Component,
"valid_phase_types": [PhaseType.vaporPhase],
"visc_d_phase_comp": {"Vap": ChapmanEnskogLennardJones},
"therm_cond_phase_comp": {"Vap": Eucken},
"elemental_composition": {"O": 2},
"enth_mol_ig_comp": NIST,
"entr_mol_ig_comp": NIST,
"cp_mol_ig_comp": NIST,
"parameter_data": {
"mw": (0.031998, pyunits.kg / pyunits.mol),
"pressure_crit": (50.4e5, pyunits.Pa),
"temperature_crit": (154.6, pyunits.K),
"omega": 0.025,
"cp_mol_ig_comp_coeff": {
"A": 30.03235,
"B": 8.772972,
"C": -3.988133,
"D": 0.788313,
"E": -0.741599,
"F": -11.32468,
"G": 236.1663,
"H": 0.0,
},
"lennard_jones_sigma": (3.467, pyunits.angstrom),
"lennard_jones_epsilon_reduced": (106.7, pyunits.K),
"f_int_eucken": 1,
},
},
"CH4": {
"type": Component,
"valid_phase_types": [PhaseType.vaporPhase],
"elemental_composition": {"C": 1, "H": 4},
"enth_mol_ig_comp": NIST,
"entr_mol_ig_comp": NIST,
"cp_mol_ig_comp": NIST,
"visc_d_phase_comp": {"Vap": ChapmanEnskogLennardJones},
"therm_cond_phase_comp": {"Vap": Eucken},
"parameter_data": {
"mw": (0.0160425, pyunits.kg / pyunits.mol),
"pressure_crit": (46e5, pyunits.Pa),
"temperature_crit": (190.4, pyunits.K),
"omega": 0.011,
"cp_mol_ig_comp_coeff": {
"A": -0.703029,
"B": 108.4773,
"C": -42.52157,
"D": 5.862788,
"E": 0.678565,
"F": -76.84376,
"G": 158.7163,
"H": -74.8731,
},
"lennard_jones_sigma": (3.758, pyunits.angstrom),
"lennard_jones_epsilon_reduced": (148.6, pyunits.K),
"f_int_eucken": 1,
},
},
}
_component_params_solid = {
"Fe": {
"type": Component,
"valid_phase_types": [PhaseType.solidPhase],
"elemental_composition": {"Fe": 1},
"enth_mol_sol_comp": SolidNIST,
"cp_mol_sol_comp": SolidNIST,
"entr_mol_sol_comp": SolidNIST,
"dens_mol_sol_comp": SolidNIST,
"parameter_data": {
"mw": (0.055845, pyunits.kg / pyunits.mol),
"enth_mol_form_ref": (0, pyunits.J / pyunits.mol),
"dens_mol": (70000, pyunits.mol / pyunits.m**3),
"cp_mol_ig_comp_coeff": {
"A": 23.97449, "B": 8.367750, "C": 0.000277, "D": -0.000088,
"E": 0, "F": 0, "G": 0, "H": 0
},
},
},
"FeO": {
"type": Component,
"valid_phase_types": [PhaseType.solidPhase],
"elemental_composition": {"Fe": 1, "O": 1},
"enth_mol_sol_comp": SolidNIST,
"cp_mol_sol_comp": SolidNIST,
"entr_mol_sol_comp": SolidNIST,
"dens_mol_sol_comp": SolidNIST,
"parameter_data": {
"mw": (0.071844, pyunits.kg / pyunits.mol),
"enth_mol_form_ref": (-272000, pyunits.J / pyunits.mol),
"dens_mol": (60000, pyunits.mol / pyunits.m**3),
"cp_mol_ig_comp_coeff": {
"A": 45.75120, "B": 18.78553, "C": -5.952201, "D": 0.852779,
"E": 0, "F": 0, "G": 0, "H": 0
},
},
},
"Fe3O4": {
"type": Component,
"valid_phase_types": [PhaseType.solidPhase],
"elemental_composition": {"Fe": 3, "O": 4},
"enth_mol_sol_comp": SolidNIST,
"cp_mol_sol_comp": SolidNIST,
"entr_mol_sol_comp": SolidNIST,
"dens_mol_sol_comp": SolidNIST,
"parameter_data": {
"mw": (0.231533, pyunits.kg / pyunits.mol),
"enth_mol_form_ref": (-1118000, pyunits.J / pyunits.mol),
"dens_mol": (25000, pyunits.mol / pyunits.m**3),
"cp_mol_ig_comp_coeff": {
"A": 104.2096, "B": 178.5108, "C": -68.2520, "D": 9.1979,
"E": 0, "F": 0, "G": 0, "H": 0
},
},
},
"Fe2O3": {
"type": Component,
"valid_phase_types": [PhaseType.solidPhase],
"elemental_composition": {"Fe": 2, "O": 3},
"enth_mol_sol_comp": SolidNIST,
"cp_mol_sol_comp": SolidNIST,
"entr_mol_sol_comp": SolidNIST,
"dens_mol_sol_comp": SolidNIST,
"parameter_data": {
"mw": (0.15969, pyunits.kg / pyunits.mol),
"enth_mol_form_ref": (-824200, pyunits.J / pyunits.mol),
"dens_mol": (30000, pyunits.mol / pyunits.m**3),
"cp_mol_ig_comp_coeff": {
"A": 110.9362, "B": 32.04714, "C": -9.192333, "D": 0.901506,
"E": 0, "F": 0, "G": 0, "H": 0
},
},
},
}
def get_prop(components=None, phases=["Vap", "Sol"], eos=EosType.IDEAL, scaled=False):
if components is None:
components = list(comp for comp in _component_params.keys()) + list(comp for comp in _component_params_solid.keys())
#components = list(comp for comp in _component_params.keys())
configuration = {
"components": {},
"parameter_data": {},
"phases": {
"Vap": copy.deepcopy(_phase_dicts_ideal["Vap"]),
"Sol": copy.deepcopy(_phase_dicts_ideal["Sol"]),
},
"base_units": {
"time": pyunits.s,
"length": pyunits.m,
"mass": pyunits.kg,
"amount": pyunits.mol,
"temperature": pyunits.K,
},
"state_definition": FTPx,
"state_bounds": {
"flow_mol": (0, 8000, 50000, pyunits.mol / pyunits.s),
"temperature": (273.15, 500, 2500, pyunits.K),
"pressure": (5e4, 1.3e5, 1e8, pyunits.Pa),
},
"pressure_ref": (101325, pyunits.Pa),
"temperature_ref": (298.15, pyunits.K),
"parameter_data": {},
# scaling factor도 아마 여기에 들어가야할듯
}
#phase_comp_set = []
c = configuration["components"]
for comp in components:
if comp in _component_params:
c[comp] = copy.deepcopy(_component_params[comp])
if PhaseType.vaporPhase in c[comp]["valid_phase_types"]:
configuration["phases"]["Vap"] = copy.deepcopy(_phase_dicts_ideal["Vap"])
elif comp in _component_params_solid:
c[comp] = copy.deepcopy(_component_params_solid[comp])
if PhaseType.solidPhase in c[comp]["valid_phase_types"]:
configuration["phases"]["Sol"] = copy.deepcopy(_phase_dicts_ideal["Sol"])
else:
raise ConfigurationError(f"Component '{comp}' not found.")
#configuration["phase_component_set"] = phase_comp_set
return configuration
from pyomo.environ import ConcreteModel, value, TransformationFactory, Var
from idaes.core import FlowsheetBlock
from idaes.models.unit_models import Feed, Product
from idaes.models.unit_models import GibbsReactor
#from idaes.models.properties.modular_properties import GenericParameterBlock
#from generic_property_revised import GenericParameterBlock
from idaes.core.util.initialization import propagate_state
from idaes.core.solvers import get_solver
import idaes.logger as idaeslog
# 1. 모델 생성
m = ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)
# 2. Property package 설정
thermo_config = get_prop(components=["CH4", "H2O", "H2", "CO", "CO2", "Fe", "FeO", "Fe3O4", "Fe2O3"])
m.fs.thermo_props = GenericParameterBlock(**thermo_config)
# 3. 유닛 구성
m.fs.feed = Feed(property_package=m.fs.thermo_props)
m.fs.reactor = GibbsReactor(
property_package=m.fs.thermo_props,
has_heat_transfer=False,
has_pressure_change=False,
)
m.fs.product = Product(property_package=m.fs.thermo_props)
# 4. 연결
from pyomo.network import Arc
m.fs.s01 = Arc(source=m.fs.feed.outlet, destination=m.fs.reactor.inlet)
m.fs.s02 = Arc(source=m.fs.reactor.outlet, destination=m.fs.product.inlet)
TransformationFactory("network.expand_arcs").apply_to(m)
# 5. Feed 조건 설정
m.fs.feed.outlet.flow_mol[0].fix(100)
m.fs.feed.outlet.pressure[0].fix(1e6)
m.fs.feed.outlet.temperature[0].fix(1200)
m.fs.feed.outlet.mole_frac_comp[0, "CH4"].fix(1e-5)
m.fs.feed.outlet.mole_frac_comp[0, "CO"].fix(0.337)
m.fs.feed.outlet.mole_frac_comp[0, "CO2"].fix(0.039)
m.fs.feed.outlet.mole_frac_comp[0, "H2"].fix(0.225)
m.fs.feed.outlet.mole_frac_comp[0, "H2O"].fix(1e-5)
m.fs.feed.outlet.mole_frac_comp[0, "Fe2O3"].fix(0.399)
m.fs.feed.outlet.mole_frac_comp[0, "Fe3O4"].fix(1e-5)
m.fs.feed.outlet.mole_frac_comp[0, "FeO"].fix(1e-5)
m.fs.feed.outlet.mole_frac_comp[0, "Fe"].fix(1e-5)
# m.fs.feed.outlet.mole_frac_comp[0, "CH4"].fix(0.01)
# m.fs.feed.outlet.mole_frac_comp[0, "CO"].fix(0.325)
# m.fs.feed.outlet.mole_frac_comp[0, "CO2"].fix(0.031)
# m.fs.feed.outlet.mole_frac_comp[0, "H2"].fix(0.205)
# m.fs.feed.outlet.mole_frac_comp[0, "H2O"].fix(0.01)
# m.fs.feed.outlet.mole_frac_comp[0, "Fe2O3"].fix(0.389)
# m.fs.feed.outlet.mole_frac_comp[0, "Fe3O4"].fix(0.01)
# m.fs.feed.outlet.mole_frac_comp[0, "FeO"].fix(0.01)
# m.fs.feed.outlet.mole_frac_comp[0, "Fe"].fix(0.01)
from idaes.core.util import scaling as iscale
#from pyomo.util.scaling import scale_model
m.fs.reactor.calculate_scaling_factors()
from pyomo.core.base.constraint import Constraint
# component_scaling = {
# "Fe": 1e-5,
# "FeO": 1e-5,
# "Fe3O4": 1e-5,
# "Fe2O3": 1e-5,
# "CH4": 1e-5,
# "CO": 1e-5,
# "CO2": 1e-5,
# "H2": 1e-5,
# "H2O": 1e-5
# }
# constraint_scaling = {
# "sum_mole_frac": 1.0, # 단순한 비율식이므로 보통 1.0
# "phase_fraction_constraint": 1.0,
# "component_flow_balances": 1e-10, # 혹은 더 적절한 값
# "total_flow_balance": 1e-10,
# }
# for c in m.component_objects(ctype=Constraint, descend_into=True):
# if hasattr(c, 'index_set'):
# for index in c:
# if isinstance(index, tuple) and len(index) >= 2:
# phase, comp = index[:2]
# if comp in component_scaling:
# sf = component_scaling[comp]
# iscale.constraint_scaling_transform(c[index], s=sf)
# else:
# # 기본값 (예: 1.0)
# iscale.constraint_scaling_transform(c[index], s=1.0)
# #개별 제약식 scaling 적용 (필요한 경우)
# for c in m.component_objects(ctype=Constraint, descend_into=True):
# for index in c:
# if iscale.get_scaling_factor(c[index]) is None:
# iscale.constraint_scaling_transform(c[index], s=1e-12)
# solid_components = ["Fe", "FeO", "Fe3O4", "Fe2O3"]
# for c in m.component_objects(ctype=Constraint, descend_into=True):
# if hasattr(c, 'index_set'):
# for index in c:
# # index가 phase, comp 정보 포함하고 있는지 확인
# if isinstance(index, tuple) and len(index) >= 2:
# phase, comp = index[:2]
# if phase == "Sol" and comp in solid_components:
# iscale.constraint_scaling_transform(c[index], s=1e-12)
# Scaling 현황 보고 (디버깅용)
#iscale.report_scaling_factors(m)
# 6. 초기화 및 풀이
m.fs.feed.initialize()
propagate_state(m.fs.s01)
# 주요 초기화 로그 확인
m.fs.reactor.initialize(outlvl=idaeslog.DEBUG)
propagate_state(m.fs.s02)
m.fs.product.initialize()
solver = get_solver()
#solver.options = {'nlp_scaling_method': 'user-scaling'}
solver.options["halt_on_ampl_error"] = "yes"
results = solver.solve(m, tee=True)
# solver = get_solver()
# results = solver.solve(m, tee=True)
# 7. 결과 출력
print("\n[제품 조성]")
for c in m.fs.thermo_props.component_list:
x = value(m.fs.product.inlet.mole_frac_comp[0, c])
if x > 1e-6:
print(f"{c}: {x:.4f}") |
Beta Was this translation helpful? Give feedback.
All reactions
-
As a side comment, it's recommended to avoid mutable objects, like lists, sets, dictionaries, etc. as default arguments for functions, because Python uses the same instance of the object every time the function is called. The design pattern we use in IDAES is to assign There's no reason to take Other than that, I don't see any obvious issues. The Gibbs reactor isn't well-scaled by default, though. There's a |
Beta Was this translation helpful? Give feedback.
All reactions
-
|
I forgot to address the The cubic equation of state uses it to calculate gibbs energy, whereas the ideal equation of state, whereas the ideal equation of state simply takes the log of You could try changing the implementation in the ideal equation of state to see if that helps your Gibbs reactor. However, note that adding these log variables can also cause problems if you have components with mole fractions on the order of 1e-16 going through an isentropic compressor, because the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I’m currently working on modeling a Chemical Looping Hydrogen Production (CLHP) process using IDAES. While I am aware of the counter-current moving bed example, my current implementation is more aligned with the Aspen Plus configuration, where the system consists of a series of five Gibbs reactors.
To explore better optimization capabilities, I’m trying to replicate this setup in IDAES using Gibbs reactors. However, I'm encountering some confusion, especially related to property packages. Since the Gibbs reactor in IDAES requires a single property package, I attempted to include both gas and solid phases in one package. This led to the following error:
KeyError: "Index '('Vap', 'Fe')' is not valid for indexed component 'fs.reactor.control_volume.properties_in[0.0].flow_mol_phase_comp'"
I haven't yet found a working example where a single property package handles multiphase (Vap + Sol) components for a Gibbs reactor.
Are there any existing examples that demonstrate this, or would you have any recommendations on how to properly set up a unified multiphase property package?
Also, I understand that in general, solids do not require an equation of state (EOS). Is it still mandatory to provide one in IDAES for the solid phase, or is there a way around it?
Thank you for your help!
Beta Was this translation helpful? Give feedback.
All reactions