/usr/bin/viper is in python-viper 1.0.0-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | #!/usr/bin/python
"""
Viper: A simple mesh plotter and run--time visualization module for plotting
and saving simulation data. The class C{Viper} can visualize solutions given
as numpy arrays, and meshes that provide the two methods C{cells()} and
C{coordinates()}. These methods should return numpy arrays specifying the
node-element ordering and coordinates of the nodes, respectively.
To use the module as a script, the syntax is:
viper.py -i <infile.xml[.gz]> [-o <savefile>]
or,
viper.py --input <infile.xml[.gz]> [--output <savefile>]
If the optional command line argument -o is given, the mesh is stored in vtk
format.
"""
from viper import *
from viper import __version__
import sys
import getopt
import numpy
import os
def _dolfin_mesh_plotter(infile, outfile, data=None, lutfile="gauss_120.lut", datatype=None):
from dolfin import Mesh, UnitSquare, File, plot
from dolfin import MeshFunction
if infile:
title = "Mesh plot"
mesh = Mesh(infile)
else:
title = "Unit Square plot"
mesh = UnitSquare(10,10)
if data is None:
p = Viper(mesh=mesh, title=title)
p.update()
else:
assert os.path.isfile(lutfile) or \
os.path.isfile(os.path.join(os.path.dirname(viper.__file__), "data", lutfile)), \
"Could not locate lutfile \"%s\" in current directory or default data dir." % (lutfile,)
file = File(data)
dim = datatype["dim"]
if datatype["type"] == "i":
mf = MeshFunction("int", mesh, dim)
file >> mf
elif datatype["type"] == "u":
mf = MeshFunction("uint", mesh, dim)
file >> mf
elif datatype["type"] == "r":
mf = MeshFunction("real", mesh, dim)
file >> mf
else:
print _help()
sys.exit()
p = plot(mf, lutfile=lutfile, title="Data plot")
if outfile:
p.init_writer("")
p.write_vtk(os.path.splitext(os.path.splitext(outfile)[0])[0]+".vtk")
p.interactive()
return p
def _vtk_plotter(infile):
p = Viper()
p.init_from_file(infile)
p.interactive()
return p
def _main(infile, outfile, data=None, lutfile="gauss_120.lut", datatype={}):
if infile:
suffix = os.path.splitext(infile)[-1]
if suffix == ".vtk":
return _vtk_plotter(infile)
return _dolfin_mesh_plotter(infile, outfile, data=data, lutfile=lutfile, datatype=datatype)
def _help():
print """This is Viper, the simple FEniCS run-time plotter, version %s.
For further information, go to http://www.fenics.org/wiki/Viper
Usage: viper -i file [-d data (xml meshfunction file) -tdatatype -l lutfile -o file ]
Alternatively: viper file (mesh file in dolfin mesh format)
datatype is a format string specifying i or r for integer or real valued data,
and the dimensionality of the data set. E.g. -tr0 (real vertex data), -ti2
(integer cell data).
""" % __version__
def _usage():
return """This is Viper, the simple FEniCS run-time plotter, version %s.
For further information, go to http://www.fenics.org/wiki/Viper
Usage:
viper file [--lut=lut_file --mode=mode --title=title]
or
viper file [-l lut_file -m mode -t title]
where 'file' is is a dolfin data file, like a Mesh, FunctionPlotData, or a file
containing both a Mesh and either a cell or vertex valued MeshFunction of type
uint or double. The 'mode' argument can be either 'auto', 'scalar', or
'vector', 'lut_file' a color lookup table, and 'title' the title field of the
plotting window.
""" % (__version__,)
def _plot_function_plot_data(infile, lutfile, mode, title):
from dolfin.cpp import FunctionPlotData, File
from dolfin import plot
d = FunctionPlotData()
f = File(infile)
f >> d
return plot(d, lutfile=lutfile, mode=mode, title=title)
def _plot_mesh(infile, lutfile, mode, title):
import dolfin
f = dolfin.File(infile)
d = dolfin.Mesh()
f >> d
return dolfin.plot(d, title=title)
def _plot_mesh_function(infile, lutfile, mode, title):
import dolfin
f = dolfin.File(infile)
mesh = dolfin.Mesh()
f >> mesh
try:
f = dolfin.File(infile)
mf = dolfin.MeshFunction("double", mesh, mesh.topology().dim())
f >> mf
return dolfin.plot(mf, title=title)
except:
pass
try:
f = dolfin.File(infile)
mf = dolfin.MeshFunction("uint", mesh, mesh.topology().dim())
f >> mf
return dolfin.plot(mf, title=title)
except:
raise ValueError, "No meshfunction found."
def __main(infile, lutfile, mode, title):
try:
return _plot_function_plot_data(infile, lutfile, mode, title)
except:
pass
try:
return _plot_mesh_function(infile, lutfile, mode, title)
except:
pass
return _plot_mesh(infile, lutfile, mode, title)
print "Cannot plot data in file %s" % (infile,)
def _oldmain():
import sys
(opts, args) = getopt.getopt(sys.argv[1:], "i:d:o:l:h:t:", ["input=", "data=", "output=", "lut=", "help", "datatype="])
infile = None
outfile = None
datafile = None
datatype = {"type": "r", "dim": 0}
lutfile = "gauss_120.lut"
for (opt, val) in opts:
if (opt == "--input" or opt == "-i"):
infile = val
elif (opt =="--output" or opt == "-o"):
outfile = val
elif (opt =="--lut" or opt == "-l"):
lutfile = val
elif (opt =="--datatype" or opt == "-t"):
import re
if re.search("i", val):
datatype["type"] = "i"
if re.search("u", val):
datatype["type"] = "u"
match = re.search("(\d+)", val)
if match:
datatype["dim"] = int(match.groups()[0])
elif (opt =="--data" or opt == "-d"):
datafile = val
elif (opt == "--help" or opt == "-h"):
_help()
sys.exit()
if infile == outfile == None:
if len(args) > 0:
_main(args[-1], None)
sys.exit()
p = _main(infile, outfile, data=datafile, lutfile=lutfile, datatype=datatype)
def _newmain():
import sys, os
(opts, args) = getopt.getopt(sys.argv[1:], "o:l:hm:", ["output=", "lut=", "mode=", "title=", "help",])
outfile = None
lutfile = "gauss_120.lut"
mode = "auto"
title = "FEniCS Viper"
for (opt, val) in opts:
if (opt in ("--output", "-o")):
outfile = val
elif (opt in ("--lut", "-l")):
lutfile = val
elif (opt in ("--help", "-h")):
_newhelp()
elif (opt in ("--mode", "-m")):
mode = val
elif (opt in ("--title", "-t")):
title = val
if len(args) > 0:
infile = args[-1]
if not os.path.isfile(infile):
raise RuntimeError, "No such file %s" % (infile,)
else:
raise RuntimeError, _usage()
if mode == "":
mode = "auto"
p = __main(infile, lutfile, mode, title)
p.interactive()
if __name__ == '__main__':
#_oldmain()
_newmain()
|