Modern Advances in Software and Solution Algorithms for Reservoir Simulation
Total Page:16
File Type:pdf, Size:1020Kb
MODERN ADVANCES IN SOFTWARE AND SOLUTION ALGORITHMS FOR RESERVOIR SIMULATION A DISSERTATION SUBMITTED TO THE DEPARTMENT OF ENERGY RESOURCES ENGINEERING AND THE COMMITTEE ON GRADUATE STUDIES OF STANFORD UNIVERSITY IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF DOCTOR OF PHILOSOPHY Rami M. Younis August 2011 © 2011 by Rami Mustafa Younis. All Rights Reserved. Re-distributed by Stanford University under license with the author. This work is licensed under a Creative Commons Attribution- Noncommercial 3.0 United States License. http://creativecommons.org/licenses/by-nc/3.0/us/ This dissertation is online at: http://purl.stanford.edu/fb287kz3299 ii I certify that I have read this dissertation and that, in my opinion, it is fully adequate in scope and quality as a dissertation for the degree of Doctor of Philosophy. Hamdi Tchelepi, Primary Adviser I certify that I have read this dissertation and that, in my opinion, it is fully adequate in scope and quality as a dissertation for the degree of Doctor of Philosophy. Khalid Aziz, Co-Adviser I certify that I have read this dissertation and that, in my opinion, it is fully adequate in scope and quality as a dissertation for the degree of Doctor of Philosophy. Juan Alonso Approved for the Stanford University Committee on Graduate Studies. Patricia J. Gumport, Vice Provost Graduate Education This signature page was generated electronically upon submission of this dissertation in electronic format. An original signed hard copy of the signature page is on file in University Archives. iii Abstract As conventional hydrocarbon resources dwindle, and environmentally-driven markets start to form and mature, investments are expected to shift into the development of novel emerging subsurface process technologies. While these processes are charac- terized by a high commercial potential, they are also typically associated with high technical risk. The time-to-market along comparable development pipelines, such as for Enhanced Oil Recovery (EOR) methods in the Oil and Gas sector, is on the order of tens of years. It is anticipated that in the near future, there will be much value in developing simulation tools that can shorten time-to-market cycles, making invest- ment shifts more attractive. There are two forces however that may debilitate us from delivering simulation as a scientific discovery tool. The first force is the growing nonlinearity of the problem base. The second force is the flip-side of a double edged sword; a rapidly evolving computer architecture scene. The first part of this work concerns the formulation and linearization of nonlinear simultaneous equations; the archetypal inflexible component of all large scale simu- lators. The proposed solution is an algorithmic framework and library of data-types called the Automatically Differentiable Expression Templates Library (ADETL). The ADETL provides generic representations of variables and discretized expressions on a simulation grid, and the data-types provide algorithms employed behind the scenes to automatically compute the sparse analytical Jacobian. Using the library, large- scale simulators can be developed rapidly by simply writing the residual equations, and without any hand differentiation, hand crafted performance tuning loops, or any other low-level constructs. A key challenge that is addressed is in enabling this level of abstraction and programming ease while making it easy to develop code that runs iv fast. Faster than any of several existing automatic differentiation packages, faster than any purely Object Oriented implementation, and at least in the order of the execution speed of code delivered by a development team with hand-optimized resid- uals, analytical derivatives, and Jacobian assembly routines. A second challenge is in providing a generic multi-layered software framework that incorporates plug-in low-level constructs tuned to emerging architectures. The inception of the ADETL spurred an effort to develop the new generation AD-GPRS simulator, which we use to demonstrate the powers of the ADETL. We conclude with a thought towards a future where simulators can write themselves. The second part of this work develops nonlinear methods that can exploit the nature of the underlying physics to deal with the current and upcoming challenges in physical nonlinearity. The Fully Implicit Method offers unconditional stability of the discrete approximations. This stability comes at the expense of transferring the inherent physical stiffness onto the coupled nonlinear residual equations that are solved at each timestep. Current reservoir simulators apply safe-guarded variants of Newton's method that can neither guarantee convergence, nor provide estimates of the relation between convergence rate and timestep size. In practice, timestep chops become necessary, and they are guided heuristically. With growing complex- ity, convergence difficulties can lead to substantial losses in computational effort and prohibitively small timesteps. We establish an alternate class of nonlinear iteration that converges and that associates a timestep to each iteration. Moreover, the linear solution process within each iteration is performed locally. Several challenging ex- amples are presented, and the results demonstrate the robustness and computational efficiency of the proposed class of methods. We conclude with thoughts to unify timestepping and iterative nonlinear methods. v Acknowledgements It has been an interesting journey. I am fortunate to have had the company of many who have challenged and supported me. I would like to thank Khalid Aziz for taking me in and for accommodating my sometimes rogue ways. I would also like to thank Hamdi Tchelepi for reminding me to pause and appreciate intermediate milestones before "turning round more new corners". I would also like to thank Juan Alonso for reading this dissertation and providing valuable feedback. I have had the opportunity to learn from exceptional classroom teachers; I am especially indebted to Julie Levandosky, Doron Levy, Gene Golub, and Lou Durlofsky. Your classes were not easy and they were always fun. I would also like to thank the staff at the Center for Teaching and Learning for recruiting me as a Teaching Consultant during my studies. The Department of Energy Resources Engineering (known as Petroleum Engineering at the time I joined) is a very special one at the university primarily because of its administrative leadership and citizens. I would like to thank Roland Horne who served as Department Chair throughout most of the duration of my studies. I would also like to thank my colleagues for making every day (and night) at the office feel like a walk in the park; Saman Aryana, Marc Hesse, Shalini Krishnamurthy, Morten R. Kristensen, Felix Kwok, and Jonas Nilson it would not have been fun without you. I am indebted to Sylvianne Dufour and to Dr. B. for helping learn some of life's hardest lessons. I would also like to thank my girlfriend Stephanie E. Holm for putting up with my nonlinear humor. My thanks go to my parents, Hiyam and Mustafa Younis, for guiding me and for supporting me unconditionally at the times I needed it most. This work was prepared with financial support from the Stanford University Petroleum Research Institute-B (SUPRI-B) Industrial Affiliates Program. vi Contents Abstract iv Acknowledgements vi I The Automatically Differentiable Expression Templates Library 1 1 Introduction 2 1.1 Modern Simulation Software . .4 1.1.1 Simulation Software Architectures . .4 1.1.2 Programming Abstraction Paradigms . 13 1.1.3 The Software Goals . 17 1.2 Formulation and linearization . 17 1.2.1 Formulation concepts . 18 1.2.2 Linearization operations . 19 1.3 Automatically Differentiable Expression Templates Library ADETL . 27 2 The AD Core; Its Design And Evolution 29 2.1 Common aspects of all OO implementations . 30 2.1.1 Customized AD data-types . 32 2.1.2 Overloading Operators in C++ . 33 2.2 OOAD by Instantaneous Evaluation . 38 2.2.1 Univariate expressions . 39 vii 2.2.2 Multivariate expressions . 41 2.3 Lazy AD with Expression Templates . 44 2.3.1 Building Expression Templates at compile time . 46 2.3.2 ET Evaluation; Dense Multivariates . 51 2.3.3 ET Evaluation; Sparse Multivariates . 52 2.3.4 Summary . 58 2.4 Sparse Linear Combination Expressions . 59 2.4.1 Building and destroying SPLC expressions dynamically . 61 3 Using and extending the ADETL 65 3.1 Automatic Variable Set Objects AVSO. 67 3.1.1 ADCollection concept and types. 69 3.1.2 VariableOrdering concept and types. 70 3.1.3 VariableActivation concept and types. 72 3.1.4 A complete AVSO VariableSet usage example. 74 3.2 Automatically differentiable variable data types . 77 3.2.1 The ADCollection concept. 78 4 ADETL Simulators and computational examples 83 4.1 So, what is the overhead of this abstraction? . 84 4.1.1 Example 1: Two dimensional, nine component model . 86 4.1.2 Example 2: A five-spot pattern in a two-dimensional heteroge- neous domain . 88 4.2 Summary . 93 5 Possibilities for the future of the ADETL 95 5.1 Old concepts, new directions . 96 5.1.1 More datastructures and heterogeneous expressions across them 97 5.1.2 What is a variable set today and what will it be tomorrow? . 97 5.1.3 Thread safety first . 99 5.2 Synthesized Concepts For The ADETL . 99 5.2.1 Automated performance tuning . 99 viii 5.2.2 Code verification, generation, and evolution . 100 II The Nature Of Nonlinearities In Simulation And Solu- tion Methods That Understand Them 102 6 Introduction 103 6.1 Timestepping and nonlinearity in implicit models . 105 6.1.1 The Newton Flow and Newton-like methods . 106 6.1.2 An example to illustrate challenges encountered by Newton's method . 107 6.2 Safeguarded Newton-Like Methods In Reservoir Simulation . 113 6.2.1 Examples of the performance of state-of-the-art solvers. 116 7 Adaptive Localization 121 7.1 Basic ideas and motivation .