\section{Upfront considerations} \label{tutorial1} The process of setting up a problem using \eWoms can be roughly divided into three parts: \begin{enumerate} \item A suitable model has to be chosen. \item The geometry of the problem has to be defined and the suitable grid has to be created. \item Boundary and initial conditions and material properties have to be specified. \end{enumerate} The physical set-up of the flow problem being solved in this tutorial is illustrated in Figure \ref{tutorial1:problemfigure}: It consists of a rectangular domain with no-flow boundary conditions on the top and on the bottom of the domain, which is initially fully saturated by a light oil. Water infiltrates from the left side and replaces the oil. The effect of gravity is neglected. \begin{figure}[ht] \psfrag{x}{x} \psfrag{y}{y} \psfrag{no flow}{no flow} \psfrag{water}{\textbf{water}} \psfrag{oil}{\textcolor{white}{\textbf{oil}}} \psfrag{p_w = 2 x 10^5 [Pa]}{$p_w = 2 \times 10^5$ [Pa]} \psfrag{p_w_initial = 2 x 10^5 [Pa]}{\textcolor{white}{\textbf{$\mathbf{p_{w_{initial}} = 2 \times 10^5}$ [Pa]}}} \psfrag{S_n = 0}{$S_n = 0$} \psfrag{S_n_initial = 0}{\textcolor{white}{$\mathbf{S_{n_{initial}} = 1}$}} \psfrag{q_w = 0 [kg/m^2s]}{$q_w = 0$ $\left[\frac{\textnormal{kg}}{\textnormal{m}^2 \textnormal{s}}\right]$} \psfrag{q_n = -3 x 10^-4 [kg/m^2s]}{$q_n = 3 \times 10^{-2}$ $\left[\frac{\textnormal{kg}}{\textnormal{m}^2 \textnormal{s}}\right]$} \centering \includegraphics[width=0.9\linewidth,keepaspectratio]{EPS/tutorial-problemconfiguration} \caption{Geometry of the tutorial problem with initial and boundary conditions.}\label{tutorial1:problemfigure} \end{figure} The solved equations are the mass balances of water and oil: \begin{align} \label{massbalancewater} \frac {\partial (\phi \, S_{w}\, \varrho_{w})}{\partial t} - \nabla \cdot \left( \varrho_{w} \, \frac{k_{rw}}{\mu_{w}} \, \mathbf{K}\;\nabla p_w \right) - q_w & = 0 \\ \label{massbalanceoil} \frac {\partial (\phi \, S_{o}\, \varrho_{o})}{\partial t} - \nabla \cdot \left( \varrho_{o} \, \frac{k_{ro}}{\mu_{o}} \, \mathbf{K}\;\nabla p_o \right) - q_o & = 0 \end{align} \subsection{The main source file} Listing \ref{tutorial1:mainfile} shows the main file \texttt{tutorial/tutorial1.cc} for the tutorial problem using a fully-implicit model that assumes immiscibility. This file has to be compiled and executed in order to solve the problem described above. \begin{lst}[File tutorial/tutorial1.cc]\label{tutorial1:mainfile} \mbox{} \lstinputlisting[style=eWomsCode, numbersep=5pt, firstline=27, firstnumber=27]{../../tutorial/tutorial1.cc} \end{lst} In \eWoms, this file is usually quite short, as most of the work for setting up the simulation is done by the generic startup routine \texttt{Ewoms::start()}. The tasks left for the main source file are: \begin{itemize} \item Inclusion of the necessary header files from line \ref{tutorial1:include-begin} to line \ref{tutorial1:include-end}. \item Specifying the type tag of the problem which is going to be simulated at line \ref{tutorial1:set-type-tag}. \item Starting the simulation using default \eWoms startup routine \texttt{Ewoms::start()} on line \ref{tutorial1:call-start}. \end{itemize} The default \eWoms startup routine parses the command line arguments, optionally reads a file which may specify further parameters, creates the grid which represents the spatial domain, and then starts the actual simulation. Parameters for the simulation, can be either specified using command line arguments of the form (\texttt{--parameter-name=value}), or in the file specified by the \texttt{--parameter-file="file\_name"} argument. The list of all parameters used by a simulation can be obtained by passing \texttt{--help} to the executable on the command line. \subsection{The problem file} \begin{lst}[File tutorial/tutorial1problem.hh] \label{tutorial1:problemfile}\mbox{} \lstinputlisting[style=eWomsCode, numbersep=5pt, firstline=28, firstnumber=28]{../../tutorial/tutorial1problem.hh} \end{lst} For using \eWoms, the central file is the \emph{problem file} as shown in listing~\ref{tutorial1:problemfile}. This file is responsible for specifying the physical setup of the problem which is to be simulated. In this context, all problems first need to set up the relevant properties for the \eWoms property system: \begin{itemize} \item First, a new type tag is created for the problem on line \ref{tutorial1:create-type-tag}. In this case, the new type tag inherits all properties from the \texttt{ImmiscibleTwoPhaseModel} type tag, which means that for this problem the immiscible model for two fluid phases is chosen as discretization scheme. \item Next, the spatial discretization which ought to be used is selected on line~\ref{tutorial1:include-discretization}. In this case, the vertex-centered finite volume (VCFV) method is chosen. \item On line \ref{tutorial1:set-problem}, the problem class is specified for the new type tag, while the kind of grid that is to be used is defined in line \ref{tutorial1:set-grid} -- in this case it is \texttt{Dune::YaspGrid}. \item Since \Dune does not provide a uniform mechanism to create or load grids, \eWoms features the concept of grid managers. In this case, the generic \texttt{CubeGridManager} is used. This grid manager constructs a structured rectangular grid with a specified size and resolution. For this grid manager, the physical domain of the grid is specified via the run-time parameters \texttt{DomainSizeX} and \texttt{DomainSizeY} and its resolution by \texttt{CellsX} and \texttt{CellsY}. These parameters can be specified via the command-line or in a parameter file, but the problem file must define default values for them. Defining these defaults is done on lines \ref{tutorial1:grid-default-params-begin} to \ref{tutorial1:default-params-end}. \end{itemize} Next, an appropriate fluid system -- which specifies the thermodynamic relations of the fluid phases -- has to be chosen. By default, the immiscible model for two fluid phases uses \texttt{\justifyNoHyphen{}Ewoms::Fluid\-Systems::TwoPImmiscible}. This fluid system simplifies things considerably by assuming immiscibility of the phases, but it requires to explicitly specify the fluids of the wetting and non-wetting phases. In this case, liquid water based on simple relations is selected as the wetting phase on line \ref{tutorial1:wettingPhase} and a light liquid oil is chosen as the non-wetting phase on line \ref{tutorial1:nonwettingPhase}. The next property, which is set on line \ref{tutorial1:gravity}, tells the model not to use gravity. This is then followed by the specification default values for parameters specifying the temporal and spatial simulation domain from line \ref{tutorial1:default-params-begin} to line \ref{tutorial1:default-params-end}. The values of those can be overwritten at run-time if desired. Following the property definitions, is the problem class which specifies the variable parameters of the physical set-up to be simulated. Such parameters are, for example, boundary and initial conditions, source terms and spatially dependent quantities like temperature, porosity, intrinsic permeability and the parameters required by the capillary pressure/relative permeability law within the domain. Since there are quite a few methods necessary to fully specify a problem, and it is often possible to specify meaningful defaults, it is strongly recomended to derive the problem from the class specified by the \texttt{BaseProblem} property as done on line \ref{tutorial1:def-problem}\footnote{Technically, deriving the problem from the \texttt{BaseProblem} is not required if it implements all necessary methods. Do not complain if things explode in this case, though.}. For the isothermal multi-phase porous media model which assumes immiscibility, the problem class provided by the user must implement at least the following methods: \begin{itemize} \item \texttt{initial()} for specifying the initial condition within the domain, \item \texttt{source()} which defines the source term for each conservation quantity, \item \texttt{boundary()} for the conditions at the spatial domain's boundary, \item \texttt{temperature()} which provides the temperature within the spatial domain. Note, that if energy is conserved, this method is not necessary. Instead, energy fluxes must be specified by the \texttt{boundary()} and \texttt{source()} methods and an initial temperature needs to be defined by the \texttt{initial()} method in this case. \item \texttt{intrinsicPermeability()} for returning the intrinsic permeability matrix $\mathbf{K}$ in $[m^2]$ at a given location. \item \texttt{porosity()} which specifies the ratio of pore space to total volume of the medium at a given location. \item \texttt{materialLawParams()} which defines the parameters for the capillary pressure and relative permeability relations at a given location. \end{itemize} All of these methods take a single template argument, \texttt{Context}, and the three function arguments \texttt{context}, \texttt{spaceIdx} and \texttt{timeIdx}. Together, these form the so-called \emph{execution context}. The execution context can be thought of as a collection of all available information for a given method. Thus, execution contexts a way to abstract away the differences of discretization schemes. The following methods are provided by all \texttt{context} objects: \begin{itemize} \item \texttt{pos(spaceIdx, timeIdx)}: This method returns the relevant position of the execution context within the spatial domain. \item \texttt{globalSpaceIndex(spaceIdx, timeIdx)}: Returns a global index for the spatial degree of freedom which is associated to the execution context. This index can be used to store spatially dependent information in an array. \item \texttt{element()}: Returns the \Dune grid element to which the execution context applies. \item \texttt{gridView()}: Returns the \Dune grid view of which the element is part of. \item \texttt{problem()}: Returns the \eWoms object which describes the physical problem to be solved. \item \texttt{model()}: Returns the \eWoms model which is used to simulate the physical problem. \end{itemize} The execution contexts for the \texttt{source} and \texttt{boundary} methods always provide the following methods in addition: \begin{itemize} \item \texttt{volVars(spaceIdx, timeIdx)}: The secondary variables used by the model relevant for the execution context. These are useful to specify solution dependent source and boundary terms. \item \texttt{primaryVars(spaceIdx, timeIdx)}: The vector of primary variables to which the model solves for. \end{itemize} Finally, the execution context for the \texttt{boundary} method provides the methods \texttt{boundarySegmentArea(spaceIdx, timeIdx)}, and \texttt{normal(spaceIdx, timeIdx)}, which return the area of the boundary segment and outer unit normal of the boundary segment. When specifying the boundary conditions in the problem class, a small safeguard value \texttt{eps\_} should usually be added when comparing spatial coordinates. For the problem considered here, the left boundary might not be detected if checking whether the first coordinate of the global position is equal to zero, but it is detected reliably by testing whether it is smaller than an $\epsilon$-value. Also, the \texttt{bboxMax()} (``\textbf{max}imum coordinate of the grid's \textbf{b}ounding \textbf{box}'') method is used here to determine the extend of the physical domain. It returns a vector with the maximum values on each axis of the grid. This method and the analogous \texttt{bboxMin()} method are provided by the problem's base class. In addition to these methods, there might be some additional model-specific methods. \subsection{Defining fluid properties} \label{tutorial1:description-fluid-class} The \eWoms distribution includes representations of some common substances which can be used out of the box. The properties of pure substances (such as nitrogen, water, or the pseudo-component air) are provided by header files located in the folder \texttt{ewoms/material/components}. When two or more substances are considered, interactions between these become relevant and the properties of these mixtures of substances -- e.g. composition, density or enthalpy -- are required. In \eWoms, such interactions are defined by {\em fluid systems}, which are located in \texttt{ewoms/material/fluidsystems}. A more thorough overview of the \eWoms fluid framework can be found in chapter~\ref{sec:fluidframework}. \subsection{Exercises} \label{tutorial1:exercises} The following exercises will give you the opportunity to learn how you can change soil parameters, boundary conditions, run-time parameters and fluid properties in \eWoms. \subsubsection{Exercise 1} \renewcommand{\labelenumi}{\alph{enumi})} For Exercise 1 you have to modify the tutorial files only sightly, or even not at all. \begin{enumerate} \item \textbf{Running the Program} \\ To get an impression what the results should look like, you can first run the original version of the tutorial problem by entering the directory into which you installed \eWoms, followed typing \texttt{make tutorial1 \&\& ./bin/tutorial1}. Note, that the time-step size is automatically adapted during the simulation. For visualizing the results using the program \texttt{paraview}, please refer to section \ref{quick-start-guide}. \item \textbf{Changing the Model Domain} \\ Change the size of the model domain so that you get a rectangle with edge lengths of $\text{x} = \unit[400]{m}$ and $\text{y} = \unit[500]{m}$ and with discretization lengths of $\Delta \text{x} = \unit[20]{m}$ and $\Delta \text{y} = \unit[20]{m}$. For this, you can either change the properties defined between lines \ref{tutorial1:default-params-begin} and \ref{tutorial1:default-params-end}, or you may pass them as command line parameters to the simulation when you run it. If you chose to change the problem file, re-compile the simulation by typing \texttt{make tutorial1} in the toplevel directory of your \eWoms build directory. Note, that you do not have to recompile the program if you use command line parameters. In both cases, don't forget run the simulation before re-inspecting the results using \texttt{paraview}. \item \textbf{Boundary Conditions} \\ Change the boundary conditions in the problem file \texttt{tutorial1problem.hh} so that water enters from the bottom and oil is extracted from the top boundary. The right and the left boundary should be closed for both, water and oil. Note that in \eWoms, flux boundary conditions are specified as fluxes of the conserved quantities into the direction of the outer normal per area. This means a mass flux into the domain is negative, a flux out of the domain is always positive. Re-compile the simulation by typing \texttt{make tutorial1} and re-run it as explained above. \item \textbf{Changing the Spatial Discretization} \\ Change the spatial discretization used for this problem from the vertex-centered finite element method (VCFV) to the element-centered one (ECFV). For this, you need to change the file included on line~\ref{tutorial1:include-discretization} and the definition of the splice for the spatial discretization on line~\ref{tutorial1:set-spatial-discretization}. \item \textbf{Changing the Shape of the Discrete Elements} \\ In order to complete this exercise you need a \Dune grid manager that is capable of handling simplex grids. By default, \Dune does not include such a grid manager in its core modules, but the freely available \texttt{ALUGrid}~\cite{ALUGRID-HP} can be used. If you do not want to go through the trouble of installing this grid manager, please skip this exercise. Change the grid manager used by the problem to \texttt{SimplexGridManager} and the type of the grid to \texttt{Dune::ALUSimplexGrid<2, 2>}. The grid manager is specified on line \ref{tutorial1:set-grid-manager}, while the type of the \Dune grid manager is set on line \ref{tutorial1:set-grid}. You also need to change the include statement of the grid manager from \texttt{cubegridmanager.hh} to \texttt{simplexgridmanager.hh} on line \ref{tutorial1:include-grid-manager} and the one for the grid manager from \texttt{dune/grid/yaspgrid.hh} to \texttt{dune/grid/alugrid.hh} on line \ref{tutorial1:include-grid-manager}. The resulting grid can be examined by re-compiling and starting the simulation, loading the result into \texttt{paraview}, and selecting \texttt{Surface with Edges} instead of the default visualization mode \texttt{Surface}. \item \textbf{Changing Fluids} \\ In this exercise you will change the fluids used: Use DNAPL instead of LNAPL and Brine instead of Water. This can be done by the following steps: \begin{enumerate} \item Brine: Brine is thermodynamically very similar to pure water but also includes a fixed amount of salt in the liquid phase. Hence, the class \texttt{Ewoms::Brine} calls back to a class which represents pure water. (This can be, for example \texttt{Ewoms::H2O}, or \texttt{Ewoms::SimpleH2O}.) The class which represents pure water is passed to \texttt{Ewoms::Brine} as the second template argument after the data type for scalar values, i.e. the full definition of the brine component is \texttt{Ewoms::Brine >}. The file which defines the brine component is located in the folder \texttt{ewoms/material/components/}. Include this file and select use the brine component as the wetting phase. \item DNAPL: Now let us use a component that represents an oil that is heavier than water (in environmental engineering this class of substances is often called \textbf{d}ense \textbf{n}on-\textbf{a}queous \textbf{p}hase \textbf{l}iquid (DNAPL)) which is also located in the folder \texttt{ewoms/material/components/}. Include the correct file and use the DNAPL component as the non-wetting phase. \end{enumerate} If you want to take a closer look on how the fluid classes are defined and which substances are available in the \eWoms distribution, feel free to browse through the files in the directory \texttt{ewoms/material/components} and read chapter~\ref{sec:fluidframework}. \item \textbf{Use a Full-Fledged Fluid System} \\ In \eWoms, the canonical way to describe fluid mixtures is via \emph{fluid systems}\footnote{For a thorough introduction into fluid systems and the concepts related to it, see chapter \ref{sec:fluidframework}}. In order to include a fluid system, you first have to comment out lines \ref{tutorial1:2p-system-start} to \ref{tutorial1:2p-system-end} in the problem file.\\ Now include the file \texttt{ewoms/material/fluidsystems/h2oairfluidsystem.hh}, and instruct the model to use this fluid system by setting the \texttt{FluidSystem} property via:\\ \begin{lstlisting}[style=eWomsCode] SET_TYPE_PROP(Tutorial1Problem, FluidSystem, Ewoms::FluidSystems::H2OAir) \end{lstlisting} However, this is a rather complicated fluid system which considers all fluid phases as a mixture of the components and also uses tabulated components that need to be filled with values (i.e. some components use tables to speed up expensive computations). The initialization of the fluid system is normally done in the constructor of the problem by calling \texttt{FluidSystem::init();}. As water flow replacing a gas is much faster, simulate the problem only until $2.000$ seconds is reached and start with a time step of $1$ second. Now, revert the changes made in this part of the exercise, as we will continue to use immiscible phases from here on and hence do not need a complex fluid system. \item \textbf{Changing Constitutive Relations} \\ Instead of using a regularized Brooks-Corey law for the relative permeability and for the capillary pressure saturation relationship, use an linear material law which does not consider residual saturation. The new material law should exhibit an entry pressure of $p_e = 0.0\;\text{Pa}$ and maximal capillary pressure of $p_{c_{max}} = 2000.0\;\text{Pa}$. To do that, you have to change the material law property on line \ref{tutorial1:eff2abs} as follows: \begin{itemize} \item First, switch to the linear material law. This can be achieved by replacing \texttt{RegularizedBrooksCorey} in the private section of the property definition by \texttt{LinearMaterial} and rename \texttt{RawMaterialLaw} to \texttt{TwoPMaterialLaw}. Also remove the line which contains the \texttt{EffToAbsLaw} typedef. \item Then, adapt the necessary parameters of the linear law and the respective \texttt{set}-functions can be found in the file \texttt{ewoms/material/fluidmatrixinteractions/2p/linearmaterialparams.hh}.\\ Call the \texttt{set}-functions from the constructor of the problem. \item Finally, re-compile and re-run the simulation. In order to successfully compile the simulation, you also have to include the header file which contains the linear material law. This header is called \texttt{linearmaterial.hh} and is located in the same directory as the header for the regularized Brooks-Corey law, \texttt{regularizedbrookscorey.hh}. \end{itemize} \item \textbf{Heterogeneities} \\ Set up a model domain with the soil properties given in Figure \ref{tutorial1:exercise1_d}. Adjust the boundary conditions so that water is flowing from the left to the right of the domain again. \begin{figure}[ht] \psfrag{K1 =}{$\mathbf{K} = 10^{-8}\;\text{m}^2$} \psfrag{phi1 =}{$\phi = 0.15$} \psfrag{K2 =}{\textcolor{white}{$\mathbf{K} = 10^{-9}\;\text{m}^2$}} \psfrag{phi2 =}{\textcolor{white}{$\phi = 0.3$}} \psfrag{600 m}{$600 \;\text{m}$} \psfrag{300 m}{$300 \;\text{m}$} \centering \includegraphics[width=0.5\linewidth,keepaspectratio]{EPS/exercise1_c.eps} \caption{Exercise 1f: Set-up of a model domain with a heterogeneity. $\Delta x = 20 \;\text{m}$ $\Delta y = 20\;\text{m}$.}\label{tutorial1:exercise1_d} \end{figure} You can use the fluids of exercise 1b). \textbf{Hint:} The relevant position in the domain can be obtained using \texttt{const auto \&pos=context.pos(spaceIdx, timeIdx);} When does the front cross the material border? In paraview, the animation view (\emph{View} $\rightarrow$ \textit{Animation View}) is a convenient way to get a rough feeling of the time-step sizes. \end{enumerate} \subsubsection{Exercise 2} For this exercise, first create a new problem file analogous to the file \texttt{tutorial1problem.hh} (e.g. with the name \texttt{ex2\_tutorial1problem.hh}. The new problem file needs to be included in the file \texttt{tutorial1.cc}. The new file should contain definitions of new classes with names that relate to the file name, such as \texttt{Ex2TutorialProblemCoupled}. Make sure that you also adjust the guardian macros in lines \ref{tutorial1:guardian1} and \ref{tutorial1:guardian1} in the header files (e.g. change \mbox{\texttt{EWOMS\_TUTORIAL1PROBLEM\_HH}} to \mbox{\texttt{EWOMS\_EX2\_TUTORIAL1PROBLEM\_HH}}). Include the new problem file in \texttt{tutorial1.cc}. Besides adjusting the guardian macros, the new problem file should define and use a new type tag for the problem as well as a new problem class e.g. \mbox{\texttt{Ex2TutorialProblemCoupled}}. The type tag for the problem should be adjusted, too. For this, modify line \ref{tutorial1:set-type-tag} in the problem file and the adapt the \texttt{main} function in the file \texttt{tutorial1.cc}. After this, change the domain parameters so that they match the domain described by figure \ref{tutorial1:ex2_Domain}. Adapt the problem class so that the boundary conditions are consistent with figure \ref{tutorial1:ex2_BC}. Initially, the domain is fully saturated with water and the pressure is $p_w = 5\cdot 10^5\;\text{Pa}$. Oil infiltrates from the left side. Create a grid with $20$ cells in $x$-direction and $10$ cells in $y$-direction. The simulation time should end at $10^6\;\text{s}$ with an initial time step size of $100\;\text{s}$. \begin{figure}[ht] \psfrag{K1}{K $= 10^{-7}\;\text{m}^2$} \psfrag{phi1}{$\phi = 0.2$} \psfrag{Lin}{\textsc{Brooks}-\textsc{Corey} Law} \psfrag{Lin2}{$\lambda = 1.8$, $p_e = 1000\;\text{Pa}$} \psfrag{K2}{K $= 10^{-9}\;\text{m}^2$} \psfrag{phi2}{$\phi = 0.15$} \psfrag{BC1}{\textsc{Brooks}-\textsc{Corey} Law} \psfrag{BC2}{$\lambda = 2$, $p_e = 1500\;\text{Pa}$} \psfrag{H1y}{$50\;\text{m}$} \psfrag{H2y}{$15\;\text{m}$} \psfrag{H3y}{$20\;\text{m}$} \psfrag{L1x}{$100\;\text{m}$} \psfrag{L2x}{$50\;\text{m}$} \psfrag{L3x}{$25\;\text{m}$} \centering \includegraphics[width=0.8\linewidth,keepaspectratio]{EPS/Ex2_Domain.eps} \caption{Set-up of the model domain and the soil parameters}\label{tutorial1:ex2_Domain} \end{figure} \begin{figure}[ht] \psfrag{pw}{$p_w = 5 \times 10^5\;\text{Pa}$} \psfrag{S}{$S_n = 1.0$} \psfrag{qw}{$q_w = 2 \times 10^{-4} \;\text{kg}/\text{m}^2\text{s}$} \psfrag{qo}{$q_n = 0.0 \;\text{kg}/\text{m}^2\text{s}$} \psfrag{no flow}{no flow} \centering \includegraphics[width=0.8\linewidth,keepaspectratio]{EPS/Ex2_Boundary.eps} \caption{Boundary Conditions}\label{tutorial1:ex2_BC} \end{figure} \begin{itemize} \item Increase the simulation time to e.g. $4\times 10^7 \;\text{s}$. Investigate the saturation of the wetting phas: Is the value range reasonable? \item What happens if you use a grid with more cells in each direction? \end{itemize} \subsubsection{Exercise 3: Create a New Component} Create a new file for the benzene component called \texttt{benzene.hh} and implement a new component. (\textbf{Hint:} The easiest way to do this is to copy and modify one of the existing components located in the directory \texttt{ewoms/material/components}.) Use benzene as a new non-wetting fluid and run the problem of Exercise 2 with water and benzene. Benzene has a density of $889.51 \, \text{kg} / \text{m}^3$ and a viscosity of $0.00112 \, \text{Pa} \; \text{s}$. \clearpage \newpage %%% Local Variables: %%% mode: latex %%% TeX-master: "ewoms-handbook" %%% End: