def __init__(self, npts): if not mp.isint(mp.sqrt(npts)): raise ValueError('Invalid number of points for quad rule') rulecls = subclass_where(BaseLineQuadRule, name=self.name) rule = rulecls(int(mp.sqrt(npts))) self.points = [(i, j) for j in rule.points for i in rule.points] if hasattr(rule, 'weights'): self.weights = [i*j for j in rule.weights for i in rule.weights]
def order_from_nspts(cls, nspts): # Obtain the coefficients for the poly: P(n) - nspts = 0 coeffs = list(cls.npts_coeffs) coeffs[-1] -= cls.npts_cdenom * nspts # Solve to obtain the order (a positive integer) roots = mp.polyroots(coeffs) roots = [int(x) for x in roots if mp.isint(x) and x > 0] if roots: return roots[0] else: raise ValueError('Invalid number of shape points')
def order_from_nspts(cls, nspts): # Obtain the coefficients for the poly: P(n) - nspts = 0 coeffs = list(cls.npts_coeffs) coeffs[-1] -= cls.npts_cdenom*int(nspts) # Solve to obtain the order (a positive integer) roots = mp.polyroots(coeffs) roots = [int(x) for x in roots if mp.isint(x) and x > 0] if roots: return roots[0] else: raise ValueError('Invalid number of shape points')
def __init__(self, npts): roots = mp.polyroots([1, 1, 0, -2*npts]) roots = [int(x) for x in roots if mp.isint(x) and x > 0] if not roots: raise ValueError('Invalid number of points for quad rule') tname, lname = self.name.split('*') trulecls = subclass_where(BaseTriQuadRule, name=tname) trule = trulecls(roots[0]*(roots[0] + 1) // 2) lrulecls = subclass_where(BaseLineQuadRule, name=lname) lrule = lrulecls[lname](roots[0]) self.points = [(t[0], t[1], l) for l in lrule.points for t in trule.points] if hasattr(trule, 'weights') and hasattr(lrule, 'weights'): self.weights = [i*j for j in lrule.weights for i in trule.weights]