Commit da0e4dcc authored by bonnell's avatar bonnell
Browse files

Updates from Fred Morris

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@23527 18c085ea-50e0-402c-830e-de6fd14e8384
parent 5b480e39
......@@ -68,6 +68,8 @@ CLASSES
| * halt
| * step
| * run
|
| Keyword arguments are passed to initialize()
|
| MainLoop(self)
| This is the main loop. It does not have a subclass-overridable companion,
......@@ -80,10 +82,13 @@ CLASSES
| and to save the VisIt base directory.
|
| Parameters:
| lib_path: Path to simv2.py
| lib_path: Path to simv2.py. It is probably a good idea to set
| an environment variable VISIT_LIBPATH and pull from
| that.
| visit_base: Base path to the VisIt installation. In practice,
| this is one directory above the bin/ directory that
| VisIt runs out of.
| VisIt runs out of. It is probably a good idea to set
| an environment variable VISIT_HOME and pull from that.
|
| callback_command(self, cmd, visit_args, cbdata)
| Overridable method.
......@@ -158,7 +163,9 @@ CLASSES
| This is the subclass-overridable companion to Finalize.
|
| initialize(self, **kwargs)
| This is the subclass-overridable companion to Initialize.
| This is the subclass-overridable companion to Initialize().
| The keyword arguments are what were supplied in the call to
| Initialize().
|
| Specific values which you might want to override:
| trace_qualifier: Used while naming the trace file. Defaults to
......@@ -172,6 +179,16 @@ CLASSES
| exposed. Otherwise you are going to need to
| override main_doVisItConnect and do a heap o'
| work.
|
| callbacks in turn has substructures:
| commands: Defines commands which can be triggered from the
| VisIt sim control panel.
| metadata: Defines/names metadata for which callbacks should
| be made. The following types of metadata are
| supported: mesh, variable, curve expression.
| See the source for callback_metadata() method
| for enumeration of the properties which can be
| set for specific types of metadata.
|
| main_doConsoleCommand(self, cmd)
| Processes console commands.
......@@ -203,6 +220,9 @@ CLASSES
| print_to_console(self, message)
| Prints to the console and reissues the console prompt.
|
| set_runMode(self, running)
| Sets self.runMode to the appropriate VISIT_ constant.
|
| truth_to_0_1(self, truth)
| Returns 1 if truth is true, 0 if false.
|
......@@ -236,13 +256,6 @@ CLASSES
| 1 (no stride). For character strings (such as labels), this is the
| length of the label; it is required that each string be the same length.
|
| visit_variableArray(self, data_func, nComp, data, owner='VISIT')
| Creates a variable.
|
| This version is deprecated, the preferred method is visit_variable(),
| passing nComp as a keyword arg. However this may read easier for
| users who are already familiar with sims and VisIt.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
......
......@@ -115,10 +115,13 @@ class Simulation(object):
and to save the VisIt base directory.
Parameters:
lib_path: Path to simv2.py
lib_path: Path to simv2.py. It is probably a good idea to set
an environment variable VISIT_LIBPATH and pull from
that.
visit_base: Base path to the VisIt installation. In practice,
this is one directory above the bin/ directory that
VisIt runs out of.
VisIt runs out of. It is probably a good idea to set
an environment variable VISIT_HOME and pull from that.
"""
# This is really such a glorious hack. Shout out to Quashie...
if lib_path not in sys.path: sys.path.insert(1,lib_path)
......@@ -187,6 +190,17 @@ class Simulation(object):
self.main_doPrompt()
return
#*********************************************************
# SETTERS
def set_runMode(self,running):
"""Sets self.runMode to the appropriate VISIT_ constant."""
if running:
self.runMode = simV2.VISIT_SIMMODE_RUNNING
else:
self.runMode = simV2.VISIT_SIMMODE_STOPPED
return
#*********************************************************
def Initialize(self,sim_name,sim_description,**kwargs):
......@@ -199,6 +213,8 @@ class Simulation(object):
* halt
* step
* run
Keyword arguments are passed to initialize()
"""
self.done = False
self.trace_qualifier = os.getpid()
......@@ -225,7 +241,9 @@ class Simulation(object):
if self.trace_qualifier is not None: simV2.VisItOpenTraceFile("trace.%d.txt" % self.trace_qualifier)
simV2.VisItSetDirectory(self.visit_base)
if not simV2.VisItSetupEnvironment():
print >> sys.stderr, 'VisItSetupEnvironment: could not get environment'
print >> sys.stderr, \
"VisItSetupEnvironment: could not get environment\n\nVISIT_HOME is '%s', is this correct?" % \
(self.visit_base,)
sys.exit(1)
# We don't have to worry about the rank, because we only ever run a single compute kernel.
if not simV2.VisItInitializeSocketAndDumpSimFile(
......@@ -236,7 +254,9 @@ class Simulation(object):
return
def initialize(self,**kwargs):
"""This is the subclass-overridable companion to Initialize.
"""This is the subclass-overridable companion to Initialize().
The keyword arguments are what were supplied in the call to
Initialize().
Specific values which you might want to override:
trace_qualifier: Used while naming the trace file. Defaults to
......@@ -250,6 +270,16 @@ class Simulation(object):
exposed. Otherwise you are going to need to
override main_doVisItConnect and do a heap o'
work.
callbacks in turn has substructures:
commands: Defines commands which can be triggered from the
VisIt sim control panel.
metadata: Defines/names metadata for which callbacks should
be made. The following types of metadata are
supported: mesh, variable, curve expression.
See the source for callback_metadata() method
for enumeration of the properties which can be
set for specific types of metadata.
"""
return
......@@ -601,17 +631,6 @@ class Simulation(object):
h = simV2.VisIt_VariableData_alloc()
data_func(h,self.DATAOWNERS[owner],nComp,len(data),data)
return h
def visit_variableArray(self, data_func, nComp, data, owner='VISIT'):
"""Creates a variable.
This version is deprecated, the preferred method is visit_variable(),
passing nComp as a keyword arg. However this may read easier for
users who are already familiar with sims and VisIt.
"""
h = simV2.VisIt_VariableData_alloc()
data_func(h,self.DATAOWNERS[owner],nComp,len(data),data)
return h
# TODO: Change the owner to 'SIM' and see what happens.
def visit_curve(self, data_func, data_x, data_y, data_z=None, owner='VISIT'):
......
#!/usr/bin/python
#*****************************************************************************
#
# Portions derived from works
# Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
# Produced at the Lawrence Livermore National Laboratory
# LLNL-CODE-442911
# All rights reserved.
#
# This file is part of VisIt. For details, see https://visit.llnl.gov/. The
# full copyright notice is contained in the file COPYRIGHT located at the root
# of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the disclaimer below.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the disclaimer (as noted below) in the
# documentation and/or other materials provided with the distribution.
# - Neither the name of the LLNS/LLNL nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
# LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
#*****************************************************************************
# Copyright (c) 2014 Fred Morris, Tacoma WA.
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
......@@ -26,40 +63,52 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#*****************************************************************************
import sys,math
import sys,math,os
# Where to find simV2.py
#VISIT_LIB_PATH = "/opt/downloads/visit/build_visit/visit2.7.2/src/lib"
VISIT_LIB_PATH = "../../../../lib"
VISIT_LIBPATH = os.environ.get('VISIT_LIBPATH',"../../../../lib")
# The directory above the bin/ directory.
#VISIT_BASE_DIR = "/opt/downloads/visit/build_visit/visit2.7.2/src"
VISIT_BASE_DIR = "../../../.."
VISIT_HOME = os.environ.get('VISIT_HOME',"../../../..")
from simbase import Simulation
class PlotSim(Simulation):
def initialize(self):
def initialize(self, dims, ndims):
# By default the sim starts running at startup.
# self.set_runMode(False)
self.rmesh_dims = dims
self.rmesh_ndims = ndims
self.cycle = 0
self.time = 0.
self.angle = 0.
self.NPTS = 1000
# X, Y and Z stored as three vectors NPTS long, rather than as
# 3-tuples NPTS long.
self.points = [ [0.0]*self.NPTS, [0.0]*self.NPTS, [0.0]*self.NPTS ]
self.labels = [ "%03d\0" % (i,) for i in range(self.NPTS) ]
print "len labels: %d" %len(self.labels)
print "len labels[0]: %d" %len(self.labels[0])
# Labels have to be fixed-length strings. Be sure to pad with
# enough extra space/nulls. Nulls seems to be the preferred idiom.
# Our labels here are of the form 'P-000'..'P-999'.
self.labels = [ "P-%03d\0" % (i,) for i in range(self.NPTS) ]
self.tick = True
addplot = (
'AddPlot("Pseudocolor", "zonal")',
'DrawPlots()'
)
self.console['addplot'] = (self.visit_execute, addplot)
self.console['tick on'] = (self.tick_on, None)
self.console['tick off'] = (self.tick_off, None)
self.callbacks['commands']['addplot'] = (self.visit_execute, addplot, 'GENERIC')
self.callbacks['metadata'] = {
'mesh':
[
{
'Name': "point2d",
'MeshType': "POINT",
'TopologicalDimension': 0,
'Name': "mesh2d",
'MeshType': "RECTILINEAR",
'TopologicalDimension': 2,
'SpatialDimension': 2,
'NumDomains': 1,
'DomainTitle': "Domains",
......@@ -67,9 +116,11 @@ class PlotSim(Simulation):
'NumGroups': 0,
'XUnits': "cm",
'YUnits': "cm",
'ZUnits': "cm",
'XLabel': "Width",
'YLabel': "Height",
},
'ZLabel': "Depth"
},
{
'Name': "point3d",
'MeshType': "POINT",
......@@ -85,10 +136,16 @@ class PlotSim(Simulation):
'XLabel': "Width",
'YLabel': "Height",
'ZLabel': "Depth"
}
],
}
],
'variable':
[
{
'Name': "zonal",
'MeshName': "mesh2d",
'Type': "SCALAR",
'Centering': "ZONE"
},
{
'Name': "px",
'MeshName': "point3d",
......@@ -107,22 +164,33 @@ class PlotSim(Simulation):
'Type': "SCALAR",
'Centering': "NODE"
},
{
'Name': "z2d",
'MeshName': "point2d",
'Type': "SCALAR",
'Centering': "NODE"
},
{
'Name': "pointLabels",
'MeshName': "point3d",
'Type': "LABEL",
'Centering': "NODE"
}
],
# 'curve': [],
# 'expression': []
],
'curve':
[
{
'Name': "sine",
'XLabel': "Angle",
'XUnits': "radians",
'YLabel': "Amplitude",
'YUnits': ""
}
],
'expression':
[
{
'Name': "zvec",
'Definition': "{zonal, zonal}",
'Type': "VECTOR"
}
]
}
return
def tick_on(self, arg, cmd, visit_args, cbdata):
......@@ -149,6 +217,8 @@ class PlotSim(Simulation):
self.time += math.pi/10.
self.angle += 0.05
points = self.points
# This might be an actual simulation. Your actual simulation would
# go here.
for i in range(self.NPTS - 1):
t = float(i) / float(self.NPTS - 1)
a = math.pi * 10.0 * t
......@@ -162,11 +232,37 @@ class PlotSim(Simulation):
def callback_mesh(self, domain, name, cbdata):
h = None
if name == 'point2d':
h = self.visit_point_mesh(self.VARDATATYPES['FLOAT'],
self.points[0], self.points[1]
)
if name == "mesh2d":
# If the data being displayed was derived from the "actual"
# simulation data, but not the simulation data itself, then
# the mesh might be built when requested.
minRealIndex = [0,0,0]
maxRealIndex = [0,0,0]
maxRealIndex[0] = self.rmesh_dims[0]-1;
maxRealIndex[1] = self.rmesh_dims[1]-1;
maxRealIndex[2] = self.rmesh_dims[2]-1;
rmesh_x = []
for i in range(self.rmesh_dims[0]):
t = float(i) / float(self.rmesh_dims[0]-1)
rmesh_x = rmesh_x + [t * 5. - 2.5 + 5. * domain]
rmesh_y = []
for i in range(self.rmesh_dims[1]):
t = float(i) / float(self.rmesh_dims[1]-1)
rmesh_y = rmesh_y + [t * 5. - 2.5]
h = self.visit_rectilinear_mesh(self.VARDATATYPES['FLOAT'],
minRealIndex, maxRealIndex,
rmesh_x, rmesh_y
)
if name == 'point3d':
# If this was "actual" simulation data, the calculations might
# be done in the main loop.
#
# NOTE: "*self.points" causes Python to perform one level of
# expansion, into x, y and z. This is the same syntax used
# for expanding undeclared positional args.
h = self.visit_point_mesh(self.VARDATATYPES['FLOAT'],
*self.points
)
......@@ -174,25 +270,71 @@ class PlotSim(Simulation):
def callback_variable(self, domain, name, cbdata):
h = None
if name == "zonal":
sx = -2.5 + domain * 5.
ex = sx + 5.
sy = -2.5
ey = sy + 5.
# Calculate a zonal variable that moves around.
rmesh_zonal = []
angle = self.time
xpos = 2.5 * math.cos(angle)
ypos = 2.5 * math.sin(angle)
for j in range(self.rmesh_dims[1]-1):
ty = float(j) / float(self.rmesh_dims[1]-1-1)
cellY = (1.-ty)*sy + ey*ty
dY = cellY - ypos
for i in range(self.rmesh_dims[0]-1):
tx = float(i) / float(self.rmesh_dims[0]-1-1)
cellX = (1.-tx)*sx + ex*tx
dX = cellX - xpos
rmesh_zonal = rmesh_zonal + [math.sqrt(dX * dX + dY * dY)]
h = self.visit_variable(self.VARDATATYPES['FLOAT'], rmesh_zonal)
if name == 'px':
h = self.visit_variable(self.VARDATATYPES['FLOAT'], self.points[0])
if name == 'py':
h = self.visit_variable(self.VARDATATYPES['FLOAT'], self.points[1])
if name == 'pz':
h = self.visit_variable(self.VARDATATYPES['FLOAT'], self.points[2])
if name == 'z2d':
h = self.visit_variable(self.VARDATATYPES['FLOAT'], self.points[2])
if name == 'pointLabels':
# As noted earlier, labels are fixed-length strings. The extra parameter
# passes that length (since all labels will be the same length as the
# first one).
h = self.visit_variable(self.VARDATATYPES['CHAR'], self.labels, nComp=len(self.labels[0]))
return h
def callback_curve(self, name, cbdata):
h = None
if name == "sine":
x = [0.] * 200
y = [0.] * 200
for i in range(200):
angle = self.time + (float(i) / float(200-1)) * 4. * math.pi
x[i] = angle
y[i] = math.sin(x[i])
h = self.visit_curve(self.VARDATATYPES['FLOAT'], x, y)
return h
#
# Main program
#
def main():
sim = PlotSim(VISIT_LIB_PATH, VISIT_BASE_DIR)
try:
sim = PlotSim(VISIT_LIBPATH, VISIT_HOME)
except ImportError, e:
print >>sys.stderr, "%s\n\nVISIT_LIBPATH is '%s', is this correct?" % (e, VISIT_LIBPATH)
sys.exit(1)
# The second pair of arguments are passed to initialize() as kwargs.
sim.Initialize("pointmesh", "PointMesh POC")
sim.Initialize("updateplots", "LLNL updateplots... reloaded",
dims=[50,50,1], ndims=2)
sim.MainLoop()
sim.Finalize()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment