(356e) Automatic Differentiation and Source Code Generation for Dynamic Modeling and Simulation of Brine Separations Systems | AIChE

(356e) Automatic Differentiation and Source Code Generation for Dynamic Modeling and Simulation of Brine Separations Systems

Authors 

Xu, P. - Presenter, University of Connecticut
Gottlieb, R., University of Connecticut
Rawlings, E. S., Universidad Michoacana de San Nicolas de Hidalgo
Stuber, M., University of Connecticut
Title: Automatic Differentiation and Source Code Generation for Dynamic Modeling and Simulation of Brine Separations Systems

Authors: Pengfei Xu, Robert Gottlieb, Edna SorayaRawlings, and Matthew D. Stuber

AIChE 2023 Annual Meeting Abstract

Session: CAST Applied Math for Energy and Environmental Applications

Accurate mechanistic models enable advanced dynamic simulation and optimization-based design of water treatment technologies to increase sustainability, reduce costs, and improve system robustness. Modeling the thermodynamic properties of concentrated brine solutions is critical to the overall efforts of modeling and simulation desalination and brine concentrator systems. Since current models suffer from large error in the high-concentration regime, and therefore their prediction accuracy is poor, we employ a modified version [1-3] of the refined electrolyte non-random two-liquid model (r-eNRTL) [4]. The r-eNRTL model is more accurate in the high-concentration regimes compared to the original eNRTL [5]. However, the activity coefficient expression of the r-eNRTL model is far more complex and, as such, increases the difficulty in its derivation from fundamentals and implementation in code.

To solve this challenge, we propose an approach using symbolic algebra and source-code generation/transformation packages Symbolics.jl [6] and SymbolicUtils.jl [7], to generate symbolic expressions of the r-eNRTL Gibbs free energy expression in the Julia programming language [8]. To aid the automatic source code generation approach, a new mathematical notation and indexing scheme was formalized that better mirrors data structures in computing. Specifically, the interaction parameters of the r-eNRTL model [9] were restructured into a more intuitive and translatable tensor form which, in turn, also better generalizes the model to multi-electrolyte/multi-solvent mixtures. Furthermore, we use automatic differentiation to derive the activity coefficient expression and generate corresponding evaluator functions for numerical evaluation. With this approach, we avoid potential human errors and dramatically improve the efficiency of the derivation, implementation, and verification steps. In addition, to allow r-eNRTL to be used in other platforms like Pyomo [10-12]/IDAES [13], we propose a toolchain for transplanting, which is based on the SymPy.jl [14,15] package and source code transformation. Lastly, we implemented our fitted r-eNRTL model in the modeling language of the dynamic modeling and simulation package ModelingToolkit.jl [19,20]. These developments were applied to a relevant flowsheet for a multi-effect mechanical vapor compression (MVC) brine concentrator [21].

The development of next-generation brine separations technologies is critical to addressing sustainability challenges in the food-energy-water nexus. High-accuracy models, such as r-eNRTL, and advanced equation-oriented simulation approaches are pivotal to this endeavor. Symbolic algebra tools and automatic source code generation in this space have the potential to reduce development time and errors and provide automatic model verification for engineers and practitioners at the design stage.



Disclaimer

Sandia National Laboratories is a multimission laboratory managed and operated by National Technology and Engineering Solutions of Sandia, LLC., a wholly owned subsidiary of Honeywell International, Inc., for the U.S. Department of Energy's National Nuclear Security Administration under contract DE-NA-0003525. This paper describes objective technical results and analysis. Any subjective views or opinions that might be expressed in the paper do not necessarily represent the views of the U.S. Department of Energy or the United States Government.

References

[1] Yang, Xi, P. I. Barton, and Bollas, G. M. “The significance of frameworks in electrolyte thermodynamic model development” Under Review. (2023)

[2] Yang, Xi, P. I. Barton, and Bollas, G. M. “Refined electrolyte-NRTL model: Inclusion of hydration for the detailed description of electrolyte solutions. Part I. Single electrolytes up to moderate concentrations, single salts up to the solubility limit.” Under Review. (2023)

[3] Yang, Xi, P. I. Barton, and Bollas, G. M. “Refined electrolyte-NRTL model: Inclusion of hydration for the detailed description of electrolyte solutions. Part II. Detailed simulation of speciation and activities of aqueous solutions of acids and bases.” Under Review. (2023)

[4] Bollas, G. M., Chau-Chyun Chen, and P. I. Barton. "Refined electrolyte‐NRTL model: Activity coefficient expressions for application to multi‐electrolyte systems." AIChE Journal 54, no. 6 (2008): 1608-1624.

[5] Song, Yuhua, and Chau-Chyun Chen. "Symmetric electrolyte nonrandom two-liquid activity coefficient model." Industrial & Engineering Chemistry Research 48, no. 16 (2009): 7788-7797.

[6] Gowda, Shashi, Yingbo Ma, Alessandro Cheli, Maja Gwóźzdź, Viral B. Shah, Alan Edelman, and Christopher Rackauckas. "High-performance symbolic-numerics via multiple dispatch." ACM Communications in Computer Algebra 55, no. 3 (2022): 92-96.

[7] Shashi Gowda, Yingbo Ma, Mason Protter, Julia Computing, JuliaSymbolics/SymbolicUtils.jl, 2020. URL: https://github.com/JuliaSymbolics/SymbolicUtils.jl

[8] Bezanson, Jeff, Alan Edelman, Stefan Karpinski, and Viral B. Shah. "Julia: A fresh approach to numerical computing." SIAM review 59, no. 1 (2017): 65-98.

[9] Gottlieb, Robert X., Pengfei Xu, and Matthew D. Stuber. "Automatic Source Code Generation of Complicated Models for Deterministic Global Optimization with Parallel Architectures."

[10] Bynum, Michael L., Gabriel A. Hackebeil, William E. Hart, Carl D. Laird, Bethany L. Nicholson, John D. Siirola, Jean-Paul Watson, and David L. Woodruff. Pyomo-optimization modeling in python. Vol. 67. Berlin/Heidelberg, Germany: Springer, 2021.

[11] Hart, William E., Jean-Paul Watson, and David L. Woodruff. "Pyomo: modeling and solving mathematical programs in Python." Mathematical Programming Computation 3 (2011): 219-260.

[12] Nicholson, Bethany, John D. Siirola, Jean-Paul Watson, Victor M. Zavala, and Lorenz T. Biegler. "pyomo. dae: A modeling and automatic discretization framework for optimization with differential and algebraic equations." Mathematical Programming Computation 10 (2018): 187-223.

[13] The IDAES process modeling framework and model library—Flexibility for process simulation and optimization

[14] Meurer, Aaron, Christopher P. Smith, Mateusz Paprocki, Ondřej Čertík, Sergey B. Kirpichev, Matthew Rocklin, AMiT Kumar et al. "SymPy: symbolic computing in Python." PeerJ Computer Science 3 (2017): e103.

[15] John Verzani, Michele Zaffalon, etc., JuliaPy/Sympy.jl, 2013. URL: https://github.com/JuliaPy/SymPy.jl

[16] Wilhelm, Matthew E., and Matthew D. Stuber. "EAGO. jl: easy advanced global optimization in Julia." Optimization Methods and Software 37, no. 2 (2022): 425-450.

[17] Matthew E. Wilhelm, Robert X. Gottlieb, and Matthew D. Stuber. PSORLab/McCormick.jl, 2020. URL: https://github.com/PSORLab/McCormick.jl.
[18] Matthew E. Wilhelm and Matthew D. Stuber. Easy advanced global optimization (EAGO): An open-source platform for robust and global optimization in Julia. In AIChE Annual Meeting. AIChE, 2017.

[19] Rackauckas, Christopher, and Qing Nie. "Differentialequations. jl–a performant and feature-rich ecosystem for solving differential equations in julia." Journal of open research software 5, no. 1 (2017).

[20] Ma, Yingbo, Shashi Gowda, Ranjan Anantharaman, Chris Laughman, Viral Shah, and Chris Rackauckas. "Modelingtoolkit: A composable graph transformation system for equation-based modeling." arXiv preprint arXiv:2103.05244 (2021).

[21] Stuber, Matthew D., Christopher Sullivan, Spencer A. Kirk, Jennifer A. Farrand, Philip V. Schillaci, Brian D. Fojtasek, and Aaron H. Mandell. "Pilot demonstration of concentrated solar-powered desalination of subsurface agricultural drainage water and other brackish groundwater sources." Desalination 355 (2015): 186-196.