def construct(self, xyzk, uvk=None, exportGeometry=True): cxyz = self.fit(xyzk, uvk=uvk) U = self.PDE.unknown geo_ini = self.geometry if exportGeometry: geo_f = cad_geometry() else: list_nrb = [] for patch_id in range(0, self.geometry.npatchs): nrb = self.geometry[patch_id] C = np.zeros(list(nrb.shape) + [3]) for i, cx in enumerate(cxyz): U.set(cx) C[..., i] = U.tomatrix(patch_id).reshape(nrb.shape) if exportGeometry: srf = cad_nurbs(nrb.knots, C, weights=nrb.weights) srf.orientation = nrb.orientation srf.rational = nrb.rational geo_f.append(srf) else: srf = cad_nurbs(nrb.knots, C, weights=nrb.weights) list_nrb.append(srf) if exportGeometry: geo_f.set_internal_faces(geo_ini.internal_faces) geo_f.set_external_faces(geo_ini.external_faces) geo_f.set_connectivity(geo_ini.connectivity) return geo_f else: return list_nrb
def construct(self, xyzk, uk=None): cxyz = self.fit(xyzk, uk=uk) U = self.PDE.unknown geo_ini = self.geometry geo_f = cad_geometry() for patch_id in range(0, self.geometry.npatchs): nrb = self.geometry[patch_id] C = np.zeros(list(nrb.shape) + [3]) for i, cx in enumerate(cxyz): U.set(cx) C[..., i] = U.tomatrix(patch_id).reshape(nrb.shape) srf = cad_nurbs(nrb.knots, C, weights=nrb.weights) srf.orientation = nrb.orientation srf.rational = nrb.rational geo_f.append(srf) geo_f._internal_faces = geo_ini._internal_faces geo_f._external_faces = geo_ini._external_faces geo_f._connectivity = geo_ini._connectivity return geo_f
def transferSolution(self, geo_H, U_H, geo_h, U_h): patch_id = 0 nrb_H = geo_H[patch_id] nrb_h = geo_h[patch_id] # degrees of the input surface px_in = nrb_H.degree[0] py_in = nrb_H.degree[1] # degrees of the output surface px = nrb_h.degree[0] py = nrb_h.degree[1] C = np.zeros_like(nrb_H.points) shape = list(nrb_H.shape) C = np.zeros(shape+[3]) _C = U_H.tomatrix(patch_id) C[...,0] = _C srf = cad_nurbs(nrb_H.knots, C, weights= nrb_H.weights) geo_f = cad_geometry() geo_f.append(srf) list_t = [] for axis in range(0, nrb_H.dim): tx = [t for t in nrb_h.knots[axis] if t not in nrb_H.knots[axis]] list_t.append(tx) geo_f.refine(list_t = list_t, list_p=[px-px_in, py-py_in]) uh = geo_f[0].points[...,0] U_h.frommatrix(patch_id, uh)
def __call__(self, u=None, v=None, w=None, patch_id=None): geo = self.space.geometry U = self dim = geo.dim uvw = [u,v,w][:dim] list_patchs = [] if patch_id is None: list_patchs = [nrb for nrb in geo] else: list_patchs = [geo[patch_id]] list_P = [] for nrb in list_patchs: nrb_id = geo.index(nrb) C = zeros_like(nrb.points) x = nrb.points[...,0] y = nrb.points[...,1] z = U.tomatrix(nrb_id) #.transpose() C[...,0] = x C[...,1] = y C[...,2] = z srf = cad_nurbs(nrb.knots, C, weights=nrb.weights) P = srf(u=u,v=v,w=w) if patch_id is not None: return P[...,-1] else: list_P.append(P[...,-1]) return list_P
def genGeometry(self): from caid.op_nurbs import opNURBS, grad from caid.cad_geometry import cad_geometry, cad_grad_nurbs, cad_nurbs geo = self.geo_h PDE = self.PDE_h if PDE.Dirichlet: U = PDE.unknown_dirichlet else: U = PDE.unknown geo_f = cad_geometry() for patch_id in range(0, geo.npatchs): met = geo[patch_id] _C = U.tomatrix(patch_id) C = np.zeros_like(met.points) C[..., :2] = met.points[..., :2] C[..., 2] = _C srf = cad_nurbs(met.knots, C, weights=met.weights) gsrf = grad(srf) grad_nrb = cad_grad_nurbs(gsrf) print("name ", grad_nrb.__class__.__name__) geo_f.append(grad_nrb) geo_f[-1].set_orientation(met.orientation) geo_f[-1].set_rational(met.rational) geo_f.set_internal_faces(geo.internal_faces) geo_f.set_external_faces(geo.external_faces) geo_f.set_connectivity(geo.connectivity) return geo_f
def cutCurve(self): wk = self.workGroup try: list_patchs = [] for item in wk.inspector.tree.selectionsItems: patch = wk.inspector.tree.GetItemData(item) if patch.dim > 1: print("cut curves algorithm only works with curves") return list_patchs.append(patch) if len(list_patchs) > 1: print(("cut curves algorithm needs 1 curve, but "\ , len(list_patchs), " curves were given")) return from caid.utils.intersect import intersect_crv c0 = list_patchs[0] geo0 = cad_geometry() geo0.append(c0) freq = wk.viewer.cutCurveFreq list_P = wk.viewer.CutCurvePoints[::freq] x, y, z = list(zip(*list_P)) x = np.asarray(x) y = np.asarray(y) z = np.asarray(z) from scipy import interpolate smooth = 0. degree = 3 tck, u = interpolate.splprep([x, y], s=smooth, k=degree) knots = tck[0] Px = tck[1][0] Py = tck[1][1] C = np.zeros((len(Px), 3)) C[:, 0] = array(Px) C[:, 1] = array(Py) c1 = cad_nurbs([knots], C) geo1 = cad_geometry() geo1.append(c1) list_P, list_t, list_s, ierr = intersect_crv(c0, c1) list_t = np.asarray(list_t) list_t.sort() axis = 0 for i, t in enumerate(list_t): geo0.split(i, t, axis) wk.add_geometry(geometry(geo0)) wk.Refresh() except: self.statusbar.SetStatusText( 'Cannot use cut Curve. Check that a patch is selected on the inspector' )
def make_curve(): T = np.array([0., 0., 0., 0.5, 0.75, 0.75, 1., 1., 1.]) C = [[ 6.0, 0.0, 6.0], [-5.5, 0.2, 5.5], [-5.0, 1.3,-5.0], [ 4.5, 2.,-4.5], [ 4.0, 2.5, 4.0], [-3.5, 2.75, 3.5],] crv = cad_nurbs([T], C) return crv
def cutCurve(self): wk = self.workGroup try: list_patchs = [] for item in wk.inspector.tree.selectionsItems: patch = wk.inspector.tree.GetPyData(item) if patch.dim > 1: print("cut curves algorithm only works with curves") return list_patchs.append(patch) if len(list_patchs) > 1: print(("cut curves algorithm needs 1 curve, but ", len(list_patchs), " curves were given")) return from caid.utils.intersect import intersect_crv c0 = list_patchs[0] geo0 = cad_geometry() geo0.append(c0) freq = wk.viewer.cutCurveFreq list_P = wk.viewer.CutCurvePoints[::freq] x, y, z = list(zip(*list_P)) x = np.asarray(x) y = np.asarray(y) z = np.asarray(z) from scipy import interpolate smooth = 0.0 degree = 3 tck, u = interpolate.splprep([x, y], s=smooth, k=degree) knots = tck[0] Px = tck[1][0] Py = tck[1][1] C = np.zeros((len(Px), 3)) C[:, 0] = array(Px) C[:, 1] = array(Py) c1 = cad_nurbs([knots], C) geo1 = cad_geometry() geo1.append(c1) list_P, list_t, list_s, ierr = intersect_crv(c0, c1) list_t = np.asarray(list_t) list_t.sort() axis = 0 for i, t in enumerate(list_t): geo0.split(i, t, axis) wk.add_geometry(geometry(geo0)) wk.Refresh() except: self.statusbar.SetStatusText("Cannot use cut Curve. Check that a patch is selected on the inspector")
def make_curve(): T = np.array([0., 0., 0., 0.5, 0.75, 0.75, 1., 1., 1.]) C = [ [6.0, 0.0, 6.0], [-5.5, 0.2, 5.5], [-5.0, 1.3, -5.0], [4.5, 2., -4.5], [4.0, 2.5, 4.0], [-3.5, 2.75, 3.5], ] crv = cad_nurbs([T], C) return crv
def make_curve(): T = np.array([0., 0., 0., 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1., 1., 1.]) C = [[ 0.,-2., 0.], [ 1.,-2., 0.], [ 1., 0., 0.], [ 1., 1., 0.], [ 0., 1., 0.], [-1., 1., 0.], [-1., 0., 0.], [-1.,-2., 0.], [ 0.,-2., 0.],] crv = cad_nurbs([T], C) return crv
def make_curve(): T = np.array([0., 0., 0., 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1., 1., 1.]) C = [ [0., -2., 0.], [1., -2., 0.], [1., 0., 0.], [1., 1., 0.], [0., 1., 0.], [-1., 1., 0.], [-1., 0., 0.], [-1., -2., 0.], [0., -2., 0.], ] crv = cad_nurbs([T], C) return crv
def export(self, filename): from caid.cad_geometry import cad_geometry, cad_nurbs from caid.field import field as iga_field U = self geo = U.space.geometry geo_c = cad_geometry() for i in range(0, geo.npatchs): nrb = geo[i] C = zeros_like(nrb.points) _C = U.tomatrix(i) shape = list(nrb.shape) C = zeros(shape+[3]) C[...,0] = _C srf = cad_nurbs(nrb.knots, C, weights= nrb.weights) geo_c.append(srf) F = iga_field(geo, geo_c) F.save(filename)
def points_to_geo_interp(x, y, z=None, p=3): if z is None: z = np.zeros_like(x) tck, u = splprep([x,y], s=0, k=p) #----------------------------------- geo = cad_geometry() knots = [tck[0]] Px = tck[1][0] Py = tck[1][1] P = np.zeros((len(Px),3)) P[:,0] = Px P[:,1] = Py nrb = cad_nurbs(knots, P) geo.append(nrb) #----------------------------------- return geo
def plot(self, withpcolor=False, n=None): from matplotlib.pyplot import contourf, pcolor from numpy import min, max, linspace, zeros_like geo = self.space.geometry U = self vmin = min(U.get()) vmax = max(U.get()) dim = geo.dim for patch_id in range(0, geo.npatchs): nrb = geo[patch_id] list_n = n if n is None: list_n = [50]*nrb.dim C = zeros_like(nrb.points) x = nrb.points[...,0] y = nrb.points[...,1] z = U.tomatrix(patch_id) #.transpose() C[...,0] = x C[...,1] = y C[...,2] = z srf = cad_nurbs(nrb.knots, C, weights=nrb.weights) list_t = [] for axis in range(0, nrb.dim): t = linspace(nrb.knots[axis][0],nrb.knots[axis][-1],list_n[axis]) list_t.append(t) P = srf(u=list_t[0], v=list_t[1]) if dim == 1: x = P[...,0] y = P[...,1] plot(x,y) if dim == 2: x = P[...,0] y = P[...,1] z = P[...,2] if withpcolor: pcolor(x,y,z,vmin=vmin,vmax=vmax) else: contourf(x,y,z)
def create_wall(R_wall, Z_wall): zz = np.zeros_like(R_wall) list_P = list(zip(R_wall, Z_wall, zz)) list_crv = [] for P,Q in zip(list_P[:-1], list_P[1:]): points = np.zeros((2,2)) points[0,0] = P[0] ; points[0,1] = P[1] points[1,0] = Q[0] ; points[1,1] = Q[1] crv = linear(points = points)[0] list_crv.append(crv) nrb = list_crv[0] axis = 0 for crv in list_crv[1:]: nrb = join(nrb, crv, axis) nrb = cad_nurbs(nrb.knots, nrb.points, weights=nrb.weights) geo = cad_geometry() geo.append(nrb) return geo
def genNewMesh(nrb): P = nrb.points x = P[:,:,0] y = P[:,:,1] shp = P.shape nx = shp[0] ; ny = shp[1] tx = np.linspace(0.,1.,nx) ty = np.linspace(0.,1.,ny) Tx,Ty = np.meshgrid(tx,ty) Tx = Tx.transpose() Ty = Ty.transpose() x[1:-1,1:-1] += eps*sin(kx*t*Tx[1:-1,1:-1]) y[1:-1,1:-1] += eps*sin(ky*t*Ty[1:-1,1:-1]) P[:,:,0] = x P[:,:,1] = y return cad_nurbs(nrb.knots, P, weights=nrb.weights)
def createArc(self): wk = self.workGroup list_P = wk.viewer.MarkerPoints if len(list_P) != 3 : print("You have to specify 3 markers.") return dlg = edtTxtDialog(None, title="Edit Angle") dlg.ShowModal() ls_text = dlg.getValue() try: lr_degree = float(ls_text) except: lr_degree = 0.0 theta = lr_degree * pi / 180 dlg.Destroy() A0 = list_P[0] A1 = list_P[1] A2 = list_P[2] knots = [0.,0.,0.,1.,1.,1.] C = np.zeros((3,3)) C[0,:] = A0[:3] C[1,:] = A1[:3] C[2,:] = A2[:3] weights = [1.,cos(theta),1.] nrb = cad_nurbs([knots], C, weights=weights) wk.viewer.CleanMarkerPoints() geo = cad_geometry() geo.append(nrb) wk.add_geometry(geometry(geo)) wk.Refresh()
def createArc(self): wk = self.workGroup list_P = wk.viewer.MarkerPoints if len(list_P) != 3: print("You have to specify 3 markers.") return dlg = edtTxtDialog(None, title="Edit Angle") dlg.ShowModal() ls_text = dlg.getValue() try: lr_degree = float(ls_text) except: lr_degree = 0.0 theta = lr_degree * pi / 180 dlg.Destroy() A0 = list_P[0] A1 = list_P[1] A2 = list_P[2] knots = [0., 0., 0., 1., 1., 1.] C = np.zeros((3, 3)) C[0, :] = A0[:3] C[1, :] = A1[:3] C[2, :] = A2[:3] weights = [1., cos(theta), 1.] nrb = cad_nurbs([knots], C, weights=weights) wk.viewer.CleanMarkerPoints() geo = cad_geometry() geo.append(nrb) wk.add_geometry(geometry(geo)) wk.Refresh()
# geo = patch(n=[nx,ny],p=[px,py]) geo_s = square(p=[2, 2]) nrb = geo_s[0] U, V = nrb.knots #C = nrb.points C = np.zeros_like(nrb.points) s = 1. / np.sqrt(2) weights = np.ones((3, 3)) weights[1, 0] = s weights[0, 1] = s weights[2, 1] = s weights[1, 2] = s srf = cad_nurbs([U, V], C, weights=weights) geo = cad_geometry() geo.append(srf) geo._internal_faces = geo_s._internal_faces geo._external_faces = geo_s._external_faces geo._connectivity = geo_s._connectivity # srf = geo[0] dim = srf.dim n = [nx, ny] list_t = [] for axis in range(0, dim): ub = srf.knots[axis][0] ue = srf.knots[axis][-1] list_t.append(np.linspace(ub, ue, n[axis] + 2)[1:-1])
def plotMesh(self, ntx=60, nty=60): from matplotlib import pylab as plt geo = self.geometry patch_id = 0 nrb = geo[patch_id] C = np.zeros_like(nrb.points) if self.Dirichlet: U = self.unknown_dirichlet else: U = self.unknown _C = U.tomatrix(patch_id) shape = list(nrb.shape) C = np.zeros(shape+[3]) C[...,0] = _C srf = cad_nurbs(nrb.knots, C, weights= nrb.weights) ub = srf.knots[0][0] ue = srf.knots[0][-1] vb = srf.knots[1][0] ve = srf.knots[1][-1] tx = np.linspace(ub, ue, ntx) ty = np.linspace(vb, ve, nty) nderiv = 1 nderiv = 2 # ... P = nrb.evaluate_deriv(tx,ty,nderiv=nderiv) x = P[0,:,:,0] xdu = P[1,:,:,0] xdv = P[2,:,:,0] xduu = P[3,:,:,0] xduv = P[4,:,:,0] xdvv = P[5,:,:,0] y = P[0,:,:,1] ydu = P[1,:,:,1] ydv = P[2,:,:,1] yduu = P[3,:,:,1] yduv = P[4,:,:,1] ydvv = P[5,:,:,1] jac = xdu * ydv - xdv * ydu # ... # ... D = srf.evaluate_deriv(tx,ty,nderiv=nderiv) Udu = D[1,...,0] Udv = D[2,...,0] Uduu = D[3,...,0] Uduv = D[4,...,0] Udvv = D[5,...,0] Udx = ydv * Udu - ydu * Udv Udx /= jac Udy = - xdv * Udu + xdu * Udv Udy /= jac C1 = Uduu - xduu * Udx - yduu * Udy C2 = Uduv - xduv * Udx - yduv * Udy C3 = Udvv - xdvv * Udx - ydvv * Udy Udxx = C1 * ydv**2 - 2 * C2 * ydu * ydv + C3 * ydu**2 Udxy = - C1 * xdv * ydv + C2 *(xdu * ydv + xdv * ydu) - C3 * xdu * ydu Udyy = C1 * xdv**2 - 2 * C2 * xdu * xdv + C3 * xdu**2 # ... # ... fig = plt.figure() # Udx[:,0] = 0. # Udx[:,-1] = 1. # Udy[0,:] = 0. # Udy[-1,:] = 1. for i,v in enumerate(ty): # phidx = Udu[:,i] # phidy = Udv[:,i] phidx = Udx[:,i] phidy = Udy[:,i] plt.plot(phidx, phidy, '-b') for i,u in enumerate(tx): # phidx = Udu[i,:] # phidy = Udv[i,:] phidx = Udx[i,:] phidy = Udy[i,:] plt.plot(phidx, phidy, '-b')
def evaluate(self, patch_id=None, sites=None, elts=None, fmt=True, nderiv=0, operator=None, parametric=False): # print "XXXXXXXXXXXXXXXXXXXXXXXXXXXX" V = self.space geo = V.geometry # print geo G = V.grids if operator == "grad": nderiv=1 if operator == "second_deriv": nderiv=2 if patch_id is None: patch = V.currentPatch patch_id = V.geometry.index(patch) # print "patch_id : ", patch_id if sites is not None: _sites = sites else: _sites = G.get_sites()[patch_id] npts = G.k nrb = geo[patch_id] nx = G.list_grid[patch_id].nx knots = nrb.knots weights = nrb.weights shape = list(nrb.shape) _C = self.tomatrix(patch_id) C = zeros(shape+[3]) C[...,0] = _C srf = cad_nurbs(knots, C, weights=weights) # ... defining the evaluate function APPEND = False NOUT = 1 if nderiv == 0: EVALUATE = srf.__call__ APPEND = True NOUT = 1 if nderiv > 0: def EVALUATE (u=None, v=None, w=None): return srf.evaluate_deriv(u=u, v=v, w=w, nderiv=nderiv) # ... # print "=======================" # print "INPUT" from .utils import evaluator D = evaluator(nrb.dim, _sites, EVALUATE, APPEND, nx=nx, npts=npts, elts=elts, fmt=fmt) # print "OUTPUT" # print D[0,0,:] # print D.shape # print "=======================" ndim = len(shape) xyz_arrays = None if operator is None: if APPEND: xyz_arrays = D[0,0] else: xyz_arrays = D else: if operator == "grad": if ndim == 1: nb = 1 ne = 2 if ndim == 2: nb = 1 ne = 3 if ndim == 3: nb = 1 ne = 4 if operator == "second_deriv": if ndim == 1: nb = 2 ne = 3 if ndim == 2: nb = 3 ne = 6 if ndim == 3: nb = 4 ne = 10 xyz_arrays = [] for i in range(nb,ne): du = D[0,i,:] xyz_arrays.append(du) # returns values on the logical domain if parametric: return xyz_arrays # returns values on the physical domain else: # ... P = V.get_points() # ... if nderiv >= 1: xyz = P[:,0,:] U = xyz_arrays[0,0,:] if ndim == 1: xyzdu = P[:,1,:] Udu = xyz_arrays[0,1,:] print("Physical evaluation not yet implemented") if ndim == 2: xyzdu = P[:,1,:] xyzdv = P[:,2,:] Udu = xyz_arrays[0,1,:] Udv = xyz_arrays[0,2,:] xdu = xyzdu[0,...] ydu = xyzdu[1,...] xdv = xyzdv[0,...] ydv = xyzdv[1,...] jac = xdu * ydv - xdv * ydu Udx = ydv * Udu - ydu * Udv Udx /= jac Udy = - xdv * Udu + xdu * Udv Udy /= jac if ndim == 3: xyzdu = P[:,1,:] xyzdv = P[:,2,:] xyzdw = P[:,3,:] Udu = xyz_arrays[0,1,:] Udv = xyz_arrays[0,2,:] Udw = xyz_arrays[0,3,:] print("Physical evaluation not yet implemented") # ... # ... if nderiv >= 2: if ndim == 1: xyzduu = P[:,2,:] Uduu = xyz_arrays[0,2,:] if ndim == 2: xyzduu = P[:,3,:] xyzduv = P[:,4,:] xyzdvv = P[:,5,:] Uduu = xyz_arrays[0,3,:] Uduv = xyz_arrays[0,4,:] Udvv = xyz_arrays[0,5,:] xdu = xyzdu[0,...] ydu = xyzdu[1,...] xdv = xyzdv[0,...] ydv = xyzdv[1,...] xduu = xyzduu[0,...] yduu = xyzduu[1,...] xduv = xyzduv[0,...] yduv = xyzduv[1,...] xdvv = xyzdvv[0,...] ydvv = xyzdvv[1,...] C1 = Uduu - xduu * Udx - yduu * Udy C2 = Uduv - xduv * Udx - yduv * Udy C3 = Udvv - xdvv * Udx - ydvv * Udy Udxx = C1 * ydv**2 - 2 * C2 * ydu * ydv + C3 * ydu**2 Udxx /= jac**2 Udxy = - C1 * xdv * ydv + C2 *(xdu * ydv + xdv * ydu) - C3 * xdu * ydu Udxy /= jac**2 Udyy = C1 * xdv**2 - 2 * C2 * xdu * xdv + C3 * xdu**2 Udyy /= jac**2 if ndim == 3: xyzduu = P[:,4,:] xyzdvv = P[:,5,:] xyzdww = P[:,6,:] xyzduv = P[:,7,:] xyzdvw = P[:,8,:] xyzduw = P[:,9,:] Uduu = xyz_arrays[0,4,:] Udvv = xyz_arrays[0,5,:] Udww = xyz_arrays[0,6,:] Uduv = xyz_arrays[0,7,:] Udvw = xyz_arrays[0,8,:] Uduw = xyz_arrays[0,9,:] # ... # ... copy data into xyz_arrays if nderiv >= 1: xyz_arrays[0,0,:] = U if ndim == 1: xyz_arrays[0,1,:] = Udx if ndim == 2: xyz_arrays[0,1,:] = Udx xyz_arrays[0,2,:] = Udy if ndim == 3: xyz_arrays[0,1,:] = Udx xyz_arrays[0,2,:] = Udy xyz_arrays[0,3,:] = Udz # ... # ... if nderiv >= 2: if ndim == 1: xyz_arrays[0,2,:] = Udxx if ndim == 2: xyz_arrays[0,3,:] = Udxx xyz_arrays[0,4,:] = Udxy xyz_arrays[0,5,:] = Udyy if ndim == 3: xyz_arrays[0,4,:] = Udxx xyz_arrays[0,5,:] = Udyy xyz_arrays[0,6,:] = Udzz xyz_arrays[0,7,:] = Udxy xyz_arrays[0,8,:] = Udyz xyz_arrays[0,9,:] = Udxz # ... return xyz_arrays
# ... # ... kx = 2. * pi ky = 2. * pi # ... exact solution u = lambda x,y : [sin ( kx * x ) * sin ( ky * y )] # ... rhs f = lambda x,y : [( kx**2 + ky**2 ) * sin ( kx * x ) * sin ( ky * y )] AllDirichlet = True nx=15; ny = 15; px = 2; py = 2 geo = domain(n=[nx,ny],p=[px,py]) PDE = poisson(geometry=geo, AllDirichlet=AllDirichlet) PDE.assembly(f=f) PDE.solve() # ... # ... normU = PDE.norm(exact=u) print(("norm U = ", normU)) U = PDE.unknown u = U.tomatrix(0) from caid.cad_geometry import cad_nurbs nrb = geo[0] C = np.zeros_like(nrb.points) C[...,0]=u nrb_f = cad_nurbs(nrb.knots, C, weights=nrb.weights) from caid.cad_geometry import cad_geometry geo_f = cad_geometry() geo_f.append(nrb_f) geo_f.save("u.xml") geo.save("geo.xml")
def xmltogeo(self, geo, doc, rootElt): from caid.cad_geometry import cad_nurbs, cad_op_nurbs, cad_grad_nurbs from caid.op_nurbs import grad geo_attributs = {} # ... geometry attributs for TAG in list(rootElt.attributes.keys()): txt = rootElt.attributes[TAG].value if txt == "True": txt = True if txt == "False": txt = False if txt is not None: geo_attributs[TAG] = txt # ... for datas in rootElt.getElementsByTagName(self.PATCH_TAG): attributs = {} # ... patch attributs for TAG in list(datas.attributes.keys()): txt = datas.attributes[TAG].value if txt is not None: attributs[TAG] = txt # ... if datas.nodeType == datas.ELEMENT_NODE: try: # ... reading dim list_dim = self._get_data(self.DIM_TAG, datas, fmt="int") li_dim = list_dim[0] # ... # ... reading the shape list_n = self._get_data(self.SHAPE_TAG, datas, fmt="int") # ... # ... reading the degree list_p = self._get_data(self.DEGREE_TAG, datas, fmt="int") # ... # ... reading the knots list_knots = [] for axis in range(0, li_dim): knots = self._get_data(self.KNOTS_TAG, datas, fmt="float", id=axis) list_knots.append(knots) # ... # ... reading the points list_points = self._get_data(self.POINTS_TAG, datas, fmt="float") C = np.asarray(list_points) C = C.reshape(list_n+[3]) # we need to add the Rd dimension # ... # ... reading the weights list_weights = self._get_data(self.WEIGHTS_TAG, datas, fmt="float") W = np.asarray(list_weights) W = W.reshape(list_n) # ... # ... reading rational try: list_rational = self._get_data(self.RATIONAL_TAG, datas, fmt="string") rational = list_rational[0] if rational.lower() == "yes": rational = True else: rational = False except: print("XML.read: Exception while reading rational arg") rational = False # ... # ... reading faces orientation list_sgn = self._get_data(self.ORIENTATION_TAG, datas, fmt="int") # ... try: nrb_type = attributs["type"] except: nrb_type = "cad_nurbs" try: nrb_operator = attributs["operator"] except: nrb_operator = None try: if nrb_type == "cad_nurbs": nrb = cad_nurbs(list_knots, C, weights=W) elif nrb_type == "cad_grad_nurbs": _nrb = NURBS(list_knots, C, weights=W) grad_nrb = grad(_nrb) nrb = cad_grad_nurbs(grad_nrb) elif nrb_type == "cad_op_nurbs": if nrb_operator == "grad": _nrb = NURBS(list_knots, C, weights=W) grad_nrb = grad(_nrb) nrb = cad_op_nurbs(grad_nrb) print("Warning: creates a cad_op_nurbs instead of cad_grad_nurbs") else: print("Operator not yet implemented") raise nrb.set_attributs(attributs) nrb.set_orientation(list_sgn) nrb.set_rational(rational) except: print("XML.read: Exception while creating the corresponding cad_nurbs") except: nrb = None print('Un des TAGS suivant est manquants') geo.append(nrb) # ... read connectivity list_connectivity = [] for Elt in rootElt.getElementsByTagName(self.CONNECTIVITY_TAG): original = self._get_data(self.ORIGINAL_TAG, Elt, fmt="int") clone = self._get_data(self.CLONE_TAG, Elt, fmt="int") connectivity = {} connectivity['original'] = original connectivity['clone'] = clone list_connectivity.append(connectivity) # ... # ... read internal_faces list_intFaces = [] try: Elt = rootElt.getElementsByTagName(self.INTERNALFACES_TAG)[0] nFaces = len(Elt.getElementsByTagName(self.FACE_TAG)) for id in range(0, nFaces): face = self._get_data(self.FACE_TAG, Elt, fmt="int", id=id) list_intFaces.append(face) except: pass # ... # ... read external_faces list_extFaces = [] try: Elt = rootElt.getElementsByTagName(self.EXTERNALFACES_TAG)[0] nFaces = len(Elt.getElementsByTagName(self.FACE_TAG)) for id in range(0, nFaces): face = self._get_data(self.FACE_TAG, Elt, fmt="int", id=id) list_extFaces.append(face) except: pass # ... geo.set_internal_faces(list_intFaces) geo.set_external_faces(list_extFaces) geo.set_connectivity(list_connectivity) geo.set_attributs(geo_attributs) return geo
ny = ny_in for i in range(0, nstagex): nx = 2 * nx + 1 for i in range(0, nstagey): ny = 2 * ny + 1 geo = domain(n=[nx_in, ny_in], p=[px_in, py_in]) nrb = geo[0] C = np.zeros_like(nrb.points) # import the solution _C = np.genfromtxt("u.txt") shape = list(nrb.shape) C = np.zeros(shape + [3]) C[..., 0] = _C srf = cad_nurbs(nrb.knots, C, weights=nrb.weights) geo_f = cad_geometry() geo_f.append(srf) geo_tmp = domain(n=[nx, ny], p=[px, py]) tx = [t for t in geo_tmp[0].knots[0] if t not in geo[0].knots[0]] ty = [t for t in geo_tmp[0].knots[1] if t not in geo[0].knots[1]] geo_f.refine(list_t=[tx, ty], list_p=[px - px_in, py - py_in]) u = geo_f[0].points[..., 0] import pylab as pl pl.contourf(u) pl.colorbar() pl.show() print(u.shape)