v0.8.17

In this tutorial, we show how to solve a strongly nonlinear time dependent equation using mixfiniteelements. We focus attention on construction of finite elements, finite elements user data operators (UDO), setting up discrete manager (DM) and time solver (TS). Issues related to the nonlinear solver and line searchers are briefly discussed. Also, we show how to use automatic differentiation (ADOLC) to calculate derivatives of a constitutive model.
Problem solved here is similar to the solution of nonlinear Poisson's equation described in A nonlinear Poisson equation and is a generalization of the problem described in Mix formulation and integration on skeleton (hadaptivity). You might look to those tutorials if some implementation aspects of presented methodology are unclear. Also, you are encouraged to post questions on our Q&A forum.
Presented methodology is applied to the problem of unsaturated water transport. We have no intention to give a detailed description of transport in unsaturated materials, here we only focus on problem discretization, equations linearization and implementation of finite element. Also, we do not show here how to do hpadaptivity, this is part of other tutorials. This problem can be solved with block solver, improving its efficiency and robustness, see example Using fieldsplit solver and DM sub problem.. If you like to extend this work, adding block solver or hpadaptivity, we offer our guidance and help.
The application for unsaturated flow is implemented in unsaturated_transport.cpp, material models are implemented in MaterialUnsaturatedFlow.hpp, problem definition and implementation are implemented in UnsaturatedFlow.hpp.
The tutorial is organized as follows. First, we explain how to run the application. Next, we show how the material model is implemented, after that we explain the mathematical and numerical models. Finally, we explain implementation details.
You can imagine that we do an experiment, such that we have wet silt and dry clay, we make three layers, with silt in the middle, and clay on the top and below. Such column of soil we put in the box, for example, made for plexiglass. Thus all sides are impermeable. We will observe water content and capillary pressure for two days, that is long enough to approach equilibrium.
First, we create a mesh which can be made in Salome, gMesh, Tetgen, or any other code. MoFEM uses MOAB for mesh database with can read various mesh file formats. Here we using Cubit to make mesh, journal file this problem is as follows
reset # create body volume brick x 0.01 y 0.002 z 0.1 move Volume all x 0 y 0 z 0.05 include_merged brick x 0.1 y 0.06 z 0.02 move Volume 2 location volume 1 include_merged chop volume 1 with volume 2 imprint volume all merge volume all # make block for clay block 1 volume 4 5 block 1 name 'SOIL_CLAY1' # make block for silt block 2 volume 3 block 2 name 'SOIL_SILT2' # make mesh volume all size auto factor 10 volume all scheme Tetmesh mesh volume all # refine mesh at interfaces between clay & silt refine surface 13 14 size 0.0025 bias 1.5 depth 1 smooth
Note that we do not set any boundary conditions here, in that case, is assumed that fluxes on the boundary are zero, that is boundary is impermeable.
We need to make a configuration file, where all problem specific parameters are set. We discuss details how of that file in mix_us_flow_physical_equation_impl
[mat_block_1] # VanGenuchten # SimpleDarcy material_name=VanGenuchten # Default material for VanGenuchten is Clay (no need to set parameters if clay is used) # Assumed units are in meters and days. # Model parameters controlling convergence sCale=1e6 # Scale mass conservation equation ePsilon1=1e5 # Minimal capacity when removing spurious oscillations in time Ah=9 # head suction at z = 0 AhZ=1 # gradient of initial head suction AhZZ=0 # initial head suction is calculated from equation h = Ah + AhZZ*z + AhZZ*zz [mat_block_2] material_name=VanGenuchten # Material parameters for Silt from Vogel., van Genuchten Cislerova 2001 sCale=1e6 ePsilon1=1e5 Ah=0.09 AhZ=1 thetaS=0.46 thetaM=0.46 thetaR=0.034 alpha=1.6 n=1.37 Ks=0.006 hS=0
The material parameters are taken from [44], the initial parameters for clay (mat_block_1) and silt (mat_block_2) are set with the \(A_h\) and \(A_h^z\), such that initial capillary pressure head is given by \( h = A_h+A_h^z z \) where
\[ \left\{ \begin{array}{ll} h(z,t=0) = 9+z&\textrm{for clay}\\ h(z,t=0) = 0.09+z&\textrm{for silt} \end{array} \right. \]
The analysis is run using script
Editing that file you can set range of parameters, control time solve, tolerances, stop criteria, linesearcher. For details look to PETSc manual link.
Note solved problem is strongly nonlinear, and we use here secant linesearch in the L2 norm (see link). For stability of the result at each Newton iteration, we execute three subiterations with line searcher. Also, you have option controlling time step adaptively and linear solver preconditioner. All command line options, both PETSc and MoFEM are printed if you add switch help when you run MoFEM application.
MoFEM specific options are
Finally, we can run simulation, be executing above script
where
For problem setup like above, results are shown in Figure 1, where the evolution of various parameters over time until equilibrium is reached is shown. You can note that initially, clay is relatively dry, whereas silt is wet. Over time clay suck the water from silt. On the lefthand side observed the distribution of saturation. Initially, high gradients of pressure head are created on the interface between two materials. Those are captured very well, despite coarse mesh, showing capabilities of presented problem formulation. For creating of this figure we used the 2nd order of polynomial to approximate the pressure head and 3rd order polynomial to approximate the fluxes.
In the second example, we show how to run downward infiltration problem with three layers, i.e. clay, silt and clay.
In that case on the top, we apply zero pressure head, rest of the boundary is impermeable. See journal script to generate such mesh
reset # create body volume brick x 0.01 y 0.002 z 0.1 move Volume all x 0 y 0 z 0.05 include_merged brick x 0.1 y 0.06 z 0.02 move Volume 2 location volume 1 include_merged chop volume 1 with volume 2 imprint volume all merge volume all # make block for clay block 1 volume 4 5 block 1 name 'SOIL_CLAY1' # make block for silt block 2 volume 3 block 2 name 'SOIL_SILT2' block 3 surface 1 block 3 name 'HEAD1' block 3 attribute count 1 block 3 attribute index 1 0 # make mesh volume all size auto factor 10 volume all scheme Tetmesh mesh volume all # refine mesh at interfaces between clay & silt refine surface 1 13 14 size 0.0025 bias 1.5 depth 1 smooth
Here we add third block name HEAD1, where boundary condition is applied. Similarly, nonzero fluxes can be applied by making a block with some surface elements and called it for example "FLUX1".
The material parameters are similar to one given in the previous problem
[mat_block_1] # VanGenuchten # SimpleDarcy material_name=VanGenuchten # Default material for VanGenuchten is Clay (no need to set parameters if clay is used) # Assumed units are in meters and days. # Model parameters controlling convergence sCale=1e6 # Scale mass conservation equation ePsilon1=1e5 # Minimal capacity when removing spurious oscillations in time Ah=9 # head suction at z = 0 AhZ=1 # gradient of initial head suction AhZZ=0 # initial head suction is calculated from equation h = Ah + AhZZ*z + AhZZ*zz [mat_block_2] material_name=VanGenuchten # Material parameters for Silt from Vogel., van Genuchten Cislerova 2001 sCale=1e6 ePsilon1=1e5 Ah=9 AhZ=1 thetaS=0.46 thetaM=0.46 thetaR=0.034 alpha=1.6 n=1.37 Ks=0.006 hS=0 # You can change boundary conditions here #[head_block_3] #head = 0
Note for this example we set initial pressure head distribution such that clay and silt are in equilibrium.
\[ \left\{ \begin{array}{ll} h(z,t=0) = 9+z&\textrm{for clay}\\ h(z,t=0) = 9+z&\textrm{for silt} \end{array} \right. \]
Moreover at the end we show how to modify boundary condition. As an excrete one can change value of head on the top of the sample.
We run script as before
For this example, we observe an influx of water into the column of solid, we can plot how it is changing over time. At every time step, solver monitor printing on the screen following lines
63 TS dt 0.00242774 time 0.0710581 Flux at time 0.07106 3.859e07 0 SNES Function norm 4.123926528377e02 1 SNES Function norm 6.552371691866e02 2 SNES Function norm 7.740255184123e02 3 SNES Function norm 7.999178179888e02 4 SNES Function norm 7.881110800442e02 5 SNES Function norm 7.582982118207e02 6 SNES Function norm 7.173427725809e02 7 SNES Function norm 6.666200930695e02 8 SNES Function norm 6.040633270649e02 9 SNES Function norm 5.232159632926e02 10 SNES Function norm 4.057267597689e02 11 SNES Function norm 1.625005251310e02 12 SNES Function norm 4.316837250846e05 13 SNES Function norm 8.980432593466e07 Nonlinear solve converged due to CONVERGED_FNORM_RELATIVE iterations 13 TSAdapt 'basic': step 63 accepted t=0.0710581 + 2.428e03 wlte=0.546 family='beuler' scheme=0:'' dt=2.627e03 64 TS dt 0.00262737 time 0.0734859 Flux at time 0.07349 3.812e07 0 SNES Function norm 4.023589003253e02 1 SNES Function norm 6.962486297267e02 2 SNES Function norm 8.329691099303e02 3 SNES Function norm 8.641640743250e02 4 SNES Function norm 8.532070311444e02 5 SNES Function norm 8.223165652333e02 6 SNES Function norm 7.792739113001e02 7 SNES Function norm 7.257891287567e02 8 SNES Function norm 6.598809018682e02 9 SNES Function norm 5.751011198160e02 10 SNES Function norm 4.535116560548e02 11 SNES Function norm 2.147388609216e02 12 SNES Function norm 1.073710142541e05 13 SNES Function norm 4.011739514453e11 Nonlinear solve converged due to CONVERGED_FNORM_ABS iterations 13 TSAdapt 'basic': step 64 accepted t=0.0734859 + 2.627e03 wlte=0.588 family='beuler' scheme=0:'' dt=2.742e03
where for step 63 and 64, total flux is printed in \(m^3/day\),
Flux at time 0.07106 3.859e07 Flux at time 0.07349 3.812e07
We can extract that information using awk/grep as follows
This shell command line takes all lines which have the phrase "Flux at", takes the fourth and the fifth columns from those lines, whereas fifth column is divided by area of the surface where the head is applied. Finally, results are stored in file gp. You can plot results in MS Excel or any other software, we choose to use gnuplot. As a result, we get Figure 2 below.
On Figure 3 below, we can observe how wetting front is moving downwards. Note how the gradient of head differs between clay and silt, and how it moves through the interface between materials.
We consider porous material partially filled with water. In this tutorial, we are going to simulate water transport in such system. The primary behaviour of the system depends on the material structure, capillary forces and wetting angle, taken into count by experimentally estimated material parameters. Darcy's law gives the relation between flux and suction head (capillary pressure). Constitutive equations describe the relationship between hydraulic conductivity and water content. It is assumed that state of the material is a function of water content, and using water retention curve one can map between capillary head and water content, i.e. \(\theta=\theta(h)\). The process of water flow has to obey conservation of mass, and consequently, process of unsaturated transport is described by the parabolic differential equation.
The Richards equation describes problem of unsaturated flow
\[ \frac{\partial \theta}{\partial t} \nabla \cdot \left[ \left( K(\theta) \nabla ( h  z) \right) \right] = 0 \]
where \(z\) is depth and \(K=K(\theta)\) is hydraulic conductivity. \(\nabla\) and \(\nabla \cdot\) are differential operators for gradient and divergence, respectively. The above equation alternatively can be expressed by the system of first order partial differential equations
\[ \left\{ \begin{array}{l} \frac{1}{K(\theta)}\boldsymbol\sigma + \nabla (h z) = 0 \\ c(\theta)\frac{\partial h}{\partial t}  \nabla \cdot \boldsymbol\sigma = 0 \end{array} \right. \]
where \(\boldsymbol\sigma\) is flux. The first equation expresses constitutive relation while the second is conservation law. The second equation is called as well continuity equation, and it does not allow for creation or annihilation of mass. The capacity term \(c\) in the second equation is given by
\[ c = \frac{\partial \theta}{\partial h} \]
It exists semiempirical relation between \(\theta\) and \(h\), called water retention curve, and for unsaturated state one can uniquely map between one and another when water retention hysteresis is not included. For simplicity here, we do not include hysteresis in our equations, and relations need to be established,
\[ \left\{ \begin{array}{l} \theta=\theta(h)\\ K = K(\theta) \end{array} \right. \]
Generic material model is implemented in MixTransport::GenericMaterial, which is an abstract class, thus its instance cannot be created. This class sets methods and data used by finite element instances. It is not modified when new material is implemented. This class is located in UnsaturatedFlow.hpp. To implement new material model user need to implement method
From MixTransport::GenericMaterial, the MixTransport::CommonMaterialData is derived. This class is unchanged if new material is implemented unless new material parameters need to be added to the model. Material parameters are read from text file given with command line option configure unsaturated.cfg. Example of such fill looks as follows,
[mat_block_1] # VanGenuchten # SimpleDarcy material_name=VanGenuchten # Default material for VanGenuchten is Clay (no need to set paramters if clay is used) # Assumed usinits are in meters and days. # Model parameters controlling convergence sCale=1e6 # Scale mass conservation equation ePsilon1=1e5 # Minimal capacity when removing spurious oscillations in time Ah=9 # head suction at z = 0 AhZ=1 #Â gradient of initial head suction AhZZ=0 # initial head suction is calculated from equation h = Ah + AhZZ*z + AhZZ*zz [mat_block_2] material_name=VanGenuchten # Material parameters for Silt from Vogel., van Genuchten Cislerova 2001 sCale=1e6 ePsilon1=1e5 Ah=0.09 AhZ=1 thetaS=0.46 thetaM=0.46 thetaR=0.034 alpha=1.6 n=1.37 Ks=0.006 hS=0 # You can change boundary conditions here #[head_block_3] #head = 0
Note that we have two blocks, which are sets of elements on the mesh. To each block, we can attach material and set material parameters. A user can add more material parameters by declaring them in MixTransport::CommonMaterialData and adding them to method MixTransport::CommonMaterialData::addOptions, such that added material parameter are read from the configuration file.
For proposes of this tutorial we have implemented two material models, i.e. MixTransport::MaterialDarcy and MixTransport::MaterialVanGenuchten, both classes are derived from MixTransport::CommonMaterialData.
The simplest method to implement new material is to derive class form MixTransport::MaterialWithAutomaticDifferentiation, and add it to file MaterialUnsaturatedFlow.cpp. MixTransport::MaterialWithAutomaticDifferentiation is a class to simplify implementation of the material model by utilizing advantages of automatic differentiation. Comprehensive description of library ADOLC for automatic differentiation can be found here (link).
In principle automatic differentiation records mathematical operations in the function. Recorded mathematical operations are represented algorithmically in the tree, where each tree leaf is expanded into Taylor series, with sufficient order to calculate derivatives exactly. Automatic differentiation is different from symbolic differentiation, such that it can calculate derivatives of algorithm, so you can have loops and other commands in your differentiated function.
In consequence, user needs to build a tree to calculate water content density \(\theta=\theta(h)\) and relative hydraulic conductivity \(K_r=K_r(h)\). Using terminology from ADOLC, one has to record tape with differentiated function. This is done by overloading two functions, MaterialWithAutomaticDifferentiation::recordTheta and MaterialWithAutomaticDifferentiation::recordKr. For example
where method recordTheta represents equation
\[ \theta = \theta_r + \frac{\theta_s\theta_r}{(1+(\alpha h)^n)^m} \]
and method recordKr represents equation
\[ K_r(S_e) = S_e\left[1(1S_e^{1/m})^m\right]^2 \]
Note that \(h\) is independent variable, whereas \(\theta\) and \(K_r\) are dependent variables. \(\alpha\), \(n\) and \(m\) are model parameters, see for details here [44]. Dissecting method recordTheta, we have
where we start and stop tape recording/tracing. Each tape has unique Id, in our case we have a convention that even Id's are used to record operations to calculate \(\theta\) and odd Id's are used to record \(K_r\). Each material block has own set of tapes since it uses unique material parameters and physical model has calculated from block number set on the mesh. In following code
we start by seeding point for which we build tree, \(h\) can be arbitrary but for the unsaturated state. Next, using "<<=" we set indented variable and using operator ">>=" to set dependent variable.
Finally new material model need to be registered, by adding line to the following code as follows
In the following, we apply mixformulation, building on tutorial Mix formulation and integration on skeleton (hadaptivity). We will show below that such approximation enables to solve Richards equation efficiently. This enables to address some issues of the regularity of equation that are difficult to approximate for classical formulation of finite elements.
Mixformulations allow converging to the solution faster than classical single filed finite element formulation. Mixelements have builtin error estimators into formulation letting for efficient hpadaptation and least not least separation of nonlinearities, driving the development of effect solvers for strongly nonlinear problems.
Our PDE is system of two equations. The second equation is universal law of conservation of mass, which enforces continuity of fluxes, such that for arbitrary surface \(\Gamma\) dividing body on two parts, that is \(\Omega = \Omega^1 \cup \Omega^2\)
\[ \mathbf{n}(\mathbf{x}) \cdot \left( \boldsymbol\sigma^1(\mathbf{x})  \boldsymbol\sigma^2(\mathbf{x}) \right) = 0,\;\forall\mathbf{x}\in\Gamma \]
Utilizing this observation, we choose approximation base which a priori satisfies such continuity on element faces. However, it does not enforce continuity of tangential components on the element face, since those do not contribute to mass exchange on element faces. Such approximation base is constructed for Raviart Thomas elements. Here we are using the recipe from [23] to construct arbitrary polynomial base order on elements, which a priori enforces continuity of fluxes.
The mass conservation in discrete form can be expressed as follows
\[ (v,c(\theta) \frac{\partial h}{\partial t})_\Omega  (v,\boldsymbol\sigma)_\Omega = 0 \quad \forall v \]
We obtain this equation by multiplying mass conservation by test function \(v\) and integrating both sides. Tested and test base functions are \(h,v \in L^2(\Omega)\), whereas \(\boldsymbol\sigma \in H(\nabla\cdot,\Omega)\) are divergence integrable functions which have been properly explained in the above paragraph. Here, we use notation, suitable for problems with many terms in the variational formulations, requires some explanation. First, we use the shorthand notation
\[ (v,c(\theta) \frac{\partial h}{\partial t})_\Omega = \int_\Omega v c(\theta) \frac{\partial h}{\partial t} \textrm{d}\Omega \]
and analogically for other terms.
The physical equation is the source of strong nonlinearities and problems with convergence of nonlinear solver and irregularities in the solution. We note that continuity of capillary head (capillary pressure) is not derived from conservation law, but dictated by the regularity of hydraulic conductivity \(K=K(\theta)\).
The philosophy of the finite element formulation presented here is to use approximation base having a priory continuity demanded by conservation law, whereas not to enforce continuity of capillary pressure head, which is controlled by the regularity of a constitutive law. That allows developing a numerical model for the bigger class of materials, initial and boundary conditions, suitable for analysis interface effects. Here, continuity of capillary pressure head is enforced posterior, as a consequence of assumed physical model.
Taking physical equation and testing it with test function \(\boldsymbol\tau \in H(\nabla\cdot,\Omega)\) we get
\[ (\boldsymbol\tau,\frac{1}{K(\theta)} \boldsymbol\sigma)_\Omega + (\boldsymbol\tau,\nabla (hz))_\Omega = 0 \quad \forall \boldsymbol\tau \]
next applying integration by parts we get
\[ (\boldsymbol\tau,\frac{1}{K(\theta)} \boldsymbol\sigma)_\Omega  (\nabla \cdot \boldsymbol\tau,(hz))_\Omega + (\mathbf{n} \cdot \boldsymbol\tau,(\overline{h}z))_{\partial\Omega} = 0 \]
where \(\overline{h}\) is prescribed capillary pressure on the boundary. Note that
In MoFEM we do not implement own Newton method, but use one implemented in PETSc. PETSc Newton solver is implemented in a package of nonlinear solvers SNES. In the nonlinear time dependent problem, SNES is called by TS (time solver). Here we focus attention on the calculation of residual vector and tangent matrix.
In this section, we focus attention on discretization in space, without restricting yourself to the particular time integration scheme. That is exclusively managed by TS solver from PETSc. This explains title of this section, the formulation is semidiscrete, since here apply discretization in space, but we assume that function in time is given by some unknown analytical function.
Above we put physical justification for using particular spaces for fluxes, which is \(\boldsymbol\tau,\boldsymbol\sigma \in H(\nabla\cdot,\Omega)\), and capillary pressure head \(u,h \in L^2(\Omega)\). One can show that selection of such approximation spaces, once the problem is discretized (i.e. finite element approximation spaces are used), numerical solution is stable since the choice of approximation spaces complies with De Rham diagram.
To solve problem we define residuals
\[ \left\{ \begin{array}{l} r_\tau = (\boldsymbol\tau,\frac{1}{K(\theta)} \boldsymbol\sigma)_\Omega  (\nabla \cdot \boldsymbol\tau,(hz))_\Omega + (\mathbf{n} \cdot \boldsymbol\tau,(\overline{h}z))_{\partial\Omega}\\ r_v = (v,c(\theta) \frac{\partial h}{\partial t})_\Omega  (v,\boldsymbol\sigma)_\Omega \end{array} \right. \]
Applying standard procedure where one solves nonlinear system of equations, we expand both equations into Taylor series, for terms \(\boldsymbol\sigma\), \(h\) and \(\frac{\partial h}{\partial t}\) since we have time dependent problem. Truncating the Taylor series after linear term, we get
\[ \left\{ \begin{array}{l} r^i_\tau + (\boldsymbol\tau,\frac{1}{K^i} \delta\boldsymbol\sigma^{i+1})_\Omega  (\nabla \cdot \boldsymbol\tau,\delta h^{i+1})_\Omega + (\boldsymbol\tau,\frac{\textrm{d}K}{\textrm{d}\theta}^i\frac{\textrm{d}\theta}{\textrm{d}h}^i(K^i)^{2} \boldsymbol\sigma^i) \delta h^{i+1})_\Omega = 0\\ r_v^i + (v,c^i\frac{\partial \delta h}{\partial t}^{i+1})_\Omega + (v,\frac{\textrm{d}c}{\textrm{d}\theta}^i\frac{\textrm{d}\theta}{\textrm{d}h}^i \frac{\partial h}{\partial t}^i) \delta h^{i+1})_\Omega  (v,\delta\boldsymbol\sigma^{i+1})_\Omega = 0 \end{array} \right. \]
where \(i\) is Newton iteration number. Note that tangent matrices and residuals are evaluated at known iteration \(i\) and unknowns are solved for iteration \(i+1\). Iterations are repeated until residuals are small in the absolute or relative norm. Once we achieve equilibrium we move to the next time step.
Expressing test and tested function by vectors of basis functions and vectors of degrees of freedom, we have
\[ \boldsymbol\sigma^i_n(\mathbf{x}) = \boldsymbol \phi^\textrm{T}(\mathbf{x}) \mathbf{q}^i_n,\; h^i_n(\mathbf{x},t_n) = \boldsymbol \psi^\textrm{T}(\mathbf{x},t_n) \mathbf{p}^i_n \]
where base vectors \(\boldsymbol \phi\) and \(\boldsymbol \psi\) are for Hdiv and L2 space respectively. \(n\) is time step. Finally, we get system of linear equations
\[ \left[ \begin{array}{cc} \mathbf{C} & \mathbf{G} \\ \mathbf{H} & \mathbf{A} \end{array} \right] \left\{ \begin{array}{c} \delta \mathbf{q}^{i+1}\\ \delta \mathbf{p}^{i+1} \end{array} \right\} = \left[ \begin{array}{c} \mathbf{r}^i_\tau\\ \mathbf{r}^i_v \end{array} \right] \]
where vectors of unknowns are updated as follows
\[ \mathbf{q}^{i+1}_{n+1} = \mathbf{q}_n + \Delta \mathbf{q}_{n+1}^i + \delta \mathbf{q}^{i+1}\quad \mathbf{p}^{i+1}_{n+1} = \mathbf{p}_n + \Delta \mathbf{p}_{n+1}^i + \delta \mathbf{p}^{i+1} \]
Tangent matrices and vectors are implemented in following operators
\[ \mathbf{r}_\tau = \mathbf{r}^\textrm{internal}_\tau + \mathbf{f}^\textrm{external}_\tau = (\boldsymbol\phi^\textrm{T},\frac{1}{K^i} \boldsymbol\sigma^i)_\Omega  (\nabla \cdot \boldsymbol\phi^\textrm{T},(h^iz))_\Omega + (\mathbf{n} \cdot \boldsymbol\phi^\textrm{T},(\overline{h}z))_{\partial\Omega} \]
\[ \mathbf{r}_v = (\boldsymbol\psi^\textrm{T},c(\theta) \frac{\partial h}{\partial t}^i)_\Omega  (\boldsymbol\psi^\textrm{T},\boldsymbol\sigma^i)_\Omega \]
\[ \mathbf{A} = (\boldsymbol\phi^\textrm{T},\frac{1}{K^i} \boldsymbol\phi)_\Omega \]
\[ \mathbf{C} = (\boldsymbol\psi^\textrm{T},c^i \frac{\partial \boldsymbol\psi}{\partial t})_\Omega + (\boldsymbol\psi^\textrm{T},\frac{\textrm{d}c}{\textrm{d}\theta}^i\frac{\textrm{d}\theta}{\textrm{d}h}^i \frac{\partial h}{\partial t}^i \boldsymbol\psi)_\Omega \]
\[ \mathbf{H}=(\nabla \cdot \boldsymbol\phi^\textrm{T},\boldsymbol\psi)_\Omega + (\boldsymbol\phi^\textrm{T},\frac{\textrm{d}K}{\textrm{d}\theta}^i\frac{\textrm{d}\theta}{\textrm{d}h}^i(K^i)^{2} \boldsymbol\sigma^i) \boldsymbol\psi)_\Omega \]
\[\mathbf{G} = (\boldsymbol\psi^\textrm{T},\boldsymbol\phi)_\Omega\]
In MoFEM, we do not implement time discretization algorithms unless we like to do something novel and nonstandard, and we would rather recommend implementing such an algorithm using PETSc time solver shell rather directly in MoFEM. Detailed description of how to use time solver (TS) in PETSc can be found in link, see chapter 6.
The constructions of time discretized problem are managed transparently for the user. If you are interested in details, see MoFEM::TsCtx class and auxiliary functions like MoFEM::f_TSSetIFunction, MoFEM::f_TSSetIJacobian and MoFEM::f_TSMonitorSet. Those functions are called by the discrete manager (DM) which is linked to time solver.
In the previous section, we transform PDE, by applying space discretization, into the system of linearized ordinary differential equations (ODE). In the following description, we transform the system of ODEs into a system of linear equations. In our particular problem, we need to calculate the rate of capillary head, which is discretized in time and space by
\[ h(\mathbf{x},t) = \boldsymbol \psi(\mathbf{x},t)^\textrm{T} \mathbf{p} = [\boldsymbol \xi(t).\boldsymbol{\tilde{\psi}}(\mathbf{x})]^\textrm{T} \mathbf{p} \]
where \([\xi(t).\boldsymbol{\tilde{\psi}}(\mathbf{x})]\) is element by element product of two vectors. With that at hand we can calculate rate of hydraulic head
\[ \frac{\partial h}{\partial t}(\mathbf{x},t) = \left[ \frac{\textrm{d}\boldsymbol\xi}{\textrm{d}t} (t).\boldsymbol{\tilde{\psi}}(\mathbf{x}) \right]^\textrm{T} \mathbf{p} \]
With above at hand, matrix \(\mathbf{C}\) where time derivative is present has the following form
\[ \mathbf{C} = \left(\boldsymbol\psi^\textrm{T}, \left( c^i \frac{\partial \boldsymbol\xi}{\partial t}+ \frac{\textrm{d}c}{\textrm{d}\theta}^i\frac{\textrm{d}\theta}{\textrm{d}h}^i \frac{\partial h}{\partial t}^i \right) \boldsymbol{\tilde\psi}\right)_\Omega \]
Note for any ODE integration method, the approximation of \(\frac{\partial h}{\partial t}\) is by linear function, hence
\[ \frac{\partial \boldsymbol\xi}{\partial t} = (shift). \]
For example, iterative change of capillary pressure head, when backwards Euler’s method is applied, \((shift) = 1/\Delta t\), what can be derived as follows
\[ \left(\frac{\partial \delta h}{\partial t}\right)^{i+1}_{n+1} = \left(\frac{\partial \delta h}{\partial \delta \mathbf{p}}\frac{\partial \delta \mathbf{p}}{\partial t} \right)^{i+1}_{n+1} = \left( \boldsymbol{\tilde \psi} \delta \mathbf{p}^{i+1}\right) \left( 1/\Delta t \right) = \left( \boldsymbol{\tilde \psi} \delta \mathbf{p}^{i+1} \right) (shift) \]
Such approach allows for code generalisation such that finite element formulation which concerns discretization in space, does not depend on discretization in time. That makes it possible to switch between time integration schemes without changing implementation, see list of time integration schemes in link, table 10.
Above is exploited in MixTransport::UnsaturatedFlowElement::OpVU_L2L2::doWork, where shift, as follows, is applied at integration points
where \(\textrm{ts_a} = (shift)\). Note that evaluation of capillary head DOFs, i.e. \(\frac{\partial \mathbf{p}}{\partial t}\) is managed exclusively by PETSc and depends on used time integration shame.
In method MixTransport::UnsaturatedFlowElement::addFields, we declare and define fields on entities and set order of approximation as follows
Note that we set field space independently from the approximation base. We can have different recipes to construct approximation base, for example, [1] and [23]. Note, to get solvable system of linear equations, pressure head approximation has one order lower that approximation for fluxes. Here for simplicity, we set homogeneous approximation order, however, implementation can be easily extended to the case where approximation order is locally increased near interfaces or boundary where pressure head is applied.
In similar way, we declare and define finite elements in MixTransport::UnsaturatedFlowElement::addFiniteElements, as follows
Note that we create three elements including "MIX", "MIX_BCVALUE" and "MIX_BCFLUX", to evaluate fields in volume, on the boundary where natural conditions are applied and where essential conditions are applied, respectively.
Both fields and finite elements are defined on part of the mesh, i.e. entities set, where mesh block name starts with first four letters "SOIL". In case of "MIX_BCVALUE" and "MIX_BCFLUX" where blocks name having first for letters "HEAD" and "FLUX", respectively. A user can define multiple blocks and attach material model, material parameters and initial conditions independently to each of them independently.
In a similar way, other types of elements can be added to the formulation, for example, we can create evaporation element on some parts of the boundary, or one can extend formulation with other mechanical and nonmechanical fields. For example, one can add heat conduction and solve coupled problem with freezing and thawing processes.
In method MixTransport::UnsaturatedFlowElement::buildProblem, we create problem and Discrete Manager operating on that problem
Note that problem in DM is created by setting finite elements on which it operates.
Definition of the problem enables to construct a matrix since matrix connectivity is derived from problem definition. To fill the matrix with the numbers, you need to implement finite element. In fact, you can have more than one implementation of the same problem.
Once you have problem defined, the developer is released from the need managing complexities related to management of DOFs, iteration over elements, matrix assembly, etc. It can focus on the integration of local entity matrices, as shown in Semidiscrete linearized system of equations.
MoFEM provides technology with simplifies implementation of the element, enabling the developer to break a complex problem into smaller tasks, which are easier to implement, debug and reuse in different contexts, that has been discussed in several tutorials already. Assembly of residual vectors and tangent matrices is made with the use of so called user data operators (UDO). For example, the sequence of user data operators of finite element instance to assemble tangent matrix is shown in Figure 4.
We have already discussed last four operators in sequence for feVolLhs finite element instance, those are used to assemble tangent matrix blocks, i.e. \(\mathbf{C}\), \(\mathbf{G}\), \(\mathbf{H}\) and \(\mathbf{A}\). First, three operators are used to evaluate fields at integration points, i.e. capillary head, flux and rate of capillary head. Note first three operators have been reused from other tutorials.
In this problem, we use two generic implementations of finite element, MoFEM::VolumeElementForcesAndSourcesCore and MoFEM::FaceElementForcesAndSourcesCore, for integrating fields on volumes and faces. Finite element instances are iterated over a particular element in the problem, and for each entity on finite element entity, the sequence of UDO is called.
We use smart pointers to create finite element instances, which gives code flexibility and safe memory management. Finite element instances are created in method MixTransport::UnsaturatedFlowElement::setFiniteElements, as follows
Next, we set integration rule, as has been discussed in tutorial Solving the Poisson equation, as follows
In addition, we add hooks to functions which are run at the beginning and the end of the loop over a particular element. Those functions are used to preprocess, and postprocess matrix assemble. Those preprocessing and postprocessing hooks are added as follows
We use classes MixTransport::UnsaturatedFlowElement::preProcessVol and MixTransport::UnsaturatedFlowElement::postProcessVol to enforce essential boundary conditions. The method of enforcing essential boundary conditions is discussed in Mix formulation and integration on skeleton (hadaptivity). In additional in function MixTransport::UnsaturatedFlowElement::postProcessVol::operator()(), we scatter vector of rate of capillary pressure on field data. Since rate of capillary head is not primary unknown, but linear function of solution at current and previous steps, is evaluated by PETSc for particular integration scheme.
Time solver provides vector of DOFs, \(\left(\frac{\textrm{d}\mathbf{p}}{\textrm{d}t}\right)^{i+1}_{n+1}\) at integration \(i+1\) and time step \(n+1\), and above code scatter vector values on mesh, such that values of capillary head at integration points are early evaluated, i.e. \(\frac{\textrm{d}h}{\textrm{d}t}^{i+1}_{n+1}\). Capillary head DOFs are subvector of fePtr>ts_u_t.
User data operators are added to finite element calculating tangent matrix as follows
and similarly for other elements, evaluating boundary conditions and vector of residuals. For more details we refer to tutorial Hello world.
In addition, finite element instances are created to postprocess results and to run time stepping monitor, see code in MixTransport::UnsaturatedFlowElement::setFiniteElements.
Once we have created finite element instances, in MixTransport::UnsaturatedFlowElement::setFiniteElements, we add finite instances to DM manager, such that system of equations could be assembled. This is simply done by
Those functions are specific to MoFEM implementation, they have been implemented based on PETSc documentation, link, see Chapter 6.
Finally, we can solve problem, by creating TS solver and link it to DM, as follows
Note that TS calls finite elements instance by DM, similarly how SNES (Newton solver) calls finite elements in A nonlinear Poisson equation, or KSP (Krylov solver) calls finite elements in Solving the Poisson equation. Above is implemented in MixTransport::UnsaturatedFlowElement::solveProblem, where prior to solution initial conditions are calculated, and statistics at the end printed to the terminal.
Application code is unsaturated_transport.cpp, which calls sequence of functions
Add example with hpadaptivity
Implement blocksolver and multigrid
Apply Kirchhoff transform
Add boundary condition for evaporation
Add air phase and mechanical filed
Add diffusion and other physical phenomena
Make example with flux history or head history. That is implemented but no example is added
Add diffusion and other physical phenomenas