Exemple #1
0
    def calculate_req(problem, opts, volume, post_process_hook, name, req_info,
                      coef_info, sd_names, dependencies):
        # compute coefficient
        if name.startswith('c.'):
            coef_name = name[2:]

            output('computing %s...' % coef_name)

            cargs = coef_info[coef_name]
            mini_app = MiniAppBase.any_from_conf(coef_name, problem, cargs)
            problem.clear_equations()

            # Pass only the direct dependencies, not the indirect ones.
            dep_requires = cargs.get('requires', [])
            data = {key: dependencies[key] for key in dep_requires}

            val = mini_app(volume, data=data)

            output('...done')

        # compute corrector(s)
        else:
            output('computing dependency %s...' % name)

            rargs = req_info[name]
            mini_app = MiniAppBase.any_from_conf(name, problem, rargs)
            mini_app.setup_output(save_format=opts.save_format,
                                  dump_format=opts.dump_format,
                                  post_process_hook=post_process_hook,
                                  file_per_var=opts.file_per_var)

            if not '(not_set)' in mini_app.get_save_name_base():
                sd_names['s.' + mini_app.name] = mini_app.get_save_name_base()
            if not '(not_set)' in mini_app.get_dump_name_base():
                sd_names['d.' + mini_app.name] = mini_app.get_dump_name_base()

            problem.clear_equations()

            # Pass only the direct dependencies, not the indirect ones.
            dep_requires = rargs.get('requires', [])
            data = {key: dependencies[key] for key in dep_requires}

            val = mini_app(data=data)

            output('...done')

        return val
Exemple #2
0
    def calculate_req(problem, opts, volume, post_process_hook,
                      name, req_info, coef_info, sd_names, dependencies):
        # compute coefficient
        if name.startswith('c.'):
            coef_name = name[2:]

            output('computing %s...' % coef_name)

            cargs = coef_info[coef_name]
            mini_app = MiniAppBase.any_from_conf(coef_name, problem, cargs)
            problem.clear_equations()

            # Pass only the direct dependencies, not the indirect ones.
            dep_requires = cargs.get('requires', [])
            data = {key: dependencies[key] for key in dep_requires}

            val = mini_app(volume, data=data)

            output('...done')

        # compute corrector(s)
        else:
            output('computing dependency %s...' % name)

            rargs = req_info[name]
            mini_app = MiniAppBase.any_from_conf(name, problem, rargs)
            mini_app.setup_output(save_format=opts.save_format,
                                  dump_format=opts.dump_format,
                                  post_process_hook=post_process_hook,
                                  file_per_var=opts.file_per_var)

            if not '(not_set)' in mini_app.get_save_name_base():
                sd_names['s.' + mini_app.name] = mini_app.get_save_name_base()
            if not '(not_set)' in mini_app.get_dump_name_base():
                sd_names['d.' + mini_app.name] = mini_app.get_dump_name_base()

            problem.clear_equations()

            # Pass only the direct dependencies, not the indirect ones.
            dep_requires = rargs.get('requires', [])
            data = {key: dependencies[key] for key in dep_requires}

            val = mini_app(data=data)

            output('...done')

        return val
Exemple #3
0
    def compute_requirements( self, requirements, dependencies, store ):
        problem = self.problem

        opts = self.app_options
        req_info = getattr( self.conf, opts.requirements )

        requires = insert_sub_reqs( copy( requirements ), [], req_info )
        
        for req in requires:
            if req in dependencies and (dependencies[req] is not None):
                continue

            output( 'computing dependency %s...' % req )

            rargs = req_info[req]

            mini_app = MiniAppBase.any_from_conf( req, problem, rargs )
            mini_app.setup_output( save_format = opts.save_format,
                                   dump_format = opts.dump_format,
                                   post_process_hook = self.post_process_hook,
                                   file_per_var = opts.file_per_var )
            store( mini_app )

            problem.clear_equations()

            # Pass only the direct dependencies, not the indirect ones.
            dep_requires = rargs.get('requires', [])
            data = {}
            for key in dep_requires:
                data[key] = dependencies[key]

            dep = mini_app(data=data)

            dependencies[req] = dep
            output( '...done' )

        return dependencies
Exemple #4
0
    def compute_requirements( self, requirements, dependencies, store ):
        problem = self.problem

        opts = self.app_options
        req_info = getattr( self.conf, opts.requirements )

        requires = insert_sub_reqs( copy( requirements ), [], req_info )
        
        for req in requires:
            if req in dependencies and (dependencies[req] is not None):
                continue

            output( 'computing dependency %s...' % req )

            rargs = req_info[req]

            mini_app = MiniAppBase.any_from_conf( req, problem, rargs )
            mini_app.setup_output( save_format = opts.save_format,
                                   dump_format = opts.dump_format,
                                   post_process_hook = self.post_process_hook,
                                   file_per_var = opts.file_per_var )
            store( mini_app )

            problem.clear_equations()

            # Pass only the direct dependencies, not the indirect ones.
            dep_requires = rargs.get('requires', [])
            data = {}
            for key in dep_requires:
                data[key] = dependencies[key]

            dep = mini_app(data=data)

            dependencies[req] = dep
            output( '...done' )

        return dependencies
Exemple #5
0
    def call( self, ret_all = False ):
        problem = self.problem

        opts = self.app_options
        coef_info = getattr( self.conf, opts.coefs )

        is_store_filenames = coef_info.pop('filenames', None) is not None

        dependencies = {}
        save_names = {}
        dump_names = {}
        def store_filenames( app ):
            if not '(not_set)' in app.get_save_name_base():
                save_names[app.name] = app.get_save_name_base()
            if not '(not_set)' in app.get_dump_name_base():
                dump_names[app.name] = app.get_dump_name_base()

        def _get_parents(req_list):
            out = []
            for req_name in req_list:
                aux = req_name.split('.')
                if len(aux) == 2:
                    out.append(aux[1])
            return out

        # Some coefficients can require other coefficients - resolve theirorder
        # here.
        graph = {}
        for coef_name, cargs in coef_info.iteritems():
            if not coef_name in graph:
                graph[coef_name] = [0]

            requires = cargs.get('requires', [])
            for parent in _get_parents(requires):
                graph[coef_name].append(parent)
                requires.remove('c.' + parent)
            
        sorted_coef_names = sort_by_dependency(deepcopy(graph))
        ## print graph
        ## print sorted_coef_names
        
        coefs = Struct()
        for coef_name in sorted_coef_names:
            cargs = coef_info[coef_name]
            output( 'computing %s...' % coef_name )
            requires = cargs.get( 'requires', [] )

            self.compute_requirements( requires, dependencies, store_filenames )

            mini_app = MiniAppBase.any_from_conf( coef_name, problem, cargs )
            if len(graph[coef_name]) > 1:
                for name in graph[coef_name][1:]:
                    key = 'c.' + name
                    requires.append(key)
                    dependencies[key] = getattr(coefs, name)

            problem.clear_equations()

            # Pass only the direct dependencies, not the indirect ones.
            data = {}
            for key in requires:
                data[key] = dependencies[key]

            val = mini_app(self.volume, data=data)
            setattr( coefs, coef_name, val )
            output( '...done' )

        # Store filenames of all requirements as a "coefficient".
        if is_store_filenames:
            coefs.save_names = save_names
            coefs.dump_names = dump_names
            
        if ret_all:
            return coefs, dependencies
        else:
            return coefs
Exemple #6
0
    def call( self, ret_all = False ):
        problem = self.problem

        opts = self.app_options
        coef_info = getattr( self.conf, opts.coefs )

        compute_names = set(get_default(opts.compute_only, coef_info.keys()))
        compute_names = ['c.' + key for key in compute_names]

        is_store_filenames = coef_info.pop('filenames', None) is not None
        try:
            compute_names.remove('c.filenames')
        except:
            pass

        dependencies = {}
        save_names = {}
        dump_names = {}
        def store_filenames( app ):
            if not '(not_set)' in app.get_save_name_base():
                save_names[app.name] = app.get_save_name_base()
            if not '(not_set)' in app.get_dump_name_base():
                dump_names[app.name] = app.get_dump_name_base()

        # Some coefficients can require other coefficients - resolve their
        # order here.
        req_info = self.conf.get(opts.requirements, {})
        info = copy(coef_info)
        info.update(req_info)
        all_deps = set(compute_names)
        sorted_names = []
        for coef_name in compute_names:
            cargs = coef_info[coef_name[2:]]
            requires = cargs.get('requires', [])
            deps = insert_sub_reqs(copy(requires), [], info)
            all_deps.update(deps)

            aux = [key for key in deps if key.startswith('c.')] + [coef_name]
            sorted_names.extend(aux)

        sorted_coef_names = []
        for name in sorted_names:
            if name[2:] not in sorted_coef_names:
                sorted_coef_names.append(name[2:])

        coefs = Struct()
        for coef_name in sorted_coef_names:
            cargs = coef_info[coef_name]
            output('computing %s...' % coef_name)
            requires = cargs.get('requires', [])
            requirements = [name for name in requires if not
                            name.startswith('c.')]

            self.compute_requirements(requirements, dependencies,
                                      store_filenames)

            for name in requires:
                if name.startswith('c.'):
                    dependencies[name] = getattr(coefs, name[2:])

            mini_app = MiniAppBase.any_from_conf( coef_name, problem, cargs )

            problem.clear_equations()

            # Pass only the direct dependencies, not the indirect ones.
            data = {}
            for key in requires:
                data[key] = dependencies[key]

            val = mini_app(self.volume, data=data)
            setattr(coefs, coef_name, val)
            output( '...done' )

        # remove "auxiliary" coefs
        for coef_name in sorted_coef_names:
            cstat = coef_info[coef_name].get('status', 'main')
            if cstat == 'auxiliary':
                delattr(coefs, coef_name)

        # Store filenames of all requirements as a "coefficient".
        if is_store_filenames:
            coefs.save_names = save_names
            coefs.dump_names = dump_names

        if opts.coefs_info is not None:
            coefs.info = opts.coefs_info

        if ret_all:
            return coefs, dependencies
        else:
            return coefs