예제 #1
0
    def __init__(self, parent):
        """Build GUI, allocate solver, etc."""
        self.master = parent

        self.row_frame = Frame(self.master, borderwidth=2, relief='groove')
        self.row_frame.pack()
        Button(self.row_frame, text='Physics', command=self.set_physics,
               width=12).pack(side='left')
        Button(self.row_frame, text='Numerics', command=self.set_numerics,
               width=12).pack(side='left')
        Button(self.row_frame, text='Simulate', command=self.simulate,
               width=12).pack(side='left')
        Button(self.row_frame, text='Stop', command=self.stop,
               width=12).pack(side='left')
        Button(self.row_frame, text='Continue', command=self.continue_,
               width=12).pack(side='left')
        Button(self.row_frame, text='Quit', command=self.master.destroy,
               width=12).pack(side='left')

        self.w = WaveSolverWithViz(WaveEq2(), plot=True,
                 program='BLT', parent_frame=self.master, sleep=0)

        self._setup_shapes()

        self.nGUI = Parameters(interface='GUI')  # numerics part of GUI
        self.nGUI.add('stop time for simulation', 60.0, widget_type='entry')
        self.nGUI.add('safety factor for time step', 1.0, widget_type='entry')
        self.nGUI.add('no of grid cells', 100,
                      widget_type='slider', values=(0,1000))
        self.nGUI.add('movie speed', 1.0,
                      widget_type='slider', values=(0,1))

        self.scheme_coding = 'vectorized'
예제 #2
0
    def __init__(self, parent):
        """Build GUI, allocate solver, etc."""
        self.master = parent

        self.row_frame = Frame(self.master, borderwidth=2, relief='groove')
        self.row_frame.pack()
        Button(self.row_frame,
               text='Physics',
               command=self.set_physics,
               width=12).pack(side='left')
        Button(self.row_frame,
               text='Numerics',
               command=self.set_numerics,
               width=12).pack(side='left')
        Button(self.row_frame,
               text='Simulate',
               command=self.simulate,
               width=12).pack(side='left')
        Button(self.row_frame, text='Stop', command=self.stop,
               width=12).pack(side='left')
        Button(self.row_frame,
               text='Continue',
               command=self.continue_,
               width=12).pack(side='left')
        Button(self.row_frame,
               text='Quit',
               command=self.master.destroy,
               width=12).pack(side='left')

        self.w = WaveSolverWithViz(WaveEq2(),
                                   plot=True,
                                   program='BLT',
                                   parent_frame=self.master,
                                   sleep=0)

        self._setup_shapes()

        self.nGUI = Parameters(interface='GUI')  # numerics part of GUI
        self.nGUI.add('stop time for simulation', 60.0, widget_type='entry')
        self.nGUI.add('safety factor for time step', 1.0, widget_type='entry')
        self.nGUI.add('no of grid cells',
                      100,
                      widget_type='slider',
                      values=(0, 1000))
        self.nGUI.add('movie speed', 1.0, widget_type='slider', values=(0, 1))

        self.scheme_coding = 'vectorized'
예제 #3
0
def lines2prms(parsed_lines, parameters=None):
    if parameters is None:
        parameters = Parameters(interface='GUI')
    for line in parsed_lines:
        if isinstance(line, dict):
            comment = line['comment']
            if line['ref_unit'] is not None:
                # parameter has value with unit:
                help = 'unit: '+line['ref_unit']+'; '+comment[1:]
                unit = line['ref_unit']
                str2type = float  # unit conversions -> float
            else:
                help = comment[1:]
                unit = None
                str2type = line['value'].__class__
            parameters.add(name=line['parameter'],
                           default=line['value'],
                           str2type=str2type,
                           widget_type='entry',
                           help=help, unit=unit)
    return parameters
예제 #4
0
    def __init__(self, parent, layout='sort'):
        self.cwd = os.getcwd()
        self.p = Parameters(interface='GUI')
        self.master = parent
        self.initialize()

        self.GUI = AutoSimVizGUI()

        if layout == 'sort':
            # widgets sorted in columns:
            self.GUI.make_prmGUI(self.master,
                                 self.p,
                                 sort_widgets=1,
                                 height=300,
                                 pane=1)
        else:
            # only one column of input parameters:
            self.GUI.make_prmGUI(self.master,
                                 self.p,
                                 sort_widgets=0,
                                 height=300,
                                 pane=0)

        help = """\
Simulate: run oscillator code for solving the
differential equation for the spring system.

Visualize: run Gnuplot to make plots in PNG and PostScript
format and on the screen (optional). Plots are stored
in the subdirectory with name equal to 'case'.
"""
        self.GUI.make_buttonGUI(self.master,
                                buttons=[('Simulate', self.simulate),
                                         ('Visualize', self.visualize)],
                                logo=os.path.join(os.environ['scripting'],
                                                  'src', 'misc', 'figs',
                                                  'simviz2.xfig.t.gif'),
                                help=None)
예제 #5
0
 def __init__(self):
     self.cwd = os.getcwd()
     self.p = Parameters(interface='plain')
     self.initialize()
예제 #6
0
class SimViz:
    def __init__(self):
        self.cwd = os.getcwd()
        self.p = Parameters(interface='plain')
        self.initialize()

    def initialize(self):
        """Define all input parameters."""
        self.p.add('m',
                   1.0,
                   float,
                   widget_type='slider',
                   values=(0, 5),
                   help='mass')
        self.p.add('b',
                   0.7,
                   float,
                   widget_type='slider',
                   values=(0, 2),
                   help='damping')
        self.p.add('c',
                   5.0,
                   float,
                   widget_type='slider',
                   values=(0, 20),
                   help='stiffness')
        self.p.add('func',
                   'y',
                   str,
                   widget_type='option',
                   values=('y', 'y3', 'siny'),
                   help='spring model function')
        self.p.add('A',
                   5.0,
                   float,
                   widget_type='slider',
                   values=(0, 10),
                   help='forced amplitude')
        self.p.add('w',
                   2 * math.pi,
                   float,
                   widget_type='entry',
                   help='forced frequency')
        self.p.add('y0',
                   0.2,
                   float,
                   widget_type='slider',
                   values=(0, 1),
                   help='initial displacement')
        self.p.add('tstop', 30.0, float, widget_type='entry', help='stop time')
        self.p.add('dt', 0.05, float, widget_type='entry', help='time step')
        self.p.add('case', 'tmp1', str, widget_type='entry', help='case name')
        self.p.add('screenplot',
                   1,
                   int,
                   widget_type='checkbutton',
                   help='plot on the screen?')
        # alternative: (but IntVar used to represent it converts to int
        #self.p.add('screenplot', True, bool,
        #           widget_type='checkbutton',
        #           help='plot on the screen?')

    def usage(self):
        return 'Usage: ' + sys.argv[0] + ' ' + self.p.usage()

    def simulate(self):
        os.chdir(self.cwd)
        case = self.p['case']  # abbreviation
        # create a subdirectory:
        d = case
        if os.path.isdir(d):
            shutil.rmtree(d)
        os.mkdir(d)
        os.chdir(d)

        # make input file to the program:
        f = open('%s.i' % case, 'w')
        f.write('%(m)g\n%(b)g\n%(c)g\n%(func)s\n%(A)g\n%(w)g\n'\
                '%(y0)g\n%(tstop)g\n%(dt)g\n' % self.p)
        f.close()
        # run simulator:
        cmd = 'oscillator < %s.i' % case  # command to run
        scitools.misc.system(cmd)

    def visualize(self):
        # make file with gnuplot commands:
        case = self.p['case']
        f = open(case + '.gnuplot', 'w')
        f.write("set title '%(case)s: m=%(m)g b=%(b)g c=%(c)g "\
                "f(y)=%(func)s A=%(A)g w=%(w)g y0=%(y0)g "\
                "dt=%(dt)g';\n" % self.p)
        if self.p['screenplot']:
            f.write("plot 'sim.dat' title 'y(t)' with lines;\n")
        f.write("""
set size ratio 0.3 1.5, 1.0;  
# define the postscript output format:
set term postscript eps monochrome dashed 'Times-Roman' 28;
# output file containing the plot:
set output '%s.ps';
# basic plot command
plot 'sim.dat' title 'y(t)' with lines;
# make a plot in PNG format:
set term png small;
set output '%s.png';
plot 'sim.dat' title 'y(t)' with lines;
        """ % (case, case))
        f.close()
        # make plot:
        cmd = 'gnuplot -geometry 800x200 -persist ' + case + '.gnuplot'
        scitools.misc.system(cmd)
예제 #7
0
class WaveSimGUI:
    def __init__(self, parent):
        """Build GUI, allocate solver, etc."""
        self.master = parent

        self.row_frame = Frame(self.master, borderwidth=2, relief='groove')
        self.row_frame.pack()
        Button(self.row_frame,
               text='Physics',
               command=self.set_physics,
               width=12).pack(side='left')
        Button(self.row_frame,
               text='Numerics',
               command=self.set_numerics,
               width=12).pack(side='left')
        Button(self.row_frame,
               text='Simulate',
               command=self.simulate,
               width=12).pack(side='left')
        Button(self.row_frame, text='Stop', command=self.stop,
               width=12).pack(side='left')
        Button(self.row_frame,
               text='Continue',
               command=self.continue_,
               width=12).pack(side='left')
        Button(self.row_frame,
               text='Quit',
               command=self.master.destroy,
               width=12).pack(side='left')

        self.w = WaveSolverWithViz(WaveEq2(),
                                   plot=True,
                                   program='BLT',
                                   parent_frame=self.master,
                                   sleep=0)

        self._setup_shapes()

        self.nGUI = Parameters(interface='GUI')  # numerics part of GUI
        self.nGUI.add('stop time for simulation', 60.0, widget_type='entry')
        self.nGUI.add('safety factor for time step', 1.0, widget_type='entry')
        self.nGUI.add('no of grid cells',
                      100,
                      widget_type='slider',
                      values=(0, 1000))
        self.nGUI.add('movie speed', 1.0, widget_type='slider', values=(0, 1))

        self.scheme_coding = 'vectorized'

    def set_physics(self):
        """Launch dialog (Physics button in main window)."""
        self.physics_dialog = Pmw.Dialog(
            self.master,
            title='Set initial condition and bottom shape',
            buttons=('Apply', 'Cancel', 'Dismiss'),
            defaultbutton='Apply',
            command=self.physics_dialog_action)

        self.pGUI = {}  # physics parts of GUI
        self.pGUI['notebook'] = \
             FunctionSelector(self.physics_dialog.interior())
        self.pGUI['notebook'].add('Initial surface', self.I_list)
        self.pGUI['notebook'].add('Bottom shape', self.H_list)
        self.pGUI['notebook'].pack()
        self.pGUI['notebook'].page['Bottom shape'].\
                page['Drawing'].drawing.set_yaxis(-1.1, 0.1)
        self.pGUI['notebook'].page['Bottom shape'].\
                page['Drawing'].drawing.configure(width=500)
        self.pGUI['notebook'].page['Initial surface'].\
                page['Drawing'].drawing.configure(width=500)
        try:
            # load previously selected pages (if selected...):
            self.pGUI['notebook'].select('Initial surface',
                                         self.pGUI['I page'])
            self.pGUI['notebook'].select('Bottom shape', self.pGUI['H page'])
        except Exception, msg:
            # first time... no pages are user selected
            self.pGUI['notebook'].select('Initial surface', 'Gaussian bell')
            self.pGUI['notebook'].select('Bottom shape', 'Gaussian bell')
예제 #8
0
class WaveSimGUI:
    def __init__(self, parent):
        """Build GUI, allocate solver, etc."""
        self.master = parent

        self.row_frame = Frame(self.master, borderwidth=2, relief='groove')
        self.row_frame.pack()
        Button(self.row_frame, text='Physics', command=self.set_physics,
               width=12).pack(side='left')
        Button(self.row_frame, text='Numerics', command=self.set_numerics,
               width=12).pack(side='left')
        Button(self.row_frame, text='Simulate', command=self.simulate,
               width=12).pack(side='left')
        Button(self.row_frame, text='Stop', command=self.stop,
               width=12).pack(side='left')
        Button(self.row_frame, text='Continue', command=self.continue_,
               width=12).pack(side='left')
        Button(self.row_frame, text='Quit', command=self.master.destroy,
               width=12).pack(side='left')

        self.w = WaveSolverWithViz(WaveEq2(), plot=True,
                 program='BLT', parent_frame=self.master, sleep=0)

        self._setup_shapes()

        self.nGUI = Parameters(interface='GUI')  # numerics part of GUI
        self.nGUI.add('stop time for simulation', 60.0, widget_type='entry')
        self.nGUI.add('safety factor for time step', 1.0, widget_type='entry')
        self.nGUI.add('no of grid cells', 100,
                      widget_type='slider', values=(0,1000))
        self.nGUI.add('movie speed', 1.0,
                      widget_type='slider', values=(0,1))

        self.scheme_coding = 'vectorized'

    def set_physics(self):
        """Launch dialog (Physics button in main window)."""
        self.physics_dialog = Pmw.Dialog(self.master,
             title='Set initial condition and bottom shape',
             buttons=('Apply', 'Cancel', 'Dismiss'),
             defaultbutton='Apply',
             command=self.physics_dialog_action)

        self.pGUI = {}   # physics parts of GUI
        self.pGUI['notebook'] = \
             FunctionSelector(self.physics_dialog.interior())
        self.pGUI['notebook'].add('Initial surface', self.I_list)
        self.pGUI['notebook'].add('Bottom shape', self.H_list)
        self.pGUI['notebook'].pack()
        self.pGUI['notebook'].page['Bottom shape'].\
                page['Drawing'].drawing.set_yaxis(-1.1, 0.1)
        self.pGUI['notebook'].page['Bottom shape'].\
                page['Drawing'].drawing.configure(width=500)
        self.pGUI['notebook'].page['Initial surface'].\
                page['Drawing'].drawing.configure(width=500)
        try:
            # load previously selected pages (if selected...):
            self.pGUI['notebook'].select('Initial surface',
                                         self.pGUI['I page'])
            self.pGUI['notebook'].select('Bottom shape',
                                         self.pGUI['H page'])
        except Exception, msg:
            # first time... no pages are user selected
            self.pGUI['notebook'].select('Initial surface', 'Gaussian bell')
            self.pGUI['notebook'].select('Bottom shape', 'Gaussian bell')
예제 #9
0
 def __init__(self):
     self.cwd = os.getcwd()
     self.p = Parameters(interface='plain')
     self.initialize()
예제 #10
0
class SimViz:
    def __init__(self):
        self.cwd = os.getcwd()
        self.p = Parameters(interface='plain')
        self.initialize()

    def initialize(self):
        """Define all input parameters."""
        self.p.add('m', 1.0, float,
                   widget_type='slider', values=(0,5), help='mass',
                   unit='kg')
        self.p.add('b', 0.7, float,
                   widget_type='slider', values=(0,2), help='damping',
                   unit='kg/s')
        self.p.add('c', 5.0, float,
                   widget_type='slider', values=(0,20), help='stiffness',
                   unit='kg/s**2')
        # 'func' must be 'y' here to fix the dimension of 'c'
        self.p.add('func', 'y', str,
                   widget_type='option', values=('y',),
                   help='spring model function')
        self.p.add('A', '5.0 N', float,
                   widget_type='slider', values=(0,10),
                   help='forced amplitude', unit='N')
        self.p.add('w', 2*math.pi, float,
                   widget_type='entry', help='forced frequency',
                   unit='1/s')
        self.p.add('y0', 0.2, float,
                   widget_type='slider', values=(0,1),
                   help='initial displacement',
                   unit='m')
        self.p.add('tstop', 30.0, float,
                   widget_type='entry', help='stop time', unit='s')
        self.p.add('dt', 0.05, float,
                   widget_type='entry', help='time step', unit='s')
        self.p.add('case', 'tmp1', str,
                   widget_type='entry', help='case name')
        self.p.add('screenplot', 1, int,
                   widget_type='checkbutton',
                   help='plot on the screen?')

    def usage(self):
        return 'Usage: ' + sys.argv[0] + ' ' + self.p.usage()

    def simulate(self):
        os.chdir(self.cwd)
        case = self.p['case']   # abbreviation
        # create a subdirectory:
        d = case            
        if os.path.isdir(d):
            shutil.rmtree(d)
        os.mkdir(d)         
        os.chdir(d)         

        # make input file to the program:
        f = open('%s.i' % case, 'w')
        f.write('%(m)g\n%(b)g\n%(c)g\n%(func)s\n%(A)g\n%(w)g\n'\
                '%(y0)g\n%(tstop)g\n%(dt)g\n' % self.p)
        f.close()
        # run simulator:
        cmd = 'oscillator < %s.i' % case  # command to run
        scitools.misc.system(cmd)

    def visualize(self):
        # make file with gnuplot commands:
        case = self.p['case']
        f = open(case + '.gnuplot', 'w')
        f.write("set title '%(case)s: m=%(m)g b=%(b)g c=%(c)g "\
                "f(y)=%(func)s A=%(A)g w=%(w)g y0=%(y0)g "\
                "dt=%(dt)g';\n" % self.p)
        if self.p['screenplot']:
            f.write("plot 'sim.dat' title 'y(t)' with lines;\n")
        f.write("""
set size ratio 0.3 1.5, 1.0;  
# define the postscript output format:
set term postscript eps monochrome dashed 'Times-Roman' 28;
# output file containing the plot:
set output '%s.ps';
# basic plot command
plot 'sim.dat' title 'y(t)' with lines;
# make a plot in PNG format:
set term png small;
set output '%s.png';
plot 'sim.dat' title 'y(t)' with lines;
        """ % (case,case))
        f.close()
        # make plot:
        cmd = 'gnuplot -geometry 800x200 -persist '+case+'.gnuplot'
        scitools.misc.system(cmd)