def test1D2(): spl = splineRefMat(DIM_1D) # list_r = list(np.random.random(20)) list_r = [0.1,0.2,0.3] nx = 3 px = 2 geo = line(n=[nx], p=[px]) nrb = geo[0] knots = nrb.knots[0] n = nrb.shape[0] p = nrb.degree[0] P = nrb.points M = spl.construct(list_r, p, n, knots) from scipy.io import mmwrite mmwrite('M.mtx', M) R = M.dot(nrb.points[:,0]) geo = line(n=[nx], p=[px]) geo.refine(id=0, list_t=[list_r]) nrb = geo[0] P = np.asarray(nrb.points[:,0]) assert(np.allclose(P,R)) print("test1D2: OK")
def test1D2(): spl = splineRefMat(DIM_1D) # list_r = list(np.random.random(20)) list_r = [0.1, 0.2, 0.3] nx = 3 px = 2 geo = line(n=[nx], p=[px]) nrb = geo[0] knots = nrb.knots[0] n = nrb.shape[0] p = nrb.degree[0] P = nrb.points M = spl.construct(list_r, p, n, knots) from scipy.io import mmwrite mmwrite('M.mtx', M) R = M.dot(nrb.points[:, 0]) geo = line(n=[nx], p=[px]) geo.refine(id=0, list_t=[list_r]) nrb = geo[0] P = np.asarray(nrb.points[:, 0]) assert (np.allclose(P, R)) print("test1D2: OK")
def test1(): # ... print ("==== conversion on a periodic line =======") k = 3 S = matrix_conversion_ubspline_to_bernstein(k) # for i in range(0,k): # print S[i,:] geo0 = line(n=[0], p=[k-1]) c0 = geo0[0] points = c0.points points[0, 0:2] = [0.0, 0.0] points[1, 0:2] = [1.0, -1.0] points[2, 0:2] = [2.0, -2.0] c0.set_points(points) print(">>> coeff for Bernstein curve") m = c0.shape[0] y0 = c0.points for i in range(0, m): print(c0.points[i, :]) c1 = c0.copy().unclamp(0) m = c1.shape[0] print(">>> coeff for Uniform-BSpline curve") for i in range(0, m): print(c1.points[i, 0:2]) x = c1.points[:, 0] y = S.dot(c1.points) print("conversion using the conversion Matrix") print(y) assert (np.linalg.norm(y-y0) < 1.e-7) print ("==========================================")
def test1(): print("====== test 1 =====") nx = 3 px = 3 geo = line(n=[nx], p=[px]) geo.append(geo[0]) list_lmatrices = geo.bezier_extract()
def test1D1(): spl = splineRefMat(DIM_1D) list_r = list(np.random.random(20)) for r in list_r: nx = 7 px = 2 geo = line(n=[nx], p=[px]) nrb = geo[0] knots = nrb.knots[0] n = nrb.shape[0] p = nrb.degree[0] P = nrb.points dim = P.shape[1] Q = spl.refineSpline(dim, r, p, n, knots, P) M = spl.construct([r], p, n, knots) R = M.dot(nrb.points[:, 0]) geo.refine(id=0, list_t=[r]) nrb = geo[0] #print nrb.knots[0] Q = np.asarray(Q[:, 0]) P = np.asarray(nrb.points[:, 0]) assert (np.allclose(P, Q)) assert (np.allclose(P, R)) print("test1D1: OK")
def test1D1(): spl = splineRefMat(DIM_1D) list_r = list(np.random.random(20)) for r in list_r: nx = 7 px = 2 geo = line(n=[nx], p=[px]) nrb = geo[0] knots = nrb.knots[0] n = nrb.shape[0] p = nrb.degree[0] P = nrb.points dim = P.shape[1] Q = spl.refineSpline(dim, r, p, n, knots, P) M = spl.construct([r], p, n, knots) R = M.dot(nrb.points[:,0]) geo.refine(id=0, list_t=[[r]]) nrb = geo[0] #print nrb.knots[0] Q = np.asarray(Q[:,0]) P = np.asarray(nrb.points[:,0]) assert(np.allclose(P,Q)) assert(np.allclose(P,R)) print("test1D1: OK")
def test1(): # ... print ("==== conversion on a periodic line =======") k = 3 S = matrix_conversion_ubspline_to_bernstein(k) # for i in range(0,k): # print S[i,:] geo0 = line(n=[0], p=[k-1]) c0 = geo0[0] points = c0.points points[0, 0:2] = [0.0, 0.0] points[1, 0:2] = [1.0, -1.0] points[2, 0:2] = [2.0, -2.0] c0.set_points(points) print ">>> coeff for Bernstein curve" m = c0.shape[0] y0 = c0.points for i in range(0, m): print c0.points[i, :] c1 = c0.copy().unclamp(0) m = c1.shape[0] print ">>> coeff for Uniform-BSpline curve" for i in range(0, m): print c1.points[i, 0:2] x = c1.points[:, 0] y = S.dot(c1.points) print "conversion using the conversion Matrix" print y assert (np.linalg.norm(y-y0) < 1.e-7) print ("==========================================")
def test1(): geo1d = line(n=[5], p=[3]) # ... print("========= connectivity on a line =========") con1d = connectivity(geo1d) con1d.init_data_structure() con1d.printinfo() print("==========================================")
def geometry_1D(nx, px): # ... nrb = line(p0=(0, 0), p1=(1, 0)) geo = cg.cad_geometry(geo=nrb) geo.refine(id=0, list_p=[px - 1]) tx = np.linspace(0., 1., nx + 2)[1:-1] geo.refine(id=0, list_t=[tx]) # ... return geo
def test1(): geo1d = line(n=[5], p=[3]) # ... print ("========= connectivity on a line =========") con1d = connectivity(geo1d) con1d.init_data_structure() con1d.printinfo() print ("==========================================")
def test2(): geo1d = line(n=[5], p=[3]) # ... print("========= dirichlet connectivity on a line =========") con1d_dir = connectivity(geo1d) bc1d_dir = boundary_conditions(geo1d) list_DirFaces = [[0, 1]] bc1d_dir.dirichlet(geo1d, list_DirFaces) con1d_dir.init_data_structure(bc1d_dir) con1d_dir.printinfo() print("==========================================")
def test2(): geo1d = line(n=[5], p=[3]) # ... print ("========= dirichlet connectivity on a line =========") con1d_dir = connectivity(geo1d) bc1d_dir = boundary_conditions(geo1d) list_DirFaces = [[0,1]] bc1d_dir.dirichlet(geo1d, list_DirFaces) con1d_dir.init_data_structure(bc1d_dir) con1d_dir.printinfo() print ("==========================================")
def test3(): from . import fem as fem from caid.cad_geometry import line, circle, bilinear import caid.cad_geometry as cg fe = fem.fem() geo1 = cg.cad_geometry(geo=line()) geo2 = cg.cad_geometry(geo=circle()) geo3 = cg.cad_geometry(geo=bilinear()) PDE1 = pigasus(fem=fe, geometry=geo1) PDE2 = pigasus(fem=fe, geometry=geo2) PDE3 = pigasus(fem=fe, geometry=geo3)
return f, u #----------------------------------- #----------------------------------- niter = 5000 nx = 15 ny = 15 px = 2 py = 2 #----------------------------------- #----------------------------------- # ... from caid.cad_geometry import line geo1 = line(n=[nx], p=[px]) f1, u1 = testcase_line() PDE1 = poisson(geometry=geo1) # ... # ... from caid.cad_geometry import square as domain geo2 = domain(n=[nx, ny], p=[px, py]) f2, u2 = testcase_square_Dirichlet() PDE2 = poisson(geometry=geo2) # ... # ... PDE1.assembly(f=f1, u=u1)
def points_to_geo_approx(x, y, z=None, n=15, p=3, alpha=1.): if z is None: z = np.zeros_like(x) #----------------------------------- def MakeConstraint(cond, face=None, value=None): if cond.lower() == "closed": constraint = {} constraint['patch_id_m'] = 0 constraint['face_m'] = 0 constraint['patch_id_s'] = 0 constraint['face_s'] = 1 if cond.lower() == "c0": constraint = {} constraint['patch_id_m'] = 0 constraint['face_m'] = face constraint['type'] = "C0" constraint['values'] = [value] if cond.lower() == "c1": constraint = {} constraint['patch_id_m'] = 0 constraint['face_m'] = face constraint['type'] = "C1" constraint['values'] = [value] return constraint #----------------------------------- from pigasus.fit.curfit import curfit from pigasus.fit.curfit import compute_uk #----------------------------------- #method = "uniform" method = "chord" #method = "centripetal" #----------------------------------- #----------------------------------- # ... list_x = list(x) ; list_y = list(y) # ... # ... list_Q = list(zip(list_x, list_y)) uk = compute_uk(list_Q, method=method) U1 = [] U1 += list(uk) list_xk = [] ; list_yk = [] list_xk += list_x ; list_yk += list_y lists_uk = [U1] lists_xk = [list_xk] lists_yk = [list_yk] # ... #----------------------------------- #----------------------------------- constraints = [] # ... C0_COND constraint = MakeConstraint("C0", 0, [x[0], y[0]]) constraints.append(constraint) constraint = MakeConstraint("C0", 1, [x[-1], y[-1]]) constraints.append(constraint) #----------------------------------- #----------------------------------- from caid.cad_geometry import line geo = line(n=[n], p=[p]) #----------------------------------- #----------------------------------- fit = curfit(geometry=geo, constraints=constraints, alpha=alpha) #----------------------------------- #----------------------------------- patch_id = 0 xk = lists_xk[patch_id] yk = lists_yk[patch_id] geo = fit.construct([xk, yk], uk=lists_uk) #----------------------------------- return geo
def test1(): geo = line() geo_r = refine(geo, n=[2], p=[2])
for li_d in range(0, li_dim): lpr_knots = nrb.knots[li_d] u = [k for k, g in groupby(lpr_knots)] m = [len(list(g)) for k, g in groupby(lpr_knots)] index = [sum(m[0:i+1]) for i in range(0,m.__len__())] list_info.append((u,m,index)) return list_info if __name__ == '__main__': import caid.cad_geometry as cg from caid.cad_geometry import line, square, trilinear from .boundary_conditions import boundary_conditions geo1d = line(n=[5], p=[3]) # ... print ("========= connectivity on a line =========") con1d = connectivity(geo1d) con1d.init_data_structure() con1d.printinfo() print ("==========================================") # ... # ... print ("========= dirichlet connectivity on a line =========") con1d_dir = connectivity(geo1d) bc1d_dir = boundary_conditions(geo1d) list_DirFaces = [[0,1]] bc1d_dir.dirichlet(geo1d, list_DirFaces)
def run(filename): # ... from caid.cad_geometry import line geometry = line() mapping = Mapping(geometry=geometry) # ... # ... import os cmd = "mkdir -p output" os.system(cmd) # ... # ... creates discretization parameters from clapp.disco.parameters.bspline import BSpline bspline_params = BSpline([64], [5], \ bc_min=[0], \ bc_max=[0]) # ... # ... create a context from discretization context = Context(dirname="input", \ discretization_params=bspline_params) # ... # ... vale = Vale(filename=filename) pde = vale.parse(context, mapping) # ... # ... accessing the pde declarations V = pde["V"] u = pde["u"] form_a = pde["a"] form_b = pde["b"] assembler_a = form_a.assembler matrix = form_a.matrix assembler_b = form_b.assembler rhs = form_b.vector assembler_a.assemble() assembler_b.assemble() # ... # ... from clapp.plaf.parameters.linear_solver import LAPACK_LU from clapp.plaf.parameters.linear_solver import DRIVER params = DRIVER(solver=LAPACK_LU()) linsol = Linear_solver(matrix=matrix, dirname="input", parameters=params) # ... # ... y = linsol.solve(rhs) # ... # ... exports the field u.set(y) # ... # ... plot field using matplotlib filename_out = "uh_1d_"+filename.split('/')[-1].split('.')[0] + ".png" u.plot(n_pts=100) plt.savefig(filename_out) # ... # ... compute L2 error x = u.compute_l2_error(mapping=mapping, \ function_name="u_analytic") print (">> norms : ", x) # ... # ... cmd = "rm -rf input" os.system(cmd) # ... # ... plt.clf() # ... print ("> run using ", filename, " passed.")