Esempio n. 1
0
 def evaluate(self, x):
     facemap = self.mesh.connectivity*np.arange(self.mesh.nfaces)
     
     nf = len(self.vs.indices) # number of faces        
     xf = lambda f: x[self.vs.indices[f]:self.vs.indices[f]+self.vs.numbases[f]] # coefficients for each (2-sided) face                        
     vx = lambda f: np.dot(self.vs.getValues(f),xf(f)) # dirichlet values of solution at the quadrature points on each (2-sided) face        
     svx = lambda f: np.dot(self.scaledvandermondes.getValues(f),xf(f)) # dirichlet values of solution at the quadrature points on each (2-sided) face        
     evx = lambda f: vx(f) - vx(facemap[f]) # error on each face        
     DD = pcv.LocalInnerProducts(evx, evx, self.weights) # L2 inner product of solns for pairs of 2-sided faces (only makes sense when faces are from same pair)
     ipD = pus.createvbsr(self.mesh.internal, DD.product, np.ones(nf), np.ones(nf))
     elem_error_dirichlet = pms.sumrhs(self.mesh, ipD.tocsr()).todense().A.squeeze()
     
     nx = lambda f: np.dot(self.vs.getDerivs(f), xf(f))
     enx = lambda f: nx(f) + nx(facemap[f])
     NN = pcv.LocalInnerProducts(enx,enx,self.weights)
     ipN = pus.createvbsr(self.mesh.internal, NN.product, np.ones(nf), np.ones(nf))
     elem_error_neumann = pms.sumrhs(self.mesh, ipN.tocsr()).todense().A.squeeze()
     
     elem_error_bnd=np.zeros(self.mesh.nelements, dtype=complex)
     
     for entity, (coeffs, bdyftob) in self.computation.problem.bdyinfo.items():
         lc=coeffs.l_coeffs
         rc=coeffs.r_coeffs
         bndv = self.computation.faceVandermondes(bdyftob)
         # boundary error
         be = lambda f: lc[0] * svx(f) + lc[1] * nx(f) - (rc[0] * bndv.getValues(f) + rc[1] * bndv.getDerivs(f)).squeeze()
         # l2norm of boundary error on faces
         BB = pcv.LocalInnerProducts(be,be,self.weights)
         ipB = pus.createvbsr(self.mesh.entityfaces[entity], BB.product, np.ones(nf), np.ones(nf))
         elem_error_bnd += pms.sumrhs(self.mesh, ipB.tocsr()).todense().A.squeeze()
     
     return elem_error_dirichlet.real, elem_error_neumann.real, elem_error_bnd.real
Esempio n. 2
0
 def assemble(self, structures):
     """ Given a 2x2 array of structure matrices, return an assembled variable block sparse matrix
     
         A structure matrix SM.JD, for example, corresponds to the product u * [[v]].  
         SM.JD^T * SM.JD, would correspond to [[u]] * [[v]] 
     """
     structures = numpy.array(structures)
     return sum([createvbsr(structures[i,j],self.ips[i,j].product, self.numleft, self.numright) for i in [0,1] for j in [0,1]])