The SME jpython shell is a command & control component of the SME java portal. This shell provides a single environment for controlling simulation configuration, execution, visualization and output post-processing. Future versions will interface with globus/CoG kit/CCA/OPIE, etc. to integrate grid/portal functionality.
SME -python local run
It is also possible to create Python objects which represent simulation objects such as variables, actions, grids, and points. The available operations on these objects are described in the "SME Python Objects" section below. Python variable and action objects are created using the "choose" butt as described in the previous paragraph or by using the "choose" command in the Python shell as described in the "Interface Control" section below. Grid objects are created by calling Python variable "grid" method as described in the "Variable Object Methods" section below.
Examples of the use of various shell commands are provided in the "Python Shell Script Examples" section below.
conf( String cmd ): Execute configuration command cmd for the selected variable or module.
conf(): Start up the SME configuration panel.
open(): Open the current simulation ( called by first step() or run() command ).step(): Step the simulation one timestep.
run( float t ): Run the simulation up to time t.
halt(): Pause a running simulation.
restart(): Restart the current simulation.
view(): View data for selected variable.display(): Pipe data for selected variable to ViewServer.
dep(): Add dependencies & action objects to selected variable.eqn(): Display equation for selected action.
choose(): Returns a Python variable object representing the selected variable.
choose( String id ): As above but gives the Python variable object the name id.
v.view(): View data for variable v.For the following mathematical operations, a new variable object is returned with the same grid as the (spatial) operands, whose data represents the point-by-point (PbP) application of the mathematical operation to the operands. In most of the operations any of the operands can be replaced by interger or floating-point numbers. v0 + v1: Returns new variable object representing the addition of v0 and v1.v.grid(): Returns a Python grid object representing variable v's grid.
v.dep(): Add dependencies to v.
v.setID(String id): Set variable's name to id.
v.config( String cmd ): Execute configuration command cmd for v.
v.actions(): Add Actions to v.
v.value( int index ): Returns value at grid point indexed by index.
v.value( Point p ): Returns value at grid point indexed by p.
v.data( int r, int c ): Returns value at grid point indexed by (r,c).
v.setValue( int index, float value ): Set value at grid point indexed by index.
v.setValue( Point p, float value ): Set value at grid point indexed by p.
v0 - v1: PbP Subtraction of v1 from v0.v0 * v1: PbP Multiplication of v0 and v1.
v0 / v1: PbP Division of v0 by v1.
v0 + v1: PbP Addition of v0 and v1.
v0 ^ v1: PbP Raise v0 to v1 power.
v0.le(v1): = ( 1 at points p where v0(p) <= v1(p); 0 otherwise )
v0.lt(v1): = ( 1 at points p where v0(p) < v1(p); 0 otherwise )
v0.ge(v1): = ( 1 at points p where v0(p) >= v1(p); 0 otherwise )
v0.gt(v1): = ( 1 at points p where v0(p) > v1(p); 0 otherwise )
v0.eq(v1): = ( 1 at points p where v0(p) = v1(p); 0 otherwise )
v0.or(v1): = ( 1 at points p where (v0(p) > 0) or (v1(p) > 0); 0 otherwise )
v0.and(v1): = ( 1 at points p where (v0(p) > 0) and (v1(p) > 0); 0 otherwise )
a.eqn(): Display the equation associated with action a.
g.n4(): Returns a PyList containing 4 nearest neighbor Point translations.g.n8(): Returns a PyList containing 8 nearest neighbor Point translations.
g.trans( Point p, Point t ): Returns a Point representing p translated by t.
g.trans( Point p, int r, int c ): Returns a Point representing p translated by (r,c).
g.getPoint( int r, int c ): Returns Point object corresponding to (r,c)
g.var(String id, float fill): Returns a variable object with grid g, name id, and initial value fill.
p.grid(): Returns p's grid.p.row(): Returns p's row coordinate.
p.col(): Returns p's col coordinate.
p.index(): Returns p's grid index.
p.trans( Point t ): Returns a Point representing p translated by t.
p.trans( int r, int c ): Returns a Point representing p translated by (r,c).
p0 + p1: Returns a new point representing the addition of p0 and p1.
p0 - p1: Returns a new point representing the subtraction of p0 and p1.
def test_grid( v ):
g = v.grid()n = g.n4()for p in g:for pn in n:print p + pn
The argument (v) to the function should be a Variable object. The
object g is a grid. The object n is a list of the 4 nearest neighbor translations
(which are Point objects with relative coordinates). Every grid object
is also a list of point, so the Python command "for p in g:" iterates
over the points in the grid. Once this code has been entered into the shell,
the function "test_grid" can be executed, for example:
>>> test_grid( v0 )
This will print many lines of coordinates. The following slightly more complex example defines a function which computes a simple spatial average of a spatial variable.
def spatial_ave( v ):
The argument (v) to the function should be a Variable object. The object v_ave is a Variable object with the same grid as v, with name "spatial_ave". The object g is a grid. The object n is a list of the 8 nearest neighbor translations. The operator v[p]returns the value of v at point p. If the translation yields a point that is not in the study area, then px is set to the Python null object None. Once this code has been entered into the shell, the function "test_grid" can be executed, for example:g = v.grid()v_ave = g.var("spatial_ave");n = g.n8()for p in g:v_ave[p] = v[p]neighbor_cnt = 1for pn in n:px = p + pnif( px != None ):v_ave[p] = v_ave[p] + v[ px ]neighbor_cnt = neighbor_cnt + 1v_ave[p] = v_ave[p]/neighbor_cntreturn v_ave
>>> v1 = spatial_ave(
v0 )