Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update HFB HYDCHR during run #34

Open
rhugman opened this issue Jan 6, 2024 · 0 comments
Open

update HFB HYDCHR during run #34

rhugman opened this issue Jan 6, 2024 · 0 comments

Comments

@rhugman
Copy link

rhugman commented Jan 6, 2024

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()```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant