Пример #1
0
    def __init__(self, parent, layout=1):
        self.cwd = os.getcwd()
        self.p = Parameters(interface='GUI')
        self.parent = parent
        self.initialize()

        self.GUI = AutoSimVizGUI()

        if layout == 1:
            # only one column of input parameters:
            self.GUI.make_prmGUI(self.parent,
                                 self.p,
                                 sort_widgets=0,
                                 height=300,
                                 pane=0)
        else:
            # widgets sorted in columns:
            self.GUI.make_prmGUI(self.parent,
                                 self.p,
                                 sort_widgets=1,
                                 height=300,
                                 pane=1)
        help = '''
Interface to a squeeze film solver
'''

        self.GUI.make_buttonGUI(self.parent,
                                buttons=[('Simulate', self.simulate),
                                         ('Visualize', self.visualize)],
                                logo=None,
                                help=help)  # help=None to avoid help button

        self.accl, self.defm, self.load = \
                  self.GUI.make_curveplotGUI(self.parent, 3,
                                             placement='right')
Пример #2
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)
Пример #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):
     self.cwd = os.getcwd()
     self.p = Parameters(interface='plain')
     self.initialize()
Пример #5
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)
Пример #6
0
 def __init__(self):
     self.cwd = os.getcwd()
     self.p = Parameters(interface='plain')
     self.initialize()
Пример #7
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)
Пример #8
0
class SimViz:
    def __init__(self):
        self.cwd = os.getcwd()
        self.p = Parameters(interface='plain')
        self.initialize()

    def initialize(self):
        """Define input parameters."""

        self.p.add("Young's modulus", "5000", str, widget_type='entry')

        self.p.add("Poisson's ratio",
                   "0.25",
                   str,
                   widget_type='slider',
                   values=['0', '0.5'])

        self.p.add("Plate thickness",
                   "0.05",
                   str,
                   widget_type='slider',
                   values=['0', '0.4'])

        self.p.add("Acceleration omega",
                   "1",
                   str,
                   widget_type='slider',
                   values=['0', '5'])

        self.p.add("Acceleration impulse",
                   "0.05",
                   str,
                   widget_type='slider',
                   values=['0', '2'])

        self.p.add("Film gap",
                   "0.2",
                   str,
                   widget_type='slider',
                   values=['0', '0.5'])

        self.p.add("Viscosity", "1.0E-5", str, widget_type='entry')

        self.p.add("Gamma for gas",
                   "0",
                   str,
                   widget_type='option',
                   values=['0', '1.4'])

        self.p.add("Scheme",
                   "backward",
                   str,
                   widget_type='option',
                   values=['Crank-Nicolson', 'backward'])

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

    def simulate(self):
        """Run simulator with input grabbed from the GUI."""
        if 'NOR' not in os.environ:
            print 'Diffpack is not accessible on this computer.'
            sys.exit(1)
        app = os.path.join(os.environ['NOR'], 'doc', 'Book', 'src', 'app',
                           'SqueezeFilm', 'coupling', 'app')
        if not os.path.isfile(app):
            print 'The Diffpack application\n %s\nis not compiled' % app
            print 'Go to the directory and run Make MODE=opt'
            sys.exit(1)
        program = app
        cmd = program
        cmd += " --batch --Default Verify/test1b.i"
        cmd += " --Young's_modulus %s" % self.p["Young's modulus"]
        cmd += " --Poisson's_ratio %s" % self.p["Poisson's ratio"]
        cmd += " --thickness %s" % self.p["Plate thickness"]
        cmd += " --omega %s" % self.p["Acceleration omega"]
        cmd += " --impulse %s" % self.p["Acceleration impulse"]
        cmd += " --initial_gap %s" % self.p["Film gap"]
        cmd += " --viscosity %s" % self.p["Viscosity"]
        cmd += " --gamma %s" % self.p["Gamma for gas"]
        if self.p["Scheme"] == 'backward':
            theta = 1.0
        else:
            theta = 0.5
        cmd += " --theta %g" % theta

        os.system("RmCase SIMULATION")  # clean up previous runs
        failure = os.system(cmd)
        if failure:
            print "could not run", cmd
            sys.exit(1)

    def visualize(self):
        """Visualize solutions."""
        cmd = "..."
        failure = os.system(cmd)
        if failure:
            print 'could not run', cmd
            sys.exit(1)
Пример #9
0
Файл: gui.py Проект: hushell/kod
class SimViz:
    def __init__(self):
        self.cwd = os.getcwd()
        self.p = Parameters(interface="plain")
        self.initialize()

    def initialize(self):
        """Define input parameters."""

        self.p.add("Young's modulus", "5000", str, widget_type="entry")

        self.p.add("Poisson's ratio", "0.25", str, widget_type="slider", values=["0", "0.5"])

        self.p.add("Plate thickness", "0.05", str, widget_type="slider", values=["0", "0.4"])

        self.p.add("Acceleration omega", "1", str, widget_type="slider", values=["0", "5"])

        self.p.add("Acceleration impulse", "0.05", str, widget_type="slider", values=["0", "2"])

        self.p.add("Film gap", "0.2", str, widget_type="slider", values=["0", "0.5"])

        self.p.add("Viscosity", "1.0E-5", str, widget_type="entry")

        self.p.add("Gamma for gas", "0", str, widget_type="option", values=["0", "1.4"])

        self.p.add("Scheme", "backward", str, widget_type="option", values=["Crank-Nicolson", "backward"])

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

    def simulate(self):
        """Run simulator with input grabbed from the GUI."""
        if "NOR" not in os.environ:
            print "Diffpack is not accessible on this computer."
            sys.exit(1)
        app = os.path.join(os.environ["NOR"], "doc", "Book", "src", "app", "SqueezeFilm", "coupling", "app")
        if not os.path.isfile(app):
            print "The Diffpack application\n %s\nis not compiled" % app
            print "Go to the directory and run Make MODE=opt"
            sys.exit(1)
        program = app
        cmd = program
        cmd += " --batch --Default Verify/test1b.i"
        cmd += " --Young's_modulus %s" % self.p["Young's modulus"]
        cmd += " --Poisson's_ratio %s" % self.p["Poisson's ratio"]
        cmd += " --thickness %s" % self.p["Plate thickness"]
        cmd += " --omega %s" % self.p["Acceleration omega"]
        cmd += " --impulse %s" % self.p["Acceleration impulse"]
        cmd += " --initial_gap %s" % self.p["Film gap"]
        cmd += " --viscosity %s" % self.p["Viscosity"]
        cmd += " --gamma %s" % self.p["Gamma for gas"]
        if self.p["Scheme"] == "backward":
            theta = 1.0
        else:
            theta = 0.5
        cmd += " --theta %g" % theta

        os.system("RmCase SIMULATION")  # clean up previous runs
        failure = os.system(cmd)
        if failure:
            print "could not run", cmd
            sys.exit(1)

    def visualize(self):
        """Visualize solutions."""
        cmd = "..."
        failure = os.system(cmd)
        if failure:
            print "could not run", cmd
            sys.exit(1)
Пример #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)