Skip to content

update HFB HYDCHR during run #34

@rhugman

Description

@rhugman

G'day,

Not sure if bug or user-error (my default assumption is the latter...).

I am trying to change HFB hydrchr during the simulation. Pointer shows that values change. However, the solution is not affected.

I've tried using kchanged as well. When this is called, the effect of the HFB is entirely omitted, regardless of trying to change hydrchr. Is perhaps the updated K not accounting for the HFB package?

Messy code snippet below:

hydchr_new = 1e-3


api = modflowapi.ModflowApi(os.path.join(ws, lib_name), working_directory=ws)
api.initialize()

# get current sim time
ctime = api.get_current_time()
# get ending sim time
etime = api.get_end_time()
# max number of iterations
max_iter = api.get_value(api.get_var_address("MXITER", "SLN_1"))


# let's do it!
while ctime < etime:
    # the length of this sim time
    dt = api.get_time_step()

    # prep the current time step
    api.prepare_time_step(dt)
    kiter = 0

    # this is to force mf6 to update cond sat using the k11 and k33 arrays
    # which is needed for the perturbation testing
    # the current one-based stress period number
    stress_period = api.get_value(api.get_var_address("KPER", "TDIS"))[0]
    time_step = api.get_value(api.get_var_address("KSTP", "TDIS"))[0]

    # prep to solve
    # this goes into the iter level because of updating k
    #api.prepare_solve(1)

    # solve until converged
    while kiter < max_iter:
        #update hfb
        address = 'GWF/HFB/HYDCHR'
        api.get_value(address)
        pointer = api.get_value_ptr(address)
        pointer[:] = hydchr_new
       
        #k11 = api.get_value_ptr( 'GWF/NPF/K11')
        #k11[:] = 100

        kchangeper = api.get_value_ptr(api.get_var_address("KCHANGEPER", 'GWF', "NPF"))
        kchangestp = api.get_value_ptr(api.get_var_address("KCHANGESTP", 'GWF', "NPF"))
        kchangestp[0] = time_step
        kchangeper[0] = stress_period
        nodekchange = api.get_value_ptr(api.get_var_address("NODEKCHANGE", 'GWF', "NPF"))
        nodekchange[:] = 1

        # prepare to solve
        api.prepare_solve(1)

        if api.solve(1):
            print("flow stress period,time step {0},{1} converged with {2} iters".\
                  format(stress_period, time_step, kiter))

            break
        kiter += 1
    try:
        api.finalize_solve(1)
        chd0 = api.get_value('GWF/CHD_0/SIMVALS')
        print('chd:',chd0)
    except:
        pass

    api.finalize_time_step()
    # update current sim time
    ctime = api.get_current_time()
api.finalize()```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions