def produceTraceArrays(rmin, rmax, pmin=0, pmax=0, currentOn=False, modelType='VIP4'): """ To do the field trace using a model over a range of phi and radii. Each phi and radius field trace is saved as a separate text file with the radius and phi value saved in the name. Made as a function such that this could be used as a class in the future. :param rmin: :param rmax: :param pmin: :param pmax: :param modelType: Default VIP4 :param currentOn: Default False """ printTester = 1 fieldGenerator = field_models() signArray = [-1, 1] # To swap the direction of travel along the field line as well as fix array ordering for phi0 in np.arange(pmin, pmax + 0.001, 45 * np.pi/180): output = [] for r0 in np.arange(rmin, rmax + 0.001, 2): xInRJ, yInRJ, zInRJ, Bmag = [], [], [], [] # Start a new field line trace for sign in signArray: # Start a new direction along the field line theta = 0.5 * np.pi r = r0 phi = phi0 tempxInRJ, tempyInRJ, tempzInRJ, tempBmag = [], [], [], [] # So I can have two sets of arrays to # combine later x, y, z = sph_cart(r, theta, phi) print('Radius = %5.2f and Phi = %1.2f started going %1.0f' % (r, phi * 180 / np.pi, sign)) while r >= 1: Br, Bt, Bp, Bx, By, Bz = fieldGenerator.Internal_Field(r, theta, phi, currentOn, modelType) if printTester % 10 == 0: tempxInRJ.append(x) tempyInRJ.append(y) tempzInRJ.append(z) tempBmag.append(magnitudeVector(Br, Bt, Bp)) # print(r) xMove, yMove, zMove = unitVector(Bx, By, Bz) step = np.abs(np.log10(magnitudeVector(Bx, By, Bz))) * 10 if step < 100: step = 100 x += sign * xMove / step y += sign * yMove / step z += sign * zMove / step r, theta, phi = cart_sph(x, y, z) printTester += 1 # Flipping the arrays if they need to be before putting them together and saving the final trace array tempxInRJ = tempxInRJ[::sign] tempyInRJ = tempyInRJ[::sign] tempzInRJ = tempzInRJ[::sign] tempBmag = tempBmag[::sign] xInRJ.extend(tempxInRJ) yInRJ.extend(tempyInRJ) zInRJ.extend(tempzInRJ) Bmag.extend(tempBmag) output.append(np.c_[xInRJ, yInRJ, zInRJ, Bmag]) np.save('newoutput/radius%0.2fto%0.2fphi%0.2fCurrentOn=%s' % (rmin, rmax, phi0, currentOn), output) pass
'hoto+': [0.06, 134, -4.63, 1.057] } ME = 0.00054858 speciesMass = { 'e-': 0.00054858, 'o++': 15.999 - (ME * 2), 's+': 32.065 - ME, 's++': 32.065 - (ME * 2), 's+++': 32.065 - (ME * 3), 'h+': 1.00784 - ME, 'na+': 22.989769 - ME, 'hoto+': 15.999 - (ME * 2), 'o+': 15.999 - ME } fieldGenerator = field_models() # Calculate radius, scale height, x, y, equatorial magnetic field, Alfven and radial velocity # and number density by iterating over radius and angle for r in np.arange(6, 100, 0.5): radius.append(r) # scaleHeight.append(radialScaleHeight(r)) # No longer needed radialVelocityAtPi.append(radialVelocityFunc(r, speciesList, speciesMass)) alfvenVelocityATPi.append( alfvenVelocityAtRPhi(r, 0, speciesMass, speciesMass)) for phi in np.arange(0, 2 * np.pi + 0.03, 0.05): xInRJ.append(r * np.cos(phi)) yInRJ.append(r * np.sin(phi)) equatorialMagField.append(equatorialMagneticField(r, phi)) numberDensity.append(equatorialTotalPlasmaNumberDensity( r, speciesList)) radialVelocity.append(radialVelocityFunc(r, speciesList, speciesMass))