当前位置: 首页>>代码示例>>Python>>正文


Python ProblemDefinition.from_conf方法代码示例

本文整理汇总了Python中sfepy.fem.ProblemDefinition.from_conf方法的典型用法代码示例。如果您正苦于以下问题:Python ProblemDefinition.from_conf方法的具体用法?Python ProblemDefinition.from_conf怎么用?Python ProblemDefinition.from_conf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfepy.fem.ProblemDefinition的用法示例。


在下文中一共展示了ProblemDefinition.from_conf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: vary_omega1_size

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
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
开发者ID:AshitaPrasad,项目名称:sfepy,代码行数:62,代码来源:poisson_parametric_study.py

示例2: main

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
def main():
    from sfepy.base.base import output
    from sfepy.base.conf import ProblemConf, get_standard_keywords
    from sfepy.fem import ProblemDefinition
    from sfepy.applications import solve_evolutionary

    output.prefix = 'therel:'

    required, other = get_standard_keywords()
    conf = ProblemConf.from_file(__file__, required, other)

    problem = ProblemDefinition.from_conf(conf, init_equations=False)

    # Setup output directory according to options above.
    problem.setup_default_output()

    # First solve the stationary electric conduction problem.
    problem.set_equations({'eq' : conf.equations['1']})
    problem.time_update()
    state_el = problem.solve()
    problem.save_state(problem.get_output_name(suffix = 'el'), state_el)

    # Then solve the evolutionary heat conduction problem, using state_el.
    problem.set_equations({'eq' : conf.equations['2']})
    phi_var = problem.get_variables()['phi_known']
    phi_var.data_from_any(state_el())
    solve_evolutionary(problem)

    output('results saved in %s' % problem.get_output_name(suffix = '*'))
开发者ID:mikegraham,项目名称:sfepy,代码行数:31,代码来源:thermal_electric.py

示例3: from_conf

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
    def from_conf( conf, options ):
        from sfepy.fem import ProblemDefinition

        problem = ProblemDefinition.from_conf(conf, init_equations=False)
        test = Test( problem = problem,
                     conf = conf, options = options )
        return test
开发者ID:olivierverdier,项目名称:sfepy,代码行数:9,代码来源:test_term_consistency.py

示例4: save_only

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
def save_only( conf, save_names, problem = None ):
    """Save information available prior to setting equations and
    solving them."""
    if problem is None:
        problem = ProblemDefinition.from_conf( conf, init_variables = False )

    if save_names.regions is not None:
        problem.save_regions( save_names.regions )

    if save_names.field_meshes is not None:
        problem.save_field_meshes( save_names.field_meshes )

    if save_names.region_field_meshes is not None:
        problem.save_region_field_meshes( save_names.region_field_meshes )

    if save_names.ebc is not None:
        if not hasattr( problem, 'variables' ):
            problem.set_variables( conf.variables )
        try:
            ts = TimeStepper.from_conf( conf.ts )
            ts.set_step( 0 )
        except:
            ts = None
        try:
            problem.variables.equation_mapping( conf.ebcs, conf.epbcs,
                                                problem.domain.regions, ts,
                                                conf.funmod )
        except Exception, e:
            output( 'cannot make equation mapping!' )
            output( 'reason: %s' % e )
        else:
            problem.save_ebc( save_names.ebc )
开发者ID:certik,项目名称:sfepy,代码行数:34,代码来源:generic.py

示例5: main

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
def main():
    from sfepy.base.conf import ProblemConf, get_standard_keywords
    from sfepy.fem import ProblemDefinition
    from sfepy.base.plotutils import plt

    parser = OptionParser(usage=usage, version='%prog')
    parser.add_option('-n', '--no-plot',
                      action="store_true", dest='no_plot',
                      default=False, help=helps['no_plot'])
    options, args = parser.parse_args()

    required, other = get_standard_keywords()
    # Use this file as the input file.
    conf = ProblemConf.from_file( __file__, required, other )

    # Create problem instance, but do not set equations.
    problem = ProblemDefinition.from_conf( conf,
                                           init_equations = False )

    # Solve the problem. Output is ignored, results stored by using the
    # step_hook.
    u_t = solve_branch(problem, linear_tension)
    u_c = solve_branch(problem, linear_compression)

    # Get pressure load by calling linear_*() for each time step.
    ts = problem.get_timestepper()
    load_t = nm.array([linear_tension(ts, nm.array([[0.0]]), 'qp')['val']
                       for aux in ts.iter_from( 0 )],
                      dtype=nm.float64).squeeze()
    load_c = nm.array([linear_compression(ts, nm.array([[0.0]]), 'qp')['val']
                       for aux in ts.iter_from( 0 )],
                      dtype=nm.float64).squeeze()

    # Join the branches.
    displacements = {}
    for key in u_t.keys():
        displacements[key] = nm.r_[u_c[key][::-1], u_t[key]]
    load = nm.r_[load_c[::-1], load_t]


    if plt is None:
        print 'matplotlib cannot be imported, printing raw data!'
        print displacements
        print load
    else:
        legend = []
        for key, val in displacements.iteritems():
            plt.plot( load, val )
            legend.append( key )

        plt.legend( legend, loc = 2 )
        plt.xlabel( 'tension [kPa]' )
        plt.ylabel( 'displacement [mm]' )
        plt.grid( True )

        plt.gcf().savefig( 'pressure_displacement.png' )

        if not options.no_plot:
            plt.show()
开发者ID:AshitaPrasad,项目名称:sfepy,代码行数:61,代码来源:compare_elastic_materials.py

示例6: from_conf

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
    def from_conf(conf, options):
        from sfepy.fem import ProblemDefinition

        problem = ProblemDefinition.from_conf(conf)
        problem.time_update()

        test = Test(problem=problem, conf=conf, options=options)
        return test
开发者ID:certik,项目名称:sfepy,代码行数:10,代码来源:test_linear_solvers.py

示例7: solve_direct

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
def solve_direct(conf, options, problem=None, step_hook=None,
                 post_process_hook=None, post_process_hook_final=None,
                 pre_process_hook=None, nls_status=None):
    """Generic (simple) problem solver."""

    if problem is None:
        is_eqs = not options.solve_not
        problem = ProblemDefinition.from_conf(conf, init_equations=is_eqs)

        problem.setup_default_output(conf, options)

    if pre_process_hook is not None: # User pre_processing.
        pre_process_hook(problem)

    ofn_trunk = problem.ofn_trunk

    save_names = Struct( ebc = None, regions = None,
                         regions_as_groups = None, field_meshes = None,
                         region_field_meshes = None )
    if options.save_ebc:
        save_names.ebc = ofn_trunk + '_ebc.vtk'
    if options.save_regions:
        save_names.regions = ofn_trunk + '_region'
    if options.save_regions_as_groups:
        save_names.regions_as_groups = ofn_trunk + '_regions'
    if options.save_field_meshes:
        save_names.field_meshes = ofn_trunk + '_field'

    is_extra_save = False
    for name, val in save_names.to_dict().iteritems():
        if val is not None:
            is_extra_save = True
            break
    if is_extra_save:
        save_only( conf, save_names, problem=problem )

    if options.solve_not:
        return None, None, None

    if hasattr( conf.options, 'ts' ):
        ##
        # Time-dependent problem.
        state = solve_evolutionary_op(problem, options,
                                      step_hook=step_hook,
                                      post_process_hook=post_process_hook,
                                      nls_status=nls_status)
    else:
        ##
        # Stationary problem.
        state = solve_stationary_op(problem, options,
                                    post_process_hook=post_process_hook,
                                    nls_status=nls_status)

    if post_process_hook_final is not None: # User postprocessing.
       post_process_hook_final(problem, state)

    return problem, state
开发者ID:renatocoutinho,项目名称:sfepy,代码行数:59,代码来源:generic.py

示例8: solve_stationary

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
def solve_stationary(conf, save_names=None, nls_status=None):

    problem = ProblemDefinition.from_conf( conf )

    problem.time_update( None )

    if save_names is not None:
        save_only( conf, save_names, problem = problem )

    state = problem.solve( nls_status = nls_status )

    return problem, state
开发者ID:renatocoutinho,项目名称:sfepy,代码行数:14,代码来源:generic.py

示例9: main

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
def main():
    from sfepy.base.conf import ProblemConf, get_standard_keywords
    from sfepy.fem import ProblemDefinition
    from sfepy.base.plotutils import pylab

    required, other = get_standard_keywords()
    # Use this file as the input file.
    conf = ProblemConf.from_file( __file__, required, other )

    # Create problem instance, but do not set equations.
    problem = ProblemDefinition.from_conf( conf,
                                           init_equations = False )

    options = Struct( output_filename_trunk = None )
    
    # Solve the problem. Output is ignored, results stored by using the
    # step_hook.
    u_t = solve_branch( problem, options, linear_tension )
    u_c = solve_branch( problem, options, linear_compression )

    # Get pressure load by calling linear_*() for each time step.
    ts = problem.get_timestepper()
    load_t = nm.array( [linear_tension( ts, nm.array( [[0.0]] ) )['val']
                        for aux in ts.iter_from( 0 )],
                       dtype = nm.float64 ).squeeze()
    load_c = nm.array( [linear_compression( ts, nm.array( [[0.0]] ) )['val']
                        for aux in ts.iter_from( 0 )],
                       dtype = nm.float64 ).squeeze()

    # Join the branches.
    displacements = {}
    for key in u_t.keys():
        displacements[key] = nm.r_[u_c[key][::-1], u_t[key]]
    load = nm.r_[load_c[::-1], load_t]

    if pylab is None:
        print 'pylab cannot be imported, printing raw data!'
        print displacements
        print load
    else:
        legend = []
        for key, val in displacements.iteritems():
            pylab.plot( load, val )
            legend.append( key )

        pylab.legend( legend, loc = 2 )
        pylab.xlabel( 'tension [kPa]' )
        pylab.ylabel( 'displacement [mm]' )
        pylab.grid( True )

        pylab.gcf().savefig( 'pressure_displacement.png' )
        pylab.show()
开发者ID:certik,项目名称:sfepy,代码行数:54,代码来源:compare_elastic_materials.py

示例10: __init__

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
    def __init__(self, conf, options, output_prefix, init_equations=True, **kwargs):
        """`kwargs` are passed to  ProblemDefinition.from_conf()

        Command-line options have precedence over conf.options."""
        Application.__init__(self, conf, options, output_prefix)
        self.setup_options()

        is_eqs = init_equations
        if hasattr(options, "solve_not") and options.solve_not:
            is_eqs = False
        self.problem = ProblemDefinition.from_conf(conf, init_equations=is_eqs, **kwargs)

        self.setup_output_info(self.problem, self.options)
开发者ID:sdurve,项目名称:sfepy,代码行数:15,代码来源:pde_solver_app.py

示例11: vary_y3_size

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
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
开发者ID:certik,项目名称:sfepy,代码行数:51,代码来源:band_gaps_rigid.py

示例12: solve_stationary

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
def solve_stationary( conf, data = None, save_names = None, nls_status = None ):

    if data is None:
        # Term-dependent data.
        data = {}
    problem = ProblemDefinition.from_conf( conf )

    problem.time_update( None )

    if save_names is not None:
        save_only( conf, save_names, problem = problem )

    state = problem.solve( nls_status = nls_status )

    return problem, state, data
开发者ID:certik,项目名称:sfepy,代码行数:17,代码来源:generic.py

示例13: solve_direct

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
def solve_direct( conf, options, problem = None, step_hook = None,
                  post_process_hook = None ):
    """Generic (simple) problem solver."""
    if problem is None:
	problem = ProblemDefinition.from_conf( conf )
	if options.output_filename_trunk:
	    ofn_trunk = options.output_filename_trunk
	    problem.ofn_trunk = ofn_trunk
	if options.output_format:
	    problem.output_format = options.output_format
    ofn_trunk = problem.ofn_trunk
    
    save_names = Struct( ebc = None, regions = None, field_meshes = None,
                         region_field_meshes = None )
    if options.save_ebc:
        save_names.ebc = ofn_trunk + '_ebc.vtk'
    if options.save_regions:
        save_names.regions = ofn_trunk + '_region'
    if options.save_field_meshes:
        save_names.field_meshes = ofn_trunk + '_field'
    if options.save_region_field_meshes:
        save_names.region_field_meshes = ofn_trunk + '_region_field'

    is_extra_save = False
    for name, val in save_names.to_dict().iteritems():
        if val is not None:
            is_extra_save = True
            break
    if is_extra_save:
        save_only( conf, save_names )

    if options.solve_not:
        return None, None, None
            
    if hasattr( conf.options, 'ts' ):
        ##
        # Time-dependent problem.
        out = solve_evolutionary_op( problem, options,
				     post_process_hook = post_process_hook,
                                     step_hook = step_hook )
    else:
        ##
        # Stationary problem.
        out = solve_stationary_op( problem, options,
				   post_process_hook = post_process_hook )

    state, data = out
    return problem, state, data
开发者ID:certik,项目名称:sfepy,代码行数:50,代码来源:generic.py

示例14: save_only

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
def save_only( conf, save_names, problem = None ):
    """Save information available prior to setting equations and
    solving them."""
    if problem is None:
        problem = ProblemDefinition.from_conf(conf, init_equations=False)

    if save_names.regions is not None:
        problem.save_regions( save_names.regions )

    if save_names.regions_as_groups is not None:
        problem.save_regions_as_groups( save_names.regions_as_groups )

    if save_names.field_meshes is not None:
        problem.save_field_meshes( save_names.field_meshes )

    if save_names.ebc is not None:
        problem.save_ebc( save_names.ebc )
开发者ID:renatocoutinho,项目名称:sfepy,代码行数:19,代码来源:generic.py

示例15: vary_y3_size

# 需要导入模块: from sfepy.fem import ProblemDefinition [as 别名]
# 或者: from sfepy.fem.ProblemDefinition import from_conf [as 别名]
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
开发者ID:olivierverdier,项目名称:sfepy,代码行数:47,代码来源:band_gaps_rigid.py


注:本文中的sfepy.fem.ProblemDefinition.from_conf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。