def separator_go(go, angle_, reparam=False, a=4 / 5): bottom, right, top, left = separator_snail(angle_, a=a) minimum = np.min(distance(left, right)) if reparam and minimum < 0.5: left_verts, right_verts = rep.constrained_arc_length(left, right, fac=1, smooth=True) else: left_verts, right_verts = [ rep.discrete_length_param(j) for j in [left, right] ] bottom_verts, top_verts = [ rep.discrete_length_param(j) for j in [bottom, top] ] goal_boundaries = dict( left=lambda g: ut.interpolated_univariate_spline( left_verts, left, g[1])) goal_boundaries.update( right=lambda g: ut.interpolated_univariate_spline( right_verts, right, g[1])) goal_boundaries.update( bottom=lambda g: ut.interpolated_univariate_spline( bottom_verts, bottom, g[0])) goal_boundaries.update(top=lambda g: ut.interpolated_univariate_spline( top_verts, top, g[0])) corners = { (0, 0): bottom.T[0], (1, 0): bottom.T[-1], (0, 1): top.T[0], (1, 1): top.T[-1] } return go, goal_boundaries, corners
def separator(go, angle_, reparam = True): bottom, top, left, right = sep.separator(angle_) if reparam: left_verts, right_verts = rep.constrained_arc_length(left, right, 6, smooth = False) else: left_verts, right_verts = [rep.discrete_length_param(j) for j in [left,right]] bottom_verts, top_verts = [rep.discrete_length_param(j) for j in [bottom,top]] goal_boundaries = dict(left = lambda g: ut.interpolated_univariate_spline(left_verts, left, g[1])) goal_boundaries.update(right = lambda g: ut.interpolated_univariate_spline(right_verts, right, g[1])) goal_boundaries.update(bottom = lambda g: ut.interpolated_univariate_spline(bottom_verts, bottom, g[0])) goal_boundaries.update(top = lambda g: ut.interpolated_univariate_spline(top_verts, top, g[0])) corners = {(0,0): bottom.T[0], (1,0): bottom.T[-1], (0,1): top.T[0], (1,1): top.T[-1]} return go, goal_boundaries, corners
def single_left_snail(go, c0 = True): assert go.periodic == [1] left, casing_left = snail()[:2] verts = rep.discrete_length_param(left) if c0: indices = c0_indices(left, thresh = 0.3) go = go.add_knots([[],verts[indices]]) go = go.raise_multiplicities([0,go.degree[1]-1], knotvalues = [[],verts[indices]]) goal_boundaries = dict() casing_spline = lambda g: ut.interpolated_univariate_spline(verts, casing_left, g[1]) goal_boundaries.update( right = lambda g: 16*casing_spline(g)/function.sqrt((casing_spline(g)**2).sum(0)) - np.array([13.1,0]), left = lambda g: (ut.interpolated_univariate_spline(verts, left, g[1])), ) return go, goal_boundaries, None
def middle(go, reparam = 'constrained_arc_length', splinify = True, c0 = True): #Return either a spline or point-cloud representation of the screw-machine with casing problem pathdir = os.path.dirname(os.path.realpath(__file__)) #ref_geom = go.geom top = numpy.stack([numpy.loadtxt(pathdir+'/xml/t2_row_{}'.format(i)) for i in range(1, 3)]).T top = top[numpy.concatenate([((top[1:]-top[:-1])**2).sum(1) > 1e-4, [True]])] top = top[65:230][::-1].T bot = np.stack([np.loadtxt(pathdir+'/xml/t1_row_{}'.format(i)) for i in range(1, 3)]).T bot = bot[numpy.concatenate([((bot[1:]-bot[:-1])**2).sum(1) > 1.5*1e-4, [True]])] bot = bot[430:1390][::-1].T #bot = np.delete(bot.T, 568, 0).T indices = c0_indices(bot) print(indices, 'indices') if True: # fix if reparam == 'standard' or reparam == 'length': top_verts, bot_verts = [rep.discrete_length_param(item) for item in [top, bot]] ## for now only upper and lower elif reparam == 'Joost': top_verts, bot_verts = rep.discrete_reparam_joost(top, bot) elif reparam == 'constrained_arc_length': top_verts, bot_verts = rep.constrained_arc_length(top, bot, 2) else: raise ValueError(reparam +' not supported') if c0: #go = go.add_c0([go.knots[1],[]]).to_c([1,1]) go = go.add_c0([bot_verts[indices],[]]) corners = {(0,0): bot.T[0], (1,0): bot.T[-1], (0,1): top.T[0], (1,1): top.T[-1]} goal_boundaries = dict( left = lambda g: corners[0,0]*(1-g[1]) + corners[0,1]*g[1], right = lambda g: corners[1,0]*(1-g[1]) + corners[1,1]*g[1], ) if splinify: goal_boundaries.update( top = lambda g: ut.interpolated_univariate_spline(top_verts, top, g[0]), bottom = lambda g: ut.interpolated_univariate_spline(bot_verts, bot, g[0]), ) else: goal_boundaries.update( top = Pointset(top_verts[1:-1], top[1:-1]), bottom = Pointset(bot_verts[1:-1], bot[1:-1]), ) return go, goal_boundaries, corners
def single_female_casing(go, radius = 36): assert go.periodic == [1] female = twin_screw()[1] - np.array([56.52,0])[:,None] verts = rep.discrete_length_param(female) spl = ndspline(verts, female) thresh = np.max(norm(female)) indices = [i for i in range(female.shape[1]) if norm(female[:,i][:,None]) > 0.97*thresh] goal_boundaries = dict() casing = circle_point(radius,theta(female.T[indices].T)) casing_spline = lambda g: ut.interpolated_univariate_spline(verts[indices], casing, g[1]) female = twin_screw()[1] goal_boundaries.update( left = lambda g: radius*casing_spline(g)/function.sqrt((casing_spline(g)**2).sum(0)) + np.array([56.52,0]), right = lambda g: ut.interpolated_univariate_spline(verts, female, g[1]), ) return go, goal_boundaries, None
def single_male_casing(go, radius = 36.1, c0 = True): assert go.periodic == [1] male = twin_screw()[0] angle = theta(male[:,0][:,None]) absc = np.linspace(angle,angle+2*np.pi, male.shape[1]) casing = (radius*np.vstack([np.cos(absc), np.sin(absc)])) verts_male, verts_casing = [rep.discrete_length_param(item) for item in [male, casing]] indices = c0_indices(male) print(verts_male[indices], go.knots) go = go.add_knots([[],verts_male[indices]]) go = go.raise_multiplicities([0,go.degree[1]-1], knotvalues = [[],verts_male[indices]]) goal_boundaries = dict() casing_spline = lambda g: ut.interpolated_univariate_spline(verts_casing, casing, g[1]) goal_boundaries.update( right = lambda g: radius*casing_spline(g)/function.sqrt((casing_spline(g)**2).sum(0)), left = lambda g: (ut.interpolated_univariate_spline(verts_male, male, g[1], center = np.array([0, 0.0]))), ) print(go.knotmultiplicities) return go, goal_boundaries, None
def nrw(go, stepsize = 1): with open (pathdir + '/nrw.txt', "r") as nrw: data=nrw.readlines() data = str(data) vec = re.findall(r'[+-]?[0-9.]+', data[0:]) vec = np.array([float(i) for i in vec])[::stepsize] l = np.nonzero(vec)[0] vec = vec[l] vec_ = np.reshape(vec,[len(vec)//2, 2]).T stepsize = vec_.shape[1]//4 vec_0, vec_1, vec_2, vec_3 = vec_[:,0:stepsize], vec_[:,stepsize:2*stepsize - 3], vec_[:,2*stepsize-3:3*stepsize-5].T[::-1,:].T, vec_[:,3*stepsize-5:].T[::-1,:].T verts_0, verts_1, verts_2, verts_3 = [rep.discrete_length_param(item) for item in [vec_0, vec_1, vec_2, vec_3]] print(vec_1.shape) goal_boundaries = dict() goal_boundaries.update( top = lambda g: ut.interpolated_univariate_spline(verts_1, vec_1, g[0]), bottom = lambda g: ut.interpolated_univariate_spline(verts_3, vec_3, g[0]), left = lambda g: ut.interpolated_univariate_spline(verts_0, vec_0, g[1]), right = lambda g: ut.interpolated_univariate_spline(verts_2, vec_2, g[1]), ) corners = {(0,0): (vec_0[0,0],vec_0[1,0]), (1,0): (vec_3[0,-1],vec_3[1,-1]), (0,1): (vec_1[0,0],vec_1[1,0]), (1,1): (vec_1[0,-1],vec_1[1,-1])} return goal_boundaries, corners
def isoline(go, radius_male = 36.1, radius_female = 36): center = np.array([56.52,0]) x1, x2 = cusp(radius_male, radius_female, 56.52) male_angles, female_angles = [theta(i[:,None]) for i in [x1,x2]], [theta(i[:,None], center = center) for i in [x1,x2]] male, female = twin_screw(angle = np.pi/4.0) left_casing, right_casing = [single_casing(r) for r in [radius_male, radius_female]] male_indices = [i for i in range(male.shape[1]) if (theta(male[:,i][:,None]) >= male_angles[1] and theta(male[:,i][:,None]) <= male_angles[0]) ] female_indices = [i for i in range(female.shape[1]) if (theta(female[:,i][:,None], center = center) >= female_angles[0] and theta(female[:,i][:,None], center = center) <= female_angles[1] and norm(female[:,i][:,None]) <= radius_male)] left_casing_indices = [i for i in range(left_casing.shape[1]) if (theta(left_casing[:,i][:,None]) >= male_angles[1] and theta(left_casing[:,i][:,None]) <= male_angles[0])] right = np.hstack((left_casing.T[left_casing_indices][range(107,180)].T,female.T[female_indices].T, left_casing.T[left_casing_indices][range(30,107)].T)) left = male.T[male_indices].T corners = {(0,0):left.T[0], (0,1): left.T[-1], (1,0): right.T[0], (1,1): right.T[-1]} #left_verts, right_verts = rep.discrete_reparam_joost(left, right) right_verts, left_verts = rep.constrained_arc_length(right, left, 5) goal_boundaries = dict( bottom = lambda g: corners[0,0]*(1-g[0]) + corners[1,0]*g[0], top = lambda g: corners[0,1]*(1-g[0]) + corners[1,1]*g[0], ) goal_boundaries.update( left = lambda g: ut.interpolated_univariate_spline(left_verts, left, g[1]), right = lambda g: ut.interpolated_univariate_spline(right_verts, right, g[1]), ) return goal_boundaries, corners