def test4RK2(Npanels=50): """Test RK-2 time integrator with boundary conditions. Simulate a Viscous flow around a cylinder. NPoins being number of tracer points and NPanels being number of panels on the cylinder surface""" #Define parameters Re = 1000 delta = (1. / Re)**0.5 lemda = delta * math.pi gmin = 0.2 #Define V_Infinite, field generators and modifiable points vinf = numpy.array([1.0, 0.0]) fieldGens = [] toMod = [] #Create cylinder points for boundary conditions rad = 1.0 [BCpoints, BCcp, BCNormals, BCinFunction, BCreflectFunction] = wallBC.cylBCPoints(rad, Npanels) # Viscocity nu = ((vinf.dot(vinf))**0.5) * 2 * rad / Re #Initiate boundary condnitions BCList = [] BC = wallBC.wallNPNSBC(BCpoints, BCcp, BCNormals, BCinFunction, BCreflectFunction) BCList.append(BC) # Initiate time mesh startTime = 0.0 CFL = 1.0 timeStep = CFL * lemda / ((vinf.dot(vinf))**0.5) endTime = 6.0 timeMesh = dfn.linearTimeMesh(startTime, timeStep, endTime) #Start time loop for i in range(1, len(timeMesh)): print "time=%f" % timeMesh[i] dt = timeMesh[i] - timeMesh[i - 1] # Advect particles advectRK2(dt, toMod, fieldGens, vinf, BCList) # Introduce no slip boundary conditions # Vslips are calculated in the advection step. That is to be changed for better architecture [eachBC.applyNSBC(fieldGens, toMod, gmin, delta) for eachBC in BCList] #Diffuse all particles using RVM diffusion.applyRVM(dt, nu, toMod, BCList) # Post Processing: to be done after 5 time steps if i % 5 == 0: # Plot Vorticity Particles plots.plotVort(toMod, BCList, timeMesh[i]) # Plot Velocity Field plots.plotVel(fieldGens, vinf, BCList, timeMesh[i]) return ()
def test1RK2(endTime=100.): """A test case for advection RK-2 integrator without any boundaries . Take two vortices of same strength. They should rotate in a circle""" #Initiate vortex list VList = dfn.vortexList() # Define vortices p1 = numpy.array([-0.5, 0.0]) p2 = numpy.array([0.5, 0.0]) rad = 0.5 VList.addVortex(position=p1, strength=1.0, blobType=0, delta=0.0, traceFlag=1) VList.addVortex(position=p2, strength=1.0, blobType=0, delta=0.0, traceFlag=1) # Initiate time mesh startTime = 0.0 timeStep = 0.01 timeMesh = dfn.linearTimeMesh(startTime, timeStep, endTime) #Start time loop for i in range(1, len(timeMesh)): print "time=%f" % timeMesh[i] dt = timeMesh[i] - timeMesh[i - 1] advectRK2(dt, toMod=[VList], fieldGens=[VList], vinf=0.0) #Plot traces of particles plt.figure(1) plt.title('test case for RK-2 two particle motion in a circle') for i in range(VList.nPoints): plt.plot( numpy.array(VList.allV[i].traceHist).transpose()[0], numpy.array(VList.allV[i].traceHist).transpose()[1]) #Calculate Error history newPos1 = VList.allV[0].traceHist newPos2 = VList.allV[0].traceHist err1 = [ abs(newPos1[i].dot(newPos1[i]) - rad**2) for i in range(len(newPos1)) ] err2 = [ abs(newPos2[i].dot(newPos2[i]) - rad**2) for i in range(len(newPos2)) ] #Plot errors plt.figure(2) plt.title('errors with time') plt.plot(err1) plt.plot(err2) return ()
def test4RK2(Npanels=50): """Test RK-2 time integrator with boundary conditions. Simulate a Viscous flow around a cylinder. NPoins being number of tracer points and NPanels being number of panels on the cylinder surface""" #Define parameters Re=1000 delta=(1./Re)**0.5 lemda=delta*math.pi gmin=0.2 #Define V_Infinite, field generators and modifiable points vinf=numpy.array([1.0,0.0]) fieldGens=[] toMod=[] #Create cylinder points for boundary conditions rad=1.0 [BCpoints,BCcp,BCNormals,BCinFunction,BCreflectFunction]=wallBC.cylBCPoints(rad,Npanels) # Viscocity nu=((vinf.dot(vinf))**0.5)*2*rad/Re #Initiate boundary condnitions BCList=[] BC=wallBC.wallNPNSBC(BCpoints,BCcp,BCNormals,BCinFunction,BCreflectFunction) BCList.append(BC) # Initiate time mesh startTime=0.0 CFL=1.0 timeStep=CFL*lemda/((vinf.dot(vinf))**0.5) endTime=6.0 timeMesh=dfn.linearTimeMesh(startTime,timeStep,endTime) #Start time loop for i in range(1,len(timeMesh)): print "time=%f"%timeMesh[i] dt=timeMesh[i]-timeMesh[i-1] # Advect particles advectRK2(dt,toMod,fieldGens,vinf,BCList) # Introduce no slip boundary conditions # Vslips are calculated in the advection step. That is to be changed for better architecture [eachBC.applyNSBC(fieldGens,toMod,gmin,delta) for eachBC in BCList] #Diffuse all particles using RVM diffusion.applyRVM(dt,nu,toMod,BCList) # Post Processing: to be done after 5 time steps if i%5==0: # Plot Vorticity Particles plots.plotVort(toMod,BCList,timeMesh[i]) # Plot Velocity Field plots.plotVel(fieldGens,vinf,BCList,timeMesh[i]) return()
def test3RK2(Npanels=50): """Compute the motion of a single point vortex at a distance of 1.5 units from the center of the cylinder and plot its trajectory""" #Define V_Infinite, field generators and modifiable points vinf = numpy.array([0.0, 0.0]) fieldGens = [] toMod = [] #Define vortex points VList = dfn.vortexList() pos = numpy.array([0.0, 1.1]) VList.addVortex(position=pos, strength=1.0, blobType=1, delta=0.1, traceFlag=1) toMod.append(VList) fieldGens.append(VList) #Create cylinder points for boundary conditions rad = 1.0 [BCpoints, BCcp, BCNormals, iF, rF] = wallBC.cylBCPoints(rad, Npanels) #Initiate boundary condnitions BCList = [] BC = wallBC.wallNPNSBC(BCpoints, BCcp, BCNormals, iF, rF) BCList.append(BC) # Initiate time mesh startTime = 0.0 timeStep = 0.08 endTime = 100.0 timeMesh = dfn.linearTimeMesh(startTime, timeStep, endTime) #Start time loop for i in range(1, len(timeMesh)): print "time=%f" % timeMesh[i] dt = timeMesh[i] - timeMesh[i - 1] advectRK2(dt, toMod, fieldGens, vinf, BCList) #Plot traces of particles plt.figure(1) plt.title('Assignment 3 Problem 3') plt.plot(numpy.array(BCpoints).transpose()[0], numpy.array(BCpoints).transpose()[1], linewidth=3.0) for i in range(VList.nPoints): plt.plot( numpy.array(VList.allV[i].traceHist).transpose()[0], numpy.array(VList.allV[i].traceHist).transpose()[1]) plt.show() return ()
def test2RK2(Npoints=30, Npanels=50): """Test RK-2 time integrator with boundary conditions. Simulate a non-viscous flow around a cylinder. NPoins being number of tracer points and NPanels being number of panels on the cylinder surface""" #Define V_Infinite, field generators and modifiable points vinf = numpy.array([1.0, 0.0]) fieldGens = [] toMod = [] #Define tracer points TList = dfn.traceList() lowLim = numpy.array([-5.0, -2.0]) upLim = numpy.array([-5.0, 2.0]) for i in range(Npoints): pos = (lowLim + (float(i) / Npoints * (upLim - lowLim))) TList.addTracer(pos, traceFlag=1) toMod.append(TList) #Create cylinder points for boundary conditions rad = 1.0 [BCpoints, BCcp, BCNormals, iF, rF] = wallBC.cylBCPoints(rad, Npanels) #Initiate boundary condnitions BCList = [] BC = wallBC.wallNPNSBC(BCpoints, BCcp, BCNormals, iF, rF) BCList.append(BC) # Initiate time mesh startTime = 0.0 timeStep = 0.08 endTime = 10.0 timeMesh = dfn.linearTimeMesh(startTime, timeStep, endTime) #Start time loop for i in range(1, len(timeMesh)): print "time=%f" % timeMesh[i] dt = timeMesh[i] - timeMesh[i - 1] advectRK2(dt, toMod, fieldGens, vinf, BCList) #Plot traces of particles plt.figure(1) plt.title('test case for RK-2 non-viscous flow around a cylinder') plt.plot(numpy.array(BCpoints).transpose()[0], numpy.array(BCpoints).transpose()[1], linewidth=3.0) for i in range(TList.nPoints): plt.plot( numpy.array(TList.allV[i].traceHist).transpose()[0], numpy.array(TList.allV[i].traceHist).transpose()[1]) return ()
def test2RK2(Npoints=30,Npanels=50): """Test RK-2 time integrator with boundary conditions. Simulate a non-viscous flow around a cylinder. NPoins being number of tracer points and NPanels being number of panels on the cylinder surface""" #Define V_Infinite, field generators and modifiable points vinf=numpy.array([1.0,0.0]) fieldGens=[] toMod=[] #Define tracer points TList=dfn.traceList() lowLim=numpy.array([-5.0,-2.0]) upLim=numpy.array([-5.0,2.0]) for i in range(Npoints): pos=(lowLim+(float(i)/Npoints*(upLim-lowLim))) TList.addTracer(pos,traceFlag=1) toMod.append(TList) #Create cylinder points for boundary conditions rad=1.0 [BCpoints,BCcp,BCNormals,iF,rF]=wallBC.cylBCPoints(rad,Npanels) #Initiate boundary condnitions BCList=[] BC=wallBC.wallNPNSBC(BCpoints,BCcp,BCNormals,iF,rF) BCList.append(BC) # Initiate time mesh startTime=0.0 timeStep=0.08 endTime=10.0 timeMesh=dfn.linearTimeMesh(startTime,timeStep,endTime) #Start time loop for i in range(1,len(timeMesh)): print "time=%f"%timeMesh[i] dt=timeMesh[i]-timeMesh[i-1] advectRK2(dt,toMod,fieldGens,vinf,BCList) #Plot traces of particles plt.figure(1) plt.title('test case for RK-2 non-viscous flow around a cylinder') plt.plot(numpy.array(BCpoints).transpose()[0],numpy.array(BCpoints).transpose()[1],linewidth=3.0) for i in range(TList.nPoints): plt.plot(numpy.array(TList.allV[i].traceHist).transpose()[0],numpy.array(TList.allV[i].traceHist).transpose()[1]) return()
def test3RK2(Npanels=50): """Compute the motion of a single point vortex at a distance of 1.5 units from the center of the cylinder and plot its trajectory""" #Define V_Infinite, field generators and modifiable points vinf=numpy.array([0.0,0.0]) fieldGens=[] toMod=[] #Define vortex points VList=dfn.vortexList() pos=numpy.array([0.0,1.1]) VList.addVortex(position=pos,strength=1.0,blobType=1,delta=0.1,traceFlag=1) toMod.append(VList) fieldGens.append(VList) #Create cylinder points for boundary conditions rad=1.0 [BCpoints,BCcp,BCNormals,iF,rF]=wallBC.cylBCPoints(rad,Npanels) #Initiate boundary condnitions BCList=[] BC=wallBC.wallNPNSBC(BCpoints,BCcp,BCNormals,iF,rF) BCList.append(BC) # Initiate time mesh startTime=0.0 timeStep=0.08 endTime=100.0 timeMesh=dfn.linearTimeMesh(startTime,timeStep,endTime) #Start time loop for i in range(1,len(timeMesh)): print "time=%f"%timeMesh[i] dt=timeMesh[i]-timeMesh[i-1] advectRK2(dt,toMod,fieldGens,vinf,BCList) #Plot traces of particles plt.figure(1) plt.title('Assignment 3 Problem 3') plt.plot(numpy.array(BCpoints).transpose()[0],numpy.array(BCpoints).transpose()[1],linewidth=3.0) for i in range(VList.nPoints): plt.plot(numpy.array(VList.allV[i].traceHist).transpose()[0],numpy.array(VList.allV[i].traceHist).transpose()[1]) plt.show() return()
def test1RK2(endTime=100.): """A test case for advection RK-2 integrator without any boundaries . Take two vortices of same strength. They should rotate in a circle""" #Initiate vortex list VList=dfn.vortexList() # Define vortices p1=numpy.array([-0.5,0.0]) p2=numpy.array([0.5,0.0]) rad=0.5 VList.addVortex(position=p1, strength=1.0,blobType=0,delta=0.0,traceFlag=1) VList.addVortex(position=p2, strength=1.0,blobType=0,delta=0.0,traceFlag=1) # Initiate time mesh startTime=0.0 timeStep=0.01 timeMesh=dfn.linearTimeMesh(startTime,timeStep,endTime) #Start time loop for i in range(1,len(timeMesh)): print "time=%f"%timeMesh[i] dt=timeMesh[i]-timeMesh[i-1] advectRK2(dt,toMod=[VList],fieldGens=[VList],vinf=0.0) #Plot traces of particles plt.figure(1) plt.title('test case for RK-2 two particle motion in a circle') for i in range(VList.nPoints): plt.plot(numpy.array(VList.allV[i].traceHist).transpose()[0],numpy.array(VList.allV[i].traceHist).transpose()[1]) #Calculate Error history newPos1=VList.allV[0].traceHist newPos2=VList.allV[0].traceHist err1=[abs(newPos1[i].dot(newPos1[i])-rad**2) for i in range(len(newPos1))] err2=[abs(newPos2[i].dot(newPos2[i])-rad**2) for i in range(len(newPos2))] #Plot errors plt.figure(2) plt.title('errors with time') plt.plot(err1) plt.plot(err2) return()