Skip to content

Commit

Permalink
update(rhs, hcof, AdvancedInput): bug fixes for setting variable valu…
Browse files Browse the repository at this point in the history
…es for advanced inputs

* update rhs and hcof to copy values to pointer instead of overwriting the pointer
* add a check for AdvancedInput variables that do not have pointer support in xmipy
  • Loading branch information
jlarsen-usgs committed Feb 25, 2023
1 parent defd2ee commit 2c4d893
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions modflowapi/extensions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ def get_variable(self, name, model=None, package=None):

try:
values = self.mf6.get_value_ptr(var_addr)
self._ptrs[name.lower()] = values
except xmipy.errors.InputError:
values = self.mf6.get_value(var_addr)

self._ptrs[name.lower()] = values
return values.copy()

def set_variable(self, name, values, model=None, package=None):
Expand Down Expand Up @@ -601,7 +601,18 @@ def set_variable(self, name, values, model=None, package=None):
f"current shape={values.shape}, valid shape={values0.shape}"
)

self._ptrs[name.lower()] = values
if name.lower() not in self._ptrs:
# this is a set value situation
self.mf6.set_value(
self.mf6.get_var_address(
name.upper(),
self.parent.model.name,
self.parent.pkg_name
),
values
)
else:
self._ptrs[name.lower()] = values


class ScalarInput:
Expand Down
4 changes: 2 additions & 2 deletions modflowapi/extensions/pakbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def rhs(self, values):
if self._rhs is None:
return

self._rhs = values
self._rhs[:] = values[:]

@property
def hcof(self):
Expand All @@ -362,7 +362,7 @@ def hcof(self, values):
if self._hcof is None:
return

self.__hcof = values
self._hcof[:] = values[:]


class ListPackage(PackageBase):
Expand Down

0 comments on commit 2c4d893

Please sign in to comment.