Пример #1
0
def vary_omega1_size(problem):
    """Vary size of \Omega1. Saves also the regions into options['output_dir'].

    Input:
      problem: ProblemDefinition instance
    Return:
      a generator object:
      1. creates new (modified) problem
      2. yields the new (modified) problem and output container
      3. use the output container for some logging
      4. yields None (to signal next iteration to Application)
    """
    from sfepy.fem import ProblemDefinition
    from sfepy.solvers.ts import get_print_info

    output.prefix = 'vary_omega1_size:'

    diameters = nm.linspace(0.1, 0.6, 7) + 0.001
    ofn_trunk, output_format = problem.ofn_trunk, problem.output_format
    output_dir = problem.output_dir
    join = os.path.join

    conf = problem.conf
    cf = conf.get_raw('functions')
    n_digit, aux, d_format = get_print_info(len(diameters) + 1)
    for ii, diameter in enumerate(diameters):
        output('iteration %d: diameter %3.2f' % (ii, diameter))

        cf['select_circ'] = (lambda coors, domain=None: select_circ(
            coors[:, 0], coors[:, 1], 0, diameter),
                             )
        conf.edit('functions', cf)
        problem = ProblemDefinition.from_conf(conf)

        problem.save_regions(join(output_dir, ('regions_' + d_format) % ii),
                             ['Omega_1'])
        region = problem.domain.regions['Omega_1']
        if not region.has_cells_if_can():
            print region
            raise ValueError('region %s has no cells!' % region.name)

        ofn_trunk = ofn_trunk + '_' + (d_format % ii)
        problem.setup_output(output_filename_trunk=ofn_trunk,
                             output_dir=output_dir,
                             output_format=output_format)

        out = []
        yield problem, out

        out_problem, state = out[-1]

        filename = join(output_dir, ('log_%s.txt' % d_format) % ii)
        fd = open(filename, 'w')
        log_item = '$r(\Omega_1)$: %f\n' % diameter
        fd.write(log_item)
        fd.write('solution:\n')
        nm.savetxt(fd, state())
        fd.close()

        yield None
def vary_omega1_size( problem ):
    """Vary size of \Omega1. Saves also the regions into options['output_dir'].

    Input:
      problem: ProblemDefinition instance
    Return:
      a generator object:
      1. creates new (modified) problem
      2. yields the new (modified) problem and output container
      3. use the output container for some logging
      4. yields None (to signal next iteration to Application)
    """
    from sfepy.fem import ProblemDefinition
    from sfepy.solvers.ts import get_print_info
    
    output.prefix = 'vary_omega1_size:'

    diameters = nm.linspace( 0.1, 0.6, 7 ) + 0.001
    ofn_trunk, output_format = problem.ofn_trunk, problem.output_format
    output_dir = problem.output_dir
    join = os.path.join

    conf = problem.conf
    cf = conf.get_raw( 'functions' )
    n_digit, aux, d_format = get_print_info( len( diameters ) + 1 )
    for ii, diameter in enumerate( diameters ):
        output( 'iteration %d: diameter %3.2f' % (ii, diameter) )

        cf['select_circ'] = (lambda coors, domain=None: 
                             select_circ(coors[:,0], coors[:,1], 0, diameter),)
        conf.edit('functions', cf)
        problem = ProblemDefinition.from_conf( conf )

        problem.save_regions( join( output_dir, ('regions_' + d_format) % ii ),
                              ['Omega_1'] )
        region = problem.domain.regions['Omega_1']
        if not region.has_cells_if_can():
            print region
            raise ValueError( 'region %s has no cells!' % region.name )

        ofn_trunk = ofn_trunk + '_' + (d_format % ii)
        problem.setup_output(output_filename_trunk=ofn_trunk,
                             output_dir=output_dir,
                             output_format=output_format)

        out = []
        yield problem, out

        out_problem, state = out[-1]

        filename = join( output_dir,
                         ('log_%s.txt' % d_format) % ii )
        fd = open( filename, 'w' )
        log_item = '$r(\Omega_1)$: %f\n' % diameter
        fd.write( log_item )
        fd.write( 'solution:\n' )
        nm.savetxt(fd, state())
        fd.close()

        yield None
Пример #3
0
def vary_teps(problem):
    """Vary eigenmomentum threshold."""
    from sfepy.solvers.ts import get_print_info

    output.prefix = "vary_teps:"

    if tepss_g is None:
        tepss = nm.logspace(-3, -1, 11)
    else:
        tepss = tepss_g
    ofn_trunk, output_dir = problem.ofn_trunk, problem.output_dir
    join = os.path.join

    n_digit, aux, d_format = get_print_info(len(tepss) + 1)

    for ii, teps in enumerate(tepss):
        output("iteration %d: teps %.2e" % (ii, teps))
        opts = problem.conf.options

        opts.teps = teps

        opts.plot_options["show"] = False
        opts.fig_name = join(output_dir, (("band_gaps_%s" % d_format) + "_teps_%3.2e" + fig_suffix) % (ii, teps))
        problem.ofn_trunk = ofn_trunk + "_" + (d_format % ii)

        out = []
        yield problem, out

        evp, bg = out[-1]

        filename = join(output_dir, ("band_gaps_%s.txt" % d_format) % ii)
        log_item = "$10^q$: %f\n" % teps
        save_log(filename, bg, log_item)

        yield None
Пример #4
0
    def get_animation_info(self, filename, add_output_dir=True, rng=None):
        if rng is None:
            rng = self.file_source.get_step_range()

        base, ext = os.path.splitext(filename)
        if add_output_dir:
            base = os.path.join(self.output_dir, base)

        n_digit, fmt, suffix = get_print_info(rng[1] - rng[0] + 1)
        return base, suffix, ext
Пример #5
0
        def __init__(self, t0, t1, dt=None, n_step=None, step=None, **kwargs):
            Struct.__init__(self,
                            t0=t0,
                            t1=t1,
                            dt=dt,
                            n_step=n_step,
                            step=step)

            self.n_digit, self.format, self.suffix = get_print_info(
                self.n_step)
Пример #6
0
    def get_animation_info(self, filename, add_output_dir=True, rng=None):
        if rng is None:
            rng = self.file_source.get_step_range()

        base, ext = os.path.splitext(filename)
        if add_output_dir:
            base = os.path.join(self.output_dir, base)

        n_digit, fmt, suffix = get_print_info(rng[1] - rng[0] + 1)
        return base, suffix, ext
Пример #7
0
    def get_animation_info(self, filename, add_output_dir=True, last_step=None):
        if last_step is None:
            steps, _ = self.file_source.get_ts_info()
            last_step = steps[-1]

        base, ext = os.path.splitext(filename)
        if add_output_dir:
            base = os.path.join(self.output_dir, base)

        _, _, suffix1 = get_print_info(last_step)
        return base, suffix1 + '_%.5e', ext
Пример #8
0
    def get_animation_info(self, filename, add_output_dir=True, last_step=None):
        if last_step is None:
            steps, _ = self.file_source.get_ts_info()
            last_step = steps[-1]

        base, ext = os.path.splitext(filename)
        if add_output_dir:
            base = os.path.join(self.output_dir, base)

        _, _, suffix1 = get_print_info(last_step + 1)
        return base, suffix1 + '_%.5e', ext
Пример #9
0
def vary_y3_size( problem ):
    """Vary size of Y3 inclusion."""
    from sfepy.fem import ProblemDefinition
    from sfepy.solvers.ts import get_print_info
    
    default_printer.prefix = 'vary_y3_size:'

    y3_diameters = [0.2, 0.25, 0.3, 0.35, 0.4]
    if diameters_g is None:
        y3_diameters = nm.linspace( 0.15, 0.45, 16 )
    else:
        y3_diameters = diameters_g
#    y3_diameters = [0.45]
    ofn_trunk, output_dir = problem.ofn_trunk, problem.output_dir
    join = os.path.join

    conf = problem.conf
    cr = conf.get_raw( 'regions' )
    n_digit, aux, d_format = get_print_info( len( y3_diameters ) + 1 )
    for ii, diameter in enumerate( y3_diameters ):
        output( 'iteration %d: diameter %3.2f' % (ii, diameter) )
        opts = problem.conf.options

        cr['Y3'] = ('nodes by select_y3_circ( x, y, z, %.5f )' % diameter, {})
        conf.edit( 'regions', cr )
        problem = ProblemDefinition.from_conf( conf )

        problem.save_regions( join( output_dir, ('regions_' + d_format) % ii ),
			      ['Y2', 'Y3'] )
        for region in problem.domain.regions:
            if not region.has_cells_if_can():
                raise ValueError( 'region %s has no cells!' % region.name )

        opts.plot_options['show'] = False
        opts.fig_name = join( output_dir,
                              (('band_gaps_%s' % d_format)
                               + '_y3_%03.2f' + fig_suffix) % (ii, diameter) )
        problem.ofn_trunk = ofn_trunk + '_' + (d_format % ii)
        out = []
        yield problem, out

        evp, bg = out[-1]

        filename = join( output_dir,
                         ('band_gaps_%s.txt' % d_format) % ii )
        log_item = '$r(Y_3)$: %f\n' % diameter
        save_log( filename, bg, log_item )

        yield None
Пример #10
0
def vary_y3_size(problem):
    """Vary size of Y3 inclusion."""
    from sfepy.fem import ProblemDefinition
    from sfepy.solvers.ts import get_print_info

    output.prefix = "vary_y3_size:"

    y3_diameters = [0.2, 0.25, 0.3, 0.35, 0.4]
    if diameters_g is None:
        y3_diameters = nm.linspace(0.15, 0.45, 16)
    else:
        y3_diameters = diameters_g
    #    y3_diameters = [0.45]
    ofn_trunk, output_dir = problem.ofn_trunk, problem.output_dir
    join = os.path.join

    conf = problem.conf
    cr = conf.get_raw("regions")
    n_digit, aux, d_format = get_print_info(len(y3_diameters) + 1)
    for ii, diameter in enumerate(y3_diameters):
        output("iteration %d: diameter %3.2f" % (ii, diameter))
        opts = problem.conf.options

        cr["Y3"] = ("nodes by select_y3_circ( x, y, z, %.5f )" % diameter, {})
        conf.edit("regions", cr)
        problem = ProblemDefinition.from_conf(conf)

        problem.save_regions(join(output_dir, ("regions_" + d_format) % ii), ["Y2", "Y3"])
        for region in problem.domain.regions:
            if not region.has_cells_if_can():
                raise ValueError("region %s has no cells!" % region.name)

        opts.plot_options["show"] = False
        opts.fig_name = join(output_dir, (("band_gaps_%s" % d_format) + "_y3_%03.2f" + fig_suffix) % (ii, diameter))
        problem.ofn_trunk = ofn_trunk + "_" + (d_format % ii)
        out = []
        yield problem, out

        evp, bg = out[-1]

        filename = join(output_dir, ("band_gaps_%s.txt" % d_format) % ii)
        log_item = "$r(Y_3)$: %f\n" % diameter
        save_log(filename, bg, log_item)

        yield None