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

OLI API Flash update #1296

Merged
merged 44 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
eff9dc5
fixes for Water Analysis flash
Feb 6, 2024
0fc01bd
fixes for OLIApi and Flash
Feb 8, 2024
37fa8a2
update OLI jupyter notebook tutorial
Feb 8, 2024
8aa6731
remove unused imports
Feb 8, 2024
951841c
Update flash.py
avdudchenko Feb 14, 2024
ade39aa
update OLIApi client.py
Feb 15, 2024
35cad15
Merge branch 'watertap-org:main' into minor_oliapi_fixes
veccp Feb 15, 2024
d437b22
Merge branch 'minor_oliapi_fixes' of github.com:veccp/watertap into m…
Feb 15, 2024
4f48e17
Update flash.py
avdudchenko Feb 15, 2024
f7cbea4
updating OLIApi jupyter notebook
Feb 15, 2024
e1b5de1
remove print in flash.py
Feb 16, 2024
f10a90a
adds recursive data procesisng
avdudchenko Feb 16, 2024
11477e2
Update flash.py
avdudchenko Feb 16, 2024
f0608e1
Update flash.py
avdudchenko Feb 16, 2024
0c7473b
Fix recursive list
avdudchenko Feb 16, 2024
9a59306
update extraction
avdudchenko Feb 16, 2024
963eeb4
Frontend improvements for Flash and Client
Feb 26, 2024
d77454b
merge changes
Feb 26, 2024
9c8e073
fixes for checks
Feb 26, 2024
04fb068
change notebook kernel
Feb 26, 2024
8b703ed
fix indentation error
Feb 27, 2024
0900a69
Handling floats in get_clone
bknueven Feb 28, 2024
0cecb18
Merge branch 'main' of github.com:veccp/watertap into minor_oliapi_fixes
Feb 29, 2024
9b963f3
Merge branch 'watertap-org:main' into minor_oliapi_fixes
veccp Feb 29, 2024
1cf075d
Logic for calculated_variable
Feb 29, 2024
109a0a2
Merge branch 'minor_oliapi_fixes' of github.com:veccp/watertap into m…
Feb 29, 2024
fcf8ef5
fixes for incorporating_oli_calculations.ipynb
Feb 29, 2024
d8bdc50
add interactive_mode to tutorial
Feb 29, 2024
c1d86f8
AQ check for corrosion-rates in run_flash
Feb 29, 2024
829b1c4
Fix for Flash configure arguments
Feb 29, 2024
1bd683f
OLI test bug fixes
Feb 29, 2024
5a9060b
abstract references to input() in client
Mar 1, 2024
8508065
black
Mar 1, 2024
626fb51
fix Path error in Flash
Mar 1, 2024
83861f0
fix file names in notebook
Mar 1, 2024
546365a
Merge branch 'main' into minor_oliapi_fixes
bknueven Mar 6, 2024
b982cbd
fix OLI notebook
Mar 7, 2024
38bd663
Merge branch 'minor_oliapi_fixes' of github.com:veccp/watertap into m…
Mar 7, 2024
bfcb306
Add xfail marker to OLI notebooks if OLI API credentials are missing
lbianchi-lbl Mar 8, 2024
0731566
OLI notebook
Mar 8, 2024
fd6def5
Merge branch 'minor_oliapi_fixes' of github.com:veccp/watertap into m…
Mar 8, 2024
9a7b7b7
Update tutorials/incorporating_oli_calculations.ipynb
veccp Mar 21, 2024
321cd2b
Merge branch 'main' into minor_oliapi_fixes
adam-a-a Mar 22, 2024
6bd9855
Merge branch 'main' into minor_oliapi_fixes
lbianchi-lbl Mar 22, 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
149 changes: 91 additions & 58 deletions tutorials/incorporating_oli_calculations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"source": [
"# 1. Specify State Variables.\n",
"\n",
"- This data is used to construct inputs to OLI Cloud"
"- This data is used to construct inputs to OLI Cloud\n",
"- Same basic information is required by Water Analysis and Isothermal flashes (temperature, pressure, solutes)"
]
},
{
Expand All @@ -96,18 +97,12 @@
},
"outputs": [],
"source": [
"source_water = {\n",
"state_vars = {\n",
" \"temperature\": 298.15,\n",
" \"pressure\": 101325,\n",
" \"components\": {\n",
" \"Cl_-\": 870,\n",
" \"Na_+\": 739,\n",
" \"SO4_2-\": 1011,\n",
" \"Mg_2+\": 90,\n",
" \"Ca_2+\": 258,\n",
" \"K_+\": 9,\n",
" \"HCO3_-\": 385,\n",
" \"SiO2\": 30,\n",
" \"Na_+\": 1e3,\n",
" \"Cl_-\": 1e3\n",
" },\n",
" \"units\": {\n",
" \"temperature\": pyunits.K,\n",
Expand Down Expand Up @@ -163,18 +158,26 @@
},
"outputs": [],
"source": [
"survey_conditions = {\n",
" \"Temperature\": linspace(273, 373, 10),\n",
" \"SO4_2-\": linspace(0, 1e3, 10),\n",
" \"Ca_2+\": linspace(0, 1e3, 10),\n",
"}\n",
"\n",
"# a survey will sweep through one or more variables simultaneously\n",
"survey = f.build_survey(\n",
" survey_conditions,\n",
" {\"Na_+\": linspace(0, 1e5, 10)},\n",
" get_oli_names=True,\n",
" file_name=\"test_survey\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# individual sample points can be accessed to see what will be modified\n",
"samples = range(0,10,2)\n",
"survey_points = f.get_survey_sample_conditions(survey, samples)\n",
"f.write_output(survey_points, \"test_survey_points\")"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -199,12 +202,15 @@
"outputs": [],
"source": [
"try:\n",
" # credentials are entered here\n",
" # up to 5 access keys per user can be generated\n",
" # CredentialManager can save login information and access keys\n",
" credential_manager = CredentialManager(\n",
" username=\"\",\n",
" password=\"\",\n",
" root_url=\"\",\n",
" auth_url=\"\",\n",
" access_keys=[],\n",
" username=\"\", # requires password, root_url, and auth_url\n",
" password=\"\", # required with username login only\n",
" root_url=\"\", # required with username and access key login\n",
" auth_url=\"\", # required with username login only\n",
" access_keys=[], # only requires root_url\n",
" )\n",
"except (OSError, ConnectionError) as e:\n",
" print(e)\n",
Expand Down Expand Up @@ -234,44 +240,70 @@
"outputs": [],
"source": [
"if credential_manager:\n",
" # OLIApi is used as a context manager\n",
" with OLIApi(credential_manager) as oliapi:\n",
" # create a new DBS file\n",
" # alternative thermo_frameworks and private_databanks are available\n",
" dbs_file_id = oliapi.get_dbs_file_id(\n",
veccp marked this conversation as resolved.
Show resolved Hide resolved
" chemistry_source=source_water[\"components\"],\n",
" phases=[\"liquid1\", \"solid\"],\n",
" state_vars[\"components\"],\n",
" thermo_framework=\"MSE (H3O+ ion)\",\n",
" private_databanks=[\"XSC\"],\n",
" phases=[\"liquid1\", \"solid\"], # liquid2 (non-aqueous) and vapor phases can also be investigated\n",
" model_name=\"test\",\n",
" )\n",
" \n",
" # create water analysis inputs\n",
" water_analysis_input = f.build_flash_calculation_input(\n",
" # get a summary of the DBS file\n",
" file_summary = oliapi.get_dbs_file_summary(dbs_file_id)\n",
" \n",
" # save chemistry information\n",
" chemistry_info = file_summary[\"chemistry_info\"]\n",
" f.write_output(chemistry_info[\"result\"], \"chemistry_info\")\n",
" \n",
" # create water analysis input\n",
" # Water Analysis uses true species for inputs, i.e., IONS\n",
" stream_input = f.build_flash_calculation_input(\n",
" \"wateranalysis\",\n",
" state_vars,\n",
" )\n",
" \n",
" # create water analysis case\n",
" water_analysis_base_case = f.run_flash(\n",
" file_name=\"test_water_analysis_input\",\n",
" ) \n",
" # run Water Analysis flash calculation survey as specified \n",
" stream_output = f.run_flash(\n",
" \"wateranalysis\",\n",
" oliapi,\n",
" dbs_file_id,\n",
" water_analysis_input,\n",
" file_name=\"water_analysis_singlepoint\"\n",
" stream_input,\n",
" survey,\n",
" file_name=\"test_water_analysis_survey_output\"\n",
" )\n",
" # The output of Water Analysis gives apparent species\n",
" # i.e., SALTS, COMPLEXES (MgO, CaO, etc.)\n",
" \n",
" # create apparent composition from water analysis output\n",
" water_analysis_apparent_composition = f.build_flash_calculation_input(\n",
" # Other flash calculations use apparent species for inputs\n",
" # get_inflows extracts Water Analysis outputs to use with Isothermal flash\n",
" # these apparent species can be saved to a file and reloaded as needed\n",
" isothermal_inflows = f.get_inflows(\n",
" stream_output,\n",
" file_name=\"isothermal_inflows\",\n",
" )\n",
" isothermal_input = f.build_flash_calculation_input(\n",
" \"isothermal\",\n",
" state_vars,\n",
" water_analysis_base_case[0],\n",
" isothermal_inflows,\n",
" file_name=f\"isothermal_input\",\n",
" )\n",
" \n",
" # run isothermal flash for the survey parameters\n",
" isothermal_survey_result = f.run_flash(\n",
" # specify a new survey to compare apparent species\n",
" isothermal_survey = f.build_survey(\n",
" {\"NaCl\": linspace(0, 1e6, 10)},\n",
" get_oli_names=True,\n",
" file_name=\"test_isothermal_survey\",\n",
" )\n",
" isothermal_output = f.run_flash(\n",
" \"isothermal\",\n",
" oliapi,\n",
" dbs_file_id,\n",
" water_analysis_apparent_composition,\n",
" survey,\n",
" \"isothermal_composition_survey\",\n",
" )"
" isothermal_inflows,\n",
" isothermal_survey,\n",
" file_name=f\"{method}_output\",\n",
" )\n"
]
},
{
Expand All @@ -297,22 +329,23 @@
},
"outputs": [],
"source": [
"# extract properties from raw oli output\n",
"properties = [\n",
" \"prescalingTendencies\",\n",
" \"entropy\",\n",
" \"gibbsFreeEnergy\",\n",
" \"selfDiffusivities\",\n",
" \"molecularConcentration\",\n",
" \"kValuesMBased\",\n",
"]\n",
"if credential_manager:\n",
" extracted_properties = f.extract_properties(\n",
" isothermal_survey_result,\n",
" properties,\n",
" filter_zero=True,\n",
" file_name=\"properties\",\n",
" )"
" # extract properties from OLI flash survey output\n",
" properties = [\n",
" \"prescalingTendencies\",\n",
" \"molecularConcentration\",\n",
" ]\n",
" # data can be saved as a JSON file for further review and analysis\n",
" water_analysis_extract = f.extract_properties(\n",
" stream_output,\n",
" properties=properties,\n",
" file_name=\"water_analysis_extract\",\n",
" )\n",
" isothermal_extract = f.extract_properties(\n",
" isothermal_output,\n",
" properties=properties,\n",
" file_name=\"isothermal_extract\",\n",
")"
]
}
],
Expand Down
Loading
Loading