1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
\subsection{\texttt{ServoWallLoader.py}}\label{code:ServoWallLoader}
\begin{verbatim}
#import the division module for compatibility between Python 2 and Python 3
from __future__ import division
#import the appropriate ESyS-Particle modules:
from esys.lsm import *
from esys.lsm.util import *
class ServoWallLoaderRunnable (Runnable):
def __init__ (self,
LsmMpi=None,
interactionName=None,
force=Vec3(0,0,0),
startTime=0,
rampTime = 200
):
"""
Subroutine to initialise the Runnable and store parameter values.
"""
Runnable.__init__(self)
self.sim = LsmMpi
self.interactionName = interactionName
self.force = force
self.dt = self.sim.getTimeStepSize()
self.rampTime = rampTime
self.startTime = startTime
self.Nt = 0
def run (self):
"""
Subroutine to apply the force to a wall interaction. After self.startTime
timesteps, the force on the wall increases linearly over
self.rampTime timesteps until the desired wall force is achieved.
Thereafter the wall force is kept fixed.
"""
if (self.Nt > self.startTime):
#compute the slowdown factor if still accelerating the wall:
if (self.Nt < (self.startTime + self.rampTime)):
f = float(self.Nt - self.startTime) / float(self.rampTime)
else:
f = 1.0
#compute the amount by which to move the wall this timestep:
Dforce = Vec3(
f*self.force[0],
f*self.force[1],
f*self.force[2]
)
#instruct the simulation to apply the prescribed force to the wall:
self.sim.applyForceToWall (self.interactionName, Dforce)
self.Nt += 1
\end{verbatim}
|