Python Interface to MAPL: Difference between revisions
Jump to navigation
Jump to search
Line 58: | Line 58: | ||
== A python component with Children in Fortran == | == A python component with Children in Fortran == | ||
In this example, the '''GEOSgcs''' component is implemented in Python, with its | In this example, the '''GEOSgcs''' component is implemented in Python, with its children, components '''ANA''' and '''GCM''', implemented in Fortran. | ||
import MAPL | import MAPL | ||
class GridComp(MAPL.GridComp): | class GridComp(MAPL.GridComp): | ||
"""Implements the GEOSgcs component by subclassing MAPL.GridComp""" | """Implements the GEOSgcs component by subclassing MAPL.GridComp""" | ||
def SetServices(self): | def SetServices(self): | ||
"""SerServices for a composite component""" | """SerServices for a composite component""" | ||
# Instantiate Children component | # Instantiate Children component | ||
# ------------------------------ | # ------------------------------ | ||
ana = MAPL.GridComp(lib='/some/path/libGEOSana.so') | ana = MAPL.GridComp(lib='/some/path/libGEOSana.so') | ||
gcm = MAPL.GridComp(lib='/some/path/libGEOSgcm.so') | gcm = MAPL.GridComp(lib='/some/path/libGEOSgcm.so') | ||
# Adopt children | # Adopt children | ||
# -------------- | # -------------- | ||
self.AddChild(ana) | self.AddChild(ana) | ||
self.AddChild(gcm) | self.AddChild(gcm) | ||
# Set connectivity among children | # Set connectivity among children | ||
# ------------------------------- | # ------------------------------- | ||
Line 83: | Line 83: | ||
self.AddConnectivity(src=[ana,vars], dst=[gcm,vars]) | self.AddConnectivity(src=[ana,vars], dst=[gcm,vars]) | ||
self.AddConnectivity(src=[gcm,'LWI'], dst=[ana,'ORO']) | self.AddConnectivity(src=[gcm,'LWI'], dst=[ana,'ORO']) | ||
# Run the base class SetServices | # Run the base class SetServices | ||
# ------------------------------ | # ------------------------------ | ||
MAPL.GridComp.__SetServices__(self) | MAPL.GridComp.__SetServices__(self) |
Revision as of 11:55, 18 August 2008
This document presents a very high level description of a python interface to MAPL.
GEOS-5 Use Cases
The examples below are based on the actual GEOS-5 GCM Application, and a few components at the very top of the hierarchy. Here we assumed that MAPL Grid Components can be implemented entirely in C/Fortran or in Python.
GEOS-5 Application with Fortran Root Component
In this example, the very top root component is implemented entirely in a shared library.
"""" The GEOSgcm application written in python, starting from a Root Component implemented in Fortran. """
import MAPL
if __name == "__main__":
# Instantiate the root component # ------------------------------ gcs = MAPL.GridComp(lib='/some/path/libGEOSana.so')
# Instantiate MAPL # ---------------- mapl = MAPL(root=gcs)
# Run the cap # ----------- mapl.go()
GEOS-5 Application with Python Root Component
In this example, the very top root component is implemented in Python.
"""" The GEOSgcm application written in python, starting from a Root Component implemented in Fortran. """
import MAPL import GEOSgcs # the GEOSgcs component is implemented here
if __name == "__main__":
# Instantiate the Python root component # ------------------------------------- gcs = GEOSgcs(rc='gcs.rc')
# Instantiate MAPL # ---------------- mapl = MAPL(root=gcs)
# Run the cap # ----------- mapl.go()
A python component with Children in Fortran
In this example, the GEOSgcs component is implemented in Python, with its children, components ANA and GCM, implemented in Fortran.
import MAPL class GridComp(MAPL.GridComp): """Implements the GEOSgcs component by subclassing MAPL.GridComp""" def SetServices(self): """SerServices for a composite component""" # Instantiate Children component # ------------------------------ ana = MAPL.GridComp(lib='/some/path/libGEOSana.so') gcm = MAPL.GridComp(lib='/some/path/libGEOSgcm.so') # Adopt children # -------------- self.AddChild(ana) self.AddChild(gcm) # Set connectivity among children # ------------------------------- vars = ('Tinc', 'Sinc', 'Uinc', 'Vinc', 'SSHinc' ) self.AddConnectivity(src=[ana,vars], dst=[gcm,vars]) self.AddConnectivity(src=[gcm,'LWI'], dst=[ana,'ORO']) # Run the base class SetServices # ------------------------------ MAPL.GridComp.__SetServices__(self)