示例#1
0
文件: arrow.py 项目: shakhawath/Esys
 def getLength(self):
     """
     Returns the distance between this arrows head-point and tail-point.
     @rtype: float
     @return: length of this arrow from head-point to tail-point.
     """
     return (Vec3(self.getHeadPt())-Vec3(self.getTailPt())).norm()
示例#2
0
 def __init__(self,
              radius,
              endPt1=None,
              endPt2=None,
              segEndPt1=None,
              segEndPt2=None):
     """
     Initialises capsule with center-end-point coordinates and radius.
     @type radius: float
     @param radius: Radius of capsule.
     @type endPt1: sequence of 3 floats
     @param endPt1: Coordinate of one end ("apex" of hemisphere).
     @type endPt2: sequence of 3 floats
     @param endPt2: Center coordinate of other end ("apex" of hemisphere).
     @type segEndPt1: sequence of 3 floats
     @param segEndPt1: Coordinate of one end ("apex" of hemisphere).
     @type segEndPt2: sequence of 3 floats
     @param segEndPt2: Center coordinate of other end ("apex" of hemisphere).
     """
     self.radius = radius
     if (endPt1 != None) and (endPt2 != None):
         endPt1 = Vec3(endPt1)
         endPt2 = Vec3(endPt2)
         centre = 0.5 * (endPt1 + endPt2)
         direction = (endPt2 - endPt1)
         length = direction.norm()
         direction /= length
         self.segEndPt1 = centre - (0.5 * length) * direction
         self.segEndPt2 = centre + (0.5 * length) * direction
     elif (segEndPt1 != None) and (segEndPt2 != None):
         self.segEndPt1 = Vec3(segEndPt1)
         self.segEndPt2 = Vec3(segEndPt2)
     else:
         raise Exception(
             "Must specified end-points or segment-end-points, not both.")
示例#3
0
文件: cone.py 项目: shakhawath/Esys
 def getHeight(self):
     """
     Returns the height of this cone.
     @rtype: float
     @return: Center coordinate of this cone.
     """
     return (Vec3(self.getEndPt1()) - Vec3(self.getEndPt2())).norm()
示例#4
0
 def getHeadPt(self, record):
     return \
         (
             Vec3(self.getTailPt(record))
             +
             (Vec3(self.getVec(record))*self.getLengthScale())
         )
示例#5
0
 def getSegmentLength(self):
     """
     Returns the segment-length of this capsule.
     @rtype: float
     @return: minimum distance between end-points of cylinder.
     """
     return \
         (Vec3(self.getSegmentEndPt1()) - Vec3(self.getSegmentEndPt2())).norm()
示例#6
0
 def configure(self,
               lookAt=Vec3(0, 0, 0),
               camPosn=Vec3(0, 0, 20),
               zoomFactor=0.1,
               imageSize=[800, 600]):
     self.lookAt = lookAt
     self.camPosn = camPosn
     self.zoomFactor = zoomFactor
     self.imageSize = imageSize
示例#7
0
 def rotatePosn(self, axis, axisPt):
     """
     Rotates the camera position about the specified axis.
     @type axis: iterable of 3 C{float} elements
     @param axis: Axis of rotation and angle of rotation
     (C{ = axis.norm()} radians).
     @type axisPt: iterable of 3 C{float} elements
     @param axisPt: Axis of rotation is assumed to pass through this point.
     """
     self.setPosn(Vec3(self.getPosn()).rotate(Vec3(axis), Vec3(axisPt)))
示例#8
0
 def getLength(self):
     """
     Returns the length of this capsule.
     @rtype: float
     @return: Distance between hemi-sphere apexes.
     """
     return \
         2.0*self.radius() \
         +\
         (Vec3(self.getSegmentEndPt1()) - Vec3(self.getSegmentEndPt2())).norm()
示例#9
0
 def run(self):
     """
     Moves upper and lower walls by an increment parallel to the gouge
     axis and applies a constant force perpendicular to it.
     """
     t=self.theLSM.getTimeStep()
     if(t<1000):
         dx_cur=self.dx*(t/1000.0)
     else:
         dx_cur=self.dx
     self.theLSM.moveWallBy("lowerWall",Vec3(dx_cur,0.0,0.0))
     self.theLSM.moveWallBy("upperWall",Vec3(-1.0*dx_cur,0.0,0.0))
     self.theLSM.applyForceToWall("upperWallInteraction",Vec3(0.0,-0.25,0.0));
     self.theLSM.applyForceToWall("lowerWallInteraction",Vec3(0.0,0.25,0.0));
示例#10
0
def snapshot(particles=None, index=0):
    pkg = povray
    scene = pkg.Scene()
    for pp in particles:
        povsphere = pkg.Sphere(pp.getPosn(), pp.getRadius())
        povsphere.apply(pkg.Colors.Red)
        scene.add(povsphere)

    camera = scene.getCamera()
    camera.setLookAt(Vec3(0, 0, 0))
    camera.setPosn(Vec3(0, 0, 20))
    camera.setZoom(0.1)

    scene.render(offScreen=True,
                 interactive=False,
                 fileName="snap_{0:04d}.png".format(index),
                 size=[800, 600])
    return
示例#11
0
 def visitNodeRef(self, nodeRef):
     displArray = numarray.array([0.0] * self.lsm.getDim())
     self.data.getRefValue(nodeRef, displArray)
     displVec = Vec3()
     for i in range(0, self.lsm.getDim()):
         displVec[i] = displArray[i]
     getLogger().debug("Moving node " + str(nodeRef) + " by " +
                       str(displVec))
     self.lsm.moveNodeBy(nodeRef, displVec)
示例#12
0
def runSimulation():
    """
    Initialises elastic block model and runs the compression simulation.
    """
    #setVerbosity(True)
    mySim = LsmMpi(1, [0, 0, 0])
    mySim.initVerletModel("RotSphere", 2.5, 0.5)
    mySim.setTimeStepSize(0.01)
    mySim.setSpatialDomain(
        BoundingBox(Vec3(-5.0, -5.0, -5.0), Vec3(15.0, 25.0, 15.0)))
    mySim.readGeometry(
        InstallInfo.getDataFilePath("bench_block_10x20x10_r0.15.geo"))
    # setup interactions
    bip = RotBondPrms(0, "bonded", 0.5, 0.15, 0.04, 0.017, 0.0025, 0.0125,
                      0.00125, 0.00125)
    fip = RotFrictionPrms("friction", 1.0, 0.6, 0.6, 1.0)
    dip = DampingPrms("Damping", "damping1", 0.01, 50)
    rdip = DampingPrms("RotDamping", "damping2", 0.01, 50)
    mySim.createInteractionGroup(bip)
    mySim.createInteractionGroup(fip)
    mySim.createExclusion("bonded", "friction")
    mySim.createInteractionGroup(dip)
    mySim.createInteractionGroup(rdip)
    # create walls
    mySim.createWall("lowerWall", Vec3(0.0, 0.0, 0.0), Vec3(0.0, 1.0, 0.0))
    mySim.createWall("upperWall", Vec3(0.0, 20.0, 0.0), Vec3(0.0, -1.0, 0.0))
    wp1 = NRotElasticWallPrms("upperWallInteraction", "upperWall", 1.0)
    wp2 = NRotElasticWallPrms("lowerWallInteraction", "lowerWall", 1.0)
    mySim.createInteractionGroup(wp1)
    mySim.createInteractionGroup(wp2)
    # setup savers
    nb_prm = InteractionScalarFieldSaverPrms("bonded", "count", "nbonds",
                                             "SUM", 0, 12000, 4)
    mySim.createFieldSaver(nb_prm)
    mySim.createFieldSaver(
        WallVectorFieldSaverPrms(fileName="wf.dat",
                                 fieldName="Force",
                                 wallName=["lowerWall", "upperWall"],
                                 fileFormat="RAW_SERIES",
                                 beginTimeStep=0,
                                 endTimeStep=12000,
                                 timeStepIncr=4))
    # add loading function
    lf = Loading(mySim)
    mySim.addPreTimeStepRunnable(lf)
    mySim.setNumTimeSteps(12000)
    start_time = time()
    mySim.run()
    stop_time = time()
    print("runtime: ", stop_time - start_time, " seconds")
示例#13
0
def runSimulation():
    """
    Runs a compression simulation on an elastic block.
    Outputs wall-forces and wall-positions to file.
    """
    setVerbosity(True)
    mySim = LsmMpi(2, [0, 0, 0])
    mySim.initVerletModel("NRotSphere", 2.5, 0.5)
    mySim.setTimeStepSize(0.02)
    mySim.setSpatialDomain(
        BoundingBox(Vec3(-5.0, 0.0, -5.0), Vec3(15.0, 10.0, 15.0)))
    mySim.readGeometry(InstallInfo.getDataFilePath("cube10r0.2.geo"))
    # setup interactions
    bip = NRotBondPrms(1, "bonded", 1.0, 1.05)
    fip = NRotFrictionPrms("friction", 1.0, 0.6, 1.0)
    mySim.createInteractionGroup(bip)
    mySim.createInteractionGroup(fip)
    mySim.createExclusion("bonded", "friction")
    # wall parameters
    mySim.createWall("lowerWall", Vec3(0.0, 0.0, 0.0), Vec3(0.0, 1.0, 0.0))
    mySim.createWall("upperWall", Vec3(0.0, 10.0, 0.0), Vec3(0.0, -1.0, 0.0))
    wp1 = NRotElasticWallPrms("upperWallInteraction", "upperWall", 1.0)
    wp2 = NRotElasticWallPrms("lowerWallInteraction", "lowerWall", 1.0)
    # setup savers
    mySim.createFieldSaver(
        WallVectorFieldSaverPrms(fileName="wf2.dat",
                                 fieldName="Force",
                                 wallName=["lowerWall", "upperWall"],
                                 fileFormat="RAW_SERIES",
                                 beginTimeStep=0,
                                 endTimeStep=10,
                                 timeStepIncr=1))
    mySim.createFieldSaver(
        WallVectorFieldSaverPrms(fileName="wp2.dat",
                                 fieldName="Position",
                                 wallName=["lowerWall", "upperWall"],
                                 fileFormat="RAW_SERIES",
                                 beginTimeStep=0,
                                 endTimeStep=10,
                                 timeStepIncr=1))
    # create walls
    mySim.createInteractionGroup(wp1)
    mySim.createInteractionGroup(wp2)
    # add loading function
    lf = Loading(mySim)
    mySim.addPreTimeStepRunnable(lf)
    mySim.setNumTimeSteps(10)
    mySim.run()
#import the appropriate ESyS-Particle modules:
from esys.lsm import *
from esys.lsm.util import Vec3, BoundingBox
from esys.lsm.geometry import CubicBlock, ConnectionFinder
from POVsnaps import POVsnaps
#instantiate a simulation object
#and initialise the neighbour search algorithm:
sim = LsmMpi(numWorkerProcesses=1, mpiDimList=[1, 1, 1])
sim.initNeighbourSearch(particleType="NRotSphere",
                        gridSpacing=2.5,
                        verletDist=0.5)
#set the number of timesteps and timestep increment:
sim.setNumTimeSteps(10000)
sim.setTimeStepSize(0.001)
#specify the spatial domain for the simulation:
domain = BoundingBox(Vec3(-20, -20, -20), Vec3(20, 20, 20))
sim.setSpatialDomain(domain)
#add a cube of particles to the domain:
cube = CubicBlock(dimCount=[6, 6, 6], radius=0.5)
cube.rotate(axis=Vec3(0, 0, 3.141592654 / 6.0), axisPt=Vec3(0, 0, 0))
sim.createParticles(cube)
#create bonds between particles separated by less than the specified
#maxDist:
sim.createConnections(ConnectionFinder(maxDist=0.005, bondTag=1, pList=cube))
#specify bonded elastic interactions between bonded particles:
bondGrp = sim.createInteractionGroup(
    NRotBondPrms(name="sphereBonds",
                 normalK=10000.0,
                 breakDistance=50.0,
                 tag=1,
                 scaling=True))
示例#15
0
文件: cone.py 项目: shakhawath/Esys
 def getCenter(self):
     """
     Returns the coordinate of the center of this cone.
     @return: Center coordinate of this cone.
     """
     return (Vec3(self.getEndPt1()) + Vec3(self.getEndPt2())) * 0.5
示例#16
0
def uniform(L=10):
    return Vec3(
        2*L*rand() - L,
        2*L*rand() - L,
        2*L*rand() - L,
        )
示例#17
0
sim.initNeighbourSearch(
    particleType="NRotSphere",
    gridSpacing=0.2,
    verletDist=0.1
)

# set the number of timesteps and timestep increment:
sim.setNumTimeSteps(5000000)
sim.setTimeStepSize(0.0001)
L = 10
Ld = L + 1
kT = 0.1
a = sqrt(kT)

# specify the spatial domain for the simulation:
domain = BoundingBox(Vec3(-Ld, -Ld, -Ld), Vec3(Ld, Ld, Ld))
sim.setSpatialDomain(
    bBox=domain, circDimList=[False, False, False])
# add a cube of particles to the domain:
#cube = CubicBlock(dimCount=[20, 20, 20], radius=0.05)
#sim.createParticles(cube)
N = 100
seed(1234)
for n in range(N):
    p = NRotSphere(id=n, posn=uniform(), radius=0.05, mass=1.0)
    sim.createParticle(p)

for n in range(sim.getNumParticles()):
    sim.setParticleVelocity(
        id=n,
        Velocity=Vec3(a*randn(), a*randn(), a*randn()))
示例#18
0
 def getCenter(self):
     return (Vec3(self.getMaxPt())+Vec3(self.getMinPt()))*0.5
示例#19
0
    def run(self):
        """
	      Moves upper and lower walls by an increment.
	      """
        self.theLSM.moveWallBy("lowerWall", Vec3(0.0, 0.00005, 0.0))
        self.theLSM.moveWallBy("upperWall", Vec3(0.0, -0.00005, 0.0))
示例#20
0
 def run(self):
     """
     Moves walls in compressive fashion.
     """
     self.theLSM.moveWallBy("lowerWall", Vec3(0.0, 0.0001, 0.0))
     self.theLSM.moveWallBy("upperWall", Vec3(0.0, -0.0001, 0.0))
示例#21
0
#
#
#import the appropriate ESyS-Particle modules:
from esys.lsm import *
from esys.lsm.util import Vec3, BoundingBox
#instantiate a simulation object
#and initialise the neighbour search algorithm:
sim = LsmMpi(numWorkerProcesses=1, mpiDimList=[1, 1, 1])
sim.initNeighbourSearch(particleType="NRotSphere",
                        gridSpacing=2.5,
                        verletDist=0.5)
#specify the number of timesteps and timestep increment:
sim.setNumTimeSteps(10000)
sim.setTimeStepSize(0.001)
#specify the spatial domain for the simulation:
domain = BoundingBox(Vec3(-20, -20, -20), Vec3(20, 20, 20))
sim.setSpatialDomain(domain)
#add the first particle to the domain:
particle = NRotSphere(id=0, posn=Vec3(-5, 5, -5), radius=1.0, mass=1.0)
particle.setLinearVelocity(Vec3(1.0, -1.0, 1.0))
sim.createParticle(particle)
#add the second particle to the domain:
particle = NRotSphere(id=1, posn=Vec3(5, 5, 5), radius=1.5, mass=2.0)
particle.setLinearVelocity(Vec3(-1.0, -1.0, -1.0))
sim.createParticle(particle)
#specify the type of interactions between colliding particles:
sim.createInteractionGroup(
    NRotElasticPrms(name="elastic_repulsion", normalK=10000.0, scaling=True))
#Execute the simulation:
sim.run()
示例#22
0
def runSimulation():
    """
    Initialises elastic block model and runs the compression simulation.
    """
    dt=0.02
    v=0.002
    nt=10000
    ncpu_x=int(sys.argv[1])
    ncpu_y=int(sys.argv[2])
##    setVerbosity(True)
    mySim=LsmMpi(ncpu_x*ncpu_y,[ncpu_x,ncpu_y,1])
    mySim.initVerletModel("RotSphere", 2.5, 0.5)
    mySim.setTimeStepSize(dt)
    mySim.force2dComputations(True)
    # read geometry
    mySim.readGeometry("bench_gouge.geo")
    # setup interactions
    bip=RotBondPrms(0,"bonded",0.5,0.15,0.04,0.017,0.025,0.125,0.0125,0.0125)
    fip=RotFrictionPrms("friction", 1.0, 0.6, 0.6, 1.0)
    dip=DampingPrms("Damping","damping1",0.01,50)
    rdip=DampingPrms("RotDamping","damping2",0.01,50)
    mySim.createInteractionGroup(bip)
    mySim.createInteractionGroup(fip)
    mySim.createExclusion("bonded","friction")
    mySim.createInteractionGroup(dip)
    mySim.createInteractionGroup(rdip)
    # create walls
    mySim.createWall("lowerWall",Vec3(0.0,0.0,0.0),Vec3(0.0,1.0,0.0))
    mySim.createWall("upperWall",Vec3(0.0,40.0,0.0),Vec3(0.0,-1.0,0.0))
    wp1=NRotBondedWallPrms("upperWallInteraction","upperWall",1.0,4)
    wp2=NRotBondedWallPrms("lowerWallInteraction","lowerWall",1.0,3);
    mySim.createInteractionGroup(wp1)
    mySim.createInteractionGroup(wp2)
    # setup savers
    mySim.createFieldSaver(
      WallVectorFieldSaverPrms(
        fileName="wf.dat",
        fieldName="Force",
        wallName=["lowerWall","upperWall"],
        fileFormat="RAW_SERIES",
        beginTimeStep=0,
        endTimeStep=nt,
        timeStepIncr=10
      )
    )
    mySim.createFieldSaver(
      WallVectorFieldSaverPrms(
        fileName="wp.dat",
        fieldName="Position",
        wallName=["lowerWall","upperWall"],
        fileFormat="RAW_SERIES",
        beginTimeStep=0,
        endTimeStep=nt,
        timeStepIncr=10
      )
    )
    ek_prm=ParticleScalarFieldSaverPrms("e_kin","ekin.dat","SUM",0,nt,10)
    mySim.createFieldSaver(ek_prm)
    # add loading function
    lf=Loading(mySim,dt,v)
    mySim.addPreTimeStepRunnable(lf)
    mySim.setNumTimeSteps(nt)
    nparts=mySim.getNumParticles()
    print("Particles in the model: ", nparts)
    start_time=time()
    mySim.run()
    stop_time=time()
    run_time=stop_time-start_time
    # calculate relative performance
    perf=(nparts*nt)/run_time
    # print results
    print("runtime     : ", run_time, " seconds") 
    print("performance : ", perf, " particles*timesteps/second")
示例#23
0
#
#import the appropriate ESyS-Particle modules:
from esys.lsm import *
from esys.lsm.util import Vec3, BoundingBox
from POVsnaps import POVsnaps
#instantiate a simulation object
#and initialise the neighbour search algorithm:
sim = LsmMpi(numWorkerProcesses=1, mpiDimList=[1, 1, 1])
sim.initNeighbourSearch(particleType="NRotSphere",
                        gridSpacing=2.5,
                        verletDist=0.5)
#set the number of timesteps and timestep increment:
sim.setNumTimeSteps(20000)
sim.setTimeStepSize(0.001)
#specify the spatial domain for the simulation:
domain = BoundingBox(Vec3(-20, -20, -20), Vec3(20, 20, 20))
sim.setSpatialDomain(domain)
#add a particle to the domain:
particle = NRotSphere(id=0, posn=Vec3(0, 5, 0), radius=1.75, mass=1.8)
particle.setLinearVelocity(Vec3(1.0, 10.0, 1.0))
sim.createParticle(particle)
#initialise gravity in the domain:
sim.createInteractionGroup(
    GravityPrms(name="earth-gravity", acceleration=Vec3(0, -9.81, 0)))
#add a horizontal wall to act as a floor on which to bounce particles:
sim.createWall(name="floor", posn=Vec3(0, -10, 0), normal=Vec3(0, 1, 0))
#specify the type of interactions between wall and particles:
sim.createInteractionGroup(
    NRotElasticWallPrms(name="elasticWall", wallName="floor", normalK=10000.0))
#add local viscosity to simulate air resistance:
sim.createInteractionGroup(
示例#24
0
 def getSideLength(self):
     return (Vec3(self.getMaxPt())-Vec3(self.getMinPt()))