watertap.core.util package
Subpackages
Submodules
watertap.core.util.initialization module
This module contains utility functions for initialization of WaterTAP models.
- watertap.core.util.initialization.assert_degrees_of_freedom(blk, expected_dof)[source]
Assert that degrees of freedom are
expected_dof
. If notexpected_dof
, throw an error and stop.- Keyword Arguments:
blk – block to check
expected_dof – Integer number of degrees of freedom
blk
should have
- Returns:
None
- watertap.core.util.initialization.assert_no_degrees_of_freedom(blk)[source]
Assert that degrees of freedom are 0. If
blk
has non-zero degrees of freedom, throw an error and stop.- Keyword Arguments:
blk – block to check
- Returns:
None
- watertap.core.util.initialization.check_dof(blk, fail_flag=False, logger=<LoggerAdapter idaes.watertap.core.util.initialization (INFO)>, expected_dof=0)[source]
Check that degrees of freedom are 0, or the expected amount
expected_dof
. If not 0 orexpected_dof
, either throw a warning and continue or throw an error and stop.- Keyword Arguments:
blk – block to check
fail_flag – Boolean argument to specify error or warning
(Default – fail_flag=False produces logger warning. Set fail_flag=True to raise an error and stop the initialization routine.)
logger – Optional argument for loading idaes.getInitLogger object (e.g., logger=init_log)
expected_dof – Integer number of degrees of freedom
blk
should have
- Returns:
None
- watertap.core.util.initialization.check_solve(results, checkpoint=None, logger=<LoggerAdapter idaes.watertap.core.util.initialization (INFO)>, fail_flag=False)[source]
Check that solver termination is optimal and OK in an initialization routine. If the check fails, proceed through initialization with only a logger warning by default, or set fail_flag=True to raise an error. This should also work for checking a solve outside of an initialization routine.
- Keyword Arguments:
results – solver results
checkpoint – Optional string argument to specify the step of initialization being checked (e.g., checkpoint=”Initialization step 1: solve indexed blocks”)
logger – Optional argument for loading idaes.getInitLogger object (e.g., logger=init_log)
fail_flag – Boolean argument to specify error or warning (Default: fail_flag=False produces logger warning. set fail_flag=True to raise an error and stop the initialization routine.)
- Returns:
None
watertap.core.util.misc module
watertap.core.util.oli_api module
This class provides methods for using the OLI Cloud API and augments the code provided via OLI API documentation. [WIP]
Most of this code was adopted from examples in OLI’s documentation, with modifications implemented for interfacing w/WaterTap and addition of other functions for better utilizing OLI API functionality
- class watertap.core.util.oli_api.OLIApi(username=None, password=None, root_url=None, auth_url=None)[source]
Bases:
object
A class to wrap OLI Cloud API calls to be accessible in a simple manner. This is just an example
- __init__(username=None, password=None, root_url=None, auth_url=None)[source]
Constructs all necessary attributes for OLIApi class
Args: username: user’s username password: user’s password root_url: root url auth_url: authorization url
- call(function_name, chemistry_model_file_id, json_input={}, poll_time=1.0, max_request=1000, tee=False)[source]
calls a function in the OLI Engine API.
- Parameters:
function_name – name of function to call
chemistry_model_file_id – the chemistry model file if for this calculation
json_input – calculation input JSON
poll_time – max delay between each call
max_request – maximum requests
tee – boolean argument to hide or display print messages
Returns: dictionary containing result or error
- composition_survey(survey=None, chemistry_file_ID=None, input_dict=None, stateblock=None, time_point=None, AllowSolidsToForm=False, zero_species=None, tee=True)[source]
This method allows the user to conduct an OLI composition survey. A survey can be conducted over as many components as desired, hypothetically, enabled by _recursive_survey().
- Parameters:
survey – dictionary with component name as the key, and the min, max, and number of samples (corresponding to start, stop, and num args in numpy linspace)
e.g. – {“CAOH2”: (0, 350, 3), “NA2CO3”: (0, 350, 3), “NAION”: (10000,20000,3),}
chemistry_file_ID – OLI chemistry file ID (i.e., DBS file ID)
input_dict – dictionary with input concentration data for call function which runs calculations in OLI Cloud API
- Returns:
OLI results inflows: inflow data used in OLI calculations
- Return type:
final_results
- create_dbs_dict(ions=None, phases=None, thermo_framework=None, model_name=None)[source]
Creates dict for chemistry-builder to later generate a DBS file ID :param ions: OLI-compatible ion names as a Pyomo Set, list, or dict where the keys are ion names :param phases: OLI-compatible phases; if None, use default of liquid1 and solid
Returns: dbs_dict: dictionary in OLI format needed to generate chemistry [DBS] file ID
#TODO: support not None for phases
- create_input_dict(stateblock, time_point=None, AllowSolidsToForm=False, zero_species=None)[source]
Creates dict for call function that performs calculations via OLI Cloud API stateblock: stateblock that contains ion concentrations, ion charge, temp and pressure time_point: stateblock time dimension
- generate_chemistry_file(function_name, chemistry_model_file_id='', json_input={})[source]
calls chemistry-builder function in the OLI Engine API.
- Parameters:
function_name – name of function to call
chemistry_model_file_id – the chemistry model file if for this calculation
json_input – calculation input JSON
poll_time – max delay between each call
max_request – maximum requests
Returns: dictionary containing result or error
- get_dbs_file_id(dbs_file_path=None, ions=None, phases=None, thermo_framework=None, model_name=None)[source]
Returns the chemistry file ID (dbs_file_id) from either (1) creating a DBS dict that requires ion names and is then fed to chemistry-builder or (2) an uploaded DBS via the “manual” workflow without using chemistry-builder
- Parameters:
dbs_file_path – file path to DBS file.
ions – ion names as pyomo set
Returns: chemistry file ID as a string
- get_flash_history(dbs_file_id)[source]
Retrieves history of flash information, e.g., input for a chemistry model :param dbs_file_id: the DBS file ID
Returns: dictionary containing array of submitted jobs, from which the jobID and input data can be obtained
- get_job_id(dbs_file_id)[source]
Retrieves jobID which is useful for troubleshooting with OLI Support Team :param dbs_file_id: the DBS file ID
Returns: OLI jobID
- get_user_dbs_files()[source]
Returns a dictionary containing a list of all user dbs file(s) uploaded
- login(tee=True, fail_flag=True)[source]
Login into user credentials for the OLI Cloud
- Parameters:
tee – boolean argument to print status code when True
fail_flag – boolean argument to raise exception upon login failure when True
Returns: True on success, False on failure
- refresh_token()[source]
Refreshes the access token using the refresh token got obtained on login Returns: True on success, False on failure
watertap.core.util.scaling module
This module contains a utility function for the scaling of WaterTAP property model constraints.