コード例 #1
0
class SystemProperties:
    """Gets the flow and contaminant properties."""
    def __init__(self, master, system):
        """Constructor method.  Defines the parameters to be obtained in this
        window."""

        self.master = master
        self.system = system
        self.fonttype = system.fonttype
        self.version = system.version
        self.superfont = get_superfont(self.fonttype)  #superscript font
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)

        self.advs = ['None', 'Steady flow', 'Period oscillation']
        self.bios = ['None', 'Uniform', 'Depth-dependent']
        self.cons = ['None', 'Consolidation']

        self.adv = StringVar(value=self.advs[0])  #tidal flag
        self.bio = StringVar(value=self.bios[0])  #bioturbation flag
        self.con = StringVar(value=self.cons[0])  #consolidation flag

        self.hbio = DoubleVar(value=10.)  #bioturbation depth
        self.sigma = DoubleVar(value=10.)  #bioturbation depth
        self.Dbiop = DoubleVar(value=1.)  #particle bioturbation coeff
        self.Dbiopw = DoubleVar(value=100.)  #pore water bioturbation coeff
        self.Vdar = DoubleVar(value=0.)  #Darcy velocity
        self.Vtidal = DoubleVar(value=0.)  #Tidal velocity
        self.ptidal = DoubleVar(value=0.0014)  #Tidal frequency
        self.hcon = DoubleVar(value=0)  #total consolidation
        self.t90 = DoubleVar(value=1.)  #time to 90% consolidation
        self.top = None  #flag for existence of toplevel

        if system.layers[0].number == 0: self.toplayer_h = system.layers[1].h
        else: self.toplayer_h = system.layers[0].h

        self.lengthunit = system.lengthunit
        self.timeunit = system.timeunit
        self.diffunit = system.diffunit
        self.diffunits = system.diffunits

        try:
            self.adv.set(system.adv)
            self.bio.set(system.bio)
            self.con.set(system.con)
            self.Vdar.set(system.Vdar)

            self.hbio.set(system.hbio)
            self.sigma.set(system.sigma)
            self.Dbiop.set(system.Dbiop)
            self.Dbiopw.set(system.Dbiopw)

            self.Vtidal.set(system.Vtidal)
            self.ptidal.set(system.ptidal)

            self.hcon.set(system.hcon)
            self.t90.set(system.t90)
        except:
            pass

    def make_widgets(self):
        """Make the widgets for the window."""

        self.bgcolor = self.frame.cget('bg')
        self.instructions = Label(
            self.frame,
            text=
            ' Please provide the information of the following system properties:  '
        )

        self.blank1 = Label(self.frame, width=30)
        self.blank2 = Label(self.frame, width=20)
        self.blank3 = Label(self.frame, width=15)
        self.blank4 = Label(self.frame, width=20)

        self.headings1 = Label(self.frame, text='Parameter')
        self.headings2 = Label(self.frame, text='Value')
        self.headings3 = Label(self.frame, text='Units')

        self.advlabel = Label(self.frame, text='Upwelling groundwater flow')
        self.advwidget = OptionMenu(self.frame,
                                    self.adv,
                                    *self.advs,
                                    command=self.updatesystem)
        self.Vdarlabel = Label(self.frame, text='Darcy velocity:')
        self.Vtidallabel = Label(self.frame,
                                 text='Oscillation maximum velocity:')
        self.ptidallabel = Label(self.frame, text='Oscillation period:')
        self.Vdarwidget = Entry(self.frame,
                                width=10,
                                textvariable=self.Vdar,
                                justify='center')
        self.Vtidalwidget = Entry(self.frame,
                                  width=10,
                                  textvariable=self.Vtidal,
                                  justify='center')
        self.ptidalwidget = Entry(self.frame,
                                  width=10,
                                  textvariable=self.ptidal,
                                  justify='center')
        self.Vdarunits = Label(self.frame,
                               text=self.lengthunit + '/' + self.timeunit)
        self.Vtidalunits = Label(self.frame,
                                 text=self.lengthunit + '/' + self.timeunit)
        self.ptidalunits = Label(self.frame, text=self.timeunit)

        self.biolabel = Label(self.frame, text='Modeling bioturbation')
        self.biowidget = OptionMenu(self.frame,
                                    self.bio,
                                    *self.bios,
                                    command=self.updatesystem)
        self.hbiolabel = Label(self.frame, text='Bioturbation depth:')
        self.sigmalabel = Label(self.frame, text='Gaussian model coefficient:')
        self.Dbioplabel = Label(self.frame,
                                text='Particle biodiffusion coefficient:')
        self.Dbiopwlabel = Label(self.frame,
                                 text='Pore water biodiffusion coefficient:')
        self.hbiowidget = Entry(self.frame,
                                width=10,
                                textvariable=self.hbio,
                                justify='center')
        self.sigmawidget = Entry(self.frame,
                                 width=10,
                                 textvariable=self.sigma,
                                 justify='center')
        self.Dbiopwidget = Entry(self.frame,
                                 width=10,
                                 textvariable=self.Dbiop,
                                 justify='center')
        self.Dbiopwwidget = Entry(self.frame,
                                  width=10,
                                  textvariable=self.Dbiopw,
                                  justify='center')
        self.hbiounits = Label(self.frame, text=self.lengthunit)
        self.Dbiopunits = Label(self.frame, text=self.diffunits[1])
        self.Dbiopwunits = Label(self.frame, text=self.diffunits[1])

        self.conlabel = Label(self.frame, text='Modeling consolidation')
        self.conwidget = OptionMenu(self.frame,
                                    self.con,
                                    *self.cons,
                                    command=self.updatesystem)
        self.hconlabel = Label(self.frame, text='Maximum consolidation depth:')
        self.t90label = Label(self.frame, text='Time to 90% consolidation:')
        self.hconwidget = Entry(self.frame,
                                width=10,
                                textvariable=self.hcon,
                                justify='center')
        self.t90widget = Entry(self.frame,
                               width=10,
                               textvariable=self.t90,
                               justify='center')
        self.hconunits = Label(self.frame, text=self.lengthunit)
        self.t90units = Label(self.frame, text=self.timeunit)

        self.advwidget.config(width=20)
        self.biowidget.config(width=20)
        self.conwidget.config(width=20)

        #self.okbutton   = Button(self.frame, text = 'OK',         command = self.OK,       width = 20)

        #show the widgets on the grid
        self.instructions.grid(row=0,
                               column=0,
                               columnspan=3,
                               padx=6,
                               sticky='W')
        self.blank1.grid(row=1, column=0)
        self.blank2.grid(row=1, column=1)
        self.blank3.grid(row=1, column=2)

        self.row = 3

        self.focusbutton = None

        self.updatesystem()

    def updatesystem(self, event=None):

        try:
            self.advlabel.grid_forget()
            self.advwidget.grid_forget()
            self.Vdarlabel.grid_forget()
            self.Vdarwidget.grid_forget()
            self.Vdarunits.grid_forget()
            self.Vtidallabel.grid_forget()
            self.Vtidalwidget.grid_forget()
            self.Vtidalunits.grid_forget()
            self.ptidallabel.grid_forget()
            self.ptidalwidget.grid_forget()
            self.ptidalunits.grid_forget()

            self.biolabel.grid_forget()
            self.biowidget.grid_forget()
            self.sigmalabel.grid_forget()
            self.sigmawidget.grid_forget()
            self.hbiolabel.grid_forget()
            self.hbiowidget.grid_forget()
            self.hbiounits.grid_forget()
            self.Dbioplabel.grid_forget()
            self.Dbiopwidget.grid_forget()
            self.Dbiopunits.grid_forget()
            self.Dbiopwlabel.grid_forget()
            self.Dbiopwwidget.grid_forget()
            self.Dbiopwunits.grid_forget()

            self.conlabel.grid_forget()
            self.conwidget.grid_forget()
            self.hconlabel.grid_forget()
            self.hconwidget.grid_forget()
            self.hconunits.grid_forget()
            self.t90label.grid_forget()
            self.t90widget.grid_forget()
            self.t90units.grid_forget()

        except:
            pass

        row = self.row

        self.advlabel.grid(row=row, column=0, sticky='E', padx=4)
        self.advwidget.grid(row=row,
                            column=1,
                            sticky='W',
                            padx=4,
                            columnspan=2)

        row = row + 1

        if self.adv.get() == self.advs[1] or self.adv.get() == self.advs[2]:

            self.Vdarlabel.grid(row=row, column=0, sticky='E', padx=4)
            self.Vdarwidget.grid(row=row, column=1, pady=1)
            self.Vdarunits.grid(row=row, column=2, sticky='W', padx=4)

            row = row + 1

        if self.adv.get() == self.advs[2]:

            self.Vtidallabel.grid(row=row, column=0, sticky='E', padx=4)
            self.Vtidalwidget.grid(row=row, column=1, pady=1)
            self.Vtidalunits.grid(row=row, column=2, sticky='W', padx=4)

            row = row + 1

            self.ptidallabel.grid(row=row, column=0, sticky='E', padx=4)
            self.ptidalwidget.grid(row=row, column=1, pady=1)
            self.ptidalunits.grid(row=row, column=2, sticky='W', padx=4)

            row = row + 1

        self.biolabel.grid(row=row, column=0, sticky='E', padx=4)
        self.biowidget.grid(row=row,
                            column=1,
                            sticky='W',
                            padx=4,
                            columnspan=2)

        row = row + 1

        if self.bio.get() == self.bios[1]:

            self.hbiolabel.grid(row=row, column=0, sticky='E', padx=4)
            self.hbiowidget.grid(row=row, column=1, pady=1)
            self.hbiounits.grid(row=row, column=2, sticky='W', padx=4)

            row = row + 1

        if self.bio.get() == self.bios[2]:

            self.sigmalabel.grid(row=row, column=0, sticky='E', padx=4)
            self.sigmawidget.grid(row=row, column=1, pady=1)
            self.hbiounits.grid(row=row, column=2, sticky='W', padx=4)

            row = row + 1

        if self.bio.get() == self.bios[1] or self.bio.get() == self.bios[2]:

            self.Dbioplabel.grid(row=row, column=0, sticky='E', padx=4)
            self.Dbiopwidget.grid(row=row, column=1, pady=1)
            self.Dbiopunits.grid(row=row, column=2, sticky='W', padx=4)

            row = row + 1

            self.Dbiopwlabel.grid(row=row, column=0, sticky='E', padx=4)
            self.Dbiopwwidget.grid(row=row, column=1, pady=1)
            self.Dbiopwunits.grid(row=row, column=2, sticky='W', padx=4)

            row = row + 1

        self.conlabel.grid(row=row, column=0, sticky='E', padx=4)
        self.conwidget.grid(row=row,
                            column=1,
                            sticky='W',
                            padx=4,
                            columnspan=2)

        row = row + 1

        if self.con.get() == self.cons[1]:
            self.hconlabel.grid(row=row, column=0, sticky='E', padx=4)
            self.hconwidget.grid(row=row, column=1, pady=1)
            self.hconunits.grid(row=row, column=2, sticky='W', padx=4)

            row = row + 1

            self.t90label.grid(row=row, column=0, sticky='E', padx=4)
            self.t90widget.grid(row=row, column=1, pady=1)
            self.t90units.grid(row=row, column=2, sticky='W', padx=4)

            row = row + 1

        self.blank4.grid(row=row)

        row = row + 1

        self.focusbutton = None

        self.master.geometry()

    def error_check(self, event=None):
        """Finish and move on.  Checks that the number chemicals are less than the
        total number of chemicals in database."""

        error = 0
        #if self.bio.get() == self.bios[1] and self.hbio.get() > self.toplayer_h: error = 1

        return error

    def warning(self):

        tkmb.showerror(
            title=self.version,
            message='The bioturbation ' +
            'depth (%.1f cm) ' % self.hbio.get() + 'cannot exceed the ' +
            'thickness of the top layer (%.1f). ' % self.toplayer_h +
            'Automatically increasing ' +
            'the thickness of the top layer to the bioturbation ' + 'depth.')
        self.hbio.set(self.toplayer_h)
        self.focusbutton = None
        self.master.tk.lift()
コード例 #2
0
class CoefficientEditor:
    """Gets the chemical reaction information for each layer."""
    def __init__(self, master, system, coefficient, coefficients, editflag):
        """Constructor method.  Makes the GUI using the list of "Layer" objects
        "layers." """

        # Read the Tkinter information
        self.master = master
        self.version = system.version
        self.fonttype = system.fonttype
        self.formulatype = system.formulatype
        self.superfont = get_superfont(self.fonttype)
        self.subfont = get_superfont(self.formulatype)
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)
        self.bgcolor = self.frame.cget('bg')
        self.top = None

        self.concunit = system.concunit
        self.timeunit = system.timeunit

        self.concunits = system.concunits

        # Convert mass concentration units to corresponding molar concentration units
        if self.concunit == system.concunits[0]:
            self.concunit = system.concunits[3]
        if self.concunit == system.concunits[1]:
            self.concunit = system.concunits[4]
        if self.concunit == system.concunits[2]:
            self.concunit = system.concunits[5]

        # Read the system information
        self.coefficient = coefficient
        self.coefficients = coefficients
        self.layers = system.layers
        self.editflag = editflag

        if self.editflag == 0:

            self.layer_full_list = []
            self.reaction_full_list = []
            for layer in system.layers:
                self.layer_full_list.append(layer.name)
            for reaction in system.reactions:
                self.reaction_full_list.append(reaction.name)

            self.layer_list = []
            self.reaction_list = []

            for layer in system.layers:
                coef_check = 0
                for reaction in system.reactions:
                    if coefficients[layer.name][reaction.name].lam == 0:
                        coef_check = 1
                if coef_check == 1:
                    self.layer_list.append(layer.name)
                    self.reaction_list.append([])
                    for reaction in system.reactions:
                        if coefficients[layer.name][reaction.name].lam == 0:
                            self.reaction_list[-1].append(reaction.name)

            self.layer = StringVar(value=self.layer_list[0])
            self.reaction = StringVar(value=self.reaction_list[0][0])
            self.equation = StringVar(value='')

        else:
            self.layer = coefficient.layer.name
            self.reaction = coefficient.reaction.name
            self.equation = coefficient.reaction.equation
            self.reactants = coefficient.reaction.reactants

        self.lam = DoubleVar(value=coefficient.lam)

        self.cancelflag = 0

    def make_widgets(self):

        self.instructions = Label(
            self.frame,
            text=
            'Please input the following information for the added kinetic process:        '
        )

        self.blankcolumn = Label(self.frame, text=' ', width=2)
        self.layercolumn = Label(self.frame, text=' ', width=15)
        self.namecolumn = Label(self.frame, text=' ', width=15)
        self.equationcolumn = Label(self.frame, text=' ', width=20)
        self.ratecolumn = Label(self.frame, text=' ', width=10)
        self.coef1column = Label(self.frame, text=' ', width=10)
        self.unit1column = Label(self.frame, text=' ', width=3)
        self.endcolumn = Label(self.frame, text=' ', width=2)

        self.layerlabel = Label(self.frame, text='Layer')
        self.namelabel = Label(self.frame, text='Reaction')
        self.equationlabel = Label(self.frame, text='Chemical equation')
        self.ratelabel = Label(self.frame, text='Rate equation')
        self.lamcoeflabel = Label(self.frame, text='Coefficient  ' + u'\u03BB')

        self.blank1 = Label(self.frame, text=' ')

        self.instructions.grid(row=0,
                               column=0,
                               padx=8,
                               sticky='W',
                               columnspan=11)

        self.blankcolumn.grid(row=1, column=0, padx=2, sticky='WE')
        self.layercolumn.grid(row=1, column=1, padx=2, sticky='WE')
        self.namecolumn.grid(row=1, column=2, padx=2, sticky='WE')
        self.equationcolumn.grid(row=1, column=3, padx=2, sticky='WE')
        self.ratecolumn.grid(row=1, column=4, padx=2, sticky='WE')
        self.coef1column.grid(row=1, column=5, padx=2, sticky='WE')
        self.unit1column.grid(row=1, column=6, padx=2, sticky='WE')
        self.endcolumn.grid(row=1, column=7, padx=2, sticky='WE')

        self.layerlabel.grid(row=2, column=1, padx=2, sticky='WE')
        self.namelabel.grid(row=2, column=2, padx=2, sticky='WE')
        self.equationlabel.grid(row=2, column=3, padx=2, sticky='WE')
        self.ratelabel.grid(row=2, column=4, padx=2, sticky='WE')

        self.blank1.grid(row=3, column=0, padx=2, sticky='WE', columnspan=11)

        if self.editflag == 1:

            self.layerwidget = Label(self.frame, text=self.layer)
            self.namewidget = Label(self.frame, text=self.reaction)
            self.equationwidget = Label(self.frame,
                                        text=self.equation,
                                        font=self.formulatype)

            self.layerwidget.grid(row=4, column=1, padx=2)
            self.namewidget.grid(row=4, column=2, padx=2)
            self.equationwidget.grid(row=4, column=3, padx=10)

            if self.coefficient.reaction.model == 'User-defined' or self.coefficient.reaction.model == 'Fundamental':

                unitindex = 0

                tkfont = tkFont.Font(font=self.formulatype)
                tksubfont = tkFont.Font(font=self.subfont)
                tksuperfont = tkFont.Font(font=self.superfont)

                # Measure the width of rate and lambda expression
                rate_len = tkfont.measure(u'r = \u03BB')
                rate_len = rate_len + tksubfont.measure(
                    str(self.coefficient.reaction.number) + ',')
                if self.coefficient.layer.number == 0:
                    rate_len = rate_len + tksubfont.measure('D')
                else:
                    rate_len = rate_len + tksubfont.measure(
                        str(self.coefficient.layer.number))
                for reactant in self.coefficient.reaction.reactants:
                    if reactant.index <> 0:
                        rate_len = rate_len + tkfont.measure('C')
                        rate_len = rate_len + tksubfont.measure(
                            reactant.formula)
                        if reactant.index == int(reactant.index):
                            index = int(reactant.index)
                        else:
                            index = reactant.index

                        if index <> 1.:
                            rate_len = rate_len + tksuperfont.measure(
                                str(index) + ' ')
                        unitindex = unitindex + reactant.index
                print(unitindex)
                lam_len = tkfont.measure('')
                if unitindex == int(unitindex): unitindex = int(unitindex)
                print(unitindex)
                if (unitindex - 1) != 0:
                    if (unitindex - 1) != -1:
                        lam_len = lam_len + tkfont.measure('(' +
                                                           self.concunit + ')')
                        lam_len = lam_len + tksuperfont.measure(
                            str(-(unitindex - 1)))
                    else:
                        lam_len = lam_len + tkfont.measure(self.concunit + ' ')
                lam_len = lam_len + tkfont.measure(self.timeunit)
                lam_len = lam_len + tksuperfont.measure('-1')

                self.ratewidget = Text(self.frame,
                                       width=int(rate_len * 1.1424219345 / 8) +
                                       1,
                                       height=1,
                                       font=self.formulatype)
                self.ratewidget.insert('end', u'r')
                self.ratewidget.insert('end', ' = ')
                self.ratewidget.insert('end', u'\u03BB')
                self.ratewidget.insert(
                    'end',
                    str(self.coefficient.reaction.number) + ',', 'sub')
                if self.coefficient.layer.number == 0:
                    self.ratewidget.insert('end', 'D', 'sub')
                else:
                    self.ratewidget.insert('end',
                                           str(self.coefficient.layer.number),
                                           'sub')
                for reactant in self.coefficient.reaction.reactants:
                    if reactant.index <> 0:
                        self.ratewidget.insert('end', 'C')
                        self.ratewidget.insert('end', reactant.formula, 'sub')
                        if reactant.index == int(reactant.index):
                            index = int(reactant.index)
                        else:
                            index = reactant.index
                        if index <> 1.:
                            self.ratewidget.insert('end',
                                                   str(index) + ' ', 'super')

                self.ratewidget.tag_config('sub', offset=-4, font=self.subfont)
                self.ratewidget.tag_config('super',
                                           offset=5,
                                           font=self.superfont)
                self.ratewidget.tag_config('right', justify='right')
                self.ratewidget.config(state='disabled',
                                       background=self.bgcolor,
                                       borderwidth=0,
                                       spacing3=3)

                self.lamcoefwidget = Entry(self.frame,
                                           textvariable=self.lam,
                                           justify='center',
                                           width=8)

                self.lamunitlabel = Text(
                    self.frame,
                    width=int(lam_len * 1.1424219345 / 8) + 1,
                    height=1,
                    font=self.formulatype)
                if (unitindex - 1) != 0:
                    if (unitindex - 1) != -1:
                        self.lamunitlabel.insert('end',
                                                 '(' + self.concunit + ')')
                        self.lamunitlabel.insert('end', str(-(unitindex - 1)),
                                                 'super')
                    else:
                        self.lamunitlabel.insert('end', self.concunit + ' ')
                self.lamunitlabel.insert('end', self.timeunit)
                self.lamunitlabel.insert('end', '-1', 'super')
                self.lamunitlabel.tag_config('sub',
                                             offset=-4,
                                             font=self.subfont)
                self.lamunitlabel.tag_config('super',
                                             offset=5,
                                             font=self.superfont)
                self.lamunitlabel.tag_config('right', justify='right')
                self.lamunitlabel.config(state='disabled',
                                         background=self.bgcolor,
                                         borderwidth=0,
                                         spacing3=3)

                self.lamcoeflabel.grid(row=2,
                                       column=5,
                                       padx=2,
                                       sticky='WE',
                                       columnspan=4)

                self.ratewidget.grid(row=4, column=4, padx=5)
                self.lamcoefwidget.grid(row=4, column=5, padx=2, sticky='E')
                self.lamunitlabel.grid(row=4, column=6, padx=2, sticky='W')

        else:
            self.layerwidget = OptionMenu(self.frame,
                                          self.layer,
                                          *self.layer_list,
                                          command=self.click_layer)
            self.layerwidget.grid(row=4, column=1, padx=2, sticky='WE')
            self.click_layer()

        self.okbutton = Button(self.frame,
                               text='OK',
                               width=20,
                               command=self.OK)
        self.cancelbutton = Button(self.frame,
                                   text='Cancel',
                                   width=20,
                                   command=self.Cancel)
        self.blank2 = Label(self.frame, text=' ')
        self.blank3 = Label(self.frame, text=' ')
        self.blank4 = Label(self.frame, text=' ')
        self.focusbutton = None

        self.blank3.grid(row=5)
        self.okbutton.grid(row=6, columnspan=11)
        self.cancelbutton.grid(row=7, columnspan=11)
        self.blank4.grid(row=8)
        self.okbutton.bind('<Return>', self.OK)
        self.focusbutton = self.okbutton

    def click_layer(self, event=None):

        try:
            self.namewidget.grid_forget()
        except:
            pass

        self.reaction.set(self.reaction_list[self.layer_list.index(
            self.layer.get())][0])
        self.namewidget = OptionMenu(self.frame,
                                     self.reaction,
                                     *self.reaction_list[self.layer_list.index(
                                         self.layer.get())],
                                     command=self.click_reaction)
        self.namewidget.grid(row=4, column=2, padx=2, sticky='WE')

        self.click_reaction()

    def click_reaction(self, event=None):

        try:
            self.equationwidget.grid_forget()
            self.ratewidget.grid_forget()
        except:
            pass

        try:
            self.lamcoeflabel.grid_forget()
            self.lamcoefwidget.grid_forget()
            self.lamunitlabel.grid_forget()
        except:
            pass

        coefficient = self.coefficients[self.layer.get()][self.reaction.get()]
        self.lam.set(coefficient.lam)

        self.equation = coefficient.reaction.equation
        self.equationwidget = Label(self.frame,
                                    text=self.equation,
                                    font=self.formulatype)
        self.equationwidget.grid(row=4, column=3, padx=5)

        if coefficient.reaction.model == 'User-defined' or coefficient.reaction.model == 'Fundamental':

            unitindex = 0

            tkfont = tkFont.Font(font=self.formulatype)
            tksubfont = tkFont.Font(font=self.subfont)
            tksuperfont = tkFont.Font(font=self.superfont)

            # Measure the width of rate and lambda expression
            rate_len = tkfont.measure(u'r = \u03BB')
            rate_len = rate_len + tksubfont.measure(
                str(coefficient.reaction.number) + ',')
            if coefficient.layer.number == 0:
                rate_len = rate_len + tksubfont.measure('D')
            else:
                rate_len = rate_len + tksubfont.measure(
                    str(coefficient.layer.number))
            for reactant in coefficient.reaction.reactants:
                if reactant.index <> 0:
                    rate_len = rate_len + tkfont.measure('C')
                    rate_len = rate_len + tksubfont.measure(reactant.formula)
                    if reactant.index == int(reactant.index):
                        index = int(reactant.index)
                    else:
                        index = reactant.index

                    if index <> 1.:
                        rate_len = rate_len + tksuperfont.measure(
                            str(index) + ' ')
                    unitindex = unitindex + reactant.index

            lam_len = tkfont.measure('')
            if unitindex == int(unitindex): unitindex = int(unitindex)
            if (unitindex - 1) != 0:
                if (unitindex - 1) != 1:
                    lam_len = lam_len + tkfont.measure('(' + self.concunit +
                                                       ')')
                    lam_len = lam_len + tksuperfont.measure(
                        str(-(unitindex - 1)))
                else:
                    lam_len = lam_len + tkfont.measure(self.concunit)
            lam_len = lam_len + tkfont.measure(self.timeunit)
            lam_len = lam_len + tksuperfont.measure('-1')

            self.ratewidget = Text(self.frame,
                                   width=int(rate_len * 1.1424219345 / 8) + 1,
                                   height=1,
                                   font=self.formulatype)
            self.ratewidget.insert('end', u'r = \u03BB')
            self.ratewidget.insert('end',
                                   str(coefficient.reaction.number) + ',',
                                   'sub')
            if coefficient.layer.number == 0:
                self.ratewidget.insert('end', 'D', 'sub')
            else:
                self.ratewidget.insert('end', str(coefficient.layer.number),
                                       'sub')
            for reactant in coefficient.reaction.reactants:
                if reactant.index <> 0:
                    self.ratewidget.insert('end', 'C')
                    self.ratewidget.insert('end', reactant.formula, 'sub')
                    if reactant.index == int(reactant.index):
                        index = int(reactant.index)
                    else:
                        index = reactant.index
                    if index <> 1.:
                        self.ratewidget.insert('end',
                                               str(index) + ' ', 'super')

            self.ratewidget.tag_config('sub', offset=-4, font=self.subfont)
            self.ratewidget.tag_config('super', offset=5, font=self.superfont)
            self.ratewidget.tag_config('right', justify='right')
            self.ratewidget.config(state='disabled',
                                   background=self.bgcolor,
                                   borderwidth=0,
                                   spacing3=3)

            self.lamcoefwidget = Entry(self.frame,
                                       textvariable=self.lam,
                                       justify='center',
                                       width=8)

            self.lamunitlabel = Text(self.frame,
                                     width=int(lam_len * 1.1424219345 / 8) + 1,
                                     height=1,
                                     font=self.formulatype)
            if unitindex == int(unitindex): unitindex = int(unitindex)
            if (unitindex - 1) != 0:
                if (unitindex - 1) != 1:
                    self.lamunitlabel.insert('end', '(' + self.concunit + ')')
                    self.lamunitlabel.insert('end', str(-(unitindex - 1)),
                                             'super')
                else:
                    self.lamunitlabel.insert('end', self.concunit)
            self.lamunitlabel.insert('end', self.timeunit)
            self.lamunitlabel.insert('end', '-1', 'super')
            self.lamunitlabel.tag_config('sub', offset=-4, font=self.subfont)
            self.lamunitlabel.tag_config('super',
                                         offset=5,
                                         font=self.superfont)
            self.lamunitlabel.tag_config('right', justify='right')
            self.lamunitlabel.config(state='disabled',
                                     background=self.bgcolor,
                                     borderwidth=0,
                                     spacing3=3)

            self.lamcoeflabel.grid(row=2,
                                   column=5,
                                   padx=2,
                                   sticky='WE',
                                   columnspan=4)

            self.ratewidget.grid(row=4, column=4, padx=5)
            self.lamcoefwidget.grid(row=4, column=5, padx=2, sticky='E')
            self.lamunitlabel.grid(row=4, column=6, padx=2, sticky='W')

        self.frame.update()
        self.focusbutton = None
        self.master.geometry()
        self.master.center()

    def OK(self, event=None):
        """Finish and move on.  Checks that the number chemicals are less than the
        total number of chemicals in database."""

        if self.editflag == 0:
            self.layerindex = self.layer_full_list.index(self.layer.get())
            self.reactionnumber = self.reaction_full_list.index(
                self.reaction.get()) + 1

        if self.master.window.top is not None: self.master.open_toplevel()
        elif self.lam == 0: self.coefficient_error()
        else: self.master.tk.quit()

    def coefficient_error(self):

        tkmb.showerror(
            title=self.version,
            message='At least one chemical has been replicated in the reaction!'
        )
        self.focusbutton = self.okbutton
        self.master.tk.lift()

    def Cancel(self):

        try:
            self.reactants = self.reaction.reactants
            self.products = self.reaction.products

        except:
            self.cancelflag = 1

        if self.master.window.top is not None: self.master.open_toplevel()
        else: self.master.tk.quit()
コード例 #3
0
class SolverEditor:
    """Makes a window for the user to specify output options."""
    def __init__(self, master, system, ptype, ptotal, tvariable, delt, delz,
                 players):
        """Constructor method."""

        self.master = master
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)
        self.fonttype = system.fonttype
        self.version = system.version
        self.top = None

        self.adv = system.adv
        self.bio = system.bio
        self.Dbiop = system.Dbiop * self.diff_factor / 86400 / 365
        self.Dbiopw = system.Dbiopw * self.diff_factor / 86400 / 365

        self.diffunit = system.diffunit
        self.timeunit = system.timeunit
        self.lengthunit = system.lengthunit

        self.components = [component.copy() for component in system.components]
        self.chemicals = [chemical.copy() for chemical in system.chemicals]
        self.matrices = [matrix.copy() for matrix in system.matrices]
        self.layers = [layer.copy() for layer in system.layers]

        self.nlayers = system.nlayers
        self.nchemicals = system.nchemicals

        self.sorptions = {}
        for component in self.components:
            self.sorptions[component.name] = {}
            for chemical in self.chemicals:
                self.sorptions[component.name][
                    chemical.name] = system.sorptions[component.name][
                        chemical.name].copy()

        self.BCs = {}
        self.ICs = {}
        for chemical in self.chemicals:
            self.BCs[chemical.name] = system.BCs[chemical.name].copy()

        for layer in self.layers:
            self.ICs[layer.name] = {}
            for chemical in self.chemicals:
                self.ICs[layer.name][chemical.name] = system.ICs[layer.name][
                    chemical.name].copy()

        if system.con == 'Consolidation':
            self.kcon = 2.3026 / system.t90
            self.Vcon0 = self.kcon * system.hcon
            self.U = system.Vdar + consolidation(0, self.Vcon0, self.kcon)
        else:
            self.U = system.Vdar

        if system.adv == 'Tidal oscillation': self.U = self.U + system.Vtidal

        self.non_linear_check = 0

        for component in system.component_list:
            for chemical in system.chemicals:
                self.non_linear_check = self.non_linear_check + (
                    system.sorptions[component][chemical.name].isotherm
                    == 'Freundlich')
                self.non_linear_check = self.non_linear_check + (
                    system.sorptions[component][chemical.name].isotherm
                    == 'Langmuir')

        if system.reactions is not None:
            for reaction in system.reactions:
                if sum([reactant.index
                        for reactant in reaction.reactants]) > 1:
                    self.non_linear_check = self.non_linear_check + 1

        self.length_unit_converter = 1.
        self.time_unit_converter = 1.
        self.diff_unit_converter = 1.

        if self.lengthunit == 'm':
            self.length_unit_converter = self.length_unit_converter / (0.01)**2
        elif self.lengthunit == u'\u03BCm':
            self.length_unit_converter = self.length_unit_converter / (
                10000)**2

        elif self.timeunit == 's':
            self.time_unit_converter = self.time_unit_converter * 365.25 * 24 * 3600
        if self.timeunit == 'min':
            self.time_unit_converter = self.time_unit_converter * 365.25 * 24 * 60
        elif self.timeunit == 'hr':
            self.time_unit_converter = self.time_unit_converter * 365.25 * 24
        elif self.timeunit == 'day':
            self.time_unit_converter = self.time_unit_converter * 365.25

        if self.diffunit == u'cm\u00B2/s':
            self.diff_unit_converter = self.diff_unit_converter * 86400 * 365.25

        self.ptypes = ['Uniform size', 'Uniform Number', 'User-defined']
        self.tvariables = ['slowest layer', 'geometric mean', 'User-defined']

        self.ptype = StringVar(value=ptype)
        self.tvariable = StringVar(value=tvariable)
        self.ptotal = IntVar(value=ptotal)  #minimum grid points
        self.delt = DoubleVar(value=delt)  #minimumu time steps

        self.htot = sum([layer.h for layer in self.layers])
        self.D = []
        self.R = []

        self.players = [player for player in players]
        self.delz = [dz for dz in delz]

        self.Cmax = {}
        for chemical in self.chemicals:
            self.Cmax[chemical.name] = max(
                max([
                    self.ICs[ilayer.name][chemical.name].uniform
                    for ilayer in self.layers
                ]),
                max([
                    self.ICs[ilayer.name][chemical.name].top
                    for ilayer in self.layers
                ]),
                max([
                    self.ICs[ilayer.name][chemical.name].bot
                    for ilayer in self.layers
                ]), self.BCs[chemical.name].Co, self.BCs[chemical.name].Cw,
                self.BCs[chemical.name].Cb)

        for i in range(system.nlayers):
            self.D.append([])
            matrix = self.matrices[self.layers[i].type_index]
            for n in range(system.nchemicals):
                self.D[i].append(self.layers[i].get_D(
                    self.chemicals[n].Dw * self.diff_unit_converter, self.U,
                    matrix.e))
                if self.layers[i].number < 2 and system.bio == 1:
                    self.D[i][n] = self.D[i][n] + system.Dbiopw
                    for component in matrix.components:
                        self.D[i][n] = self.D[i][
                            n] + system.Dbiop * component.fraction * component.rho * self.sorptions[
                                component.name][chemical.name].get_K(
                                    component, self.Cmax[chemical.name],
                                    self.Cmax[chemical.name])

        for i in range(system.nlayers):
            self.R.append([])
            matrix = self.matrices[self.layers[i].type_index]
            for n in range(self.nchemicals):
                chemical = self.chemicals[n]
                Kd_rho = 0
                for component in matrix.components:
                    Kd_rho = Kd_rho + component.fraction * component.rho * self.sorptions[
                        component.name][chemical.name].get_K(
                            component, self.Cmax[chemical.name],
                            self.Cmax[chemical.name])
                self.R[i].append(
                    (matrix.e * (1 + layer.doc /
                                 (10**6) * 10**(chemical.Kdoc)) + Kd_rho) /
                    (1 + layer.doc / (10**6) * 10**(chemical.Kdoc)))

        self.cancelflag = 0

        if self.layers[0].number == 0:
            self.deplayersolveroptions = [
                LayerSolverOption(
                    self.layers[0], self.players[0], self.D[0], self.U *
                    self.length_unit_converter * self.time_unit_converter,
                    self.R[0], self.length_unit_converter, self.timeunit)
            ]
            self.dep = 1
        else:
            self.dep = 0
            self.deplayersolveroptions = []

        self.layersolveroptions = []

        for i in range(self.dep, self.nlayers):
            layer = self.layers[i]
            self.layersolveroptions.append(
                LayerSolverOption(
                    layer, self.players[i], self.D[i], self.U *
                    self.length_unit_converter * self.time_unit_converter,
                    self.R[i], self.length_unit_converter))

    def make_widgets(self):
        """Make the widgets."""

        self.instructions = Label(
            self.tframe,
            text=
            'Please specify the grid and time step options for the system:  ')
        self.blank1 = Label(self.tframe, text=' ')
        self.blank2 = Label(self.bframe, text=' ')
        self.blank3 = Label(self.bframe, text=' ')
        self.blank4 = Label(self.bframe, text=' ')
        self.blank5 = Label(self.bframe, text=' ')
        self.blank6 = Label(self.bframe, text=' ')
        self.blank7 = Label(self.bframe, text=' ')

        self.leftcolumn = Label(self.tframe,
                                text='',
                                font='courier 10',
                                width=5)
        self.layercolumn = Label(self.tframe,
                                 text='',
                                 font='courier 10',
                                 width=10)
        self.thickcolumn = Label(self.tframe,
                                 text='',
                                 font='courier 10',
                                 width=10)
        self.gridnumbercolumn = Label(self.tframe,
                                      text='',
                                      font='courier 10',
                                      width=12)
        self.gridsizecolumn = Label(self.tframe,
                                    text='',
                                    font='courier 10',
                                    width=10)
        self.penumbercolumn = Label(self.tframe,
                                    text='',
                                    font='courier 10',
                                    width=15)
        self.timestepcolumn = Label(self.tframe,
                                    text='',
                                    font='courier 10',
                                    width=15)
        self.endcolumn = Label(self.tframe,
                               text='',
                               font='courier 10',
                               width=2)

        self.ptypelabel = Label(self.tframe, text='Grid option:', width=15)
        self.ptypewidget = OptionMenu(self.tframe,
                                      self.ptype,
                                      *self.ptypes,
                                      command=self.updatesolvereditor)
        self.ptypewidget.config(width=15)
        self.ptotallabel = Label(self.tframe,
                                 text='Total number of grids:',
                                 width=15)
        self.ptotalwidget = Label(self.tframe,
                                  textvariable=self.ptotal,
                                  width=10,
                                  justify='center')
        self.ptotalentry = Entry(self.tframe,
                                 textvariable=self.ptotal,
                                 width=10,
                                 justify='center')

        self.tvariablelabel = Label(self.tframe,
                                    text='Time step option:',
                                    width=15)
        self.tvariablewidget = OptionMenu(self.tframe,
                                          self.tvariable,
                                          *self.tvariables,
                                          command=self.updatesolvereditor)
        self.tvariablewidget.config(width=15)
        self.tsteplabel = Label(self.tframe,
                                text='Time step size (' + self.timeunit + '):',
                                width=15)
        self.tstepwidget = Label(self.tframe,
                                 textvariable=self.delt,
                                 width=10,
                                 justify='center')
        self.tstepentry = Entry(self.tframe,
                                textvariable=self.delt,
                                width=10,
                                justify='center')

        self.layerlabel = Label(self.tframe, text='Layer')
        self.thicklabel = Label(self.tframe, text='Thickness')
        self.gridnumberlabel = Label(self.tframe, text='Number of grids')
        self.gridsizelabel = Label(self.tframe, text='Grid size')
        self.gridPelabel = Label(self.tframe, text='Max Peclet number')
        self.timesteplabel = Label(self.tframe, text='CFL Time Step')

        self.thickunit = Label(self.tframe, text=self.lengthunit)
        self.gridsizeunit = Label(self.tframe, text=self.lengthunit)
        self.timestepunit = Label(self.tframe, text=self.timeunit)

        self.botleftcolumn = Label(self.frame,
                                   text='',
                                   font='courier 10',
                                   width=5)
        self.botlayercolumn = Label(self.frame,
                                    text='',
                                    font='courier 10',
                                    width=10)
        self.botthickcolumn = Label(self.frame,
                                    text='',
                                    font='courier 10',
                                    width=10)
        self.botgridnumbercolumn = Label(self.frame,
                                         text='',
                                         font='courier 10',
                                         width=12)
        self.botgridsizecolumn = Label(self.frame,
                                       text='',
                                       font='courier 10',
                                       width=10)
        self.botpenumbercolumn = Label(self.frame,
                                       text='',
                                       font='courier 10',
                                       width=15)
        self.bottimestepcolumn = Label(self.frame,
                                       text='',
                                       font='courier 10',
                                       width=15)
        self.botendcolumn = Label(self.frame,
                                  text='',
                                  font='courier 10',
                                  width=2)

        self.updatebutton = Button(self.bframe,
                                   text='Update',
                                   width=20,
                                   command=self.updatesolvereditor)
        self.okbutton = Button(self.bframe,
                               text='OK',
                               width=20,
                               command=self.OK)
        self.cancelbutton = Button(self.bframe,
                                   text='Cancel',
                                   width=20,
                                   command=self.Cancel)

        #show the widgets that don't change on the grid

        row = 0

        self.instructions.grid(row=row,
                               column=0,
                               sticky='W',
                               padx=8,
                               columnspan=7)

        row = 1
        self.leftcolumn.grid(row=row, column=0, sticky='WE', padx=2)
        self.layercolumn.grid(row=row, column=1, sticky='WE', padx=2)
        self.thickcolumn.grid(row=row, column=2, sticky='WE', padx=2)
        self.gridnumbercolumn.grid(row=row, column=3, sticky='WE', padx=2)
        self.gridsizecolumn.grid(row=row, column=4, sticky='WE', padx=2)
        self.penumbercolumn.grid(row=row, column=5, sticky='WE', padx=2)
        self.timestepcolumn.grid(row=row, column=6, sticky='WE', padx=2)
        self.endcolumn.grid(row=row, column=7, sticky='WE', padx=2)

        row = 2
        self.ptypelabel.grid(row=row,
                             column=0,
                             sticky='E',
                             padx=2,
                             columnspan=2)
        self.ptypewidget.grid(row=row,
                              column=2,
                              sticky='W',
                              padx=2,
                              columnspan=2)
        self.ptotallabel.grid(row=row,
                              column=4,
                              sticky='E',
                              padx=2,
                              columnspan=2)

        row = 3
        self.tvariablelabel.grid(row=row,
                                 column=0,
                                 sticky='E',
                                 padx=2,
                                 columnspan=2)
        self.tvariablewidget.grid(row=row,
                                  column=2,
                                  sticky='W',
                                  padx=2,
                                  columnspan=2)
        self.tsteplabel.grid(row=row,
                             column=4,
                             sticky='E',
                             padx=2,
                             columnspan=2)

        row = 4
        self.blank1.grid(row=row, column=0, sticky='WE', padx=2, columnspan=7)

        row = 5
        self.layerlabel.grid(row=row, column=1, sticky='WE', padx=2)
        self.thicklabel.grid(row=row, column=2, sticky='WE', padx=2)
        self.gridnumberlabel.grid(row=row, column=3, sticky='WE', padx=2)
        self.gridsizelabel.grid(row=row, column=4, sticky='WE', padx=2)
        self.gridPelabel.grid(row=row, column=5, sticky='WE', padx=2)
        self.timesteplabel.grid(row=row, column=6, sticky='WE', padx=2)

        row = 6
        self.thickunit.grid(row=row, column=2, sticky='WE', padx=2)
        self.gridsizeunit.grid(row=row, column=4, sticky='WE', padx=2)
        self.timestepunit.grid(row=row, column=6, sticky='WE', padx=2)

        try:
            self.ptotalwidget.grid_forget()
            self.ptotalentry.grid_forget()
            self.tstepwidget.grid_forget()
            self.tstepentry.grid_forget()
        except:
            pass

        if self.ptype.get() == self.ptypes[2]:
            self.ptotalwidget.grid(row=2, column=6, sticky='E', padx=2)
        else:
            self.ptotalentry.grid(row=2, column=6, sticky='E', padx=2)

        if self.tvariable.get() == self.tvariables[2]:
            self.tstepentry.grid(row=3, column=6, sticky='E', padx=2)
        else:
            self.tstepwidget.grid(row=3, column=6, sticky='E', padx=2)

        row = 7

        if self.dep == 1:
            layersolveroption = self.deplayersolveroptions[0]
            layersolveroption.propertieswidgets(self.frame, row,
                                                self.ptype.get())
            row = row + 1

        for i in range(self.dep, self.nlayers):
            layersolveroption = self.layersolveroptions[i - self.dep]
            layersolveroption.propertieswidgets(self.frame, row,
                                                self.ptype.get())
            row = row + 1

        self.botleftcolumn.grid(row=row, column=0, sticky='WE', padx=2)
        self.botlayercolumn.grid(row=row, column=1, sticky='WE', padx=2)
        self.botthickcolumn.grid(row=row, column=2, sticky='WE', padx=2)
        self.botgridnumbercolumn.grid(row=row, column=3, sticky='WE', padx=2)
        self.botgridsizecolumn.grid(row=row, column=4, sticky='WE', padx=2)
        self.botpenumbercolumn.grid(row=row, column=5, sticky='WE', padx=2)
        self.bottimestepcolumn.grid(row=row, column=6, sticky='WE', padx=2)
        self.botendcolumn.grid(row=row, column=7, sticky='WE', padx=2)

        row = row + 1
        self.blank4.grid(row=row)
        row = row + 1
        self.updatebutton.grid(row=row, columnspan=11)
        row = row + 1
        self.okbutton.grid(row=row, columnspan=11)
        row = row + 1
        self.cancelbutton.grid(row=row, columnspan=11)
        row = row + 1
        self.blank5.grid(row=row)

        self.okbutton.bind('<Return>', self.OK)
        self.focusbutton = self.okbutton

        self.master.geometry()
        self.master.center()

    def updatesolverparameters(self):

        if self.ptype.get() == self.ptypes[0]:
            delz = self.htot / self.ptotal.get()
            for i in range(self.dep, self.nlayers):
                if self.layersolveroptions[i - self.dep].h / 5 < delz:
                    delz = self.layersolveroptions[i - self.dep].h / 5
                for n in range(self.nchemicals):
                    if self.U != 0: delzcfl = 2. * self.D[i][n] / abs(self.U)
                    else: delzcfl = 0
                    if delzcfl != 0 and delzcfl < delz: delz = delzcfl
            ptotal = 0
            for i in range(self.dep, self.nlayers):
                if int(self.layers[i].h /
                       delz) <> self.layers[i - self.dep].h / delz:
                    self.layersolveroptions[i - self.dep].player.set(
                        int(self.layers[i].h / delz) + 1)
                else:
                    self.layersolveroptions[i - self.dep].player.set(
                        int(self.layers[i].h / delz))

                delz_temp = self.layers[i].h / self.layersolveroptions[
                    i - self.dep].player.get()
                if delz_temp > 1:
                    self.layersolveroptions[i - self.dep].delz = (
                        ceil(delz_temp * 1000) / 1000)
                else:
                    j = 2
                    while delz_temp / 100 < 0.1**j:
                        j = j + 1
                    self.layersolveroptions[i - self.dep].delz = (
                        ceil(delz_temp * 10**j) / 10**j)
                try:
                    self.layersolveroptions[i - self.dep].Pe = round(
                        self.U * self.layersolveroptions[i - self.dep].delz /
                        min(self.D[i]), 2)
                except:
                    self.layersolveroptions[i - self.dep].Pe = 0

                delt_temp = min([
                    self.R[i][n] *
                    self.layersolveroptions[i - self.dep].delz**2 / 2. /
                    self.D[i][n] for n in range(self.nchemicals)
                ])
                if delt_temp > 1:
                    self.layersolveroptions[i - self.dep].delt = (round(
                        delt_temp, 3))
                else:
                    j = 2
                    while delt_temp / 100 < 0.1**j:
                        j = j + 1
                    self.layersolveroptions[i - self.dep].delt = (round(
                        delt_temp, j))

                ptotal = ptotal + self.layersolveroptions[
                    i - self.dep].player.get()

            self.ptotal.set(ptotal)

            if self.dep == 1:
                delz = min(layersolveroption.delz
                           for layersolveroption in self.layersolveroptions)
                for n in range(self.nchemicals):
                    if self.U != 0: delzcfl = 2. * self.D[0][n] / abs(self.U)
                    else: delzcfl = 0
                    if delzcfl != 0 and delzcfl < delz: delz = delzcfl

                if delz > 1:
                    self.deplayersolveroptions[0].delz = (ceil(delz * 1000) /
                                                          1000)
                else:
                    j = 2
                    while delz / 100 < 0.1**j:
                        j = j + 1
                    self.deplayersolveroptions[0].delz = (ceil(delz * 10**j) /
                                                          10**j)
                self.deplayersolveroptions[0].player.set(
                    round(self.deplayersolveroptions[0].h / delz, 2))

        elif self.ptype.get() == self.ptypes[1]:
            players = []
            for i in range(self.dep, self.nlayers):
                delz = self.layersolveroptions[i - self.dep].h / float(
                    self.ptotal.get() / (self.nlayers - self.dep))
                for n in range(self.nchemicals):
                    if self.U != 0: delzcfl = 2. * self.D[i][n] / abs(self.U)
                    else: delzcfl = 0
                    if delzcfl != 0 and delzcfl < delz: delz = delzcfl
                players.append(
                    int(self.layersolveroptions[i - self.dep].h / delz))
            if max(players) > self.ptotal.get() / self.nlayers:
                self.ptotal.set(max(players) * (self.nlayers - self.dep))
            for i in range(self.dep, self.nlayers):
                self.layersolveroptions[i - self.dep].player.set(
                    self.ptotal.get() / (self.nlayers - self.dep))

                delz_temp = self.layers[i].h / self.layersolveroptions[
                    i - self.dep].player.get()
                if delz_temp > 1:
                    self.layersolveroptions[i - self.dep].delz = (
                        ceil(delz_temp * 1000) / 1000)
                else:
                    j = 2
                    while delz_temp / 100 < 0.1**j:
                        j = j + 1
                    self.layersolveroptions[i - self.dep].delz = (
                        ceil(delz_temp * 10**j) / 10**j)

                self.layersolveroptions[i - self.dep].Pe = round(
                    self.U * self.layersolveroptions[i - self.dep].delz /
                    min(self.D[i]), 2)

                try:
                    delt_temp = min([
                        self.R[i][n] *
                        self.layersolveroptions[i - self.dep].delz**2 / 2. /
                        self.D[i][n] for n in range(self.nchemicals)
                    ])
                except:
                    delt_temp = 0
                if delt_temp > 1:
                    self.layersolveroptions[i - self.dep].delt = (round(
                        delt_temp, 3))
                else:
                    j = 2
                    while delt_temp / 100 < 0.1**j:
                        j = j + 1
                    self.layersolveroptions[i - self.dep].delt = (round(
                        delt_temp, j))

            if self.dep == 1:
                delz = min(layersolveroption.delz
                           for layersolveroption in self.layersolveroptions)
                for n in range(self.nchemicals):
                    if self.U != 0: delzcfl = 2. * self.D[0][n] / abs(self.U)
                    else: delzcfl = 0
                    if delzcfl != 0 and delzcfl < delz: delz = delzcfl
                if delz > 1:
                    self.deplayersolveroptions[0].delz = (ceil(delz * 1000) /
                                                          1000)
                else:
                    j = 2
                    while delz / 100 < 0.1**j:
                        j = j + 1
                    self.deplayersolveroptions[0].delz = (ceil(delz * 10**j) /
                                                          10**j)
                self.deplayersolveroptions[0].player.set(
                    round(self.deplayersolveroptions[0].h / delz, 2))

        else:
            for i in range(self.dep, self.nlayers):

                if self.layersolveroptions[i - self.dep].player.get() < 5:
                    self.layersolveroptions[i - self.dep].player.set(5)

                delz_temp = self.layers[i].h / self.layersolveroptions[
                    i - self.dep].player.get()
                if delz_temp > 1:
                    self.layersolveroptions[i - self.dep].delz = (
                        ceil(delz_temp * 1000) / 1000)
                else:
                    j = 2
                    while delz_temp / 100 < 0.1**j:
                        j = j + 1
                    self.layersolveroptions[i - self.dep].delz = (
                        ceil(delz_temp * 10**j) / 10**j)

                self.layersolveroptions[i - self.dep].Pe = round(
                    self.U * self.layersolveroptions[i - self.dep].delz /
                    min(self.D[i]), 2)

                try:
                    delt_temp = min([
                        self.R[i][n] *
                        self.layersolveroptions[i - self.dep].delz**2 / 2. /
                        self.D[i][n] for n in range(self.nchemicals)
                    ])
                except:
                    delt_temp = 0
                if delt_temp > 1:
                    self.layersolveroptions[i - self.dep].delt = (round(
                        delt_temp, 3))
                else:
                    j = 2
                    while delt_temp / 100 < 0.1**j:
                        j = j + 1
                    self.layersolveroptions[i - self.dep].delt = (round(
                        delt_temp, j))
            self.ptotal.set(
                sum([
                    layersolveroption.player.get()
                    for layersolveroption in self.layersolveroptions
                ]))

            if self.dep == 1:
                delz_temp = self.layers[0].h / self.deplayersolveroptions[
                    0].player.get()
                if delz_temp > 1:
                    self.deplayersolveroptions[0].delz = (
                        ceil(delz_temp * 1000) / 1000)
                else:
                    j = 2
                    while delz_temp / 100 < 0.1**j:
                        j = j + 1
                    self.deplayersolveroptions[0].delz = (
                        ceil(delz_temp * 10**j) / 10**j)

        if self.tvariable.get() == self.tvariables[0]:
            self.delt.set(
                min([
                    self.layersolveroptions[i - self.dep].delt
                    for i in range(self.dep, self.nlayers)
                ]))
        elif self.tvariable.get() == self.tvariables[1]:
            delt_temp = (min([
                self.layersolveroptions[i - self.dep].delt
                for i in range(self.dep, self.nlayers)
            ]) * max([
                self.layersolveroptions[i - self.dep].delt
                for i in range(self.dep, self.nlayers)
            ]))**0.5
            if delt_temp > 1: self.delt.set(round(delt_temp, 3))
            else:
                j = 2
                while delt_temp / 100 < 0.1**j:
                    j = j + 1
                self.delt.set(round(delt_temp, j))

        for i in range(self.dep, self.nlayers):
            self.delz[i] = self.layersolveroptions[i - self.dep].delz
            self.players[i] = self.layersolveroptions[i -
                                                      self.dep].player.get()

        if self.dep == 1:
            self.delz[0] = self.deplayersolveroptions[0].delz
            self.players[0] = self.deplayersolveroptions[0].player.get()

    def updatesolvereditor(self, event=None):

        self.updatesolverparameters()

        try:
            self.ptotalwidget.grid_forget()
            self.ptotalentry.grid_forget()
            self.tstepwidget.grid_forget()
            self.tstepentry.grid_forget()
        except:
            pass

        if self.ptype.get() == self.ptypes[2]:
            self.ptotalwidget.grid(row=2, column=6, sticky='E', padx=2)
        else:
            self.ptotalentry.grid(row=2, column=6, sticky='E', padx=2)

        if self.tvariable.get() == self.tvariables[2]:
            self.tstepentry.grid(row=3, column=6, sticky='E', padx=2)
        else:
            self.tstepwidget.grid(row=3, column=6, sticky='E', padx=2)

        row = 7

        if self.dep == 1:
            layersolveroption = self.deplayersolveroptions[0]
            layersolveroption.propertieswidgets(self.frame, row,
                                                self.ptype.get())
            row = row + 1

        for i in range(self.dep, self.nlayers):
            layersolveroption = self.layersolveroptions[i - self.dep]
            layersolveroption.propertieswidgets(self.frame, row,
                                                self.ptype.get())
            row = row + 1

        self.botleftcolumn.grid(row=row, column=0, sticky='WE', padx=2)
        self.botlayercolumn.grid(row=row, column=1, sticky='WE', padx=2)
        self.botthickcolumn.grid(row=row, column=2, sticky='WE', padx=2)
        self.botgridnumbercolumn.grid(row=row, column=3, sticky='WE', padx=2)
        self.botgridsizecolumn.grid(row=row, column=4, sticky='WE', padx=2)
        self.botpenumbercolumn.grid(row=row, column=5, sticky='WE', padx=2)
        self.bottimestepcolumn.grid(row=row, column=6, sticky='WE', padx=2)
        self.botendcolumn.grid(row=row, column=7, sticky='WE', padx=2)

        row = row + 1
        self.blank4.grid(row=row)
        row = row + 1
        self.updatebutton.grid(row=row, columnspan=11)
        row = row + 1
        self.okbutton.grid(row=row, columnspan=11)
        row = row + 1
        self.cancelbutton.grid(row=row, columnspan=11)
        row = row + 1
        self.blank5.grid(row=row)

        self.okbutton.bind('<Return>', self.OK)
        self.focusbutton = self.okbutton

        self.master.geometry()
        self.master.center()

    def OK(self, event=None):
        """Finish and move on.  Checks that the number chemicals are less than the
        total number of chemicals in database."""

        #self.updatesolverparameters()

        self.master.tk.quit()

    def Cancel(self):

        self.cancelflag = 1

        if self.master.window.top is not None:
            self.master.open_toplevel()
        else:
            self.master.tk.quit()
コード例 #4
0
class Product:
    def __init__(self, number):

        self.number = number
        self.soluable = 1

    def copy(self):

        product = Product(self.number)

        product.coef = self.coef
        product.MW = self.MW
        product.name = self.name
        product.formula = self.formula
        product.soluable = self.soluable

        return product

    def propertieswidgets(self, frame, row, master, chemical_list,
                          formula_list, MW_list):

        self.master = master

        self.chemical_list = chemical_list
        self.formula_list = formula_list
        self.MW_list = MW_list

        self.middlelabel = Label(frame, width=8, justify='center', text=' || ')
        self.delwidget = Button(frame,
                                width=5,
                                justify='center',
                                text='Delete',
                                command=self.del_product)
        self.namewidget = OptionMenu(frame,
                                     self.name,
                                     *chemical_list,
                                     command=self.click_name)
        self.coefwidget = Entry(frame,
                                width=8,
                                justify='center',
                                textvariable=self.coef)
        self.fwidget = Entry(frame,
                             width=8,
                             justify='center',
                             textvariable=self.formula,
                             font='Calibri 11')

        self.middlelabel.grid(row=row, column=5, padx=2, pady=1, sticky='WE')
        self.delwidget.grid(row=row, column=6, padx=2, pady=1)
        self.coefwidget.grid(row=row, column=7, padx=2, pady=1)
        self.namewidget.grid(row=row, column=8, padx=2, pady=1, sticky='WE')
        self.fwidget.grid(row=row, column=9, padx=2, pady=1, sticky='WE')

    def click_name(self, event=None):

        self.formula.set(self.formula_list[self.chemical_list.index(
            self.name.get())])
        self.MW.set(self.MW_list[self.chemical_list.index(self.name.get())])

    def del_product(self):

        self.master.window.delproduct(self.number)

    def get_product(self):

        self.coef = self.coef.get()
        self.name = self.name.get()
        self.formula = self.formula.get()
        self.MW = self.MW.get()

    def remove_propertieswidgets(self):

        self.master = 0
        self.delwidget.grid_forget()
        self.namewidget.grid_forget()
        self.coefwidget.grid_forget()
        self.fwidget.grid_forget()
        self.middlelabel.grid_forget()

        self.delwidget = 0
        self.namewidget = 0
        self.coefwidget = 0
        self.fwidget = 0
        self.middlelabel = 0

    def get_dynamic_sorption(self, chemical):

        self.coef = 1
        self.index = 1
        self.MW = chemical.MW
        self.name = chemical.name
        self.formula = ''
        self.soluable = 0

    def get_dynamic_desorption(self, chemical):

        self.coef = 1
        self.index = 1
        self.name = chemical.name
        self.formula = ''
        self.MW = chemical.MW
        self.soluable = 1
コード例 #5
0
class Reactant:
    def __init__(self, number):

        self.number = number
        self.soluable = 1

    def copy(self):

        reactant = Reactant(self.number)

        reactant.coef = self.coef
        reactant.index = self.index
        reactant.name = self.name
        reactant.formula = self.formula
        reactant.MW = self.MW
        reactant.soluable = self.soluable

        return reactant

    def propertieswidgets(self, frame, row, master, chemical_list,
                          formula_list, MW_list):

        self.master = master

        self.chemical_list = chemical_list
        self.formula_list = formula_list
        self.MW_list = MW_list

        self.delwidget = Button(frame,
                                width=5,
                                justify='center',
                                text='Delete',
                                command=self.del_reactant)
        self.namewidget = OptionMenu(frame,
                                     self.name,
                                     *chemical_list,
                                     command=self.click_name)
        self.coefwidget = Entry(frame,
                                width=8,
                                justify='center',
                                textvariable=self.coef)
        self.fwidget = Entry(frame,
                             width=8,
                             justify='center',
                             textvariable=self.formula,
                             font='Calibri 11')
        self.middlelabel = Label(frame, width=8, justify='center', text=' || ')

        self.delwidget.grid(row=row, column=1, padx=2, pady=1)
        self.coefwidget.grid(row=row, column=2, padx=2, pady=1)
        self.namewidget.grid(row=row, column=3, padx=2, pady=1, sticky='WE')
        self.fwidget.grid(row=row, column=4, padx=2, pady=1, sticky='WE')
        self.middlelabel.grid(row=row, column=5, padx=2, pady=1, sticky='WE')

    def click_name(self, event=None):

        self.formula.set(self.formula_list[self.chemical_list.index(
            self.name.get())])
        self.MW.set(self.MW_list[self.chemical_list.index(self.name.get())])

        self.master.window.updaterateequation()

    def del_reactant(self):

        self.master.window.delreactant(self.number)

    def get_reactant(self):

        self.coef = self.coef.get()
        self.name = self.name.get()
        self.formula = self.formula.get()
        self.MW = self.MW.get()
        self.index = self.index.get()

    def indexwidgets(self, frame, row):

        self.label = Label(frame, text=self.name.get())
        self.widget = Entry(frame,
                            textvariable=self.index,
                            width=6,
                            justify='center')

        self.label.grid(row=row, column=0, padx=6, pady=2)
        self.widget.grid(row=row, column=1, padx=6, pady=2)

    def remove_indexwidgets(self):

        self.label.grid_forget()
        self.widget.grid_forget()

        self.label = 0
        self.widget = 0

    def remove_propertieswidgets(self):

        self.delwidget.grid_forget()
        self.namewidget.grid_forget()
        self.coefwidget.grid_forget()
        self.fwidget.grid_forget()
        self.middlelabel.grid_forget()
        try:
            self.label.grid_forget()
            self.widget.grid_forget()
        except:
            pass

        self.master = 0
        self.delwidget = 0
        self.namewidget = 0
        self.coefwidget = 0
        self.fwidget = 0
        self.middlelabel = 0

        self.label = 0
        self.widget = 0

    def get_dynamic_sorption(self, chemical, index):

        self.coef = 1
        self.index = index
        self.name = chemical.name
        self.formula = ''
        self.MW = chemical.MW
        self.soluable = 1

    def get_dynamic_desorption(self, chemical, index):

        self.coef = 1
        self.index = index
        self.name = chemical.name
        self.formula = ''
        self.MW = chemical.MW
        self.soluable = 0
コード例 #6
0
class KblEstimator:
    """Used to make a window to compute the value of "kbl" for Rivers."""
    def __init__(self, master, version, fonttype, bltype, blcoefs):
        """Constructor method."""

        self.version = version
        self.fonttype = fonttype
        self.tframe = Frame(master.tframe)
        self.frame = Frame(master.frame)
        self.bframe = Frame(master.bframe)
        self.superfont = get_superfont(self.fonttype)

        self.bltypes = ['River', 'Lake']
        self.bltype = StringVar(value=bltype)
        self.top = None

        self.cancelflag = 0

        #Parameters for Mass transfer coefficient in river
        self.vx = DoubleVar(value=blcoefs['vx'])
        self.n = DoubleVar(value=blcoefs['n'])
        self.hriver = DoubleVar(value=blcoefs['hriver'])
        self.rh = DoubleVar(value=blcoefs['rh'])
        self.nu = DoubleVar(value=blcoefs['nu'])

        #Parameters for Mass transfer coefficient in lake
        self.rhoair = DoubleVar(value=blcoefs['rhoair'])
        self.rhowater = DoubleVar(value=blcoefs['rhowater'])
        self.vwind = DoubleVar(value=blcoefs['vwind'])
        self.hlake = DoubleVar(value=blcoefs['hlake'])
        self.llake = DoubleVar(value=blcoefs['llake'])

    def make_widgets(self):
        """Makes the widgets for the window."""

        self.bgcolor = self.frame.cget('bg')
        self.text = Label(
            self.frame,
            text=
            'Please provide the following information regarding the benthic boundary layer:'
        )
        self.blank1 = Label(self.frame, text='')
        self.blank2 = Label(self.frame, text='')
        self.blank3 = Label(self.frame, text='')
        self.blank4 = Label(self.frame, text='')

        self.paracolumn = Label(self.frame, text=' ', width=20)
        self.valuecolumn = Label(self.frame, text=' ', width=10)
        self.unitcolumn = Label(self.frame, text=' ', width=10)

        self.paralabel = Label(self.frame, text='Parameters')
        self.valuelabel = Label(self.frame, text='Values')
        self.unitlabel = Label(self.frame, text='Units')

        self.bllabel = Label(self.frame, text='Overlying waterbody type')
        self.blwidget = OptionMenu(self.frame,
                                   self.bltype,
                                   *self.bltypes,
                                   command=self.updateparameters)

        self.vxlabel = Label(self.frame, text='River velocity:')
        self.vxentry = Entry(self.frame,
                             textvariable=self.vx,
                             width=8,
                             justify='center')
        self.vxunits = Label(self.frame, text='m/s')

        self.nlabel = Label(self.frame, text="Manning's n:")
        self.nentry = Entry(self.frame,
                            textvariable=self.n,
                            width=8,
                            justify='center')
        self.nunits = Label(self.frame, text='-')

        self.hlabel = Label(self.frame, text='River depth:')
        self.hentry = Entry(self.frame,
                            justify='center',
                            width=8,
                            textvariable=self.hriver)
        self.hunits = Label(self.frame, text='m')

        self.rhlabel = Label(self.frame, text='Hydraulic radius:')
        self.rhentry = Entry(self.frame,
                             textvariable=self.rh,
                             width=8,
                             justify='center')
        self.rhunits = Label(self.frame, text='m')

        self.nulabel = Label(self.frame, text='Kinematic viscosity:')
        self.nuentry = Entry(self.frame,
                             textvariable=self.nu,
                             width=8,
                             justify='center')
        self.nuunits = Label(self.frame, text=u'm\u00B2/s')

        self.rhoairlabel = Label(self.frame, text='Density of air:')
        self.rhoairentry = Entry(self.frame,
                                 textvariable=self.rhoair,
                                 width=8,
                                 justify='center')
        self.rhoairunits = Label(self.frame, text='g/L')

        self.rhowaterlabel = Label(self.frame, text='Density of water:')
        self.rhowaterentry = Entry(self.frame,
                                   textvariable=self.rhowater,
                                   width=8,
                                   justify='center')
        self.rhowaterunits = Label(self.frame, text='g/L')

        self.vwindlabel = Label(self.frame, text='Wind speed:')
        self.vwindentry = Entry(self.frame,
                                textvariable=self.vwind,
                                width=8,
                                justify='center')
        self.vwindunits = Label(self.frame, text='m/s')

        self.hlakelabel = Label(self.frame, text='Lake depth:')
        self.hlakeentry = Entry(self.frame,
                                textvariable=self.hlake,
                                width=8,
                                justify='center')
        self.hlakeunits = Label(self.frame, text='m')

        self.lakelabel = Label(self.frame, text='Lake fetch:')
        self.lakeentry = Entry(self.frame,
                               textvariable=self.llake,
                               width=8,
                               justify='center')
        self.lakeunits = Label(self.frame, text='m')

        self.calcbutton = Button(self.frame,
                                 text='Calculate',
                                 width=20,
                                 command=self.calculate)
        self.exitbutton = Button(self.frame,
                                 text='Cancel',
                                 width=20,
                                 command=self.exit)
        self.calcbutton.bind('<Return>', self.calculate)
        self.exitbutton.bind('<Return>', self.exit)

        self.text.grid(row=0, columnspan=3, padx=8)
        self.blank1.grid(row=1)

        self.paracolumn.grid(row=2, column=0, sticky='WE')
        self.valuecolumn.grid(row=2, column=1, sticky='WE')
        self.unitcolumn.grid(row=2, column=2, sticky='WE')

        self.paralabel.grid(row=3, column=0, sticky='E')
        self.valuelabel.grid(row=3, column=1, sticky='WE')
        self.unitlabel.grid(row=3, column=2, sticky='W')

        self.bllabel.grid(row=4, column=0, sticky='E')
        self.blwidget.grid(row=4, column=1, sticky='WE')

        self.blank2.grid(row=10)
        self.calcbutton.grid(row=11, columnspan=3, pady=1)
        self.exitbutton.grid(row=12, columnspan=3, pady=1)

        self.focusbutton = self.calcbutton
        self.updateparameters()

    def updateparameters(self, event=None):

        try:
            self.vxlabel.grid_forget()
            self.vxentry.grid_forget()
            self.vxunits.grid_forget()
            self.nlabel.grid_forget()
            self.nentry.grid_forget()
            self.nunits.grid_forget()
            self.hlabel.grid_forget()
            self.hentry.grid_forget()
            self.hunits.grid_forget()
            self.rhlabel.grid_forget()
            self.rhentry.grid_forget()
            self.rhunits.grid_forget()
            self.nulabel.grid_forget()
            self.nuentry.grid_forget()
            self.nuunits.grid_forget()
        except:
            pass

        try:
            self.rhoairlabel.grid_forget()
            self.rhoairentry.grid_forget()
            self.rhoairunits.grid_forget()
            self.rhowaterlabel.grid_forget()
            self.rhowaterentry.grid_forget()
            self.rhowaterunits.grid_forget()
            self.vwindlabel.grid_forget()
            self.vwindentry.grid_forget()
            self.vwindunits.grid_forget()
            self.hlakelabel.grid_forget()
            self.hlakeentry.grid_forget()
            self.hlakeunits.grid_forget()
            self.lakelabel.grid_forget()
            self.lakeentry.grid_forget()
            self.lakeunits.grid_forget()
        except:
            pass

        if self.bltype.get() == self.bltypes[0]:
            self.vxlabel.grid(row=5, column=0, sticky='E', padx=4)
            self.vxentry.grid(row=5, column=1)
            self.vxunits.grid(row=5, column=2, sticky='W')
            self.nlabel.grid(row=6, column=0, sticky='E', padx=4)
            self.nentry.grid(row=6, column=1)
            self.nunits.grid(row=6, column=2, sticky='W')
            self.hlabel.grid(row=7, column=0, sticky='E', padx=4)
            self.hentry.grid(row=7, column=1)
            self.hunits.grid(row=7, column=2, sticky='W')
            self.rhlabel.grid(row=8, column=0, sticky='E', padx=4)
            self.rhentry.grid(row=8, column=1)
            self.rhunits.grid(row=8, column=2, sticky='W')
            self.nulabel.grid(row=9, column=0, sticky='E', padx=4)
            self.nuentry.grid(row=9, column=1)
            self.nuunits.grid(row=9, column=2, sticky='W')
        else:
            self.rhoairlabel.grid(row=5, column=0, sticky='E', padx=4)
            self.rhoairentry.grid(row=5, column=1)
            self.rhoairunits.grid(row=5, column=2, sticky='W')
            self.rhowaterlabel.grid(row=6, column=0, sticky='E', padx=4)
            self.rhowaterentry.grid(row=6, column=1)
            self.rhowaterunits.grid(row=6, column=2, sticky='W')
            self.vwindlabel.grid(row=7, column=0, sticky='E', padx=4)
            self.vwindentry.grid(row=7, column=1)
            self.vwindunits.grid(row=7, column=2, sticky='W')
            self.hlakelabel.grid(row=8, column=0, sticky='E', padx=4)
            self.hlakeentry.grid(row=8, column=1)
            self.hlakeunits.grid(row=8, column=2, sticky='W')
            self.lakelabel.grid(row=9, column=0, sticky='E', padx=4)
            self.lakeentry.grid(row=9, column=1)
            self.lakeunits.grid(row=9, column=2, sticky='W')

    def calculate(self, event=None):
        """Finish and move on."""

        self.frame.quit()

    def exit(self, event=None):
        """Used to close the window without computing kbl."""

        self.cancelflag = 1

        self.frame.quit()