### Integrated groundwater and surface water modeling: the finite element

Numerical simulations of groundwater and surface water movements are essentially dealing with the finite element in the spatial domain.
This finite element could be in a variety of forms including cubic, node and pixel. This depends upon the methods used to conceptualize this physical world.
The dimension of these finite elements varies as well since they are characterized by spatial resolution.
For spatial distributed hydrologic models, regardless of groundwater or surface water models, these finite elements interact with each other governed by derived continuity equations such as Richard's equation.

Consequently, in most groundwater models, the finite element would interact with 6 neighbors in a 3D model. However, in a spatial distributed surface water model, the finite element may interact with 8 neighbors or 4 neighbors. Even within one model, different assumptions are possibly made in different scenarios.
Then the question is are these assumptions contradict each other? Or why it should have 8 neighbor instead of 4 and so on?

Let's first take a look at some real life examples using some existing models. For groundwater modeling, in MODFLOW, which is one of the most widely used groundwater models, each finite element can interact with 4 horizontal neighbors and 2 vertical neighbors. So there are 6 neighbors in total. Similarly for surface modeling, in SWAT/PRMS, each finite element can interact with 4 or 8 neighbors.

A close look at some watershed delineation process will unveil that even though water flow direction is predefined using digital elevation model (DEM) aspect, flow itself in fact is distributed in more than one direction using fractions.

An important reference of how this flow direction is produced is explained here:

Now it looks plausible that 8 neighbor would better describe the flow path than 4 neighbors. But why?
And why this is not implemented in groundwater modeling? Also what plays a factor in these assumptions? (spatial resolution?)

The following figure is retrieved from watershed delineation process. So will it become an issue that there are a few pixels that belong to 8 neighbor, but not 4 neighbor?
Certainly in surface water hydrology, water flow can be like this. But for groundwater modeling, this is usually not allowed if this type of pixels are on the boundary.

In fact, some watershed utilities indeed use 4 neighbors instead of 8 neighbors.
Complexity doesn't always performance better than simplicity. But sometimes complexity is a compromise between simplicity and limitation.

No matter what assumptions or strategies are made, govern equation only cares about mass balance and energy balance. As long as these laws are not violated, the models are usually reliable. However, this is also a common issue in integrated hydrologic model. And as our model continues to increase in processes and resolution, the possibility of encountering this type of issue increases as well.

### Spatial datasets operations: mask raster using region of interest

Climate change related studies usually involve spatial datasets extraction from a larger domain.
In this article, I will briefly discuss some potential issues and solutions.

In the most common scenario, we need to extract a raster file using a polygon based shapefile. And I will focus as an example.

In a typical desktop application such as ArcMap or ENVI, this is usually done with a tool called clip or extract using mask or ROI.

Before any analysis can be done, it is the best practice to project all datasets into the same projection.

If you are lucky enough, you may find that the polygon you will use actually matches up with the raster grid perfectly. But it rarely happens unless you created the shapefile using "fishnet" or other approaches.

What if luck is not with you? The algorithm within these tool usually will make the best estimate of the value based on the location. The nearest re-sample, but not limited to, will be used to calculate the value. But what about the outp…

### Numerical simulation: ode/pde solver and spin-up

For Earth Science model development, I inevitably have to deal with ODE and PDE equations. I also have come across some discussion related to this topic, i.e.,

https://www.researchgate.net/post/What_does_one_mean_by_Model_Spin_Up_Time

In an attempt to answer this question, as well as redefine the problem I am dealing with, I decided to organize some materials to illustrate our current state on this topic.

Models are essentially equations. In Earth Science, these equations are usually ODE or PDE. So I want to discuss this from a mathematical perspective.

Ideally, we want to solve these ODE/PDE with initial condition (IC) and boundary condition (BC) using various numerical methods.
https://en.wikipedia.org/wiki/Initial_value_problem
https://en.wikipedia.org/wiki/Boundary_value_problem

Because of the nature of geology, everything is similar to its neighbors. So we can construct a system of equations which may have multiple equation for each single grid cell. Now we have an array of equation…

### Lessons I have learnt during E3SM development

I have been involved with the E3SM development since I joined PNNL as a postdoc. Over the course of time, I have learnt a lot from the E3SM model. I also found many issues within the model, which reflects lots of similar struggles in the lifespan of software engineering.

Here I list a few major ones that we all dislike but they are around in almost every project we have worked on.

Excessive usage of existing framework even it is not meant to Working in a large project means that you should NOT re-invent the wheels if they are already there. But more often, developers tend to use existing data types and functions even when they were not designed to do so. The reason is simple: it is easier to use existing ones than to create new ones. For example, in E3SM, there was not a data type to transfer data between river and land. Instead, developers use the data type designed for atmosphere and land to do the job. While it is ok to do so, it added unnecessary confusion for future development a…