Ejemplo n.º 1
0
def applyRVM(dt, nu=0.1, toMod=[dfn.vortexList(), dfn.traceList()], BCList=[]):
    """Apply RVM diffusion based on kinematic viscocity nu on "toMod" list of lists
	Also, reflect any vortex which is getting diffused into the boundary"""

    #Calculate mu and sigma for random number generation gaussian distribution
    mu = 0.0
    sigma = (2 * nu * dt)**0.5

    #Modify position for each point
    for eachList in toMod:
        #Diffusion should not be applied on tracers. This is only for vortex lists. check that condition
        if eachList.__class__.__name__ == 'vortexList':
            for eachPoint in eachList.allV:
                rad = random.gauss(mu, sigma)
                theta = random.uniform(-math.pi, math.pi)
                dPos = numpy.array(
                    [rad * math.cos(theta), rad * math.sin(theta)])
                newPos = eachPoint.position + dPos
                #Reflect the new position if it is in boundary
                for eachBC in BCList:
                    if (eachBC.inBoundary(newPos)):
                        newPos = eachBC.reflect(eachPoint.position, dPos)
                eachPoint.modifyPos(
                    newPos)  #This will also change fieldGen point positions
    return ()
Ejemplo n.º 2
0
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 ()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
def testRVM(cpos=numpy.array([1., 1.]), Np=100):
    """ Test RVM diffusion function"""

    #Initiate vortex list and tracer list and toMod
    V1 = dfn.vortexList()
    T1 = dfn.traceList()
    toMod = [V1, T1]

    #Add points at the same location
    for i in range(Np):
        V1.addVortex(cpos, 0.1)

    #Add arbitary tracers, just for check
    T1.addTracer(numpy.array([.5, .5]) + cpos)
    T1.addTracer(numpy.array([.5, -.5]) + cpos)
    T1.addTracer(numpy.array([-.5, .5]) + cpos)
    T1.addTracer(numpy.array([-.5, -.5]) + cpos)

    #Apply RVM
    dt = 0.1
    nu = 0.1
    applyRVM(dt, nu, toMod)

    #Positions of all points in toMod
    pos = []
    for eachList in toMod:
        pos = pos + eachList.posit()
    pos = numpy.array(pos)

    #Plot all points. Red is the original vortex, Blue is new distribution
    plt.figure()
    plt.title("Random vortex method diffusion test")
    for i in range(len(pos)):
        plt.plot(pos[i][0], pos[i][1], 'bo', markersize=2.0)
    plt.plot(cpos[0], cpos[1], 'ro', markersize=4.0)
    plt.show()

    return ()
Ejemplo n.º 5
0
def testRVM(cpos=numpy.array([1.,1.]),Np=100):
	""" Test RVM diffusion function"""
	
	#Initiate vortex list and tracer list and toMod
	V1=dfn.vortexList()
	T1=dfn.traceList()
	toMod=[V1,T1]
		
	#Add points at the same location
	for i in range(Np):
		V1.addVortex(cpos,0.1)
	
	#Add arbitary tracers, just for check
	T1.addTracer(numpy.array([.5,.5])+cpos)
	T1.addTracer(numpy.array([.5,-.5])+cpos)
	T1.addTracer(numpy.array([-.5,.5])+cpos)
	T1.addTracer(numpy.array([-.5,-.5])+cpos)
	
	#Apply RVM
	dt=0.1
	nu=0.1
	applyRVM(dt,nu,toMod)

	#Positions of all points in toMod
	pos=[]
	for eachList in toMod:
		pos=pos+eachList.posit()
	pos=numpy.array(pos)

	#Plot all points. Red is the original vortex, Blue is new distribution
	plt.figure()
	plt.title("Random vortex method diffusion test")
	for i in range(len(pos)):
		plt.plot(pos[i][0],pos[i][1],'bo',markersize=2.0)
	plt.plot(cpos[0],cpos[1],'ro',markersize=4.0)
	plt.show()
	
	return()
Ejemplo n.º 6
0
def applyRVM(dt,nu=0.1,toMod=[dfn.vortexList(),dfn.traceList()],BCList=[]):
	"""Apply RVM diffusion based on kinematic viscocity nu on "toMod" list of lists
	Also, reflect any vortex which is getting diffused into the boundary"""
	
	#Calculate mu and sigma for random number generation gaussian distribution
	mu=0.0
	sigma=(2*nu*dt)**0.5
	
	#Modify position for each point
	for eachList in toMod:
		#Diffusion should not be applied on tracers. This is only for vortex lists. check that condition
		if eachList.__class__.__name__=='vortexList':
			for eachPoint in eachList.allV:
				rad=random.gauss(mu,sigma)
				theta=random.uniform(-math.pi,math.pi)
				dPos=numpy.array([rad*math.cos(theta),rad*math.sin(theta)])
				newPos=eachPoint.position+dPos
				#Reflect the new position if it is in boundary
				for eachBC in BCList:
					if (eachBC.inBoundary(newPos)):
						newPos=eachBC.reflect(eachPoint.position,dPos)
				eachPoint.modifyPos(newPos)          #This will also change fieldGen point positions
	return()
Ejemplo n.º 7
0
def advectRK2(dt,
              toMod=[dfn.vortexList(), dfn.traceList()],
              fieldGens=[dfn.vortexList(), dfn.linVortList()],
              vinf=0.0,
              BCList=[]):
    """Modify "toMod(List format)" objects according to RK 2 advection based on fieldGens(List format) for advection"""

    #Calculate total number of toMod Points and append their positions
    N = 0
    pos = []
    for eachList in toMod:
        N = N + eachList.nPoints
        pos = pos + eachList.posit()
    pos = numpy.array(pos)
    oldPos = pos.copy()

    # Satisfy no penetration
    [eachBC.findVcp(fieldGens, vinf) for eachBC in BCList]
    [eachBC.applyNPBC(fieldGens) for eachBC in BCList]

    #Calculate no slip velocities
    [eachBC.findVcps(fieldGens, vinf) for eachBC in BCList]

    # Calculate field at all positions
    field = dfn.velField(pos, fieldGens, vinf)

    # Close NP BC
    [eachBC.closeNPBC(fieldGens) for eachBC in BCList]

    #Take first step of RK 2 and modify positions
    n = 0
    for eachList in toMod:
        for eachPoint in eachList.allV:
            newPos = dfn.eulerInt(pos[n], field[n], dt / 2.0)
            eachPoint.modifyPos(
                newPos
            )  # Note that this step will also modify appropriate positions in fieldGens, because of pointers
            n = n + 1

    #Calculate total number of toMod Points and append their positions
    newN = 0
    pos = []
    for eachList in toMod:
        newN = newN + eachList.nPoints
        pos = pos + eachList.posit()
    pos = numpy.array(pos)

    if newN != N:
        print "number of points cannot change in an advection step"

    # Satisfy no penetration
    [eachBC.findVcp(fieldGens, vinf) for eachBC in BCList]
    [eachBC.applyNPBC(fieldGens) for eachBC in BCList]

    #Calculate field with new positions
    field = dfn.velField(pos, fieldGens, vinf)

    # Close NP BC
    [eachBC.closeNPBC(fieldGens) for eachBC in BCList]

    # Take second step of RK 2 and modify final positions
    n = 0
    for eachList in toMod:
        for eachPoint in eachList.allV:
            newPos = dfn.eulerInt(oldPos[n], field[n], dt)
            dPos = newPos - oldPos[n]
            #Reflect the new position if it is in boundary
            for eachBC in BCList:
                if (eachBC.inBoundary(newPos)):
                    newPos = eachBC.reflect(oldPos[n], dPos)
            eachPoint.modifyPos(newPos)
            n = n + 1
Ejemplo n.º 8
0
def advectRK2(dt,toMod=[dfn.vortexList(),dfn.traceList()],fieldGens=[dfn.vortexList(),dfn.linVortList()],vinf=0.0,BCList=[]):
	"""Modify "toMod(List format)" objects according to RK 2 advection based on fieldGens(List format) for advection"""
	
	#Calculate total number of toMod Points and append their positions
	N=0
	pos=[]
	for eachList in toMod:
		N=N+eachList.nPoints
		pos=pos+eachList.posit()
	pos=numpy.array(pos)
	oldPos=pos.copy()
	
	# Satisfy no penetration
	[eachBC.findVcp(fieldGens,vinf) for eachBC in BCList]
	[eachBC.applyNPBC(fieldGens) for eachBC in BCList]
	
	#Calculate no slip velocities
	[eachBC.findVcps(fieldGens,vinf) for eachBC in BCList]

	# Calculate field at all positions 
	field=dfn.velField(pos,fieldGens,vinf)

	# Close NP BC
	[eachBC.closeNPBC(fieldGens) for eachBC in BCList]

	#Take first step of RK 2 and modify positions
	n=0
	for eachList in toMod:
		for eachPoint in eachList.allV:	
			newPos=dfn.eulerInt(pos[n],field[n],dt/2.0)
			eachPoint.modifyPos(newPos)     # Note that this step will also modify appropriate positions in fieldGens, because of pointers
			n=n+1

	#Calculate total number of toMod Points and append their positions
	newN=0
	pos=[]
	for eachList in toMod:
		newN=newN+eachList.nPoints
		pos=pos+eachList.posit()
	pos=numpy.array(pos)
	
	if newN!=N:
		print "number of points cannot change in an advection step"
	
	# Satisfy no penetration
	[eachBC.findVcp(fieldGens,vinf) for eachBC in BCList]
	[eachBC.applyNPBC(fieldGens) for eachBC in BCList]
	
	#Calculate field with new positions
	field=dfn.velField(pos,fieldGens,vinf)

	# Close NP BC
	[eachBC.closeNPBC(fieldGens) for eachBC in BCList]

    # Take second step of RK 2 and modify final positions
	n=0
	for eachList in toMod:
		for eachPoint in eachList.allV:	
			newPos=dfn.eulerInt(oldPos[n],field[n],dt)
			dPos=newPos-oldPos[n]
			#Reflect the new position if it is in boundary
			for eachBC in BCList:
				if (eachBC.inBoundary(newPos)):
					newPos=eachBC.reflect(oldPos[n],dPos)
			eachPoint.modifyPos(newPos)
			n=n+1