コード例 #1
0
 def createPoints(self):
     pointList = cylinder(150)
     self.matCr = MatCreator(pointList, self.flows)
     self.vortexPList = self.matCr.getMatVP()
     self.vortexBlobPoints = []
     self.vortexPanelPoints = []
     for element in self.vortexPList:
         vPanel = element.position * (
             1 + element.length / math.pi / abs(element.position))
         self.vortexBlobPoints.append(vPanel)
         self.vortexPanelPoints.append(1.01 * element.position)
     self.currentFlowArray = []
     self.currentFlowArray.extend(self.vortexPList)
     self.currentFlowArray.extend(self.flows)
     self.sim.updateElements([], self.currentFlowArray)
コード例 #2
0
ファイル: rvm.py プロジェクト: Anshumankumar/Particle_methods
 def createPoints(self):
     pointList = cylinder(150)
     self.matCr = MatCreator(pointList,self.flows)
     self.vortexPList = self.matCr.getMatVP()
     self.vortexBlobPoints = []
     self.vortexPanelPoints = []
     for element in self.vortexPList:
         vPanel = element.position*(1+element.length/math.pi/abs(element.position))
         self.vortexBlobPoints.append(vPanel)
         self.vortexPanelPoints.append(1.01*element.position)
     self.currentFlowArray =[]
     self.currentFlowArray.extend(self.vortexPList)
     self.currentFlowArray.extend(self.flows)
     self.sim.updateElements([],self.currentFlowArray)
コード例 #3
0
import flows as f
from simulator import Simulator
import plotter as p


def addTracerPoint(pFlowArray):
    for i in range(-20, 20, 5):
        pos = complex(-2, i / 10.0)
        pFlowArray.append(f.Tracer(pos, 1, 1, False))


if __name__ == '__main__':
    print('Flow pass a circular cylinder')
    pFlowArray = []

    pFlowArray.append(f.Uniform(complex(-100, 0), 1, 1, True))
    # pFlowArray.append(f.Vortex(complex(-1.010,0),1,1,False))
    pointlist = cylinder(40)
    matCr = MatCreator(pointlist, pFlowArray)
    #addTracerPoint(pFlowArray)
    length = len(pFlowArray)
    pFlowArray.extend(matCr.getMatVP())
    sim = Simulator(timestep=0.1)
    sim.updateElements(pFlowArray)
    data, colors = sim.run(0.2, matCr.updateFlows)
    plotter = p.ParticlePlotter((-2, 2), (-2, 2))
    plotter.update(data, colors)
    filename = "temp"
    #plotter.run(filename,True,False,False)
    plotter.run(filename, False, True, False)
コード例 #4
0
ファイル: rvm.py プロジェクト: Anshumankumar/Particle_methods
class Rvm(object):

    def __init__(self,flows,gammaMax = 0.1,plotFeildFlag = False):
        self.plotFeildFlag = plotFeildFlag
        self.flows = flows
        self.sim = Simulator(timestep = 0.1,uFrames = 1)
        self.gammaMax = gammaMax
        self.createPoints()
        self.momentArray =[]
        if (self.plotFeildFlag == True):
            self.initializeGrid()
        self.currentSim = "Advection"
        self.counter = 0

    def createPoints(self):
        pointList = cylinder(150)
        self.matCr = MatCreator(pointList,self.flows)
        self.vortexPList = self.matCr.getMatVP()
        self.vortexBlobPoints = []
        self.vortexPanelPoints = []
        for element in self.vortexPList:
            vPanel = element.position*(1+element.length/math.pi/abs(element.position))
            self.vortexBlobPoints.append(vPanel)
            self.vortexPanelPoints.append(1.01*element.position)
        self.currentFlowArray =[]
        self.currentFlowArray.extend(self.vortexPList)
        self.currentFlowArray.extend(self.flows)
        self.sim.updateElements([],self.currentFlowArray)
        
    def computeDrag(self,vFlows):
        moment = 0+0j
        for element in vFlows:
            moment = moment + (element.position.real*1j - element.position.imag)* \
                        element.strength
        return moment

    def getVortexMoment(self):
        return self.momentArray

    def initializeGrid(self):
        xx = linspace(0,2,20)
        yy = linspace(0,2,20)
        self.xx,self.yy = meshgrid(xx,yy)
        self.x,self.y = self.xx.ravel(),self.yy.ravel()
        self.z = self.x+1j*self.y
        self.x,self.y = meshgrid(xx,yy)
    
    def createVortexBlob(self):
        positions = self.vortexBlobPoints
        vortexPanels = self.vortexPList
        vPositions = self.vortexPanelPoints
        velArray = self.getVel(vPositions,self.currentFlowArray)
        VortexBlobArray = []
        for pos,element,vel in zip(positions,vortexPanels,velArray):
            distance = abs(element.position - pos)
            tangent = -element.position.imag +element.position.real*1j
            tangent = tangent/abs(tangent);
            strength = component(vel*element.length,tangent)
            vortexBlob = f.Vortex(pos,strength,radius = distance)
            VortexBlobArray.append(vortexBlob)
        return VortexBlobArray

    def saveQuiverPlot(self):
        self.counter = self.counter +1
        if (self.counter%10 == 0):
            t = self.getVel(self.z,self.currentFlowArray)
            t = array(t)
            t = reshape(t,[-1,len(self.y)])
            ux = t.real
            vy = t.imag
            matplotlib.pyplot.quiver(self.x,self.y,ux,vy)
            matplotlib.pyplot.savefig(str(self.sim.counter)+"quiver.png")
            matplotlib.pyplot.clf()

    def updateFlow(self):
        if (self.plotFeildFlag == True):
            self.saveQuiverPlot()
        if self.currentSim =="Advection":
            self.currentSim = "Diffusion"
            self.advectionRun()
        elif self.currentSim =="Diffusion":
            self.currentSim = "Advection"
            self.advectionRun()
            self.diffusionRun()
            self.advectionRun()
            
    def diffusionRun(self):
        
        vortexBlobArray = self.createVortexBlob()
        smallvortexBlobArray  = []
        for element in vortexBlobArray:
            maxStr =  self.vortexPList[0].length*self.gammaMax 
            smallvortexBlobArray.extend(self.elemDivider(element,maxStr))#self.gammaMax*self.vortexPList[0].length))
        self.currentFlowArray.extend(smallvortexBlobArray)
        self.flows = self.currentFlowArray[len(self.vortexPList):]
        self.matCr.updateFlows(self.flows)
        self.vortexPList = self.matCr.getMatVP()
        self.currentFlowArray[:len(self.vortexPList)] = self.vortexPList
        self.momentArray.append(self.computeDrag(self.flows[1:]))
        passiveElem = self.currentFlowArray[:(len(self.vortexPList)+1)]

        activeElem = self.currentFlowArray[(len(self.vortexPList)+1):]
        self.sim.updateElements(activeElem,passiveElem)
        for element in self.currentFlowArray:
            self.randomWalk(element,0.004,0.1)

    def advectionRun(self):
        self.matCr.updateFlows()

    def getVel(self,currentPoints,pArray):
        VelMat = []
        for cPoint in currentPoints:
            tempVel = 0+0j
            for element in pArray:
                tempVel = tempVel + element.compute_vel(cPoint)
            VelMat.append(tempVel)
        return VelMat

    def run(self,time = 3.0):
        data = self.sim.run(time,self.updateFlow)
        return data

    def elemDivider(self,elem,maxStrength):
        sign = elem.strength/abs(elem.strength)
        strength = abs(elem.strength)
        elemList = []
        eClass = elem.__class__
        while (strength > maxStrength):
            strength = strength-maxStrength
            elemList.append(eClass(elem.position,sign*maxStrength,
                radius=elem.radius))
        elemList.append(eClass(elem.position,sign*strength,
                radius=elem.radius))
        return elemList

    def randomWalk(self,element,sigma,timestep=0.1):
        if element.fixed == True:
            return
        # Take care of the error from Advection
        if abs(element.position) <1.03:
            element.position = 1.03*element.position/abs(element.position)
        
        mean = [0,0]
        cv = sigma/timestep
        covariance = [[cv,0],[0,cv]]
        vtemp = random.multivariate_normal(mean,covariance)
        v = vtemp[0] + 1j*vtemp[1]
        position = element.position+v*timestep
        posVector = position/abs(position)
        
        #Reflection the velocity
        if (abs(position) <= 1.03):
            v = v - 2*(posVector.real*v.real+v.imag*posVector.imag)*posVector
      
        #Very Rare Case But can happen, due to precesion
        if(abs( element.position) < 1.03):
            v =0
        element.change_pos(v,timestep)
コード例 #5
0
import flows as f
from simulator import Simulator
import plotter as p


def addTracerPoint(pFlowArray):
    for i in range(-20, 20, 5):
        pos = complex(-2, i / 10.0)
        pFlowArray.append(f.Tracer(pos, 1, 1, False))


if __name__ == "__main__":
    print("Flow pass a circular cylinder")
    pFlowArray = []

    pFlowArray.append(f.Uniform(complex(-100, 0), 1, 1, True))
    # pFlowArray.append(f.Vortex(complex(-1.010,0),1,1,False))
    pointlist = cylinder(40)
    matCr = MatCreator(pointlist, pFlowArray)
    # addTracerPoint(pFlowArray)
    length = len(pFlowArray)
    pFlowArray.extend(matCr.getMatVP())
    sim = Simulator(timestep=0.1)
    sim.updateElements(pFlowArray)
    data, colors = sim.run(0.2, matCr.updateFlows)
    plotter = p.ParticlePlotter((-2, 2), (-2, 2))
    plotter.update(data, colors)
    filename = "temp"
    # plotter.run(filename,True,False,False)
    plotter.run(filename, False, True, False)
コード例 #6
0
class Rvm(object):
    def __init__(self, flows, gammaMax=0.1, plotFeildFlag=False):
        self.plotFeildFlag = plotFeildFlag
        self.flows = flows
        self.sim = Simulator(timestep=0.1, uFrames=1)
        self.gammaMax = gammaMax
        self.createPoints()
        self.momentArray = []
        if (self.plotFeildFlag == True):
            self.initializeGrid()
        self.currentSim = "Advection"
        self.counter = 0

    def createPoints(self):
        pointList = cylinder(150)
        self.matCr = MatCreator(pointList, self.flows)
        self.vortexPList = self.matCr.getMatVP()
        self.vortexBlobPoints = []
        self.vortexPanelPoints = []
        for element in self.vortexPList:
            vPanel = element.position * (
                1 + element.length / math.pi / abs(element.position))
            self.vortexBlobPoints.append(vPanel)
            self.vortexPanelPoints.append(1.01 * element.position)
        self.currentFlowArray = []
        self.currentFlowArray.extend(self.vortexPList)
        self.currentFlowArray.extend(self.flows)
        self.sim.updateElements([], self.currentFlowArray)

    def computeDrag(self, vFlows):
        moment = 0 + 0j
        for element in vFlows:
            moment = moment + (element.position.real*1j - element.position.imag)* \
                        element.strength
        return moment

    def getVortexMoment(self):
        return self.momentArray

    def initializeGrid(self):
        xx = linspace(0, 2, 20)
        yy = linspace(0, 2, 20)
        self.xx, self.yy = meshgrid(xx, yy)
        self.x, self.y = self.xx.ravel(), self.yy.ravel()
        self.z = self.x + 1j * self.y
        self.x, self.y = meshgrid(xx, yy)

    def createVortexBlob(self):
        positions = self.vortexBlobPoints
        vortexPanels = self.vortexPList
        vPositions = self.vortexPanelPoints
        velArray = self.getVel(vPositions, self.currentFlowArray)
        VortexBlobArray = []
        for pos, element, vel in zip(positions, vortexPanels, velArray):
            distance = abs(element.position - pos)
            tangent = -element.position.imag + element.position.real * 1j
            tangent = tangent / abs(tangent)
            strength = component(vel * element.length, tangent)
            vortexBlob = f.Vortex(pos, strength, radius=distance)
            VortexBlobArray.append(vortexBlob)
        return VortexBlobArray

    def saveQuiverPlot(self):
        self.counter = self.counter + 1
        if (self.counter % 10 == 0):
            t = self.getVel(self.z, self.currentFlowArray)
            t = array(t)
            t = reshape(t, [-1, len(self.y)])
            ux = t.real
            vy = t.imag
            matplotlib.pyplot.quiver(self.x, self.y, ux, vy)
            matplotlib.pyplot.savefig(str(self.sim.counter) + "quiver.png")
            matplotlib.pyplot.clf()

    def updateFlow(self):
        if (self.plotFeildFlag == True):
            self.saveQuiverPlot()
        if self.currentSim == "Advection":
            self.currentSim = "Diffusion"
            self.advectionRun()
        elif self.currentSim == "Diffusion":
            self.currentSim = "Advection"
            self.advectionRun()
            self.diffusionRun()
            self.advectionRun()

    def diffusionRun(self):

        vortexBlobArray = self.createVortexBlob()
        smallvortexBlobArray = []
        for element in vortexBlobArray:
            maxStr = self.vortexPList[0].length * self.gammaMax
            smallvortexBlobArray.extend(self.elemDivider(
                element, maxStr))  #self.gammaMax*self.vortexPList[0].length))
        self.currentFlowArray.extend(smallvortexBlobArray)
        self.flows = self.currentFlowArray[len(self.vortexPList):]
        self.matCr.updateFlows(self.flows)
        self.vortexPList = self.matCr.getMatVP()
        self.currentFlowArray[:len(self.vortexPList)] = self.vortexPList
        self.momentArray.append(self.computeDrag(self.flows[1:]))
        passiveElem = self.currentFlowArray[:(len(self.vortexPList) + 1)]

        activeElem = self.currentFlowArray[(len(self.vortexPList) + 1):]
        self.sim.updateElements(activeElem, passiveElem)
        for element in self.currentFlowArray:
            self.randomWalk(element, 0.004, 0.1)

    def advectionRun(self):
        self.matCr.updateFlows()

    def getVel(self, currentPoints, pArray):
        VelMat = []
        for cPoint in currentPoints:
            tempVel = 0 + 0j
            for element in pArray:
                tempVel = tempVel + element.compute_vel(cPoint)
            VelMat.append(tempVel)
        return VelMat

    def run(self, time=3.0):
        data = self.sim.run(time, self.updateFlow)
        return data

    def elemDivider(self, elem, maxStrength):
        sign = elem.strength / abs(elem.strength)
        strength = abs(elem.strength)
        elemList = []
        eClass = elem.__class__
        while (strength > maxStrength):
            strength = strength - maxStrength
            elemList.append(
                eClass(elem.position, sign * maxStrength, radius=elem.radius))
        elemList.append(
            eClass(elem.position, sign * strength, radius=elem.radius))
        return elemList

    def randomWalk(self, element, sigma, timestep=0.1):
        if element.fixed == True:
            return
        # Take care of the error from Advection
        if abs(element.position) < 1.03:
            element.position = 1.03 * element.position / abs(element.position)

        mean = [0, 0]
        cv = sigma / timestep
        covariance = [[cv, 0], [0, cv]]
        vtemp = random.multivariate_normal(mean, covariance)
        v = vtemp[0] + 1j * vtemp[1]
        position = element.position + v * timestep
        posVector = position / abs(position)

        #Reflection the velocity
        if (abs(position) <= 1.03):
            v = v - 2 * (posVector.real * v.real +
                         v.imag * posVector.imag) * posVector

        #Very Rare Case But can happen, due to precesion
        if (abs(element.position) < 1.03):
            v = 0
        element.change_pos(v, timestep)