PyTrilinos: a Python Interface to Selected Trilinos Packages - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

PyTrilinos: a Python Interface to Selected Trilinos Packages

Description:

Brusselator Script, cont'd # Create the Crank Nicolson solver, add the ... Great alternative to shell or perl scripts. Rapid prototyping (especially OO) ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 16
Provided by: willia193
Category:

less

Transcript and Presenter's Notes

Title: PyTrilinos: a Python Interface to Selected Trilinos Packages


1
PyTrilinos a Python Interface toSelected
Trilinos Packages
  • Bill Spotz
  • Trilinos Users Group Meeting
  • November 2, 2004

2
Outline
  • Python
  • Why Python?
  • Python basics
  • Numeric demo
  • PyTrilinos
  • Packages currently wrapped
  • PyTrilinos demo
  • Epetra/Numeric integration
  • Example
  • Multi-physics coupling environment

3
Why Python?
  • Object-oriented scripting language
  • Easy to learn
  • Clean syntax
  • Weakly typed
  • Designed for rapid prototyping
  • Designed to glue software packages together
  • Module library
  • calendar
  • commands (Unix)
  • curses
  • datetime
  • difflib
  • distutils
  • email
  • ftplib
  • getopt
  • htmllib
  • os
  • random
  • re
  • string
  • symbol
  • sys
  • tarfile
  • thread
  • time
  • Tkinter
  • unicode
  • unittest
  • url
  • xml
  • Over 300 standard
  • Numeric

4
Python Variables
a 2004
b a
a "Sandia"
5
Python Containers
  • Indexing
  • Get val containeri
  • Set containeri val
  • Slices containerijk
  • Strings
  • string "Trilinos"
  • Immutable
  • Tuples
  • tuple (1,3.14,string)
  • Immutable
  • Lists
  • list 2,2.71,tuple
  • Mutable
  • Methods append, insert, pop, remove,
  • Dictionaries
  • dict key1val1, key2val2,
  • Mutable
  • Keys must be immutable

6
Python/Numeric Demo
7
PyTrilinos
  • from PyTrilinos import
  • Epetra
  • SerialComm
  • BlockMap
  • Map
  • BLAS
  • LAPACK
  • MultiVector
  • Vector
  • IntVector
  • CrsGraph
  • MapColoring
  • CrsMatrix
  • SerialDense
  • EpetraExt
  • TransformltEpetra_CrsGraph, Epetra_MapColoringgt
  • TransformltEpetra_CrsGraph, vectorltEpetra_IntVector
    gt gt
  • NOX
  • Abstract
  • Epetra
  • Parameter
  • Solver
  • StatusTest
  • PyInterface

8
Epetra/Numeric Integration
  • C
  • class Epetra_NumPyVector
  • public Epetra_Vector
  • public
  • Epetra_NumPyVector(Epetra_BlockMap )
  • Epetra_NumPyVector(Epetra_BlockMap ,
  • PyObject )
  • Epetra_NumPyVector(PyObject )
  • PyObject getArray()
  • ...
  • Python
  • class Vector(UserArray,NumPyVector)
  • def __init__(self, args)
  • NumPyVector.__init__(self,args)
  • UserArray.__init__(self,
  • self.getArray(),
  • 'd',0,1)
  • def __str__(self)
  • return str(self.array)

Result Epetra.Vector is both Epetra_Vector and
Numeric UserArray, and both base classes share
same memory block for data.
9
PyTrilinos Demo
10
Example Multiphysics Coupling Environment
Solver


11
Multiphysics Coupling Environment Objects
MultiSolver
Solver
PhysicsModules
Fields
Grids
Coordinates
12
Example Problem 1D Brusselator
Governing Equations
Boundary Conditions
Initial Conditions
Data
13
Brusselator Script
  • !/usr/bin/env python
  • Local imports
  • import setpath
  • from BC.Dirichlet import
  • from Brusselator import
  • from CrankNicolson import
  • from Grid import
  • from Field import
  • Define a 1D uniform grid
  • n 11
  • x Coordinate("x",n)
  • grid OrthogonalGrid(x)
  • Define the Unknowns
  • speciesX Unknown("X", grid, "Species X")
  • speciesY Unknown("Y", grid, "Species Y")
  • Define parameters of Brusselator problem
  • a 0.6
  • b 2.0
  • d1 0.025
  • d2 0.025
  • bParams BrusselatorParameters(a,b,d1,d2)
  • Create the Brusselator modules
  • brussX BrusselatorX("X-Brusselator",
  • bParams, speciesX, speciesY)
  • brussY BrusselatorY("Y-Brusselator",
  • bParams, speciesX, speciesY)
  • Define the boundary conditions
  • bcx0 Dirichlet(speciesX 0, a )
  • bcx1 Dirichlet(speciesX-1, a )
  • bcy0 Dirichlet(speciesY 0, b/a)
  • bcy1 Dirichlet(speciesY-1, b/a)

14
Brusselator Script, contd
  • Create the Crank Nicolson solver, add the
  • Brusselators to it, and add the boundary
  • conditions to it
  • cnSolver CrankNicolson(0.5, endTime20.0)
  • cnSolver.addPhysicsModule(brussX)
  • cnSolver.addPhysicsModule(brussY)
  • cnSolver.addPhysicsModule(bcx0)
  • cnSolver.addPhysicsModule(bcx1)
  • cnSolver.addPhysicsModule(bcy0)
  • cnSolver.addPhysicsModule(bcy1)
  • Create the state, residual and exact
  • BlockArrays, and initialize all physics
  • modules
  • cnSolver.openIOFile("Brusselator1_cn.nc")
  • cnSolver.initialize()
  • print cnSolver
  • Assign the initial conditions
  • stateVector cnSolver.getBlockState()
  • stateVector.setArrayToPoly(speciesX,a,
  • 1.0,-1.0)
  • stateVector.setArrayToPoly(speciesY,b/a,
  • 10,-1.0)
  • Execute the forward Euler problem
  • cnSolver.execute()

15
Concluding Remarks
  • Python should be a part of every programmers
    toolkit
  • Great alternative to shell or perl scripts
  • Rapid prototyping (especially OO)
  • To install PyTrilinos
  • Check out developer branch
  • Need python, Numeric, swig 1.3.19-21 (including
    shared libraries)
  • Configure serial build
  • Configure with --enable-pytrilinos
  • Consider wrapping your own package
Write a Comment
User Comments (0)
About PowerShow.com