def __init__(self, ref_el, m): ptx, wx = compute_gauss_jacobi_rule(0., 0., m) pty, wy = compute_gauss_jacobi_rule(1., 0., m) ptz, wz = compute_gauss_jacobi_rule(2., 0., m) # map ptx , pty pts_ref = [ expansions.xi_tetrahedron((x, y, z)) for x in ptx for y in pty for z in ptz ] Ref1 = reference_element.DefaultTetrahedron() A, b = reference_element.make_affine_mapping(Ref1.get_vertices(), ref_el.get_vertices()) mapping = lambda x: numpy.dot(A, x) + b scale = numpy.linalg.det(A) pts = tuple([tuple(mapping(x)) for x in pts_ref]) wts = [ scale * 0.125 * w1 * w2 * w3 for w1 in wx for w2 in wy for w3 in wz ] QuadratureRule.__init__(self, ref_el, tuple(pts), tuple(wts))
def __init__(self, ref_el, m): if m < 2: raise ValueError( "Gauss-Labotto-Legendre quadrature invalid for fewer than 2 points") Ref1 = reference_element.DefaultLine() verts = Ref1.get_vertices() if m > 2: # Calculate the recursion coefficients. alpha, beta = orthopoly.rec_jacobi(m, 0, 0) xs_ref, ws_ref = orthopoly.lobatto(alpha, beta, verts[0][0], verts[1][0]) else: # Special case for lowest order. xs_ref = [v[0] for v in verts[:]] ws_ref = (0.5 * (xs_ref[1] - xs_ref[0]), ) * 2 A, b = reference_element.make_affine_mapping(Ref1.get_vertices(), ref_el.get_vertices()) mapping = lambda x: numpy.dot(A, x) + b scale = numpy.linalg.det(A) xs = tuple([tuple(mapping(x_ref)[0]) for x_ref in xs_ref]) ws = tuple([scale * w for w in ws_ref]) QuadratureRule.__init__(self, ref_el, xs, ws)
def __init__(self, ref_el, m): if m < 2: raise ValueError( "Gauss-Labotto-Legendre quadrature invalid for fewer than 2 points") Ref1 = reference_element.DefaultLine() verts = Ref1.get_vertices() if m > 2: # Calculate the recursion coefficients. alpha, beta = orthopoly.rec_jacobi(m, 0, 0) xs_ref, ws_ref = orthopoly.lobatto(alpha, beta, verts[0][0], verts[1][0]) else: # Special case for lowest order. xs_ref = [v[0] for v in verts[:]] ws_ref = (0.5 * (xs_ref[1] - xs_ref[0]), ) * 2 A, b = reference_element.make_affine_mapping(Ref1.get_vertices(), ref_el.get_vertices()) mapping = lambda x: numpy.dot(A, x) + b scale = numpy.linalg.det(A) xs = tuple([tuple(mapping(x_ref)[0]) for x_ref in xs_ref]) ws = tuple([scale * w for w in ws_ref]) QuadratureRule.__init__(self, ref_el, xs, ws)
def __init__(self, ref_el): if ref_el.get_spatial_dimension() != 2: raise Exception("Must have a triangle") self.ref_el = ref_el self.base_ref_el = reference_element.DefaultTriangle() v1 = ref_el.get_vertices() v2 = self.base_ref_el.get_vertices() self.A, self.b = reference_element.make_affine_mapping(v1, v2) self.mapping = lambda x: numpy.dot(self.A, x) + self.b
def __init__(self, ref_el): if ref_el.get_spatial_dimension() != 2: raise Exception("Must have a triangle") self.ref_el = ref_el self.base_ref_el = reference_element.DefaultTriangle() v1 = ref_el.get_vertices() v2 = self.base_ref_el.get_vertices() self.A, self.b = reference_element.make_affine_mapping(v1, v2) self.mapping = lambda x: numpy.dot(self.A, x) + self.b
def __init__(self, ref_el): if ref_el.get_spatial_dimension() != 3: raise Exception("Must be a tetrahedron") self.ref_el = ref_el self.base_ref_el = reference_element.DefaultTetrahedron() v1 = ref_el.get_vertices() v2 = self.base_ref_el.get_vertices() self.A, self.b = reference_element.make_affine_mapping(v1, v2) self.mapping = lambda x: numpy.dot(self.A, x) + self.b self.scale = numpy.sqrt(numpy.linalg.det(self.A))
def __init__(self, ref_el): if ref_el.get_spatial_dimension() != 3: raise Exception("Must be a tetrahedron") self.ref_el = ref_el self.base_ref_el = reference_element.DefaultTetrahedron() v1 = ref_el.get_vertices() v2 = self.base_ref_el.get_vertices() self.A, self.b = reference_element.make_affine_mapping(v1, v2) self.mapping = lambda x: numpy.dot(self.A, x) + self.b self.scale = numpy.sqrt(numpy.linalg.det(self.A))
def __init__(self, ref_el): if ref_el.get_spatial_dimension() != 1: raise Exception("Must have a line") self.ref_el = ref_el self.base_ref_el = reference_element.DefaultLine() v1 = ref_el.get_vertices() v2 = self.base_ref_el.get_vertices() self.A, self.b = reference_element.make_affine_mapping(v1, v2) self.mapping = lambda x: np.dot(self.A, x) + self.b self.scale = np.sqrt(np.linalg.det(self.A))
def __init__(self, ref_el, flat_el, degree): entity_ids = {} nodes = [] # Change coordinates here. # Vertices of the simplex corresponding to the reference element. v_simplex = hypercube_simplex_map[flat_el].get_vertices() # Vertices of the reference element. v_hypercube = flat_el.get_vertices() # For the mapping, first two vertices are unchanged in all dimensions. v_ = [v_hypercube[0], v_hypercube[int(-0.5 * len(v_hypercube))]] # For dimension 1 upwards, # take the next vertex and map it to the midpoint of the edge/face it belongs to, and shares # with no other points. for d in range(1, flat_el.get_dimension()): v_.append( tuple( np.asarray( v_hypercube[flat_el.get_dimension() - d] + np.average(np.asarray(v_hypercube[::2]), axis=0)))) A, b = make_affine_mapping( v_simplex, tuple(v_)) # Make affine mapping to be used later. # make nodes by getting points # need to do this dimension-by-dimension, facet-by-facet top = hypercube_simplex_map[flat_el].get_topology() cur = 0 for dim in sorted(top): for entity in sorted(top[dim]): pts_cur = hypercube_simplex_map[flat_el].make_points( dim, entity, degree) pts_cur = [ tuple(np.matmul(A, np.array(x)) + b) for x in pts_cur ] nodes_cur = [ functional.PointEvaluation(flat_el, x) for x in pts_cur ] nnodes_cur = len(nodes_cur) nodes += nodes_cur cur += nnodes_cur cube_topology = ref_el.get_topology() for dim in sorted(cube_topology): entity_ids[dim] = {} for entity in sorted(cube_topology[dim]): entity_ids[dim][entity] = [] entity_ids[dim][0] = list(range(len(nodes))) super(DPCDualSet, self).__init__(nodes, ref_el, entity_ids)
def __init__(self, ref_el, m, right=True): assert m >= 1 N = m - 1 # Use Chebyshev-Gauss-Radau nodes as initial guess for LGR nodes x = -np.cos(2 * np.pi * np.linspace(0, N, m) / (2 * N + 1)) P = np.zeros((N + 1, N + 2)) xold = 2 free = np.arange(1, N + 1, dtype='int') while np.max(np.abs(x - xold)) > 5e-16: xold = x.copy() P[0, :] = (-1)**np.arange(0, N + 2) P[free, 0] = 1 P[free, 1] = x[free] for k in range(2, N + 2): P[free, k] = ((2 * k - 1) * x[free] * P[free, k - 1] - (k - 1) * P[free, k - 2]) / k x[free] = xold[free] - ((1 - xold[free]) / (N + 1)) * ( P[free, N] + P[free, N + 1]) / (P[free, N] - P[free, N + 1]) # The Legendre-Gauss-Radau Vandermonde P = P[:, :-1] # Compute the weights w = np.zeros(N + 1) w[0] = 2 / (N + 1)**2 w[free] = (1 - x[free]) / ((N + 1) * P[free, -1])**2 if right: x = np.flip(-x) w = np.flip(w) xs_ref = x ws_ref = w A, b = reference_element.make_affine_mapping(((-1., ), (1.)), ref_el.get_vertices()) mapping = lambda x: np.dot(A, x) + b scale = np.linalg.det(A) xs = tuple([tuple(mapping(x_ref)[0]) for x_ref in xs_ref]) ws = tuple([scale * w for w in ws_ref]) QuadratureRule.__init__(self, ref_el, xs, ws)
def make_cell_facet_jacobian(cell, facet_dim, facet_i): facet_cell = cell.construct_subelement(facet_dim) xs = facet_cell.get_vertices() ys = cell.get_vertices_of_subcomplex(cell.get_topology()[facet_dim][facet_i]) # Use first 'dim' points to make an affine mapping dim = cell.get_spatial_dimension() A, b = make_affine_mapping(xs[:dim], ys[:dim]) for x, y in zip(xs[dim:], ys[dim:]): # The rest of the points are checked to make sure the # mapping really *is* affine. assert numpy.allclose(y, A.dot(x) + b) return A
def make_cell_facet_jacobian(cell, facet_dim, facet_i): facet_cell = cell.construct_subelement(facet_dim) xs = facet_cell.get_vertices() ys = cell.get_vertices_of_subcomplex(cell.get_topology()[facet_dim][facet_i]) # Use first 'dim' points to make an affine mapping dim = cell.get_spatial_dimension() A, b = make_affine_mapping(xs[:dim], ys[:dim]) for x, y in zip(xs[dim:], ys[dim:]): # The rest of the points are checked to make sure the # mapping really *is* affine. assert numpy.allclose(y, A.dot(x) + b) return A
def __init__(self, ref_el, m): # this gives roots on the default (-1,1) reference element # (xs_ref, ws_ref) = compute_gauss_jacobi_rule(a, b, m) (xs_ref, ws_ref) = compute_gauss_jacobi_rule(0., 0., m) Ref1 = reference_element.DefaultLine() A, b = reference_element.make_affine_mapping(Ref1.get_vertices(), ref_el.get_vertices()) mapping = lambda x: numpy.dot(A, x) + b scale = numpy.linalg.det(A) xs = tuple([tuple(mapping(x_ref)[0]) for x_ref in xs_ref]) ws = tuple([scale * w for w in ws_ref]) QuadratureRule.__init__(self, ref_el, xs, ws)
def __init__(self, ref_el, m): # this gives roots on the default (-1,1) reference element # (xs_ref, ws_ref) = compute_gauss_jacobi_rule(a, b, m) (xs_ref, ws_ref) = compute_gauss_jacobi_rule(0., 0., m) Ref1 = reference_element.DefaultLine() A, b = reference_element.make_affine_mapping(Ref1.get_vertices(), ref_el.get_vertices()) mapping = lambda x: numpy.dot(A, x) + b scale = numpy.linalg.det(A) xs = tuple([tuple(mapping(x_ref)[0]) for x_ref in xs_ref]) ws = tuple([scale * w for w in ws_ref]) QuadratureRule.__init__(self, ref_el, xs, ws)
def __init__(self, ref_el, m): if m < 1: raise ValueError( "Gauss-Legendre quadrature invalid for fewer than 2 points") xs_ref, ws_ref = numpy.polynomial.legendre.leggauss(m) A, b = reference_element.make_affine_mapping(((-1.,), (1.)), ref_el.get_vertices()) mapping = lambda x: numpy.dot(A, x) + b scale = numpy.linalg.det(A) xs = tuple([tuple(mapping(x_ref)[0]) for x_ref in xs_ref]) ws = tuple([scale * w for w in ws_ref]) QuadratureRule.__init__(self, ref_el, xs, ws)
def __init__(self, ref_el, m): if m < 1: raise ValueError( "Gauss-Legendre quadrature invalid for fewer than 2 points") xs_ref, ws_ref = numpy.polynomial.legendre.leggauss(m) A, b = reference_element.make_affine_mapping(((-1.,), (1.)), ref_el.get_vertices()) mapping = lambda x: numpy.dot(A, x) + b scale = numpy.linalg.det(A) xs = tuple([tuple(mapping(x_ref)[0]) for x_ref in xs_ref]) ws = tuple([scale * w for w in ws_ref]) QuadratureRule.__init__(self, ref_el, xs, ws)
def __init__(self, ref_el, m): ptx, wx = compute_gauss_jacobi_rule(0., 0., m) pty, wy = compute_gauss_jacobi_rule(1., 0., m) # map ptx , pty pts_ref = [expansions.xi_triangle((x, y)) for x in ptx for y in pty] Ref1 = reference_element.DefaultTriangle() A, b = reference_element.make_affine_mapping(Ref1.get_vertices(), ref_el.get_vertices()) mapping = lambda x: numpy.dot(A, x) + b scale = numpy.linalg.det(A) pts = tuple([tuple(mapping(x)) for x in pts_ref]) wts = [0.5 * scale * w1 * w2 for w1 in wx for w2 in wy] QuadratureRule.__init__(self, ref_el, tuple(pts), tuple(wts))
def __init__(self, ref_el, m): ptx, wx = compute_gauss_jacobi_rule(0., 0., m) pty, wy = compute_gauss_jacobi_rule(1., 0., m) # map ptx , pty pts_ref = [expansions.xi_triangle((x, y)) for x in ptx for y in pty] Ref1 = reference_element.DefaultTriangle() A, b = reference_element.make_affine_mapping(Ref1.get_vertices(), ref_el.get_vertices()) mapping = lambda x: numpy.dot(A, x) + b scale = numpy.linalg.det(A) pts = tuple([tuple(mapping(x)) for x in pts_ref]) wts = [0.5 * scale * w1 * w2 for w1 in wx for w2 in wy] QuadratureRule.__init__(self, ref_el, tuple(pts), tuple(wts))
def __init__(self, ref_el, degree): entity_ids = {} nodes = [] # Change coordinates here. # Vertices of the simplex corresponding to the reference element. v_simplex = hypercube_simplex_map[ref_el].get_vertices() # Vertices of the reference element. v_hypercube = ref_el.get_vertices() # For the mapping, first two vertices are unchanged in all dimensions. v_ = list(v_hypercube[:2]) # For dimension 1 upwards, # take the next vertex and map it to the midpoint of the edge/face it belongs to, and shares # with no other points. for d in range(1, ref_el.get_dimension()): v_.append(tuple(np.asarray(v_hypercube[d+1] + np.average(np.asarray(v_hypercube[2**d:2**(d+1)]), axis=0)))) A, b = make_affine_mapping(v_simplex, tuple(v_)) # Make affine mapping to be used later. # make nodes by getting points # need to do this dimension-by-dimension, facet-by-facet top = hypercube_simplex_map[ref_el].get_topology() cube_topology = ref_el.get_topology() cur = 0 for dim in sorted(top): entity_ids[dim] = {} for entity in sorted(top[dim]): pts_cur = hypercube_simplex_map[ref_el].make_points(dim, entity, degree) pts_cur = [tuple(np.matmul(A, np.array(x)) + b) for x in pts_cur] nodes_cur = [functional.PointEvaluation(ref_el, x) for x in pts_cur] nnodes_cur = len(nodes_cur) nodes += nodes_cur cur += nnodes_cur for entity in sorted(cube_topology[dim]): entity_ids[dim][entity] = [] entity_ids[dim][0] = list(range(len(nodes))) super(DPCDualSet, self).__init__(nodes, hypercube_simplex_map[ref_el], entity_ids)
def __init__(self, ref_el, m): ptx, wx = compute_gauss_jacobi_rule(0., 0., m) pty, wy = compute_gauss_jacobi_rule(1., 0., m) ptz, wz = compute_gauss_jacobi_rule(2., 0., m) # map ptx , pty pts_ref = [expansions.xi_tetrahedron((x, y, z)) for x in ptx for y in pty for z in ptz] Ref1 = reference_element.DefaultTetrahedron() A, b = reference_element.make_affine_mapping(Ref1.get_vertices(), ref_el.get_vertices()) mapping = lambda x: numpy.dot(A, x) + b scale = numpy.linalg.det(A) pts = tuple([tuple(mapping(x)) for x in pts_ref]) wts = [scale * 0.125 * w1 * w2 * w3 for w1 in wx for w2 in wy for w3 in wz] QuadratureRule.__init__(self, ref_el, tuple(pts), tuple(wts))