[cig-commits] r14499 - in short/3D/PyLith/branches/pylith-swig/playpen: . petscapp
brad at geodynamics.org
brad at geodynamics.org
Fri Mar 27 15:45:25 PDT 2009
Author: brad
Date: 2009-03-27 15:45:24 -0700 (Fri, 27 Mar 2009)
New Revision: 14499
Added:
short/3D/PyLith/branches/pylith-swig/playpen/petscapp/
short/3D/PyLith/branches/pylith-swig/playpen/petscapp/fooapp.py
Log:
Added petscapp for idea on how to create PetscApplication to handle PetscInitialize() and PetscFinalize() in a Pyre application.
Added: short/3D/PyLith/branches/pylith-swig/playpen/petscapp/fooapp.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/playpen/petscapp/fooapp.py (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/playpen/petscapp/fooapp.py 2009-03-27 22:45:24 UTC (rev 14499)
@@ -0,0 +1,172 @@
+#!/usr/bin/env nemesis
+
+from pyre.applications.Script import Script as Application
+from pyre.components.Component import Component
+
+# ======================================================================
+# PetscApplication
+class PetscApplication(Application):
+ """
+ PETSc application.
+ """
+
+ def __init__(self, name="petscapp"):
+ """
+ Constructor.
+ """
+ Application.__init__(self)
+ return
+
+
+ def main(self, *args, **kwds):
+ """
+ Run simulation in parallel on compute nodes.
+ """
+ print "Call PetscInitialize()."
+ self.fake_main(*args, **kwds)
+ self.cleanup()
+ print "Call PetscFinalize()."
+ return
+
+
+ def cleanup(self):
+ """
+ Deallocate data structures.
+ """
+ for component in self.components():
+ if isinstance(component, PetscComponent):
+ component.cleanup()
+ self._cleanup()
+ return
+
+
+ def _cleanup(self):
+ """
+ Deallocate locally managed data structures.
+ """
+ return
+
+
+# ======================================================================
+# PetscComponent
+class PetscComponent(Component):
+ """
+ PETSc component.
+ """
+
+ def __init__(self, name="petsccomponent", facility="petsccomponent"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility)
+ return
+
+
+ def cleanup(self):
+ """
+ Deallocate data structures.
+ """
+ for component in self.components():
+ if isinstance(component, PetscComponent):
+ component.cleanup()
+ self._cleanup()
+ return
+
+
+ def _cleanup(self):
+ """
+ Deallocate locally managed data structures.
+ """
+ return
+
+
+# ======================================================================
+# Bar
+class Bar(PetscComponent):
+ """
+ Bar Pyre component.
+ """
+
+ # Inventory
+ import pyre.inventory
+ value = pyre.inventory.int("value", default=0)
+ value.meta['tip'] = "An integer value."
+
+
+ def __init__(self, name="bar"):
+ """
+ Constructor.
+ """
+ PetscComponent.__init__(self, name, facility="bar")
+ return
+
+
+ def show(self):
+ """
+ Print value.
+ """
+ print " Bar value is %d" % self.value
+ return
+
+
+ def _cleanup(self):
+ """
+ Deallocate locally managed data structures.
+ """
+ print "Deallocate Bar data structures in _cleanup()."
+ return
+
+
+# ======================================================================
+# FooApp class
+class FooApp(PetscApplication):
+ """
+ FooApp application.
+ """
+
+ # Inventory
+ import pyre.inventory
+ foo = pyre.inventory.facility("foo", factory=Bar)
+ foo.meta['tip'] = "Facility foo."
+
+
+ def __init__(self, name="fooapp"):
+ """
+ Constructor.
+ """
+ Application.__init__(self, name)
+ self.foo2 = Bar()
+ self.foo2.value = 2
+ return
+
+
+ def fake_main(self, *args, **kwds):
+ """
+ Run the application.
+ """
+ print "Doing some stuff in main."
+ print "Foo:"
+ self.foo.show()
+ print "Foo 2:"
+ self.foo2.show()
+
+ return
+
+
+ def _cleanup(self):
+ """
+ Deallocate locally managed data structures.
+ """
+ print "Deallocate application data structures in _cleanup()."
+ self.foo2.cleanup()
+ return
+
+
+# ======================================================================
+if __name__ == "__main__":
+
+ app = FooApp()
+ app.run()
+
+
+# End of file
Property changes on: short/3D/PyLith/branches/pylith-swig/playpen/petscapp/fooapp.py
___________________________________________________________________
Name: svn:executable
+ *
More information about the CIG-COMMITS
mailing list