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 pde_solve 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 = pde_solve(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')
def run(self): sol = pde_solve(self.gui.input_filename, output_dir=self.gui.output_dir) do_later(assign_solution_to_gui, self.gui, sol)