##############################################################################
# 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".
##############################################################################
"""
Library of utility functions for initialization
"""
__author__ = "Andrew Lee"
[docs]def get_port_value(port, port_idx=None):
port_dict = {}
# Iterate over all members of source port
if port_idx is None:
tk = port.parent_block().time.first()
else:
tk = (port.parent_block().time.first(), port_idx)
for k in port[tk].vars.keys():
port_dict[k] = {}
if not port[tk].vars[k].is_indexed():
# Member is unindexed
for t in port.parent_block().time:
if port_idx is None:
c_key = t
else:
c_key = (t, port_idx)
port_dict[k][t] = port[c_key].vars[k].value
else:
# Member has indices
if port[tk].vars[k]._implicit_subsets is None:
# Memebr has a single index
var_idx = port[tk].vars[k]._index
else:
# Member has multiple indices
var_idx = port[tk].vars[k]._implicit_subsets
for t in port.parent_block().time:
if port_idx is None:
c_key = t
else:
c_key = (t, port_idx)
for j in var_idx:
d_key = tuple([t, j])
port_dict[k][d_key] = \
port[c_key].vars[k][j].value
return port_dict