Skip to content

Commit

Permalink
Merge branch 'dynamic_surrogates' of https://github.com/Xinhe-Chen/di…
Browse files Browse the repository at this point in the history
…spatches into dynamic_surrogates
  • Loading branch information
Xinhe-Chen committed Jun 27, 2022
2 parents 3dcb821 + a9e9de2 commit dd16988
Show file tree
Hide file tree
Showing 95 changed files with 108,893 additions and 1,420 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.env

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -42,3 +44,9 @@ auto-save-list

# log
*.log

.idea/

.ipynb_checkpoints/

sim_*/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ To test that the installation was successful, run the test suite using the `pyte
pytest
```

As a developer, to ensure that all the .py files in your workspace have the correct copyright header
info (as defineded in `header_text.txt`), use the `addheader` tool installed by `requirements-dev.txt`
as follows:

```sh
addheader -c .addheader.yml
```

### Documentation

For showing documentation from your code in the Sphinx (.rst) docs, see [the Sphinx autodoc documentation](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#module-sphinx.ext.autodoc) for details on how to format and give options in your documentation file.
Expand Down
20 changes: 20 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
coverage:
precision: 2
round: down
range: "1...100"
status:
patch:
default:
target: auto
threshold: 10%
project:
default:
target: auto
threshold: 1%
codecov:
require_ci_to_pass: false
notify:
wait_for_ci: false
# after_n_builds should match the number of CI jobs configured to upload reports to Codecov
# in DISPATCHES there are 2 such jobs (1 Windows + 1 Linux for a single sample Python version)
after_n_builds: 2
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
FlowDirection,
useDefault,
)
from idaes.generic_models.unit_models.heat_exchanger import HeatExchangerFlowPattern
from idaes.models.unit_models.heat_exchanger import HeatExchangerFlowPattern
from idaes.core.util.config import is_physical_parameter_block
from idaes.core.util.misc import add_object_reference
from idaes.core.util.exceptions import ConfigurationError
from idaes.core.util.tables import create_stream_table_dataframe
from idaes.core.util.constants import Constants as c
from idaes.core.util import scaling as iscale
from idaes.core.util import get_solver
from idaes.core.solvers import get_solver
import idaes.logger as idaeslog


Expand Down Expand Up @@ -389,7 +389,7 @@ def tube_heat_transfer_eq(self, t, x):
* pyunits.convert(self.d_tube_inner, to_units=tube_units("length")) ** 2
)

def initialize(
def initialize_build(
self, state_args=None, outlvl=idaeslog.NOTSET, solver=None, optarg=None
):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

from idaes.core import FlowsheetBlock
from heat_exchanger_tube import ConcreteTubeSide
from idaes.generic_models.unit_models.heat_exchanger \
from idaes.models.unit_models.heat_exchanger \
import HeatExchangerFlowPattern

from idaes.generic_models.properties import iapws95

from idaes.core.util.model_statistics import degrees_of_freedom

from idaes.core.util import get_solver
from idaes.core.solvers import get_solver
from idaes.core.util.testing import initialization_tester

# Get default solver for testing
Expand Down
71 changes: 28 additions & 43 deletions dispatches/models/fossil_case/properties/hitecsalt_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
# "https://github.com/gmlc-dispatches/dispatches".
#################################################################################

##############################################################################
# Institute for the Design of Advanced Energy Systems Process Systems
# Engineering Framework (IDAES PSE Framework) Copyright (c) 2018, 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.txt and LICENSE.txt for full copyright and
# license information, respectively. Both files are also available online
# at the URL "https://github.com/IDAES/idaes-pse".
##############################################################################
"""
Thermo-physical property package for Hitec Salt based on empirical correlations
obtained from literatue. Hitec salt is a tertiary salt mixture consisting
Expand Down Expand Up @@ -60,9 +48,9 @@
from idaes.core.util.initialization import solve_indexed_blocks
from idaes.core.util.model_statistics import degrees_of_freedom
from idaes.core.util.initialization import fix_state_vars, revert_state_vars
from idaes.core.phases import LiquidPhase
from idaes.core.components import Component
from idaes.core.util import get_solver
from idaes.core.base.phases import LiquidPhase
from idaes.core.base.components import Component
from idaes.core.solvers import get_solver
import idaes.logger as idaeslog

# Some more inforation about this module
Expand Down Expand Up @@ -91,11 +79,11 @@ def build(self):
self.set_default_scaling('flow_mass', 0.1)
self.set_default_scaling('temperature', 0.01)
self.set_default_scaling('pressure', 1e-5)
self.set_default_scaling('enthalpy_mass', 1e-5)
self.set_default_scaling('density', 1e-3)
self.set_default_scaling('cp_specific_heat', 1e-3)
self.set_default_scaling('dynamic_viscosity', 10)
self.set_default_scaling('thermal_conductivity', 10)
self.set_default_scaling('enth_mass', 1e-5)
self.set_default_scaling('dens_mass', 1e-3)
self.set_default_scaling('cp_mass', 1e-3)
self.set_default_scaling('visc_d_phase', 10)
self.set_default_scaling('therm_cond_phase', 10)
self.set_default_scaling('enthalpy_flow_terms', 1e-6)

def _make_params(self):
Expand Down Expand Up @@ -162,14 +150,14 @@ def define_metadata(cls, obj):
obj.add_properties({'flow_mass': {'method': None, 'units': 'kg/s'},
'temperature': {'method': None, 'units': 'K'},
'pressure': {'method': None, 'units': 'Pa'},
'cp_specific_heat': {'method': None,
'cp_mass': {'method': None,
'units': 'J/kg/K'},
'density': {'method': None, 'units': 'kg/m3'},
'enthalpy': {'method': None, 'units': 'J/kg'},
'dynamic_viscosity': {'method': None,
'units': 'Pa.s'},
'thermal_conductivity': {'method': None,
'units': 'W/m/K'}})
'dens_mass': {'method': None, 'units': 'kg/m3'},
'enth_mass': {'method': None, 'units': 'J/kg'},
'visc_d_phase': {'method': None,
'units': 'Pa.s'},
'therm_cond_phase': {'method': None,
'units': 'W/m/K'}})
obj.add_default_units({'time': pyunits.s,
'length': pyunits.m,
'mass': pyunits.kg,
Expand All @@ -183,7 +171,7 @@ class _StateBlock(StateBlock):
whole, rather than individual elements of indexed Property Blocks.
"""
def initialize(blk, state_args=None,
outlvl=idaeslog.NOTSET,
outlvl=idaeslog.WARNING,
hold_state=False,
state_vars_fixed=False,
solver=None,
Expand Down Expand Up @@ -227,14 +215,11 @@ def initialize(blk, state_args=None,
if state_vars_fixed is False:
# Fix state variables if not already fixed
flags = fix_state_vars(blk, state_args)

else:
# Check when the state vars are fixed already result in dof 0
for k in blk.keys():
if degrees_of_freedom(blk[k]) != 0:
raise Exception("State vars fixed but degrees of freedom "
"for state block is not zero during "
"initialization.")
for k in blk.keys():
if degrees_of_freedom(blk[k]) != 0:
raise Exception("State vars fixed but degrees of freedom "
"for state block is not zero during "
"initialization.")

opt = get_solver(solver, optarg)

Expand Down Expand Up @@ -301,7 +286,7 @@ def _make_state_vars(self):
def _make_prop_vars(self):
"""Make additional variables for calcuations."""

self.enthalpy_mass = Var(self.phase_list,
self.enth_mass = Var(self.phase_list,
initialize=1,
units=pyunits.J/pyunits.kg,
doc='Specific Enthalpy')
Expand All @@ -310,15 +295,15 @@ def _make_constraints(self):
"""Create property constraints."""

# Specific heat capacity
self.cp_specific_heat = Expression(
self.cp_mass = Expression(
self.phase_list,
expr=(self.params.cp_param_1 +
(self.params.cp_param_2 * self.temperature) +
(self.params.cp_param_3 * (self.temperature**2))),
doc="Specific heat capacity")

# Density
self.density = Expression(
self.dens_mass = Expression(
self.phase_list,
expr=(self.params.rho_param_1 +
(self.params.rho_param_2 * self.temperature)),
Expand All @@ -327,7 +312,7 @@ def _make_constraints(self):
# Specific Enthalpy
def enthalpy_correlation(self, p):
return (
self.enthalpy_mass[p] ==
self.enth_mass[p] ==
((self.params.cp_param_1 * self.temperature) +
(self.params.cp_param_2 * self.temperature**2) +
(self.params.cp_param_3 * self.temperature**3)))
Expand All @@ -338,15 +323,15 @@ def enthalpy_correlation(self, p):
# Ref: (2015) Change et al., Energy Procedia, 69, 779 - 789

# Dynamic viscosity
self.dynamic_viscosity = Expression(
self.visc_d_phase = Expression(
self.phase_list,
expr=exp(self.params.mu_param_1 +
self.params.mu_param_2 * (log(self.temperature) +
self.params.mu_param_3)),
doc="dynamic viscosity")

# Thermal conductivity
self.thermal_conductivity = Expression(
self.therm_cond_phase = Expression(
self.phase_list,
expr=self.params.kappa_param_1 +
self.params.kappa_param_2 * (self.temperature +
Expand All @@ -355,7 +340,7 @@ def enthalpy_correlation(self, p):

# Enthalpy flow terms
def rule_enthalpy_flow_terms(b, p):
return (self.enthalpy_mass[p] * self.flow_mass)
return (self.enth_mass[p] * self.flow_mass)

self.enthalpy_flow_terms = Expression(
self.config.parameters.phase_list,
Expand Down
Loading

0 comments on commit dd16988

Please sign in to comment.