We can now use this function for a minimal working example. Let's set up an ensemble with only the `storage` parameter. First we create the corresponding vector...
After we've prepared our parameters, we've got everything we need for a minimal working example. Let's set up an ensemble with only the `storage` vector first.
... then we pass the original reference as well as the vector to an ensemble object.
```{r}
# First we define an ensemble object
...
...
@@ -114,9 +106,9 @@ ogs6_ens$run_simulation()
### Plot results
#### Single plot
#### Single simulation
Our simulations (hopefully) ran successfully - great! Now it'd be nice to see some results. For now, we're interested in the `pressure` and `v`elocity data.
Our simulations (hopefully) ran successfully - great! Now it'd be nice to see some results. For now, we're interested in the `pressure` and `v`elocity data of the first simulation.
```{r}
# This will get a list of tibbles - one for each simulation.
...
...
@@ -129,20 +121,163 @@ storage_tbls <-
You may leave out the `point_ids` parameter. It defaults to all points in the dataset - I specify it here because there's about 500 which would slow down building this vignette significantly.
```{r}
# Let's look at the first 10 rows of the dataset for the first simulation.
head(storage_tbls[[1]], 10)
```
You can see there's one row per timestep for each point ID. Say we want to plot the *average* pressure for each `timestep`, that is, the mean of the `pressure` values where the rows have the same `timestep`.
# Get list of dataframes that each look like avg_pr_df
avg_pr_dfs <- list()
for(i in seq_len(length(storage_tbls))){
old_df <- storage_tbls[[i]]
new_df <- old_df %>%
group_by(timestep) %>%
summarise(avg_pressure = mean(pressure))
# Add column so we can separate the values based on their old df
new_df$df_id <- rep(i, nrow(new_df))
# Add column so we can plot based on old df rownames
new_df$orig_rwns <- as.numeric(row.names(new_df))
avg_pr_dfs <- c(avg_pr_dfs, list(new_df))
}
# Combine dataframes into single dataframe for plot
avg_pr_combined_df <- bind_rows(avg_pr_dfs)
# Make plot
ggplot(avg_pr_combined_df,
aes(x = orig_rwns,
y = avg_pressure)) +
geom_point(aes(color = df_id)) +
geom_line(aes(color = df_id)) +
xlab("Timestep") +
facet_grid(rows = vars(df_id))
```
Now we have the average `pressure` over time for each of the simulations (rows). Since they're pretty similar, let's put them in the same plot for a better comparison.
```{r}
ggplot(avg_pr_combined_df, aes(x = orig_rwns,
y = avg_pressure,
group = df_id)) +
geom_point(aes(color = df_id)) +
geom_line(aes(color = df_id)) +
xlab("Timestep")
```
#### Matrix plot
So far we've only considered the `storage` parameter. Now we want to have a look at how the other two parameters influence the simulation and each other. Our `storage` vector had 7 values. Assuming the same length for `permeability` and `porosity` would lead us to a whopping 343 combinations, so we will use our `get_values` function to create smaller vectors. Say we choose a length of 4 with deviations of -1%, -10% and -50% as well as the original value.
Now we take these long vectors and feed them to a new ensemble. We can base this on the same `OGS6` object as before since our project file hasn't changed.
This will take a while on most systems since we're creating 64 objects and running the same number of simulations. Go grab a coffee (inclusive-)or two. As soon as the simulations are done, we can extract the point data just as we did before.
```{r}
# This will get a list of tibbles - one for each simulation.
Plotting time! Well, not quite. This time we have to think a bit more about how we plot. There's 3 parameters now and we replicated their original vectors to get our combinations so our ensemble is all over the place. We'll start by putting the data from the tibbles we extracted into a combined dataframe first like we did in the `storage`-only run.
#### Matrix plot
```{r}
# Get list of dataframes
avg_pr_dfs <- list()
for(i in seq_len(length(per_por_sto_tbls))){
old_df <- per_por_sto_tbls[[i]]
new_df <- old_df %>%
group_by(timestep) %>%
summarise(avg_pressure = mean(pressure))
# Add column so we can separate the values based on their old df
new_df$df_id <- rep(i, nrow(new_df))
# Add column so we can plot based on old df rownames
new_df$orig_rwns <- as.numeric(row.names(new_df))
avg_pr_dfs <- c(avg_pr_dfs, list(new_df))
}
# Combine dataframes into single dataframe for plot
avg_pr_combined_df <- bind_rows(avg_pr_dfs)
```
Maybe we want to have a look at how different parameters influence each other. For this, we can use a matrix plot like so: