本文整理汇总了Python中simulator.Simulator.updateElements方法的典型用法代码示例。如果您正苦于以下问题:Python Simulator.updateElements方法的具体用法?Python Simulator.updateElements怎么用?Python Simulator.updateElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simulator.Simulator
的用法示例。
在下文中一共展示了Simulator.updateElements方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addTracerPoint
# 需要导入模块: from simulator import Simulator [as 别名]
# 或者: from simulator.Simulator import updateElements [as 别名]
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)
示例2: Rvm
# 需要导入模块: from simulator import Simulator [as 别名]
# 或者: from simulator.Simulator import updateElements [as 别名]
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)]
#.........这里部分代码省略.........
示例3: importfile
# 需要导入模块: from simulator import Simulator [as 别名]
# 或者: from simulator.Simulator import updateElements [as 别名]
import sys
sys.path.insert(0, '../common')
from simulator import Simulator
import plotter as p
import simulator
import importlib
#Import the file to be simulated
def importfile():
if len(sys.argv) > 1:
filename = str(sys.argv[1])
else:
print("Give the name of import file")
exit()
try:
elemFile = importlib.import_module(filename, package=None)
except ImportError:
print("No such Import exist")
exit()
return elemFile,filename
if __name__ == '__main__':
elemFile,filename = importfile()
sim = Simulator()
sim.updateElements(elemFile.Array)
data,colors = sim.run(3)