modflowpy / flopy

A Python package to create, run, and post-process MODFLOW-based models.
https://flopy.readthedocs.io
Other
517 stars 313 forks source link

Package replace not working when adding another package of the same type #12

Closed langevin-usgs closed 9 years ago

langevin-usgs commented 9 years ago

The following code demonstrates the problem:

import flopy

mf = flopy.modflow.Modflow('test') dis = flopy.modflow.ModflowDis(mf)

stress_period_data = {0: [[0, 0, 0, -1.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

stress_period_data = {0: [[0, 0, 0, -2.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

stress_period_data = {0: [[0, 0, 0, -3.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

mf.write_input()

The fix is to modify the mbase module and explicitly assign the package to the packagelist position. Will commit this fix after more testing.

def add_package(self, p):
    """
    Add a package.

    Parameters
    ----------
    p : Package object

    """
    for i, pp in enumerate(self.packagelist):
        if pp.allowDuplicates:
            continue
        elif (isinstance(p, type(pp))):
            print '****Warning -- two packages of the same type: ',type(p),type(pp)                 
            print 'replacing existing Package...'                
            # pp = p
            self.packagelist[i] = p
            return        
    if self.verbose:
        print 'adding Package: ', p.name[0]
    self.packagelist.append(p)
mbakker7 commented 9 years ago

Chris, others,

Would it make more sense to store packages in a dictionary rather than a list? Each package already has a name. 'wel', 'ghb', etc. Let's use that name as the key in the dictiononary. It is explicit and easy to manipulate.

Second question: is there a reason for allowDuplicates? When is that used? With a dictionary that would be more difficult.

Thoughts?

Mark

On Thu, Feb 12, 2015 at 11:16 PM, langevin-usgs notifications@github.com wrote:

The following code demonstrates the problem:

import flopy

mf = flopy.modflow.Modflow('test') dis = flopy.modflow.ModflowDis(mf)

stress_period_data = {0: [[0, 0, 0, -1.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

stress_period_data = {0: [[0, 0, 0, -2.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

stress_period_data = {0: [[0, 0, 0, -3.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

mf.write_input()

The fix is to modify the mbase module and explicitly assign the package to the packagelist position. Will commit this fix after more testing.

def add_package(self, p): """ Add a package.

Parameters
----------
p : Package object

"""
for i, pp in enumerate(self.packagelist):
    if pp.allowDuplicates:
        continue
    elif (isinstance(p, type(pp))):
        print '****Warning -- two packages of the same type: ',type(p),type(pp)
        print 'replacing existing Package...'
        # pp = p
        self.packagelist[i] = p
        return
if self.verbose:
    print 'adding Package: ', p.name[0]
self.packagelist.append(p)

— Reply to this email directly or view it on GitHub https://github.com/modflowpy/flopy/issues/12.

jtwhite79 commented 9 years ago

I think I added allowDuplicates a while ago, but I honestly can't remember why. Does anyone else ever use it?

I think moving to a package dictionary is a great idea.

J

On Fri, Feb 13, 2015 at 7:44 AM, mbakker7 notifications@github.com wrote:

Chris, others,

Would it make more sense to store packages in a dictionary rather than a list? Each package already has a name. 'wel', 'ghb', etc. Let's use that name as the key in the dictiononary. It is explicit and easy to manipulate.

Second question: is there a reason for allowDuplicates? When is that used? With a dictionary that would be more difficult.

Thoughts?

Mark

On Thu, Feb 12, 2015 at 11:16 PM, langevin-usgs notifications@github.com wrote:

The following code demonstrates the problem:

import flopy

mf = flopy.modflow.Modflow('test') dis = flopy.modflow.ModflowDis(mf)

stress_period_data = {0: [[0, 0, 0, -1.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

stress_period_data = {0: [[0, 0, 0, -2.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

stress_period_data = {0: [[0, 0, 0, -3.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

mf.write_input()

The fix is to modify the mbase module and explicitly assign the package to the packagelist position. Will commit this fix after more testing.

def add_package(self, p): """ Add a package.

Parameters

p : Package object

""" for i, pp in enumerate(self.packagelist): if pp.allowDuplicates: continue elif (isinstance(p, type(pp))): print '****Warning -- two packages of the same type: ',type(p),type(pp) print 'replacing existing Package...'

pp = p

self.packagelist[i] = p return if self.verbose: print 'adding Package: ', p.name[0] self.packagelist.append(p)

— Reply to this email directly or view it on GitHub https://github.com/modflowpy/flopy/issues/12.

— Reply to this email directly or view it on GitHub https://github.com/modflowpy/flopy/issues/12#issuecomment-74255071.

langevin-usgs commented 9 years ago

I also do not remember why we allow duplicates. But in the next MODFLOW version, we are planning to allow multiple packages of the same type, so maybe we should stick with the list for now?

Christian LangevinResearch HydrologistOffice of GroundwaterU.S. Geological Survey411 National CenterReston, VA 20192Office: 703-648-4169Fax: 703-648-6693Email: langevin@usgs.gov langevin@usgs.govhttps://profile.usgs.gov/langevin https://profile.usgs.gov/langevin

On Fri, Feb 13, 2015 at 10:00 AM, jtwhite79 notifications@github.com wrote:

I think I added allowDuplicates a while ago, but I honestly can't remember why. Does anyone else ever use it?

I think moving to a package dictionary is a great idea.

J

On Fri, Feb 13, 2015 at 7:44 AM, mbakker7 notifications@github.com wrote:

Chris, others,

Would it make more sense to store packages in a dictionary rather than a list? Each package already has a name. 'wel', 'ghb', etc. Let's use that name as the key in the dictiononary. It is explicit and easy to manipulate.

Second question: is there a reason for allowDuplicates? When is that used? With a dictionary that would be more difficult.

Thoughts?

Mark

On Thu, Feb 12, 2015 at 11:16 PM, langevin-usgs < notifications@github.com> wrote:

The following code demonstrates the problem:

import flopy

mf = flopy.modflow.Modflow('test') dis = flopy.modflow.ModflowDis(mf)

stress_period_data = {0: [[0, 0, 0, -1.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

stress_period_data = {0: [[0, 0, 0, -2.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

stress_period_data = {0: [[0, 0, 0, -3.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

mf.write_input()

The fix is to modify the mbase module and explicitly assign the package to the packagelist position. Will commit this fix after more testing.

def add_package(self, p): """ Add a package.

Parameters

p : Package object

""" for i, pp in enumerate(self.packagelist): if pp.allowDuplicates: continue elif (isinstance(p, type(pp))): print '****Warning -- two packages of the same type: ',type(p),type(pp) print 'replacing existing Package...'

pp = p

self.packagelist[i] = p return if self.verbose: print 'adding Package: ', p.name[0] self.packagelist.append(p)

— Reply to this email directly or view it on GitHub https://github.com/modflowpy/flopy/issues/12.

— Reply to this email directly or view it on GitHub https://github.com/modflowpy/flopy/issues/12#issuecomment-74255071.

— Reply to this email directly or view it on GitHub https://github.com/modflowpy/flopy/issues/12#issuecomment-74266040.

mbakker7 commented 9 years ago

Fine with me.

Sent from my iPad

On 14 feb. 2015, at 18:55, langevin-usgs notifications@github.com wrote:

I also do not remember why we allow duplicates. But in the next MODFLOW version, we are planning to allow multiple packages of the same type, so maybe we should stick with the list for now?

Christian LangevinResearch HydrologistOffice of GroundwaterU.S. Geological Survey411 National CenterReston, VA 20192Office: 703-648-4169Fax: 703-648-6693Email: langevin@usgs.gov langevin@usgs.govhttps://profile.usgs.gov/langevin https://profile.usgs.gov/langevin

On Fri, Feb 13, 2015 at 10:00 AM, jtwhite79 notifications@github.com wrote:

I think I added allowDuplicates a while ago, but I honestly can't remember why. Does anyone else ever use it?

I think moving to a package dictionary is a great idea.

J

On Fri, Feb 13, 2015 at 7:44 AM, mbakker7 notifications@github.com wrote:

Chris, others,

Would it make more sense to store packages in a dictionary rather than a list? Each package already has a name. 'wel', 'ghb', etc. Let's use that name as the key in the dictiononary. It is explicit and easy to manipulate.

Second question: is there a reason for allowDuplicates? When is that used? With a dictionary that would be more difficult.

Thoughts?

Mark

On Thu, Feb 12, 2015 at 11:16 PM, langevin-usgs < notifications@github.com> wrote:

The following code demonstrates the problem:

import flopy

mf = flopy.modflow.Modflow('test') dis = flopy.modflow.ModflowDis(mf)

stress_period_data = {0: [[0, 0, 0, -1.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

stress_period_data = {0: [[0, 0, 0, -2.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

stress_period_data = {0: [[0, 0, 0, -3.]]} wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)

mf.write_input()

The fix is to modify the mbase module and explicitly assign the package to the packagelist position. Will commit this fix after more testing.

def add_package(self, p): """ Add a package.

Parameters

p : Package object

""" for i, pp in enumerate(self.packagelist): if pp.allowDuplicates: continue elif (isinstance(p, type(pp))): print '****Warning -- two packages of the same type: ',type(p),type(pp) print 'replacing existing Package...'

pp = p

self.packagelist[i] = p return if self.verbose: print 'adding Package: ', p.name[0] self.packagelist.append(p)

— Reply to this email directly or view it on GitHub https://github.com/modflowpy/flopy/issues/12.

— Reply to this email directly or view it on GitHub https://github.com/modflowpy/flopy/issues/12#issuecomment-74255071.

— Reply to this email directly or view it on GitHub https://github.com/modflowpy/flopy/issues/12#issuecomment-74266040.

— Reply to this email directly or view it on GitHub.