def draw_acc(index, boundary, dx): acc = acc_array() acc1 = acc[0:18,:] acc2 = acc[19:,:] print acc1 print acc2 gmsh.gmsh_geo_comment(output, 'ACC') index.start = index.point + 1 loopstartpoint = index.start for i in range(len(acc1[:,0])): index.point += 1 location = project(acc1[i,:]) gmsh.gmsh_geo_draw_point(output, index.point, location, 0.0) index = gmsh.gmsh_geo_draw_loop(output, boundary, index, loopstartpoint, False, True) #index.start = index.point + 1 #loopstartpoint = index.start for i in range(len(acc2[:,0])): index.point += 1 location = project(acc2[i,:]) gmsh.gmsh_geo_draw_point(output, index.point, location, 0.0) index = gmsh.gmsh_geo_draw_loop(output, boundary, index, loopstartpoint, True, True) return index
def draw_acc_old(index, boundary, dx): acc = acc_array() gmsh.gmsh_geo_comment(output, 'ACC') index.start = index.point + 1 loopstartpoint = index.start for i in range(len(acc[:,0])): index.point += 1 location = project(acc[i,:]) gmsh.gmsh_geo_draw_point(output, index.point, location, 0.0) for i in range(len(acc[:,0])): a = index.start + i b = a + 1 if (a == index.point): b = index.start output.write('Line(%i) = {%i,%i};\n' % (i + 100000, a, b )) output.write('Line Loop(999999) = { %i : %i};\n' % ( index.start, index.point )) return index
def draw_parallel_explicit(start, end, index, latitude_max, dx): #print start, end, index.point # Note start is actual start - 1 if (latitude_max is None): latitude_max = max(start[1], end[1]) else: latitude_max = max(latitude_max, start[1], end[1]) current = start tolerance = dx * 0.6 gmsh.gmsh_geo_comment(output, 'Closing path with parallels and merdians, from (%.8f, %.8f) to (%.8f, %.8f)' % ( start[0], start[1], end[0], end[1] ) ) if (compare_points(current, end, dx)): gmsh.gmsh_geo_comment(output, 'Points already close enough, no need to draw parallels and meridians after all') return index gmsh.gmsh_geo_comment(output, 'Drawing meridian to max latitude index %s at %f.2, %f.2 (to match %f.2)' % (index.point, current[0], current[1], latitude_max)) while (current[1] != latitude_max): if (current[1] < latitude_max): current[1] = current[1] + dx else: current[1] = current[1] - dx if (abs(current[1] - latitude_max) < tolerance): current[1] = latitude_max if (compare_points(current, end, dx)): return index index.point += 1 printvv('Drawing meridian to max latitude index %s at %f.2, %f.2 (to match %f.2)' % (index.point, current[0], current[1], latitude_max)) loc = project(current) gmsh.gmsh_geo_draw_point(output, index.point, loc, 0.0) gmsh.gmsh_geo_comment(output, 'Drawing parallel index %s at %f.2 (to match %f.2), %f.2' % (index.point, current[0], end[0], current[1])) while (current[0] != end[0]): if (current[0] < end[0]): current[0] = current[0] + dx else: current[0] = current[0] - dx if (abs(current[0] - end[0]) < tolerance): current[0] = end[0] if (compare_points(current, end, dx)): return index index.point += 1 printvv('Drawing parallel index %s at %f.2 (to match %f.2), %f.2' % (index.point, current[0], end[0], current[1])) loc = project(current) gmsh.gmsh_geo_draw_point(output, index.point, loc, 0.0) gmsh.gmsh_geo_comment(output, 'Drawing meridian to end index %s at %f.2, %f.2 (to match %f.2)' % (index.point, current[0], current[1], end[1])) while (current[1] != end[1]): if (current[1] < end[1]): current[1] = current[1] + dx else: current[1] = current[1] - dx if (abs(current[1] - end[1]) < tolerance): current[1] = end[1] if (compare_points(current, end, dx)): return index index.point += 1 printvv('Drawing meridian to end index %s at %f.2, %f.2 (to match %f.2)' % (index.point, current[0], current[1], end[1])) loc = project(current) gmsh.gmsh_geo_draw_point(output, index.point, loc, 0.0) gmsh.gmsh_geo_comment(output, 'Closed path with parallels and merdians, from (%.8f, %.8f) to (%.8f, %.8f)' % ( start[0], start[1], end[0], end[1] ) ) return index
def array_to_gmsh_points(num, index, location, minarea, region, dx, latitude_max): gmsh.gmsh_geo_comment(output, 'Ice-Land mass number %s' % (num)) count = 0 pointnumber = len(location[:,0]) valid = [False]*pointnumber validnumber = 0 loopstart = None loopend = None flag = 0 #location[:, 0] = - location[:, 0] - 90.0 for point in range(pointnumber): longitude = location[point, 0] latitude = location[point, 1] if ( check_point_required(region, location[point, :]) ): valid[point] = True validnumber += 1 if (flag == 0): loopstart = point flag = 1 elif (flag == 1): loopend = point #print latitude, valid[point] if (loopend is None): printvv('Path %i skipped (no points found in region)' % ( num )) gmsh.gmsh_geo_comment(output, ' Skipped (no points found in region)\n') return index closelast=False if (compare_points(location[loopstart,:], location[loopend,:], dx)): # Remove duplicate line at end # Note loopend no longer valid valid[loopend] = False validnumber -= 1 closelast=True validlocation = zeros( (validnumber, 2) ) close = [False]*validnumber count = 0 closingrequired = False closingrequirednumber = 0 for point in range(pointnumber): if (valid[point]): validlocation[count,:] = location[point,:] if ((closingrequired) and (count > 0)): if (compare_points(validlocation[count-1,:], validlocation[count,:], dx)): closingrequired = False close[count] = closingrequired count += 1 closingrequired = False else: if (not closingrequired): closingrequired = True closingrequirednumber += 1 if (closelast): close[-1] = True closingrequirednumber += 1 if (closingrequirednumber == 0): closingtext = '' elif (closingrequirednumber == 1): closingtext = ' (required closing in %i part of the path)' % (closingrequirednumber) else: closingtext = ' (required closing in %i parts of the path)' % (closingrequirednumber) area = area_enclosed(validlocation) if (area < minarea): printvv('Path %i skipped (area too small)' % ( num )) gmsh.gmsh_geo_comment(output, ' Skipped (area too small)\n') return index printv('Path %i points %i/%i area %g%s' % ( num, validnumber, pointnumber, area_enclosed(validlocation), closingtext )) # if (closingrequired and closewithparallel): # latitude_max = None # index_start = index + 1 # for point in range(validnumber - 1): # longitude = validlocation[point,0] # latitude = validlocation[point,1] # index += 1 # loc = project(longitude, latitude) # gmsh.gmsh_geo_draw_point(output, index, loc, 0) ) # if (latitude_max is None): # latitude_max = latitude # else: # latitude_max = max(latitude_max, latitude) # gmsh.gmsh_geo_draw_parallel(output, index, index_start, [ validlocation[point,0], max(latitude_max, validlocation[point,1]) ], [ validlocation[0,0], max(latitude_max, validlocation[0,1]) ], points=200) # index += 200 # # index += 1 # gmsh.gmsh_geo_draw_point(output, index, project(validlocation[0,0], validlocation[0,1]), 0) ) # # else: if (close[0]): close[-1] = close[0] index.start = index.point + 1 loopstartpoint = index.start for point in range(validnumber): #longitude = validlocation[point,0] #latitude = validlocation[point,1] if ((close[point]) and (point == validnumber - 1) and (not (compare_points(validlocation[point], validlocation[0], dx)))): gmsh.gmsh_geo_comment(output, '**** END ' + str(point) + '/' + str(validnumber-1) + str(close[point])) index = gmsh.gmsh_geo_draw_loop(output, boundary, index, loopstartpoint, False, False) index = draw_parallel_explicit(validlocation[point], validlocation[0], index, latitude_max, dx) index = gmsh.gmsh_geo_draw_loop(output, boundary, index, loopstartpoint, True, True) gmsh.gmsh_geo_comment(output, '**** END end of loop ' + str(closelast) + str(point) + '/' + str(validnumber-1) + str(close[point])) elif ((close[point]) and (point > 0) and (not (compare_points(validlocation[point], validlocation[0], dx)))): gmsh.gmsh_geo_comment(output, '**** NOT END ' + str(point) + '/' + str(validnumber-1) + str(close[point])) gmsh.gmsh_geo_comment(output, str(validlocation[point,:]) + str(validlocation[point,:])) index = gmsh.gmsh_geo_draw_loop(output, boundary, index, loopstartpoint, False, False) index = draw_parallel_explicit(validlocation[point - 1], validlocation[point], index, latitude_max, dx) index = gmsh.gmsh_geo_draw_loop(output, boundary, index, loopstartpoint, False, True) gmsh.gmsh_geo_comment(output, '**** NOT END end of loop ' + str(point) + '/' + str(validnumber-1) + str(close[point])) else: index.point += 1 gmsh.gmsh_geo_draw_point(output, index.point, project(validlocation[point,:]), 0) index.contournodes.append(index.point) index = gmsh.gmsh_geo_draw_loop(output, boundary, index, loopstartpoint, (closelast and (point == validnumber - 1)), False) return index