def view_file(filename, filter_names, options, view=None): if view is None: view = Viewer( filename, watch=options.watch, animate=options.anim_format is not None, anim_format=options.anim_format, ffmpeg_options=options.ffmpeg_options, output_dir=options.output_dir, offscreen=not options.show, ) if options.only_names is not None: options.only_names = options.only_names.split(",") view( show=options.show, is_3d=options.is_3d, view=options.view, roll=options.roll, layout=options.layout, scalar_mode=options.scalar_mode, vector_mode=options.vector_mode, rel_scaling=options.rel_scaling, clamping=options.clamping, ranges=options.ranges, is_scalar_bar=options.is_scalar_bar, is_wireframe=options.is_wireframe, rel_text_width=options.rel_text_width, fig_filename=options.filename, resolution=options.resolution, filter_names=filter_names, only_names=options.only_names, group_names=options.group_names, step=options.step, anti_aliasing=options.anti_aliasing, ) else: view.set_source_filename(filename) view.save_image(options.filename) return view
def view_file(filename, filter_names, options, view=None): if view is None: if options.show: offscreen = False else: offscreen = get_default(options.offscreen, True) view = Viewer(filename, watch=options.watch, animate=options.anim_format is not None, anim_format=options.anim_format, ffmpeg_options=options.ffmpeg_options, output_dir=options.output_dir, offscreen=offscreen) if options.only_names is not None: options.only_names = options.only_names.split(',') view(show=options.show, is_3d=options.is_3d, view=options.view, roll=options.roll, fgcolor=options.fgcolor, bgcolor=options.bgcolor, layout=options.layout, scalar_mode=options.scalar_mode, vector_mode=options.vector_mode, rel_scaling=options.rel_scaling, clamping=options.clamping, ranges=options.ranges, is_scalar_bar=options.is_scalar_bar, is_wireframe=options.is_wireframe, opacity=options.opacity, subdomains_args=options.subdomains_args, rel_text_width=options.rel_text_width, fig_filename=options.filename, resolution=options.resolution, filter_names=filter_names, only_names=options.only_names, group_names=options.group_names, step=options.step, anti_aliasing=options.anti_aliasing, domain_specific=options.domain_specific) else: view.set_source_filename(filename) view.save_image(options.filename) return view
def main(): from sfepy import data_dir parser = OptionParser(usage=usage, version='%prog') parser.add_option('-s', '--show', action="store_true", dest='show', default=False, help=help['show']) options, args = parser.parse_args() mesh = Mesh.from_file(data_dir + '/meshes/2d/rectangle_tri.mesh') domain = Domain('domain', mesh) min_x, max_x = domain.get_mesh_bounding_box()[:, 0] eps = 1e-8 * (max_x - min_x) omega = domain.create_region('Omega', 'all') gamma1 = domain.create_region('Gamma1', 'nodes in x < %.10f' % (min_x + eps)) gamma2 = domain.create_region('Gamma2', 'nodes in x > %.10f' % (max_x - eps)) field = H1NodalVolumeField('fu', nm.float64, 'vector', omega, approx_order=2) u = FieldVariable('u', 'unknown', field, mesh.dim) v = FieldVariable('v', 'test', field, mesh.dim, primary_var_name='u') m = Material('m', lam=1.0, mu=1.0) f = Material('f', val=[[0.02], [0.01]]) integral = Integral('i', order=3) t1 = Term.new('dw_lin_elastic_iso(m.lam, m.mu, v, u)', integral, omega, m=m, v=v, u=u) t2 = Term.new('dw_volume_lvf(f.val, v)', integral, omega, f=f, v=v) eq = Equation('balance', t1 + t2) eqs = Equations([eq]) fix_u = EssentialBC('fix_u', gamma1, {'u.all': 0.0}) bc_fun = Function('shift_u_fun', shift_u_fun, extra_args={'shift': 0.01}) shift_u = EssentialBC('shift_u', gamma2, {'u.0': bc_fun}) ls = ScipyDirect({}) nls_status = IndexedStruct() nls = Newton({}, lin_solver=ls, status=nls_status) pb = ProblemDefinition('elasticity', equations=eqs, nls=nls, ls=ls) pb.save_regions_as_groups('regions') pb.time_update(ebcs=Conditions([fix_u, shift_u])) vec = pb.solve() print nls_status pb.save_state('linear_elasticity.vtk', vec) if options.show: view = Viewer('linear_elasticity.vtk') view(vector_mode='warp_norm', rel_scaling=2, is_scalar_bar=True, is_wireframe=True)
def generate_images(images_dir, examples_dir): """ Generate images from results of running examples found in `examples_dir` directory. The generated images are stored to `images_dir`, """ from sfepy.applications import solve_pde from sfepy.postprocess import Viewer from sfepy.postprocess.utils import mlab prefix = output.prefix output_dir = tempfile.mkdtemp() trunk = os.path.join(output_dir, 'result') options = Struct(output_filename_trunk=trunk, output_format='vtk', save_ebc=False, save_ebc_nodes=False, save_regions=False, save_field_meshes=False, save_regions_as_groups=False, solve_not=False) default_views = {'' : {}} ensure_path(images_dir + os.path.sep) view = Viewer('', offscreen=False) for ex_filename in locate_files('*.py', examples_dir): if _omit(ex_filename): continue output.level = 0 output.prefix = prefix ebase = ex_filename.replace(examples_dir, '')[1:] output('trying "%s"...' % ebase) try: problem, state = solve_pde(ex_filename, options=options) except KeyboardInterrupt: raise except: problem = None output('***** failed! *****') if problem is not None: if ebase in custom: views = custom[ebase] else: views = default_views tsolver = problem.get_time_solver() if tsolver.ts is None: suffix = None else: suffix = tsolver.ts.suffix % (tsolver.ts.n_step - 1) filename = problem.get_output_name(suffix=suffix) for suffix, kwargs in views.iteritems(): fig_filename = _get_fig_filename(ebase, images_dir, suffix) fname = edit_filename(filename, suffix=suffix) output('displaying results from "%s"' % fname) disp_name = fig_filename.replace(sfepy.data_dir, '') output('to "%s"...' % disp_name.lstrip(os.path.sep)) view.filename = fname view(scene=view.scene, show=False, is_scalar_bar=True, fig_filename=fig_filename, **kwargs) mlab.clf() output('...done') remove_files(output_dir) output('...done')
def generate_images(images_dir, examples_dir): """ Generate images from results of running examples found in `examples_dir` directory. The generated images are stored to `images_dir`, """ from sfepy.applications import solve_pde from sfepy.postprocess import Viewer from sfepy.postprocess.utils import mlab prefix = output.prefix output_dir = tempfile.mkdtemp() trunk = os.path.join(output_dir, "result") options = Struct( output_filename_trunk=trunk, output_format="vtk", save_ebc=False, save_regions=False, save_field_meshes=False, save_regions_as_groups=False, solve_not=False, ) ensure_path(images_dir + os.path.sep) view = Viewer("", output_dir=output_dir, offscreen=False) for ex_filename in locate_files("*.py", examples_dir): if _omit(ex_filename): continue output.level = 0 output.prefix = prefix ebase = ex_filename.replace(examples_dir, "")[1:] output('trying "%s"...' % ebase) try: problem, state = solve_pde(ex_filename, options=options) except KeyboardInterrupt: raise except: problem = None output("***** failed! *****") if problem is not None: fig_filename = _get_fig_filename(ebase, images_dir)[1] if problem.ts_conf is None: filename = trunk + ".vtk" else: suffix = problem.ts.suffix % problem.ts.step filename = problem.get_output_name(suffix=suffix) output('displaying results from "%s"' % filename) output('to "%s"...' % fig_filename.replace(sfepy.data_dir, "")[1:]) view.filename = filename view(scene=view.scene, show=False, is_scalar_bar=True, fig_filename=fig_filename) mlab.clf() output("...done") remove_files(output_dir) output("...done")