def integrate1(mesh, local, npts=5, **kwargs): wts, upts, vpts = quadrature.full([[0.0, 1.0], [0.0, 1.0]], npts).T V = np.zeros((len(mesh),)) for elt in log.iter('integrating', mesh.elements): Il, Vl = local(elt, wts, upts, vpts, **kwargs) V[Il] += Vl return V
def integrate2(mesh, local, npts=5, **kwargs): wts, upts, vpts = quadrature.full([[0.0, 1.0], [0.0, 1.0]], npts).T I, J, V = [], [], [] for elt in log.iter('integrating', mesh.elements): Il, Jl, Vl = local(elt, wts, upts, vpts, **kwargs) I.extend(Il.flat) J.extend(Jl.flat) V.extend(Vl.flat) return sparse.csr_matrix((V, (I, J)), shape=(len(mesh), len(mesh)))
def project(self, projection): # TODO: Remove this condition assert all(p is not None for p in projection) pa, pb, pc = projection P, __ = pa.shape ass = util.CSRAssembler(self.shape[1:], self.indices[1], self.indices[2]) ret = np.empty((P, pb.shape[0], pc.shape[0]), self.data.dtype) for i in log.iter('index', range(P), length=P): data = self.data * pa[i, self.indices[0]] mx = ass(data) ret[i] = pb.dot(mx.dot(pc.T)) return NumpyArrayIntegrand(ret)
def cache_main(self, **kwargs): self.values = (itg.cache(**kwargs) for itg in log.iter('term', list(self.values))) if self.optimized: self.fallback = None return self
# for axes in log.iter('axes', axes_combs): # contraction = [None] * self.ndim # for ax in axes: # contraction[ax] = lift # sub_rep = self._lift[axes] # new_scales = [scl * scale**len(axes) for scl in self.scales] # new_values = [itg.contract(contraction) for itg in self.values] # sub_rep.extend(zip(new_scales, new_values)) # @staticmethod # def _expand(items, frozen, ndim): # ret = list(items) # for i in sorted(frozen): # ret.insert(i, None) # assert len(ret) == ndim # return tuple(ret) def project(self, case, proj): new_values = [ itg.project(proj) for itg in log.iter('term', list(self.values)) ] new = AffineIntegral(zip(self.scales, new_values)) for axes, rep in log.iter('axes', list(self.lifts.items())): remaining_axes = [i for i in range(self.ndim) if i not in axes] _proj = [proj[i] for i in remaining_axes if proj[i] is not None] new.lifts[axes] = rep.project(_proj) return new