PorousFlow: a multiphysics simulation code for coupled problems in porous media

• Groundwater studies (Crosbie et al., 2017; Herron et al., 2018). This often involves assessing the impacts of human interventions on groundwater resources, and the consequences on the biosphere. It is frequently necessary to use large and complex models that include the effect of rainfall patterns, spatially and temporally varying evaporation and transpiration, seasonal river flows, realistic topography and hydrogeology, as well as human factors such as mines, water bores, dams, etc. In certain situations, such as assessing the impact of mining on groundwater, it is vital that the model includes the deformation of the porous material (the rock) since this greatly impacts groundwater flow. In other situations, it is useful to be able to track the transport of tracers and pollutants through the system, or to model the unsaturated (vadose) zone, where air and groundwater coexist in the subsurface.

• Groundwater studies (Crosbie et al., 2017;Herron et al., 2018). This often involves assessing the impacts of human interventions on groundwater resources, and the consequences on the biosphere. It is frequently necessary to use large and complex models that include the effect of rainfall patterns, spatially and temporally varying evaporation and transpiration, seasonal river flows, realistic topography and hydrogeology, as well as human factors such as mines, water bores, dams, etc. In certain situations, such as assessing the impact of mining on groundwater, it is vital that the model includes the deformation of the porous material (the rock) since this greatly impacts groundwater flow. In other situations, it is useful to be able to track the transport of tracers and pollutants through the system, or to model the unsaturated (vadose) zone, where air and groundwater coexist in the subsurface.
• Geothermal modelling: the simulation of natural and man-made geothermal systems, typically in order to quantify heat energies that may be extracted Guglielmetti et al., 2020;Lima et al., 2019;Niederau et al., 2020). Models in this field involve the coupled transport of heat and fluid. Many models are often large-scale, but some focus on small regions close to wellbores to investigate wellbore integrity. In this field, it often is useful to assess the impacts of subsurface heterogeneity, realistic pumping regimes, geochemical effects, fracture flow, and the creation of new fractures through deliberate or unintentional hydrofracturing, as well as potential microseismicity.
• Multiphase modelling, such as the simulation of CO 2 sequestration (Green et al., 2018;Lima et al., 2019), H 2 storage, or methane flows around coal mines . These simulations involve the interaction and flow of at least two fluid phases (e.g. gas and water). Changes in temperature often impact these flows, and realistic equations of state for the fluids involved are necessary. For instance, CO 2 sequestration typically involves pumping high-pressure, cold CO 2 into a warmer aquifer filled with brine: the CO 2 dissolves into the brine, cooling it and changing its density and flow characteristics. In many of these models, the altered pressure and temperature can potentially cause mechanical failure of the subsurface, and hence the creation of new flow paths and microseismicity (Lima et al., 2019).
• Understanding mineralization (Schaubs et al., 2019) in the subsurface often involves fluid flow, heat flow and coupled 3D deformation, simulating over millennia of real time and using realistic, and therefore complicated, basin-scale geology.
Other situations where PorousFlow could be used include oil and gas production, nuclear waste repositories and chemical leaching.
In many of these cases it is not enough to only solve traditional flow and transport physics.
Coupling with other physics is necessary: solid mechanical deformations and stresses can be important; geochemistry can alter the flow characteristics of the subsurface; high-precision equations of state are required; the evolution of fluid components (tracers, pollutants, reactants) is of interest; unsaturated physics is crucial. The flow and transport often impacts the subsurface structure, and conversely, the effects of these structure-changes impact the flow and transport.
Simulating these situations can be challenging in practice. Many widely-used simulation codes typically focus on only a subset of physical processes, and therefore accurate modelling often requires the use of several loosely-coupled software packages. Such an approach can be useful in many problems of interest, particularly where the characteristic time scales for each physical process are sufficiently different. In other instances, however, the ability to tightly couple different physical processes is necessary due to comparable characteristic time scales for the different physical processes. PorousFlow allows simulation of all the relevant thermalhydraulic-mechanical-chemical (THMC) physical phenomenon in a tightly-coupled framework.

Core equations
The core equations solved by PorousFlow are fluid mass conservation, heat-energy conservation and conservation of solid-mechanical momentum.
Fluid mass conservation for fluid species κ reads Here t denotes time and ∇ is a vector of spatial derivatives; M is the mass of fluid per bulk volume (which involves a sum over all fluid phases present in the system); v s is the velocity of the porous solid skeleton (so the second term ensures mass conservation under an evolving skeleton); F is the fluid flux vector (that includes advection by Darcy's law as well as diffusion and hydrodynamic dispersion); Λ is a radioactive decay rate; ϕI chem represents chemical precipitation or dissolution (ϕ is the porosity); and q is a source. The Lagrangian coordinate system is used, meaning the mesh moves with v s .

Heat-energy conservation reads
Here E is the heat energy per unit volume in the rock-fluid system (which involves the porous skeleton's heat energy as well as the fluids' heat energy, accounting for their saturations); F T is the heat flux vector (which involves heat conduction and advection by the fluid); ν describes the ratio of plastic-deformation energy that gets transferred to heat energy during plastic deformation of the solid skeleton; and q T is a heat source. The effective stress components are denoted by σ eff ij , where i and j are spatial indices (the sum over i and j is implied) and ϵ plastic is the plastic strain.

Conservation of momentum reads
Here i and j are spatial indices; v j s is the j th component of the velocity v s ; ρ mat is the massdensity of the material (including solid and fluid contributions); and b j are the components of the external force density (for example, the gravitational acceleration). The effective stress σ eff obeys a constitutive equation, α B is the Biot coefficient, and P f an effective fluid porepressure.
A comprehensive listing of equations, including fluid equations of state, the evolution of porosity and permeability, relative-permeability functions, capillary relationships, chemical reactions, etc, may be found at https://mooseframework.org/modules/porous_flow/index.html.

Software details and comparisons
PorousFlow is built upon the open-source, massively parallel, fully implicit multiphysics simulation framework MOOSE (Multiphysics Object-Oriented Simulation Environment) (Permann et al., 2020). MOOSE is an open-source library from Idaho National Laboratory that provides a high-level interface to the libMesh finite element library (Kirk et al., 2006) and PETSc nonlinear solvers (Balay et al., 2019). MOOSE and PorousFlow follow strict quality controls.
One aspect that makes PorousFlow different to these codes is the ease of coupling additional physics to the base flow and transport capabilities, and the relative speed and simplicity of developing new capability using the APIs provided by MOOSE. Harnessing the power of MOOSE means that PorousFlow simulations efficiently use multiprocessors and automatically utilize threading/OpenMP, without developers or users having to worry about the software technicalities. From the user's perspective, mesh adaptivity with a variety of integration schemes and unstructured meshes may be used. Various time-stepping schemes may be employed. A variety of I/O formats are available, such as Exodus and VTK files as well as CSV plaintext. Users may utilize the "MultiApp" system that allows simulations to be embedded inside other simulations. A GUI helps users create, run and analyse models. An example PorousFlow result is shown in Figure 1. For convenience, the source code for PorousFlow is bundled within the MOOSE framework, and detailed documentation found at https://mooseframework.org/modules/porous_flow/ index.html.