sintef digital, mathematics and cybernetics - opm-project.orgi opm flow i mrst (sintef) mathematics...
TRANSCRIPT
![Page 1: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/1.jpg)
OPM Flow – overview and demonstration
Atgeirr Flø Rasmussen
SINTEF Digital, Mathematics and Cybernetics
MSO4SC workshop23rd May 2017
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 2: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/2.jpg)
Overview of talk
Reservoir simulation
Mathematical formulation
Implementation with automatic differentiation
What next?
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 3: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/3.jpg)
Overview of talk
Reservoir simulation
Mathematical formulation
Implementation with automatic differentiation
What next?
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 4: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/4.jpg)
What is reservoir simulation
Simulation of porous medium flow in subsurface reservoirs.
Examples of use:
I Energy industryI Forecasting and optimizing oil and gas production.I Forecasting and optimizing geothermal energy production.
I Environmental managementI Groundwater flows and pollutantsI CO2storage
Reservoir simulators solve systems of nonlinear PDEsthat are coupled to well/facility models.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 5: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/5.jpg)
Why is it hard?
I Porous medium is stronglyheterogeneous andanisotropic.
I Grids with high aspectratio, fully unstructured,polygonal cells.
I Nontrivial phasebehaviour. Phases canappear and disappear asfluid components dissolveor vaporize.
I Coupling to wells canconnect regions that arefar away from each other.
I The models are highlynonlinear.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 6: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/6.jpg)
Why is it hard?
I Porous medium is stronglyheterogeneous andanisotropic.
I Grids with high aspectratio, fully unstructured,polygonal cells.
I Nontrivial phasebehaviour. Phases canappear and disappear asfluid components dissolveor vaporize.
I Coupling to wells canconnect regions that arefar away from each other.
I The models are highlynonlinear.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 7: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/7.jpg)
Why is it hard?
I Porous medium is stronglyheterogeneous andanisotropic.
I Grids with high aspectratio, fully unstructured,polygonal cells.
I Nontrivial phasebehaviour. Phases canappear and disappear asfluid components dissolveor vaporize.
I Coupling to wells canconnect regions that arefar away from each other.
I The models are highlynonlinear.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 8: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/8.jpg)
Why is it hard?
I Porous medium is stronglyheterogeneous andanisotropic.
I Grids with high aspectratio, fully unstructured,polygonal cells.
I Nontrivial phasebehaviour. Phases canappear and disappear asfluid components dissolveor vaporize.
I Coupling to wells canconnect regions that arefar away from each other.
I The models are highlynonlinear.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 9: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/9.jpg)
Why is it hard?
I Porous medium is stronglyheterogeneous andanisotropic.
I Grids with high aspectratio, fully unstructured,polygonal cells.
I Nontrivial phasebehaviour. Phases canappear and disappear asfluid components dissolveor vaporize.
I Coupling to wells canconnect regions that arefar away from each other.
I The models are highlynonlinear.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 10: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/10.jpg)
Why is it hard?
I Porous medium is stronglyheterogeneous andanisotropic.
I Grids with high aspectratio, fully unstructured,polygonal cells.
I Nontrivial phasebehaviour. Phases canappear and disappear asfluid components dissolveor vaporize.
I Coupling to wells canconnect regions that arefar away from each other.
I The models are highlynonlinear.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 11: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/11.jpg)
Why is it hard?
I Porous medium is stronglyheterogeneous andanisotropic.
I Grids with high aspectratio, fully unstructured,polygonal cells.
I Nontrivial phasebehaviour. Phases canappear and disappear asfluid components dissolveor vaporize.
I Coupling to wells canconnect regions that arefar away from each other.
I The models are highlynonlinear.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 12: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/12.jpg)
Why does it require HPC/Cloud
I Model sizes increasing (Saudi-Aramco record: 1e12 cells)
I Model complexity increasing (well/facility models, fluid models)
I New mechanisms (polymer, CO2) require better resolved fronts
I Large ensembles for history matching, optimization, uncertaintyquantification
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 13: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/13.jpg)
The market situation
Commercial reservoir simulators (expensive but comprehensive):
I ECLIPSE, Intersect (Schlumberger)
I IMEX, GEM, STARS (CMG)
I Nexus (Landmark)
I tNavigator (Rock Flow Dynamics)
I ...
In-house simulators (unavailable to outsiders):
I (Tera)POWERS (Saudi-Aramco)
I MoReS (Shell)
I GPRS (Stanford University)
I ...
Open source simulators:
I OPM Flow
I MRST (Sintef)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 14: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/14.jpg)
OPM Flow at a glance
I Open source
I Handling cases of full industrialcomplexity (wells, properties)
I Competitive performance
I Currently used to study (forexample):
I Oil production: historymatching and prediction offield performance
I Enhanced oil recovery: CO2,polymer
I CO2 sequestration
I Automatic differentiationenables rapid development offluid models.
Ambition: to be a strong base for both industrial development andacademic research
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 15: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/15.jpg)
Overview of talk
Reservoir simulation
Mathematical formulation
Implementation with automatic differentiation
What next?
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 16: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/16.jpg)
Physical laws and behaviours
I Conservation of massI for each fluid pseudocomponent (oil, gas, water)I for injected EOR fluids (polymer, CO2, surfactants)I (for ion species)I ∂
∂t(φAα) +∇ · uα = Qα
I Darcy’s law (single phase)I v = −(1/µ)K(∇p− ρg)
I Multiphase flow: relative permeability and capillary pressureI flow rate reduced by kr, function of fluid saturationsI pressure difference between phasesI vα = −(kr,α/µα)K(∇pα − ραg)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 17: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/17.jpg)
Physical laws and behaviours
I Conservation of massI for each fluid pseudocomponent (oil, gas, water)I for injected EOR fluids (polymer, CO2, surfactants)I (for ion species)I ∂
∂t(φAα) +∇ · uα = Qα
I Darcy’s law (single phase)I v = −(1/µ)K(∇p− ρg)
I Multiphase flow: relative permeability and capillary pressureI flow rate reduced by kr, function of fluid saturationsI pressure difference between phasesI vα = −(kr,α/µα)K(∇pα − ραg)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 18: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/18.jpg)
Physical laws and behaviours
I Conservation of massI for each fluid pseudocomponent (oil, gas, water)I for injected EOR fluids (polymer, CO2, surfactants)I (for ion species)I ∂
∂t(φAα) +∇ · uα = Qα
I Darcy’s law (single phase)I v = −(1/µ)K(∇p− ρg)
I Multiphase flow: relative permeability and capillary pressureI flow rate reduced by kr, function of fluid saturationsI pressure difference between phasesI vα = −(kr,α/µα)K(∇pα − ραg)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 19: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/19.jpg)
The black-oil model
I “Black-oil” model assumptionsI Lump HC species into two (pseudo)components (oil, gas)I Allow oleic phase to contain both oil and gas components
I Dissolved gas ratio, rSI Allow gaseous phase to contain both oil and gas components
I Vaporized oil ratio, rV
I Assumed always at thermodynamic equilibriumI Simple enough PVT relations to use table lookup
I Consequence: phase and component confusion!
I Consequence: can have three different states:I fully saturated (all three phases present)I undersaturated oil (no gaseous phase)I undersaturated gas (no oleic phase)
I (Subset of more general compositional model,must solve equation of state, such as Peng-Robinson)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 20: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/20.jpg)
The black-oil model
I “Black-oil” model assumptionsI Lump HC species into two (pseudo)components (oil, gas)I Allow oleic phase to contain both oil and gas components
I Dissolved gas ratio, rSI Allow gaseous phase to contain both oil and gas components
I Vaporized oil ratio, rV
I Assumed always at thermodynamic equilibriumI Simple enough PVT relations to use table lookup
I Consequence: phase and component confusion!
I Consequence: can have three different states:I fully saturated (all three phases present)I undersaturated oil (no gaseous phase)I undersaturated gas (no oleic phase)
I (Subset of more general compositional model,must solve equation of state, such as Peng-Robinson)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 21: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/21.jpg)
The black-oil model
I “Black-oil” model assumptionsI Lump HC species into two (pseudo)components (oil, gas)I Allow oleic phase to contain both oil and gas components
I Dissolved gas ratio, rSI Allow gaseous phase to contain both oil and gas components
I Vaporized oil ratio, rV
I Assumed always at thermodynamic equilibriumI Simple enough PVT relations to use table lookup
I Consequence: phase and component confusion!
I Consequence: can have three different states:I fully saturated (all three phases present)I undersaturated oil (no gaseous phase)I undersaturated gas (no oleic phase)
I (Subset of more general compositional model,must solve equation of state, such as Peng-Robinson)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 22: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/22.jpg)
The black-oil model
I “Black-oil” model assumptionsI Lump HC species into two (pseudo)components (oil, gas)I Allow oleic phase to contain both oil and gas components
I Dissolved gas ratio, rSI Allow gaseous phase to contain both oil and gas components
I Vaporized oil ratio, rV
I Assumed always at thermodynamic equilibriumI Simple enough PVT relations to use table lookup
I Consequence: phase and component confusion!
I Consequence: can have three different states:I fully saturated (all three phases present)I undersaturated oil (no gaseous phase)I undersaturated gas (no oleic phase)
I (Subset of more general compositional model,must solve equation of state, such as Peng-Robinson)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 23: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/23.jpg)
System of equations
The continuous equations form a system of partial differential equations,one for each pseudo-component α:
∂
∂t(φAα) +∇ · uα = Qα (1)
where
Aw = mφbwsw, uw = bwvw, (2)
Ao = mφ(boso + rV bgsg), uo = bovo + rV bgvg, (3)
Ag = mφ(bgsg + rSboso), ug = bgvg + rSbovo. (4)
and these additional relations should hold:
sw + so + sg = 1 (5)
pcow = po − pw (6)
pcog = po − pg. (7)
The phase fluxes are given by Darcy’s law:
vα = −λαK(∇pα − ραg). (8)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 24: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/24.jpg)
Coupling to well model
What is the source term, anyway?
∂
∂t(φAα) +∇ · uα = Qα
Well rates!
I Computed using separate well model(s).
I Must be solved simultaneously with reservoir equations.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 25: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/25.jpg)
Coupling to well model
What is the source term, anyway?
∂
∂t(φAα) +∇ · uα = Qα
Well rates!
I Computed using separate well model(s).
I Must be solved simultaneously with reservoir equations.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 26: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/26.jpg)
Discretization
The system is discretized using:
I First-order implicit Euler in time
I First-order finite volumes in spaceI two-point flux approximation (!)I phase-based upwinding of properties
Why such “primitive methods” (low order, inconsistent)?
I Historically, finite difference methods
I Need systems that linear solvers can deal with well
I Sufficient for practical purposes
I Discretization errors not significant compared to inherent uncertainty
Quite a bit has been done by various groups (not mainstream yet):
I Consistent discretizations (MPFA, mimetic)
I Higher-order FV or DG methods
I Higher-order time discretizations
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 27: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/27.jpg)
Discrete equations (I)
The discretized equations and residuals are, for each pseudo-componentα and cell i:
Rα,i =φ0,iVi
∆t
(Aα,i −A0
α,i
)+∑j∈C(i)
uα,ij +Qα,i = 0 (9)
where
Aw = mφbwsw, uw = bwvw, (10)
Ao = mφ(boso + rogbgsg), uo = bovo + rogbgvg, (11)
Ag = mφ(bgsg + rgoboso), ug = bgvg + rgobovo. (12)
The relations (5), (6) and (7) hold for each cell i.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 28: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/28.jpg)
Discrete equations (II)
The fluxes are given for each connection ij by:
(bαvα)ij = (bαλαmT )U(α,ij)Tij∆Hα,ij (13)
(rβαbαvα)ij = (rβαbαλαmT )U(α,ij)Tij∆Hα,ij (14)
∆Hα,ij = pα,i − pα,j − gρα,ij(zi − zj) (15)
ρα,ij = (ρα,i + ρα,j)/2 (16)
U(α, ij) =
{i ∆Hα,ij ≥ 0
j ∆Hα,ij < 0(17)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 29: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/29.jpg)
Solving the discrete equations
Main method: Newton-Raphson
I solve large heterogenous linear systems
I challenging to precondition (CPR + AMG best?)
I must modify updates for phase changes
I must handle convergence failures (timestep cuts)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 30: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/30.jpg)
Overview of talk
Reservoir simulation
Mathematical formulation
Implementation with automatic differentiation
What next?
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 31: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/31.jpg)
What does AD provide
f(x) { ... } df(x) { ... }
f(x) f ′(x)
Traditional Process
I Human implements code to evaluate f(x)
I Manual or symbolic calculation to derive f ′(x)
I Human implements code to evaluate f ′(x)
Automatic Differentiation (AD)
I Human implements code to evaluate f(x)
I Computer code to evaluate f ′(x) is automatically generated
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 32: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/32.jpg)
What does AD provide
f(x) { ... } df(x) { ... }
f(x) f ′(x)
Traditional Process
I Human implements code to evaluate f(x)
I Manual or symbolic calculation to derive f ′(x)
I Human implements code to evaluate f ′(x)
Automatic Differentiation (AD)
I Human implements code to evaluate f(x)
I Computer code to evaluate f ′(x) is automatically generated
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 33: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/33.jpg)
What does AD provide
f(x) { ... } df(x) { ... }
f(x) f ′(x)
Traditional Process
I Human implements code to evaluate f(x)
I Manual or symbolic calculation to derive f ′(x)
I Human implements code to evaluate f ′(x)
Automatic Differentiation (AD)
I Human implements code to evaluate f(x)
I Computer code to evaluate f ′(x) is automatically generated
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 34: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/34.jpg)
Benefits of using AD
AD makes it easier to create simulators:
I only specify nonlinear residual equation
I automatically evaluates Jacobian
I sparsity structure of Jacobian automatically generated
Note that AD is not the same as finite differencing!
I no need to define a ’small’ epsilon
I as precise as hand-made Jacobian
I ... but much less work!
Performance (of equation assembly) will usually be somewhat slower thana good hand-made Jacobian implementation.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 35: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/35.jpg)
Basic idea
A numeric computation y = f(x) can be written (D = derivative)
y1 = f1(x)dy1dx
(x) = Df1(x)
y2 = f2(y1)dy2dx
(x) = Df2(y1) ·Df1(x)
...
y = fn(yn−1)dy
dx(x) = Dfn(yn−1) ·Dfn−1(yn−2) · · ·Df1(x)
Automatic Differentiation:
I make each line an elementary operation
I compute right derivative values as we go using chain rule
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 36: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/36.jpg)
Implementation approaches
Two main methods:
Operator overloading
I requires operator overloading in programming language
I syntax (more or less) like before (non-AD)
I efficiency can vary a lot, depends on usage scenario
I easy to implement and experiment with
I Examples: OPM, Sacado (Trilinos), ADOL-C
Source transformation with AD tool
I can be implemented for almost any language
I may restrict language syntax or features used
I efficiency can be high (depends on AD tool)
I Examples: TAPENADE, OpenAD
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 37: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/37.jpg)
Types of AD
Two different approaches.(We compute f(x), u is some intermediate variable.)
Forward ModeCarry derivatives with respect to independent variables:
(u,du
dx)
Reverse ModeCarry derivatives with respect to dependent variables (adjoints):
(u,df
du)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 38: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/38.jpg)
Forward AD example (1)
Example function: f(x) = x(sin(x2) + 3x).Sequence of elementary functions:
f1(u) = u2 f ′1(u) = 2uu′
f2(u) = sin(u) f ′2(u) = cos(u)u′
f3(u) = 3u f ′3(u) = 3u′
f4(u, v) = u+ v f ′4(u, v) = u′ + v′
f5(u, v) = u · v f ′5(u, v) = u′v + uv′
Rewritten:f(x) = f5(x, f4(f2(f1(x)), f3(x)))
f5
x f4
f2
f1
x
f3
x
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 39: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/39.jpg)
Forward AD example (2)
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 f ′1(u) = 2uu′
f2(u) = sin(u) f ′2(u) = cos(u)u′
f3(u) = 3u f ′3(u) = 3u′
f4(u, v) = u+ v f ′4(u, v) = u′ + v′
f5(u, v) = u · v f ′5(u, v) = u′v + uv′
f5
x f4
f2
f1
x
f3
x
f ′5
x′ f ′4
f ′2
f ′1
x′
f ′3
x′
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 40: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/40.jpg)
Forward AD example (2)
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 f ′1(u) = 2uu′
f2(u) = sin(u) f ′2(u) = cos(u)u′
f3(u) = 3u f ′3(u) = 3u′
f4(u, v) = u+ v f ′4(u, v) = u′ + v′
f5(u, v) = u · v f ′5(u, v) = u′v + uv′
f5
3 f4
f2
f1
3
f3
3
f ′5
1 f ′4
f ′2
f ′1
1
f ′3
1
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 41: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/41.jpg)
Forward AD example (2)
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 f ′1(u) = 2uu′
f2(u) = sin(u) f ′2(u) = cos(u)u′
f3(u) = 3u f ′3(u) = 3u′
f4(u, v) = u+ v f ′4(u, v) = u′ + v′
f5(u, v) = u · v f ′5(u, v) = u′v + uv′
f5
3 f4
f2
9
3
f3
3
f ′5
1 f ′4
f ′2
6
1
f ′3
1
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 42: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/42.jpg)
Forward AD example (2)
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 f ′1(u) = 2uu′
f2(u) = sin(u) f ′2(u) = cos(u)u′
f3(u) = 3u f ′3(u) = 3u′
f4(u, v) = u+ v f ′4(u, v) = u′ + v′
f5(u, v) = u · v f ′5(u, v) = u′v + uv′
f5
3 f4
0.4121
9
3
f3
3
f ′5
1 f ′4
-5.4668
6
1
f ′3
1
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 43: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/43.jpg)
Forward AD example (2)
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 f ′1(u) = 2uu′
f2(u) = sin(u) f ′2(u) = cos(u)u′
f3(u) = 3u f ′3(u) = 3u′
f4(u, v) = u+ v f ′4(u, v) = u′ + v′
f5(u, v) = u · v f ′5(u, v) = u′v + uv′
f5
3 f4
0.4121
9
3
9
3
f ′5
1 f ′4
-5.4668
6
1
3
1
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 44: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/44.jpg)
Forward AD example (2)
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 f ′1(u) = 2uu′
f2(u) = sin(u) f ′2(u) = cos(u)u′
f3(u) = 3u f ′3(u) = 3u′
f4(u, v) = u+ v f ′4(u, v) = u′ + v′
f5(u, v) = u · v f ′5(u, v) = u′v + uv′
f5
3 9.4121
0.4121
9
3
9
3
f ′5
1 -2.4668
-5.4668
6
1
3
1
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 45: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/45.jpg)
Forward AD example (2)
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 f ′1(u) = 2uu′
f2(u) = sin(u) f ′2(u) = cos(u)u′
f3(u) = 3u f ′3(u) = 3u′
f4(u, v) = u+ v f ′4(u, v) = u′ + v′
f5(u, v) = u · v f ′5(u, v) = u′v + uv′
28.2364
3 9.4121
0.4121
9
3
9
3
2.0118
1 -2.4668
-5.4668
6
1
3
1
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 46: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/46.jpg)
Properties of forward AD
I Easy to implement with operator overloading
I Storage required (scalar): 2× normal (value, derivative).
I Storage required (f : Rm → Rn): (n+ 1)× normal (value,derivative vector), unless sparse.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 47: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/47.jpg)
Reverse Mode AD
Recall: Reverse ModeCarry derivatives with respect to dependent variables (adjoints):
(u,df
du)
We will use the chain rule again, but in the opposite direction:
adj(u) = adj(fi)∂fi∂u
.
Using adj(u) to mean the adjoint dfdu .
(So adj(x) is our goal.)
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 48: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/48.jpg)
Reverse AD example
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 adj(u) = adj(f1) · 2uf2(u) = sin(u) adj(u) = adj(f2) · cos(u)
f3(u) = 3u adj(u) = adj(f3) · 3f4(u, v) = u+ v adj(u) = adj(f4), adj(v) = adj(f4)
f5(u, v) = u · v adj(u) = adj(f5) · v, adj(v) = adj(f5) · u
28.2364
3 9.4121
0.4121
9
3
9
3
adj(f5)
adj(x) adj(f4)
adj(f2)
adj(f1)
adj(x)
adj(f3)
adj(x)
Must sumcontributions:f ′(3) = 9.4121−16.4003+9 = 2.0118.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 49: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/49.jpg)
Reverse AD example
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 adj(u) = adj(f1) · 2uf2(u) = sin(u) adj(u) = adj(f2) · cos(u)
f3(u) = 3u adj(u) = adj(f3) · 3f4(u, v) = u+ v adj(u) = adj(f4), adj(v) = adj(f4)
f5(u, v) = u · v adj(u) = adj(f5) · v, adj(v) = adj(f5) · u
28.2364
3 9.4121
0.4121
9
3
9
3
adj(f5)
adj(x) adj(f4)
adj(f2)
adj(f1)
adj(x)
adj(f3)
adj(x)
Must sumcontributions:f ′(3) = 9.4121−16.4003+9 = 2.0118.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 50: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/50.jpg)
Reverse AD example
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 adj(u) = adj(f1) · 2uf2(u) = sin(u) adj(u) = adj(f2) · cos(u)
f3(u) = 3u adj(u) = adj(f3) · 3f4(u, v) = u+ v adj(u) = adj(f4), adj(v) = adj(f4)
f5(u, v) = u · v adj(u) = adj(f5) · v, adj(v) = adj(f5) · u
28.2364
3 9.4121
0.4121
9
3
9
3
1
adj(x) adj(f4)
adj(f2)
adj(f1)
adj(x)
adj(f3)
adj(x)
Must sumcontributions:f ′(3) = 9.4121−16.4003+9 = 2.0118.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 51: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/51.jpg)
Reverse AD example
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 adj(u) = adj(f1) · 2uf2(u) = sin(u) adj(u) = adj(f2) · cos(u)
f3(u) = 3u adj(u) = adj(f3) · 3f4(u, v) = u+ v adj(u) = adj(f4), adj(v) = adj(f4)
f5(u, v) = u · v adj(u) = adj(f5) · v, adj(v) = adj(f5) · u
28.2364
3 9.4121
0.4121
9
3
9
3
1
adj(x) 3
adj(f2)
adj(f1)
adj(x)
adj(f3)
adj(x)
Must sumcontributions:f ′(3) = 9.4121−16.4003+9 = 2.0118.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 52: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/52.jpg)
Reverse AD example
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 adj(u) = adj(f1) · 2uf2(u) = sin(u) adj(u) = adj(f2) · cos(u)
f3(u) = 3u adj(u) = adj(f3) · 3f4(u, v) = u+ v adj(u) = adj(f4), adj(v) = adj(f4)
f5(u, v) = u · v adj(u) = adj(f5) · v, adj(v) = adj(f5) · u
28.2364
3 9.4121
0.4121
9
3
9
3
1
adj(x) 3
3
adj(f1)
adj(x)
adj(f3)
adj(x)
Must sumcontributions:f ′(3) = 9.4121−16.4003+9 = 2.0118.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 53: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/53.jpg)
Reverse AD example
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 adj(u) = adj(f1) · 2uf2(u) = sin(u) adj(u) = adj(f2) · cos(u)
f3(u) = 3u adj(u) = adj(f3) · 3f4(u, v) = u+ v adj(u) = adj(f4), adj(v) = adj(f4)
f5(u, v) = u · v adj(u) = adj(f5) · v, adj(v) = adj(f5) · u
28.2364
3 9.4121
0.4121
9
3
9
3
1
adj(x) 3
3
-2.7334
adj(x)
adj(f3)
adj(x)
Must sumcontributions:f ′(3) = 9.4121−16.4003+9 = 2.0118.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 54: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/54.jpg)
Reverse AD example
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 adj(u) = adj(f1) · 2uf2(u) = sin(u) adj(u) = adj(f2) · cos(u)
f3(u) = 3u adj(u) = adj(f3) · 3f4(u, v) = u+ v adj(u) = adj(f4), adj(v) = adj(f4)
f5(u, v) = u · v adj(u) = adj(f5) · v, adj(v) = adj(f5) · u
28.2364
3 9.4121
0.4121
9
3
9
3
1
adj(x) 3
3
-2.7334
adj(x)
3
adj(x)
Must sumcontributions:f ′(3) = 9.4121−16.4003+9 = 2.0118.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 55: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/55.jpg)
Reverse AD example
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 adj(u) = adj(f1) · 2uf2(u) = sin(u) adj(u) = adj(f2) · cos(u)
f3(u) = 3u adj(u) = adj(f3) · 3f4(u, v) = u+ v adj(u) = adj(f4), adj(v) = adj(f4)
f5(u, v) = u · v adj(u) = adj(f5) · v, adj(v) = adj(f5) · u
28.2364
3 9.4121
0.4121
9
3
9
3
1
9.4121 3
3
-2.7334
-16.4003
3
9
Must sumcontributions:f ′(3) = 9.4121−16.4003+9 = 2.0118.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 56: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/56.jpg)
Reverse AD example
Example function: f(x) = x(sin(x2) + 3x). Computing f(3), f ′(3).Sequence of elementary functions:
f1(u) = u2 adj(u) = adj(f1) · 2uf2(u) = sin(u) adj(u) = adj(f2) · cos(u)
f3(u) = 3u adj(u) = adj(f3) · 3f4(u, v) = u+ v adj(u) = adj(f4), adj(v) = adj(f4)
f5(u, v) = u · v adj(u) = adj(f5) · v, adj(v) = adj(f5) · u
28.2364
3 9.4121
0.4121
9
3
9
3
1
9.4121 3
3
-2.7334
-16.4003
3
9
Must sumcontributions:f ′(3) = 9.4121−16.4003+9 = 2.0118.
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 57: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/57.jpg)
Automatic Differentiation: OPM implementations
AutoDiffBlock (legacy)
I class implementing forward AD
I deals with vectors of values at a time
I derivatives are sparse matrices
I implemented with operator overloading
I based on Eigen library for basic types and operands
I helper library provides discrete div, grad etc.
Evaluation (new effort)
I class implementing forward AD
I deals with a single scalar value at a time
I derivatives are compile-time-size vectors
I implemented with operator overloading
I discrete div, grad must be implemented “manually”
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 58: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/58.jpg)
Overview of talk
Reservoir simulation
Mathematical formulation
Implementation with automatic differentiation
What next?
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 59: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/59.jpg)
We keep pursuing...
I PerformanceI Improving preconditioners and linear solversI New discretizations, nonlinear preconditioningI Parallel scaling
I UsabilityI Reference manual started!I More output/logging optionsI Better error messages
I DeployabilityI Container usageI MSO4SC Portal and web integrationI Better error messages
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 60: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/60.jpg)
Further ahead: some possibilities
I New fluid models for CO2, EOR options.
I Scriptable? Python? Cling-able?
I More flexible boundary conditions
I Higher order DG methods?
I Consistent discretizations?
I Fully compositional fluid model?
I New I/O system for parallel scalability?
I Preprocessing tools?
Mathematics and Cybernetics MSO4SC workshop 2016–05–23
![Page 61: SINTEF Digital, Mathematics and Cybernetics - opm-project.orgI OPM Flow I MRST (Sintef) Mathematics and Cybernetics MSO4SC workshop 2016{05{23. OPM Flow at a glance I Open source I](https://reader033.vdocuments.us/reader033/viewer/2022042018/5e763cd488c5596b99325925/html5/thumbnails/61.jpg)
Thank you for listening!
Mathematics and Cybernetics MSO4SC workshop 2016–05–23