<commit_before>import os.path as op

from sfepy.base.base import *
import sfepy.base.ioutils as io
from sfepy.fem import ProblemDefinition
from sfepy.solvers.generic import solve_direct
from application import Application

class SimpleApp( Application ):

    def process_options( options ):
        """Application options setup. Sets default values for missing
        non-compulsory options."""
        get = options.get_default_attr

        save_results = get( 'save_results', True )
        # Save each variable into a separate file, using the region of its
        # definition only.
        file_per_var = get( 'file_per_var', False )
        output_format = get( 'output_format', 'vtk' )

        output_dir = get( 'output_dir', '.' )
        if not os.path.exists( output_dir ):
            os.makedirs( output_dir )

        # Called after each time step, can do anything, no return value.
        step_hook = get( 'step_hook', None )
        # Called after each time step.
        post_process_hook = get( 'post_process_hook', None )
        # Called after all time steps, or in the stationary case.
        post_process_hook_final = get( 'post_process_hook_final', None )

        return Struct( **locals() )
    process_options = staticmethod( process_options )

    def __init__( self, conf, options, output_prefix, **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()

        self.problem = ProblemDefinition.from_conf( conf, **kwargs )

        self.setup_output_info( self.problem, self.options )

    def setup_options( self ):
        self.app_options = SimpleApp.process_options( self.conf.options )
        funmod = self.conf.funmod
        
        hook = self.app_options.step_hook
        if hook is not None:
            hook = getattr( funmod, hook )
        self.step_hook = hook

        hook = self.app_options.post_process_hook
        if hook is not None:
            hook = getattr( funmod, hook )
        self.post_process_hook = hook

        hook = self.app_options.post_process_hook_final
        if hook is not None:
            hook = getattr( funmod, hook )
        self.post_process_hook_final = hook

    def setup_output_info( self, problem, options ):
        """Modifies both problem and options!"""
        if options.output_filename_trunk is None:
            ofn_trunk = op.join( self.app_options.output_dir,
                                 io.get_trunk( self.conf.filename_mesh ) )
	    options.output_filename_trunk = ofn_trunk
	else:
            ofn_trunk = options.output_filename_trunk

        problem.ofn_trunk = ofn_trunk
        problem.output_dir = self.app_options.output_dir

        if hasattr( options, 'output_format' ):
            problem.output_format = options.output_format
        else:
            problem.output_format = self.app_options.output_format

    def call( self ):
        opts = self.app_options
	dpb, vec_dp, data = solve_direct( self.conf, self.options,
					  problem = self.problem,
                                          step_hook = opts.step_hook,
                                          post_process_hook = \
                                          opts.post_process_hook )

	if opts.post_process_hook_final is not None: # User postprocessing.
	    opts.post_process_hook_final( dpb, vec_dp, data )

	return dpb, vec_dp, data<commit_msg>fixed passing hook arguments in SimpleApp.call()<commit_after>import os.path as op

from sfepy.base.base import *
import sfepy.base.ioutils as io
from sfepy.fem import ProblemDefinition
from sfepy.solvers.generic import solve_direct
from application import Application

class SimpleApp( Application ):

    def process_options( options ):
        """Application options setup. Sets default values for missing
        non-compulsory options."""
        get = options.get_default_attr

        save_results = get( 'save_results', True )
        # Save each variable into a separate file, using the region of its
        # definition only.
        file_per_var = get( 'file_per_var', False )
        output_format = get( 'output_format', 'vtk' )

        output_dir = get( 'output_dir', '.' )
        if not os.path.exists( output_dir ):
            os.makedirs( output_dir )

        # Called after each time step, can do anything, no return value.
        step_hook = get( 'step_hook', None )
        # Called after each time step.
        post_process_hook = get( 'post_process_hook', None )
        # Called after all time steps, or in the stationary case.
        post_process_hook_final = get( 'post_process_hook_final', None )

        return Struct( **locals() )
    process_options = staticmethod( process_options )

    def __init__( self, conf, options, output_prefix, **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()

        self.problem = ProblemDefinition.from_conf( conf, **kwargs )

        self.setup_output_info( self.problem, self.options )

    def setup_options( self ):
        self.app_options = SimpleApp.process_options( self.conf.options )
        funmod = self.conf.funmod
        
        hook = self.app_options.step_hook
        if hook is not None:
            hook = getattr( funmod, hook )
        self.step_hook = hook

        hook = self.app_options.post_process_hook
        if hook is not None:
            hook = getattr( funmod, hook )
        self.post_process_hook = hook

        hook = self.app_options.post_process_hook_final
        if hook is not None:
            hook = getattr( funmod, hook )
        self.post_process_hook_final = hook

    def setup_output_info( self, problem, options ):
        """Modifies both problem and options!"""
        if options.output_filename_trunk is None:
            ofn_trunk = op.join( self.app_options.output_dir,
                                 io.get_trunk( self.conf.filename_mesh ) )
	    options.output_filename_trunk = ofn_trunk
	else:
            ofn_trunk = options.output_filename_trunk

        problem.ofn_trunk = ofn_trunk
        problem.output_dir = self.app_options.output_dir

        if hasattr( options, 'output_format' ):
            problem.output_format = options.output_format
        else:
            problem.output_format = self.app_options.output_format

    def call( self ):
	dpb, vec_dp, data = solve_direct( self.conf, self.options,
					  problem = self.problem,
                                          step_hook = self.step_hook,
                                          post_process_hook = \
                                          self.post_process_hook )

	if self.post_process_hook_final is not None: # User postprocessing.
	    self.post_process_hook_final( dpb, vec_dp, data )

	return dpb, vec_dp, data
{'fraction_non_alphanumeric': 0.07960834397616007, 'fraction_numerical': 0.0, 'mean_word_length': 2.3042662916080636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1861293', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1940, 'n_words': 536}