def GPI_Poincare(x,y,z, configuration=1): from osa import Client import matplotlib.pyplot as plt tracer = Client('http://esb.ipp-hgw.mpg.de:8280/services/FieldLineProxy?wsdl') config = tracer.types.MagneticConfig() config.configIds = configuration pos = tracer.types.Points3D() pos.x1 = np.linspace(0.95*np.mean(x[0,:]), 1.05*np.mean(x[-1,:]),80) pos.x2 = np.linspace(0.95*np.mean(y[0,:]), 1.05*np.mean(y[-1,:]),80) pos.x3 = np.linspace(0.95*np.mean(z[:,0]), 1.05*np.mean(z[:,-1]),80) poincare = tracer.types.PoincareInPhiPlane() poincare.numPoints = 400 poincare.phi0 = [4.787] ## This is where the poincare plane is (bean=0, triangle = pi/5.) task = tracer.types.Task() task.step = 0.2 task.poincare = poincare res = tracer.service.trace(pos, config, task, None, None) for i in range(0, len(res.surfs)): plt.scatter(res.surfs[i].points.x1, res.surfs[i].points.x3, color="black", s=0.5) plt.xlim(x[0,0],x[-1,-1]) plt.ylim(z[0,0],z[-1,-1]) plt.show() return res
def Grid(): tracer = Client( 'http://esb.ipp-hgw.mpg.de:8280/services/FieldLineProxy?wsdl') config = tracer.types.MagneticConfig() config.configIds = [ 1 ] ## Just use machine IDs instead of coil currents because it's easier. grid = tracer.types.Grid() grid.fieldSymmetry = 5 cyl = tracer.types.CylindricalGrid() cyl.numR, cyl.numZ, cyl.numPhi = 181, 181, 481 cyl.RMin, cyl.RMax, cyl.ZMin, cyl.ZMax = 4.05, 6.75, -1.35, 1.35 grid.cylindrical = cyl config.grid = grid machine = tracer.types.Machine(1) machine.grid.numX, machine.grid.numY, machine.grid.numZ = 500, 500, 100 machine.grid.ZMin, machine.grid.ZMax = -1.5, 1.5 machine.grid.YMin, machine.grid.YMax = -7, 7 machine.grid.XMin, machine.grid.XMax = -7, 7 #machine.meshedModelsIds = [164] machine.assemblyIds = [2] return machine, config, tracer
def FLT_poincare(phi=0, coils=coils_real_stm, currents=currents_st_real): '''FLT_poincare(phi=0,coils=coils_real_stm,currents=currents_st_real)''' flt = Client('http://esb.ipp-hgw.mpg.de:8280/services/FieldLineProxy?wsdl') p = flt.types.Points3D() p.x1 = x p.x2 = y p.x3 = z coils = coils_real_st currents = currents_st_real config = flt.types.MagneticConfig() config.inverseField = 0 config.coilsIds = coils config.coilsIdsCurrents = currents task = flt.types.Task() task.step = 0.2 task.characteristics = flt.types.MagneticCharacteristics() task.characteristics.axisSettings = flt.types.AxisSettings() res = flt.service.trace(p, config, task, None, None) reff = [res.characteristics[i].reff for i in range(len(res.characteristics))] return {'reff':reff}
def get_W7X_vessel(phi=[0], nz=256): from osa import Client import matplotlib.path as path srv2 = Client("http://esb.ipp-hgw.mpg.de:8280/services/MeshSrv?wsdl") #describe geometry mset = srv2.types.SurfaceMeshSet() # a set of surface meshes mset.references = [] #add references to single components, in this case ports w1 = srv2.types.SurfaceMeshWrap() ref = srv2.types.DataReference() ref.dataId = "371" # component id w1.reference = ref # w2 = srv2.types.SurfaceMeshWrap() # ref = srv2.types.DataReference() # ref.dataId = "341" # component id # w2.reference = ref mset.meshes = [w1] #, w2] lines = [] for y in range(phi.shape[0]): # intersection call for phi_vals=phi result = srv2.service.intersectMeshPhiPlane(phi[y], mset) all_vertices = np.zeros((len(result), 2)) R = np.zeros((len(result))) z = np.zeros((len(result))) # plotting for s, i in zip(result, np.arange( 0, len(result))): #loop over non-empty triangle intersections xyz = np.array((s.vertices.x1, s.vertices.x2, s.vertices.x3)).T R[i] = np.sqrt(xyz[:, 0]**2 + xyz[:, 1]**2)[0] # major radius z[i] = xyz[:, 2][0] all_vertices[i, :] = ((R[i], z[i])) # now have all vertices of vessel, but need to put them in sensible order... # find magnetic axis # axis_line = get_VMEC_surfaces(phi=[phi[y]],s=0,npoints=20) # axis = [axis_line[0].R[0], axis_line[0].Z[0]] # loc = np.asarray([all_vertices[:,0] - axis[0], all_vertices[:,1] - axis[1]]) # theta = np.arctan2(loc[1,:],loc[0,:]) # sorted_indices = sorted(range(len(theta)), key=lambda k: theta[k]) # r, z = [all_vertices[sorted_indices][::4,0], all_vertices[sorted_indices][::4,1]] Path = path.Path(all_vertices, closed=True) r, z = [all_vertices[::3, 0], all_vertices[::3, 1]] line = zb.rzline.line_from_points(r, z) line = line.equallySpaced(n=nz) lines.append(line) return lines
def get_VMEC_surfaces(phi=[0], s=0.75, w7x_run='w7x_ref_1', npoints=100): from osa import Client client = Client("http://esb.ipp-hgw.mpg.de:8280/services/vmec_v5?wsdl") points = client.service.getFluxSurfaces(str(w7x_run), phi, s, npoints) lines = [] for y in range(len(phi)): r, z = points[y].x1, points[y].x3 line = zb.rzline.line_from_points(r, z) line = line.equallySpaced() lines.append(line) return lines
def field_line_curvature(xin, yin, zin, configuration=1): tracer = Client( 'http://esb.ipp-hgw.mpg.de:8280/services/FieldLineProxy?wsdl') pos = tracer.types.Points3D() config = tracer.types.MagneticConfig() config.configIds = configuration lineTask = tracer.types.LineTracing() lineTask.numSteps = 512 task = tracer.types.Task() task.step = 2 * np.pi * (np.sqrt(xin**2 + yin**2)) / 512 task.lines = lineTask pos.x1 = xin pos.x2 = yin pos.x3 = zin res_forward = tracer.service.trace(pos, config, task, None, None) x = np.asarray(res_forward.lines[0].vertices.x1) y = np.asarray(res_forward.lines[0].vertices.x2) z = np.asarray(res_forward.lines[0].vertices.x3) # config.inverseField=1 # res_backward = tracer.service.trace(pos, config, task, None, None) # x = np.insert(x,0,res_backward.lines[0].vertices.x1[:]) # y = np.insert(y,0,res_backward.lines[0].vertices.x2[:]) # z = np.insert(z,0,res_backward.lines[0].vertices.x3[:]) r = np.sqrt(x**2 + y**2) phi = np.arctan2(y, x) dphi = phi[1] - phi[0] drdphi = calc.deriv(r) / dphi d2rdphi2 = calc.deriv(drdphi) / dphi k = (r**2 + 2 * drdphi**2 - r * d2rdphi2) / ((r**2 + drdphi**2)**(1.5)) # dzdphi = calc.deriv(z)/dphi # d2zdphi2 = calc.deriv(dzdphi)/dphi # Ktot = np.sqrt(d2zdphi2**2 + (d2rdphi2*dzdphi - d2zdphi2*drdphi)**2 - (d2rdphi2)**2) / (drdphi**2+dzdphi**2)**1.5 # kz = Ktot - k return r, phi, x, y, z, k
from osa import Client cl = Client("http://localhost:8088/mockApiPortSoap11?WSDL") reg_call = cl.service.registerCall(" ") res = cl.service.results(" ") print("Name: " + reg_call.name) print("Note: " + reg_call.note) print('\n'.join(res))
# from osa import Client # coils_db_client = Client('http://esb.ipp-hgw.mpg.de:8280/services/CoilsDBProxy?wsdl') # extender_client = Client('http://esb.ipp-hgw.mpg.de:8280/services/Extender?wsdl') # ''' get full configuration from db: ''' # my_config = coils_db_client.types.getMagneticConfiguration(1) # vmecURL = 'http://svvmec1.ipp-hgw.mpg.de:8080/vmecrest/v1/run/w7x.1000_1000_1000_1000_+0500_+0500.03.09ll_fixed2aaa_8.48/wout.nc' # points = cl.types.Points3D() # points.x1 = [5.5, 5.6, 5.6, 5.6, 5.6, 5.6, 4.6, 4.6, 4.6, 4.6, 4.6] # points.x2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.628, 0.628, 0.628, 0.628, 0.628] # points.x3 = [0.0, -0.2, -0.1, 0.0, 0.1, 0.2, -0.2, -0.1, 0.0, 0.1, 0.2] # plasmaField = cl.service.getExtendedField(None, vmecURL, my_config, None, points, None) from osa import Client coils_db_client = Client('http://esb.ipp-hgw.mpg.de:8280/services/CoilsDBProxy?wsdl') extender_client = Client('http://esb.ipp-hgw.mpg.de:8280/services/Extender?wsdl') ''' get full configuration from db: ''' my_config = coils_db_client.service.getConfigData(15)[0] cl = Client('http://esb.ipp-hgw.mpg.de:8280/services/Extender?wsdl') vmecURL = 'http://svvmec1.ipp-hgw.mpg.de:8080/vmecrest/v1/run/test42/wout.nc' points = cl.types.Points3D() points.x1 = [5.5, 5.6, 5.6, 5.6, 5.6, 5.6, 4.6, 4.6, 4.6, 4.6, 4.6] points.x2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.628, 0.628, 0.628, 0.628, 0.628] points.x3 = [0.0, -0.2, -0.1, 0.0, 0.1, 0.2, -0.2, -0.1, 0.0, 0.1, 0.2] plasmaField = cl.service.getExtendedField(None, vmecURL, my_config, None, points, None)
def GPI_lpar(x,y,z, configuration=1, limit=5000): ### Use webservices to get connection length ### from osa import Client tracer = Client('http://esb:8280/services/FieldLineProxy?wsdl') points = tracer.types.Points3D() points.x1 = x.flatten() points.x2 = y.flatten() points.x3 = z.flatten() ### copied from webservices...# task = tracer.types.Task() task.step = 6.5e-3 con = tracer.types.ConnectionLength() con.limit = limit con.returnLoads = False task.connection = con # diff = tracer.types.LineDiffusion() # diff.diffusionCoeff = .00 # diff.freePath = 0.1 # diff.velocity = 5e4 # task.diffusion = diff config = tracer.types.MagneticConfig() config.configIds = configuration ## Just use machine IDs instead of coil currents because it's easier. ### This bit doesn't work when called as a function. # config.coilsIds = range(160,230) # config.coilsIdsCurrents = [1.43e6,1.43e6,1.43e6,1.43e6,1.43e6]*10 # # config.coilsCurrents.extend([0.13*1.43e6,0.13*1.43e6]*10) # # config.coilsCurrents.extend([0.13*1.43e6,0.13*1.43e6]*10) # config.coilsIdsCurrents = [1.43e6,1.43e6,1.43e6,1.43e6,1.43e6]*10 # # config.coilsIdsCurrents.extend([0.13*1.43e6,0.13*1.43e6]*10) grid = tracer.types.Grid() grid.fieldSymmetry = 5 cyl = tracer.types.CylindricalGrid() cyl.numR, cyl.numZ, cyl.numPhi = 181, 181, 481 cyl.RMin, cyl.RMax, cyl.ZMin, cyl.ZMax = 4.05, 6.75, -1.35, 1.35 grid.cylindrical = cyl machine = tracer.types.Machine(1) machine.grid.numX, machine.grid.numY, machine.grid.numZ = 500,500,100 machine.grid.ZMin, machine.grid.ZMax = -1.5,1.5 machine.grid.YMin, machine.grid.YMax = -7, 7 machine.grid.XMin, machine.grid.XMax = -7, 7 # machine.meshedModelsIds = [164] machine.assemblyIds = [12,14,8,9,13,21] config.grid = grid config.inverseField = False res_fwd = tracer.service.trace(points, config, task, machine) ###### end of copied code ####### nx = x.shape[0] nz = x.shape[-1] lengths = np.zeros((nx*nz)) for n in np.arange(0,nx*nz): lengths[n] = res_fwd.connection[n].length lengths = np.ndarray.reshape(lengths,(nx,nz)) return lengths
def GPI_curvature(x,y,z): phi0 = 4.787 from osa import Client from boututils import calculus as calc nx = x.shape[0] nz = x.shape[-1] tracer = Client('http://esb.ipp-hgw.mpg.de:8280/services/FieldLineProxy?wsdl') config = tracer.types.MagneticConfig() config.configIds = [1] #### Expand in phi to take derivatives phi_list = np.linspace(.99*phi0, 1.01*phi0, 9) r = x*np.cos(phi0) + y*np.sin(phi0) dz = z[0,1]-z[0,0] dx = x[1,0]-x[1,1] dphi = phi_list[1]-phi_list[0] r_extended = np.zeros((nx,9,nz)) z_extended = np.zeros((nx,9,nz)) phi_extended = np.zeros((nx,9,nz)) for j in np.arange(0,phi_list.shape[0]): r_extended[:,j,:] = x*np.cos(phi_list[j]) + y*np.sin(phi_list[j]) z_extended[:,j,:] = z phi_extended[:,j,:] = np.ones((nx,nz))*phi_list[j] points = tracer.types.Points3D() points.x1 = (r_extended*np.cos(phi_extended)).flatten() points.x2 = (r_extended*np.sin(phi_extended)).flatten() points.x3 = z_extended.flatten() res = tracer.service.magneticField(points, config) ## Reshape to 3d array Bx = np.ndarray.reshape(np.asarray(res.field.x1),(nx,9,nz)) By = np.ndarray.reshape(np.asarray(res.field.x2),(nx,9,nz)) bphi = -Bx*np.sin(phi_extended) + By*np.cos(phi_extended) Bz = np.ndarray.reshape(np.asarray(res.field.x3),(nx,9,nz)) b2 = (Bx**2 + By**2 + Bz**2) Bx /= b2 By /= b2 Bz /= b2 bphi /= b2 dbphidz = np.zeros((nx,nz)) dbrdz = np.zeros((nx,nz)) dbzdphi = np.zeros((nx,nz)) dbzdr = np.zeros((nx,nz)) dbphidr = np.zeros((nx,nz)) dbrdphi = np.zeros((nx,nz)) curlbr = np.zeros((nx,nz)) curlbphi = np.zeros((nx,nz)) curlbz = np.zeros((nx,nz)) for i in np.arange(0,nx): dbphidz[i,:] = calc.deriv(bphi[i,4,:])/dz dbrdz[i,:] = calc.deriv(Bx[i,4,:])/dz for k in np.arange(0,nz): dbzdr[:,k] = calc.deriv(Bz[:,4,k])/dx dbphidr[:,k] = calc.deriv(bphi[:,4,k])/dx for i in np.arange(0,nx): dbzdphi[i,k] = calc.deriv(Bz[i,:,k])[4]/dphi dbrdphi[i,k] = calc.deriv(Bx[i,:,k])[4]/dphi curlbr[i,k] = (dbzdphi[i,k] - dbphidz[i,k]) curlbphi[i,k] = (dbrdz[i,k] - dbzdr[i,k]) curlbz[i,k] = (dbphidr[i,k] - dbrdphi[i,k]) return curlbr, curlbphi, curlbz
# -*- coding: utf-8 -*- """ Created on Thu Nov 30 11:22:01 2017 @author: tcw """ from osa import Client import numpy as np from pyversion.version import urllib import matplotlib.pyplot as plt import os as _os VClient = Client("http://esb:8280/services/vmec_v5?wsdl") def create_local_configs(vmec_local='C:\PortablePrograms\configs\\'): ''' creates local copy of boozer files for TRAVIS''' url = 'http://svvmec1.ipp-hgw.mpg.de:8080/vmecrest/v1/geiger/w7x/' if not _os.path.exists(vmec_local): _os.mkdir(vmec_local) label = {} stream = {} label[0] = 'DBM000' stream[0] = '1000_1000_1000_1000_+0750_+0750/01/00/boozer.txt' label[1] = 'EIM000' stream[1] = '1000_1000_1000_1000_+0000_+0000/01/00/boozer.txt' label[2] = 'EIM065' stream[2] = '1000_1000_1000_1000_+0000_+0000/01/04m/boozer.txt'
from __future__ import print_function import numpy as np from matplotlib import pyplot as plt from numpy import linalg as LA from numpy import pi from osa import Client vmec = Client('http://esb:8280/services/vmec_v5?wsdl') # Some reference equilibria """ Timing: P_LP11 w7x_ref_113, sval=0.6534784 [20,20], maxits=8 -> 500ms to 2.7e-9 [30,30], maxits=7 -> 547ms to 2.7e-9 [40,40], maxits=6 -> 656ms to 2.7e-9 [50,50], maxits=6 -> 891ms to 2.7e-9 # one gui advantage of 50x50 is that you can see the whole torus # limiter centrelins at equaotr corresponds for sval=0.654871 surf_distance, dic = distance_to_surface(sval=0.654871, vmec_eq='w7x_ref_113',point=limcl[8], npts=[30,30],ax3D=None,max_its=6) 0.636 is 3mm away from lim cl All points are > 3.11 mm so if we use 0.654871, all distances are positive. # So now plot the distance from last surface to the limiter centreline # this is not the whole story for flat faced limiters such as 483 (OK for 474) SOL = [[pt[2],distance_to_surface(sval=0.654871,vmec_eq='w7x_ref_113',point=pt, ax3D=None,max_its=4)[0]] for pt in limcl] print '\n'.join([str('{0:8.2f}, {1:8.2f}'.format(*(pair*1e3))) for pair in array(SOL)]) EEM - OP1.1. limiter; config. J w7x/1000_1000_1000_1000_+0390_+0390/01/020s/ w7x_ref_60 EEM - OP1.1. limiter; config. J w7x/1000_1000_1000_1000_+0390_+0390/01/00s/ w7x_ref_59
def island_fluxtube_grid(nx, ny, nz, turns=1, configuration=1): ### Copy GPI Code: # Generates a nx by nz rectangular grid at the location of the # outboard midplane island in standard configuration #### bottom_left = [6.1, 0, -0.5] bottom_right = [6.2, 0, -0.5] top_left = [6.1, 0, 0.5] top_right = [6.2, 0, 0.5] x_array = np.zeros((nx, ny, nz)) z_array = np.zeros((nx, ny, nz)) y_array = np.zeros((nx, ny, nz)) for y in np.arange(0, ny): left_edge_x = np.linspace(bottom_left[0], top_left[0], nz) left_edge_z = np.linspace(bottom_left[2], top_left[2], nz) left_edge_y = np.linspace(bottom_left[1], top_left[1], nz) right_edge_x = np.linspace(bottom_right[0], top_right[0], nz) right_edge_z = np.linspace(bottom_right[2], top_right[2], nz) right_edge_y = np.linspace(bottom_right[1], top_right[1], nz) for z in np.arange(0, nz): line_x = np.linspace(left_edge_x[z], right_edge_x[z], nx) line_z = np.linspace(left_edge_z[z], right_edge_z[z], nx) line_y = np.linspace(left_edge_y[z], right_edge_y[z], nx) z_array[:, y, z] = line_z x_array[:, y, z] = line_x y_array[:, y, z] = line_y ### Have grid, must calculate curvature #### tracer = Client( 'http://esb.ipp-hgw.mpg.de:8280/services/FieldLineProxy?wsdl') pos = tracer.types.Points3D() config = tracer.types.MagneticConfig() config.configIds = configuration lineTask = tracer.types.LineTracing() lineTask.numSteps = turns * ny task = tracer.types.Task() task.step = turns * 2 * np.pi * np.mean(x_array) / lineTask.numSteps task.lines = lineTask pos.x1 = x_array.flatten() pos.x2 = y_array.flatten() pos.x3 = z_array.flatten() res = tracer.service.trace(pos, config, task, None, None) x = np.asarray(res.lines[0].vertices.x1) y = np.asarray(res.lines[0].vertices.x2) z = np.asarray(res.lines[0].vertices.x3) r = np.sqrt(x**2 + y**2) phi = np.arctan2(y, x) dphi = phi[1] - phi[0] drdphi = calc.deriv(r) / dphi d2rdphi2 = calc.deriv(drdphi) / dphi k = (r**2 + 2 * drdphi**2 - r * d2rdphi2) / ((r**2 + drdphi**2)**(1.5)) k = np.ndarray.reshape(k, (nx, ny, nz)) # dzdphi = calc.deriv(z)/dphi # d2zdphi2 = calc.deriv(dzdphi)/dphi # Ktot = np.sqrt(d2zdphi2**2 + (d2rdphi2*dzdphi - d2zdphi2*drdphi)**2 - (d2rdphi2)**2) / (drdphi**2+dzdphi**2)**1.5 # kz = Ktot - k return r, phi, x, y, z, k
# From http://webservices.ipp-hgw.mpg.de/docs/howto.html takes about a minute. # •Import the osa Client class into your script: from osa import Client # •Create a new client object with the URL to the WSDL of the service you want to use: cl = Client("http://esb.ipp-hgw.mpg.de:8280/services/w7xfp?wsdl") #•You can now use all web operations of the serives as methods of this client object: cl.service.getProfilesNumberOfKnots() #• You can get a listing of all methods of the service by: print(cl.service) #• Get information about the data types, that are used in this service by: print(cl.types) #• Use the client object to create new objects of such a data type by: p = cl.types.Points3D() p.x1 = [5.5, 5.55, 5.6] p.x2 = [0.0, 0.0, 0.0] p.x3 = [0.0, 3.14, 6.28] """ Full sample script: from osa import Client """ cl = Client("http://esb.ipp-hgw.mpg.de:8280/services/w7xfp?wsdl") # should be '21' print(cl.service.getProfilesNumberOfKnots()) pressure = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] jtor = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
@author: gawe """ # ========================================================================== # from __future__ import absolute_import, with_statement, absolute_import, \ division, print_function, unicode_literals # ========================================================================== # # ========================================================================== # from osa import Client import numpy as _np import matplotlib.pyplot as _plt vmec = Client("http://esb.ipp-hgw.mpg.de:8280/services/vmec_v5?wsdl") vmecid = 'w7x_ref_60' currents = vmec.service.getCoilCurrents(vmecid) s = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1] numPoints = 100 phi_t = [0.0, _np.pi / 5] ## getting VMEC input from w7x_ref_60 run #inp1 = vmec.service.getVmecRunData('w7x_ref_60', 'input') # ## calculation ID #id = 'test20160114_7' # ## start of the VMEC run
from osa import Client import numpy as np import matplotlib.pyplot as plt srv2 = Client("http://esb.ipp-hgw.mpg.de:8280/services/MeshSrv?wsdl") #describe geometry mset = srv2.types.SurfaceMeshSet() # a set of surface meshes mset.references = [] for i in [17, 16, 15, 9, 7, 6, 5, 2]: # assemblies ids from database ref = srv2.types.DataReference() # for each assembly a data reference ref.dataId = "%d" % i mset.references.append(ref) # add references to single components, in this case ports w1 = srv2.types.SurfaceMeshWrap() ref = srv2.types.DataReference() ref.dataId = "387" # component id w1.reference = ref w2 = srv2.types.SurfaceMeshWrap() ref = srv2.types.DataReference() ref.dataId = "387" # component id w2.reference = ref mset.meshes = [w1, w2] # intersection call for phi = 0 result = srv2.service.intersectMeshPhiPlane(0.0, mset) # plotting for s in result: #loop over non-empty triangle intersections xyz = np.array((s.vertices.x1, s.vertices.x2, s.vertices.x3)).T R = np.sqrt(xyz[:, 0]**2 + xyz[:, 1]**2) # major radius