def __call__(self, problem=None, data=None): from sfepy.base.base import select_by_names from sfepy.fem.variables import Variables from sfepy.fem.state import State from sfepy.fem.conditions import Conditions problem = get_default(problem, self.problem) conf_ebc = select_by_names(problem.conf.ebcs, self.ebcs) conf_epbc = select_by_names(problem.conf.epbcs, self.epbcs) ebcs = Conditions.from_conf(conf_ebc, problem.domain.regions) epbcs = Conditions.from_conf(conf_epbc, problem.domain.regions) conf_variables = select_by_names(problem.conf.variables, self.variable) problem.set_variables(conf_variables) variables = Variables.from_conf(conf_variables, problem.fields) variables.equation_mapping(ebcs, epbcs, problem.ts, problem.functions) state = State(variables) state.fill(0.0) state.apply_ebc() corr_sol = CorrSolution(name=self.name, state=state.get_parts()) self.save(corr_sol, problem, variables) return corr_sol
def save_ebc(self, filename, force=True, default=0.0): """ Save essential boundary conditions as state variables. """ output('saving ebc...') variables = self.get_variables(auto_create=True) ebcs = Conditions.from_conf(self.conf.ebcs, self.domain.regions) epbcs = Conditions.from_conf(self.conf.epbcs, self.domain.regions) try: variables.equation_mapping(ebcs, epbcs, self.ts, self.functions, problem=self) except: output('cannot make equation mapping!') raise state = State(variables) state.fill(default) if force: vals = dict_from_keys_init(variables.state) for ii, key in enumerate(vals.iterkeys()): vals[key] = ii + 1 state.apply_ebc(force_values=vals) else: state.apply_ebc() out = state.create_output_dict(extend=True) self.save_state(filename, out=out, fill_value=default) output('...done')
def __init__(self, conf, **kwargs): from sfepy.fem.state import State ScipyDirect.__init__(self, conf, **kwargs) equations = self.problem.equations aux_state = State(equations.variables) conf.idxs = {} for bk, bv in conf.blocks.iteritems(): aux_state.fill(0.0) for jj in bv: idx = equations.variables.di.indx[jj] aux_state.vec[idx] = nm.nan aux_state.apply_ebc() vec0 = aux_state.get_reduced() conf.idxs[bk] = nm.where(nm.isnan(vec0))[0]