def create_space(ne, p, order=None, xmin=0., xmax=1.): grid = np.linspace(xmin, xmax, ne+1) knots = make_knots(grid, p, periodic=False) spans = elements_spans(knots, p) # In[6]: nelements = len(grid) - 1 nbasis = len(knots) - p - 1 # we need the value a B-Spline and its first derivative nderiv = 1 # create the gauss-legendre rule, on [-1, 1] if order is None: order = p u, w = gauss_legendre( order ) # for each element on the grid, we create a local quadrature grid points, weights = quadrature_grid( grid, u, w ) # for each element and a quadrature points, # we compute the non-vanishing B-Splines basis = basis_ders_on_quad_grid( knots, p, points, nderiv ) return SplineSpace(knots=knots, degree=p, nelements=nelements, nbasis=nbasis, points=points, weights=weights, spans=spans, basis=basis)
print('Pyccelization done!') # ... parameters Nel = 1800 p = 3 Lz = 325. el_b = np.linspace(0., Lz, Nel + 1) bc = False Nbase0 = Nel + p - bc * p Nbase1 = Nbase0 - 1 + bc delta = Lz / Nel T0 = bsp.make_knots(el_b, p, bc) T1 = T0[1:-1] Np = int(5e6) xi = 0.862 rel = 1 dt = 0.04 pp0 = np.asfortranarray( [[1 / 6, -1 / (2 * delta), 1 / (2 * delta**2), -1 / (6 * delta**3)], [2 / 3, 0., -1 / delta**2, 1 / (2 * delta**3)], [1 / 6, 1 / (2 * delta), 1 / (2 * delta**2), -1 / (2 * delta**3)], [0., 0., 0., 1 / (6 * delta**3)]]) pp1 = np.asfortranarray([[1 / 2, -1 / delta, 1 / (2 * delta**2)], [1 / 2, 1 / delta, -1 / delta**2],
#===== Maxwellian for control variate =============================================== maxwell = lambda vx, vy, vz: nh / ( (2 * np.pi)**(3 / 2) * wpar * wperp**2) * np.exp(-vz**2 / (2 * wpar**2) - (vx**2 + vy**2) / (2 * wperp**2)) #==================================================================================== #===== sampling distribution for initial markers ==================================== g_sampling = lambda vx, vy, vz: 1 / ( (2 * np.pi)**(3 / 2) * wpar * wperp**2) * np.exp(-vz**2 / (2 * wpar**2) - (vx**2 + vy**2) / (2 * wperp**2)) * 1 / Lz #==================================================================================== #===== spline knot vector, global mass matrices (in V0 and V1) and gradient matrix == Tz = bsp.make_knots(el_b, p, True) tz = Tz[1:-1] M0, C0 = utils_opt.matrixAssembly_V0(p, Nbase, Tz, True) M1 = utils_opt.matrixAssembly_V1(p, Nbase, Tz, True) G = utils_opt.GRAD_1d(p, Nbase, True) print('matrix assembly done!') #==================================================================================== #===== reserve memory for unknowns ================================================== ex = np.empty(Nbase_0) ey = np.empty(Nbase_0) bx = np.empty(Nbase_0) by = np.empty(Nbase_0)
#===== masking function to damp wave fields near boundaries ========================= def damp(z): if z <= Ld: return np.sin(np.pi * z / (2 * Ld)) elif z >= Lz - Ld: return np.sin(np.pi * (Lz - z) / (2 * Ld)) else: return 1.0 #==================================================================================== #===== spline knot vector, global mass matrices (in V0 and V1) and gradient matrix == Tz = bsp.make_knots(el_b, p, False) tz = Tz[1:-1] M0, C0 = utils_opt.matrixAssembly_V0(p, Nbase0, Tz, False) M1 = utils_opt.matrixAssembly_V1(p, Nbase0, Tz, False) Mb = utils_opt.matrixAssembly_backgroundField(p, Nbase0, Tz, False, B_background_z) G = utils_opt.GRAD_1d(p, Nbase0, False) D = bsp.collocation_matrix(tz, p - 1, eva_points_Bx, False, normalize=True) print('matrix assembly done!') #==================================================================================== #===== reserve memory for unknowns ==================================================
knotlist[iknot], knotlist[iknot + 1], line, bsp, ind2=column) return S # ---------------------------------- MAIN FUNCTION --------------------------------------- # if __name__ == "__main__": # degree p = 2 ne = 9 knotlist = make_knots(ne, p) bsp = Bspline(knotlist, p) n = len(knotlist) - p # number of control points m = len(knotlist) - p - 1 # number of B-Splines # building matrices F = discretizeSecondMember(bsp, knotlist, p, 300) S = stiffnessMatrix(bsp, knotlist, p, 300) a = knotlist[0] b = knotlist[-1] # analytic solution computing t = np.linspace(a, b, 20)