Using pymf6

We can achieve the same effect with pymf6.

from modflowapi import Callbacks as states
from xmipy.errors import XMIError

from pymf6.mf6 import MF6
from pymf6.api import create_mutable_bc

from helpers import plot

We set up some initial data:

h_mean = 320.0
name = 'rivercond'
flux = []
chd = []

Now, we create an instance of MF6, get a reference to the flow model and the model loop:

mf6 = MF6(name)
gwf = mf6.models['gwf6']['rivercond']
loop = mf6.model_loop()

We create a mutable river boundary condition and get the initial value of the river conductance:

riv = create_mutable_bc(gwf.riv)
condref = riv.cond[0]

Now, we can loop over all time steps, modified the conductance and collect the flux values in both cells:

for model in loop:
    if model.state == states.iteration_start:
        if gwf.X[0, 0, 0] > h_mean:
            riv.cond = condref
        else:
            riv.cond = condref * 0.10
    elif model.state == states.timestep_end:
        flux.append(mf6.sim_values.river[0])
        chd.append(mf6.sim_values.chd_0[0])

The results are the same:

plot(flux);
../../_images/76fef1e08f855851dddd7e132ddc4ddc8e9037b3b8aea9577a7625962a234fcb.png
plot(chd);
../../_images/0160dd31b1cb9ad0403a8e7e1ad5125e9106cb91c796523b420d5ab0b8f7ca33.png