def get_integrals(self, names=None, kind=None): """ Get integrals, initialized from problem configuration if available. Parameters ---------- names : list, optional If given, only the named integrals are returned. kind : 'v' or 's', optional If given, only integrals of the given kind are returned. Returns ------- integrals : Integrals instance The requested integrals. """ conf_integrals = self.conf.get_default_attr('integrals', {}) integrals = Integrals.from_conf(conf_integrals) if names is not None: integrals.update([integrals[ii] for ii in names if ii in integrals.names]) if kind is not None: integrals.update([ii for ii in integrals if ii.kind.startswith(kind)]) return integrals
def get_integrals(self, names=None, kind=None): """ Get integrals, initialized from problem configuration if available. Parameters ---------- names : list, optional If given, only the named integrals are returned. kind : 'v' or 's', optional If given, only integrals of the given kind are returned. Returns ------- integrals : Integrals instance The requested integrals. """ conf_integrals = self.conf.get('integrals', {}) integrals = Integrals.from_conf(conf_integrals) if names is not None: integrals.update( [integrals[ii] for ii in names if ii in integrals.names]) if kind is not None: integrals.update( [ii for ii in integrals if ii.kind.startswith(kind)]) return integrals
def get_integrals(self, names=None): """ Get integrals, initialized from problem configuration if available. Parameters ---------- names : list, optional If given, only the named integrals are returned. Returns ------- integrals : Integrals instance The requested integrals. """ conf_integrals = self.conf.get("integrals", {}) integrals = Integrals.from_conf(conf_integrals) if names is not None: integrals.update([integrals[ii] for ii in names if ii in integrals.names]) return integrals
def set_equations(self, conf_equations, user=None, cache_override=None, keep_solvers=False): equations = Equations.from_conf(conf_equations) equations.setup_terms(self.domain.regions, self.variables, self.materials, user) i_names = equations.get_term_integral_names() self.integrals = Integrals.from_conf(self.conf.integrals, i_names) self.integrals.set_quadratures(fea.collect_quadratures()) self.geometries = {} equations.describe_geometry(self.geometries, self.variables, self.integrals) ## print self.geometries ## pause() # Call after describe_geometry(), as it sets ap.surface_data. self.variables.setup_dof_conns() if cache_override is None: cache_override = get_default_attr(self.conf.fe, "cache_override", True) equations.set_cache_mode(cache_override) self.equations = equations if not keep_solvers: self.solvers = None
#python implementation of the Hartree-Fock method import numpy as np import math from basis import Basis from integrals import Integrals from scf import SCF Basis = Basis() Integrals = Integrals() SCF = SCF() ################################## #init main variables #contains information user provided information about the system system = { #nuclear coordinates "R":[[0.0,0.0,-1.0], [0.0,0.0,1.0]], #atomic number "Z":[1,1], #number of electron "N":[2.0] } #basis set basis = Basis.buildBasis(system["Z"], system["R"]) print(basis)
def eval_term( state, term_desc, conf, domain, variables, materials, ts, funmod=None, chunk_size=1000, term_prefixes=None, caches=None, ret_caches=False, override=True, new_geometries=True, dw_mode="vector", tangent_matrix=None, **kwargs ): """Evaluate a term. May not succeed!""" if term_prefixes is None: term_prefixes = {} if caches is None: caches = DataCaches() equation = Equation.from_desc("tmp", term_desc, term_prefixes) equation.setup_terms(domain.regions, variables, materials, caches, kwargs) for cache in caches.itervalues(): cache.set_mode(override=override) if new_geometries: i_names = equation.get_term_integral_names() integrals = Integrals.from_conf(conf.integrals, i_names) integrals.set_quadratures(quadratures) geometries = {} equation.describe_geometry(geometries, variables, integrals) variables.data_from_state(state) if "call_mode" in kwargs: itype = kwargs["call_mode"].split("_")[0] else: # itype according to the first term in term_desc! itype = equation.terms[0].itype if itype == "dw": variables.setup_dof_conns() if not variables.has_eq_map: variables.equation_mapping(conf.ebcs, conf.epbcs, domain.regions, ts, funmod) variables.setup_lcbc_operators(conf.lcbcs, domain.regions) variables.setup_a_dof_conns() if dw_mode == "vector": residual = variables.create_stripped_state_vector() assemble_vector(residual, equation, variables, materials, chunk_size, group_can_fail=False, **kwargs) if variables.has_lcbc: op_lcbc = variables.op_lcbc residual = op_lcbc.T * residual ret_val = residual elif dw_mode == "matrix": if tangent_matrix is None: tangent_matrix = variables.create_matrix_graph() tangent_matrix.data[:] = 0.0 assemble_matrix(tangent_matrix, equation, variables, materials, chunk_size, group_can_fail=False, **kwargs) if variables.has_lcbc: op_lcbc = variables.op_lcbc tangent_matrix = op_lcbc.T * tangent_matrix * op_lcbc tangent_matrix = tangent_matrix.tocsr() tangent_matrix.sort_indices() ret_val = tangent_matrix else: print dw_mode raise ValueError elif itype == "d": kwargs.setdefault("call_mode", "d_eval") val = 0.0 for term in equation.terms: args = build_args(term, variables, materials, **kwargs) for ig in term.iter_groups(): for aux, iels, status in term(chunk_size=chunk_size, **args): val += term.sign * aux ret_val = val elif itype == "di": val = None for term in equation.terms: args = build_args(term, variables, materials, **kwargs) for ig in term.iter_groups(): for aux, iels, status in term(chunk_size=chunk_size, **args): if val is None: val = term.sign * aux else: val += term.sign * aux ret_val = val elif (itype == "de") or (itype == "dq"): val = None for term in equation.terms: args = build_args(term, variables, materials, **kwargs) for ig in term.iter_groups(): for aux, iels, status in term(chunk_size=chunk_size, **args): if val is None: val = term.sign * aux else: val = nm.concatenate((val, term.sign * aux), axis=0) ret_val = val else: raise NotImplementedError, "unknown term integration type: %s" % itype if ret_caches: return ret_val, caches else: return ret_val