Editing
IVAJ/Level1
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==<span id="Sidebar">Sidebar:</span> <font color="#0000DD">SwitchCoord Python Module</font>== Here we present a complete listing of the python code from our customized <font face="Courier">SwitchCoord</font> program module. At the beginning of the "Physics Analysis" segment of the code, we assign names to the data arrays that have been acquired as input from <font face="Courier">vtkPLOT3DReader</font>: ''<font face="Courier">pcoords</font>'' is a tuple that identifies the Cartesian-based coordinate location of each grid vertex, ''<font face="Courier">density</font>'' is a scalar that specifies the mass density, and ''<font face="Courier">momentum</font>'' is a tuple that specifies the values of the cylindrical-coordinate-based vector momentum at each grid vertex. We detail the remaining logic of the physics analysis in the main text. <pre> import core.modules.module_registry from core.modules.vistrails_module import Module, ModuleError import vtk, math version="0.0.0" name="SwitchCoord" identifier="edu.lsu.switchcoord" class SwitchCoord(Module): def compute(self): minp = self.getInputFromPort("min_density") Domega = self.getInputFromPort("Domega") dataset=self.getInputFromPort("dataset") output = self.create_instance_of_type('edu.utah.sci.vistrails.vtk', 'vtkStructuredGrid') output.vtkInstance = vtk.vtkStructuredGrid() mydata=output.vtkInstance mydata.DeepCopy(dataset.vtkInstance) self.op(mydata, minp, omega) self.setResult("changed_dataset", output) ################################### ## ## Begin: Physics Analysis ## ################################### def op(self, mydata, minp, omega): extent=mydata.GetExtent() pcoords = mydata.GetPoints().GetData() density = mydata.GetPointData().GetScalars("Density") momentum = mydata.GetPointData().GetVectors("Momentum") maxnorm = 0.0 for i in range(0, mydata.GetNumberOfPoints()): [x, y, z] = pcoords.GetTuple3(i) [_v1, _v2, _v3] = momentum.GetTuple3(i) p = density.GetValue(i) r = math.sqrt(x*x + y*y) phi = math.atan2(y, x) if p < minp: vx=vy=vz=0 else: vr = _v1 / p vphi = _v2 / (p) + r * omega vz = _v3 / p vx = vr * math.cos(phi) - vphi * math.sin(phi) vy = vr * math.sin(phi) + vphi * math.cos(phi) norm = math.sqrt(vx*vx + vy*vy + vz*vz) if norm > maxnorm: maxnorm = norm momentum.SetTuple3(i, vx, vy, vz) for i in range(0, mydata.GetNumberOfPoints()): [vx, vy, vz] = momentum.GetTuple3(i) vx = vx/maxnorm vy = vy/maxnorm vz = vz/maxnorm momentum.SetTuple3(i, vx, vy, vz) ################################### ## ## End: Physics Analysis ## ################################### def initialize(*args, **keywords): reg=core.modules.module_registry.registry reg.add_module(SwitchCoord) reg.add_input_port(SwitchCoord, "scalar_range", [core.modules.basic_modules.Float, core.modules.basic_modules.Float]) reg.add_input_port(SwitchCoord, "min_density", core.modules.basic_modules.Float) reg.add_input_port(SwitchCoord, "omega", core.modules.basic_modules.Float) reg.add_input_port(SwitchCoord, "dataset", (reg.get_descriptor_by_name( 'edu.utah.sci.vistrails.vtk', 'vtkStructuredGrid').module) ) reg.add_output_port(SwitchCoord, "changed_dataset", (reg.get_descriptor_by_name( 'edu.utah.sci.vistrails.vtk', 'vtkStructuredGrid').module) ) def package_dependencies(): import core.packagemanager manager = core.packagemanager.get_package_manager() if manager.has_package('edu.utah.sci.vistrails.vtk'): return ['edu.utah.sci.vistrails.vtk'] else: return [] </pre>
Summary:
Please note that all contributions to JETohlineWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
JETohlineWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Tiled Menu
Table of Contents
Old (VisTrails) Cover
Appendices
Variables & Parameters
Key Equations
Special Functions
Permissions
Formats
References
lsuPhys
Ramblings
Uploaded Images
Originals
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information