[cig-commits] r6017 - in
short/3D/PyLith/branches/pylith-0.8/pylith3d:
examples/lintet/tractest pylith3d
leif at geodynamics.org
leif at geodynamics.org
Tue Feb 13 16:27:45 PST 2007
Author: leif
Date: 2007-02-13 16:27:44 -0800 (Tue, 13 Feb 2007)
New Revision: 6017
Modified:
short/3D/PyLith/branches/pylith-0.8/pylith3d/examples/lintet/tractest/tractest.keyval
short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/KeyValParser.py
short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py
Log:
Reverted unintentional check-in of ComponentHarness-related
changes.
Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/examples/lintet/tractest/tractest.keyval
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/examples/lintet/tractest/tractest.keyval 2007-02-14 00:23:47 UTC (rev 6016)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/examples/lintet/tractest/tractest.keyval 2007-02-14 00:27:44 UTC (rev 6017)
@@ -14,9 +14,6 @@
#winklerScaleX = 1.0
#winklerScaleY = 1.0
#winklerScaleZ = 1.0
-winklerScaleZ = tomato
-zoo = bar
-fileRoot=tractesthh
#
#
# Parameters controlling stress integration and numerical computation
Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/KeyValParser.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/KeyValParser.py 2007-02-14 00:23:47 UTC (rev 6016)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/KeyValParser.py 2007-02-14 00:27:44 UTC (rev 6017)
@@ -38,10 +38,12 @@
def parse(self, stream):
registry = Registry("root")
+ node = registry.getNode("pylith3d")
+ node = node.getNode("scanner")
lineNumber = 1
for line in stream:
locator = locators.file(stream.name, lineNumber)
- self.parseLine(line, registry, locator)
+ self.parseLine(line, node, locator)
lineNumber = lineNumber + 1
return registry
Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py 2007-02-14 00:23:47 UTC (rev 6016)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py 2007-02-14 00:27:44 UTC (rev 6017)
@@ -33,7 +33,7 @@
import os
-class Scanner(Component):
+class Pylith3d_scan(Component):
def __init__(self):
@@ -44,20 +44,19 @@
self.trace.log("Hello from pl3dscan.__init__!")
- self.macros = {}
- self.defineMacros({'rank': '0'})
+ self.rank = 0
return
def configureProperties(self, context):
- """set the values of all the properties in my inventory"""
+ """set the values of all the properties and facilities in my inventory"""
#
# First, configure my properties as defined by the framework.
#
- super(Scanner, self).configureProperties(context)
+ super(Pylith3d_scan, self).configureProperties(context)
#
# Second, open input files. Log I/O errors.
@@ -75,7 +74,7 @@
unused = self.IOFileCategory(False, 0, "unused")
required = self.IOFileCategory(True, 1, None)
- Inventory = Scanner.Inventory
+ Inventory = Pylith3d_scan.Inventory
analysisType = self.inventory.analysisType
@@ -100,6 +99,18 @@
self._differentialForceInputFile = inputFile(Inventory.differentialForceInputFile, unused)
self._slipperyWinklerInputFile = inputFile(Inventory.slipperyWinklerInputFile, unused)
+ def openKeywordEqualsValueFile(filename, flags, mode):
+ from CodecKeyVal import CodecKeyVal
+ from os.path import splitext
+ base, ext = splitext(filename)
+ assert ext == ".keyval"
+ codec = CodecKeyVal()
+ shelf = codec.open(base, mode)
+ return shelf
+
+ self._keywordEqualsValueFile = inputFileStream(Inventory.keywordEqualsValueFile, optional,
+ opener=openKeywordEqualsValueFile)
+
# The call to glob() is somewhat crude -- basically, determine
# if any files might be in the way.
self._ucdOutputRoot = macroString(Inventory.ucdOutputRoot)
@@ -128,6 +139,21 @@
sys.exit("%s: configuration error(s)" % self.name)
#
+ # Third, read the data from the .keyval file -- potentially
+ # reconfiguring some of my properties.
+ #
+
+ if self._keywordEqualsValueFile:
+ registry = self._keywordEqualsValueFile['inventory']
+ registry = registry.getFacility("pylith3d")
+ registry = registry.getFacility("scanner")
+ if registry:
+ # Transfer .keyval input to my private registry...
+ self.updateConfiguration(registry)
+ # ..and from there to my inventory.
+ self.inventory.configureProperties(context)
+
+ #
# Finally, decorate any missing traits with my name.
#
@@ -137,8 +163,6 @@
def _configure(self):
- super(Scanner, self)._configure()
-
# get values for extra input (category 2)
self.winklerScaleX = self.inventory.winklerScaleX
@@ -193,11 +217,9 @@
import string
from mpi import MPI_Comm_rank, MPI_COMM_WORLD
- rank = MPI_Comm_rank(MPI_COMM_WORLD)
- self.defineMacros({'rank': str(rank)})
-
+ self.rank = MPI_Comm_rank(MPI_COMM_WORLD)
outputFile = self.outputFile
- Inventory = Scanner.Inventory
+ Inventory = Pylith3d_scan.Inventory
optional = self.IOFileCategory(True, 0, "optional")
# Re-initialize these with the newly acquired rank.
self._asciiOutputFile = outputFile(Inventory.asciiOutputFile, optional)
@@ -638,14 +660,23 @@
self.tryOpen = tryOpen
self.fatalPoints = fatalPoints
self.label = label
-
- def defineMacros(self, macros):
- self.macros.update(macros)
def macroString(self, trait):
from pyre.util import expandMacros
+ class InventoryAdapter(object):
+ def __init__(self, inventory, builtins):
+ self.inventory = inventory
+ self.builtins = builtins
+ def __getitem__(self, key):
+ builtin = self.builtins.get(key)
+ if builtin is None:
+ return expandMacros(str(self.inventory.getTraitValue(key)), self)
+ return builtin
descriptor = self.inventory.getTraitDescriptor(trait.name)
- return expandMacros(descriptor.value, self.macros)
+ builtins = {
+ 'rank': str(self.rank),
+ }
+ return expandMacros(descriptor.value, InventoryAdapter(self.inventory, builtins))
def ioFileStream(self, trait, flags, mode, category, opener=None):
value = self.macroString(trait)
@@ -677,6 +708,7 @@
os.remove(value)
return value
+
class Inventory(Component.Inventory):
import pyre.inventory
@@ -689,6 +721,14 @@
default="PyLith-0.8 Simulation")
title.meta['tip'] = "Title for this simulation"
+ # Basename for all files (may be overridden by specific filename entries).
+ fileRoot = pyre.inventory.str("fileRoot", default="pt1")
+ fileRoot.meta['tip'] = "Root pathname for simulation (all filenames derive from this)."
+ inputFileRoot = pyre.inventory.str("inputFileRoot", default="${fileRoot}")
+ inputFileRoot.meta['tip'] = "Root input pathname for simulation (all input filenames derive from this)."
+ outputFileRoot = pyre.inventory.str("outputFileRoot", default="${fileRoot}.${rank}")
+ outputFileRoot.meta['tip'] = "Root output pathname for simulation (all output filenames derive from this)."
+
# Output filenames (all are optional).
asciiOutputFile = OutputFile("asciiOutputFile",default="${outputFileRoot}.ascii")
asciiOutputFile.meta['tip'] = "Pathname for ascii output file (overrides default from outputFileRoot)."
@@ -723,6 +763,9 @@
fullOutputInputFile.meta['tip'] = "Pathname for file defining when to provide output (overrides default from inputFileRoot)."
# Optional input files.
+ keywordEqualsValueFile = InputFile("keywordEqualsValueFile",default="${inputFileRoot}.keyval")
+ keywordEqualsValueFile.meta['tip'] = "Pathname for keyword = value file (overrides default from inputFileRoot)."
+
winklerInputFile = InputFile("winklerInputFile",default="${inputFileRoot}.wink")
winklerInputFile.meta['tip'] = "Pathname for Winkler force input file (overrides default from inputFileRoot)."
@@ -794,7 +837,7 @@
autoRotateSlipperyNodes.meta['tip'] = "Whether to performa automatic rotation for slippery nodes (presently unused)."
#
- # category 2 parameters traditionally placed in *.keyval files
+ # category 2 parameters formerly placed in *.keyval files
#
from pyre.units.pressure import Pa
@@ -843,102 +886,6 @@
-from pyre.applications import ComponentHarnessAdapter
-#from pyre.applications.ComponentHarness import ComponentHarness as ComponentHarnessAdapter
-
-
-class ScannerComponentHarness(ComponentHarnessAdapter, Component):
-
-
- class Inventory(Component.Inventory):
-
- import pyre.inventory
- MacroString = pyre.inventory.str
- InputFile = pyre.inventory.str
-
- # Basename for all files (may be overridden by specific filename entries).
- fileRoot = MacroString("fileRoot", default="pt1")
- fileRoot.meta['tip'] = "Root pathname for simulation (all filenames derive from this)."
- inputFileRoot = MacroString("inputFileRoot", default="${fileRoot}")
- inputFileRoot.meta['tip'] = "Root input pathname for simulation (all input filenames derive from this)."
- outputFileRoot = MacroString("outputFileRoot", default="${fileRoot}.${rank}")
- outputFileRoot.meta['tip'] = "Root output pathname for simulation (all output filenames derive from this)."
-
- # Optional input files.
- keywordEqualsValueFile = InputFile("keywordEqualsValueFile",default="${inputFileRoot}.keyval")
- keywordEqualsValueFile.meta['tip'] = "Pathname for keyword = value file (overrides default from inputFileRoot)."
-
-
- def __init__(self):
- Component.__init__(self, "pl3dscan", "scanner")
- ComponentHarnessAdapter.__init__(self)
-
-
- def _configure(self):
- super(ScannerComponentHarness, self)._configure()
- self.fileRoot = self.inventory.fileRoot
- self.inputFileRoot = self.inventory.fileRoot
- self.outputFileRoot = self.inventory.outputFileRoot
- self.keywordEqualsValueFile = self.inventory.keywordEqualsValueFile
-
-
- def _init(self):
- super(ScannerComponentHarness, self)._init()
- self.scanner = self.harnessComponent()
-
-
- def createComponent(self):
- """create the harnessed component"""
-
- return Scanner()
-
-
- def prepareComponentConfiguration(self, component):
- """prepare the settings for the harnessed component"""
-
- # Expand macros.
-
- macros = self.getMacros()
- component.defineMacros(macros)
-
- # Read traits from the .keyval file.
-
- from pyre.util import expandMacros
- from CodecKeyVal import CodecKeyVal
- from os.path import splitext
-
- filename = expandMacros(self.keywordEqualsValueFile, macros)
- base, ext = splitext(filename)
- assert ext == ".keyval"
- codec = CodecKeyVal()
- shelf = codec.open(base, 'r')
-
- if shelf:
- registry = shelf['inventory']
- if registry:
- self.componentRegistry.update(registry)
-
- return super(ScannerComponentHarness, self).prepareComponentConfiguration(component)
-
-
- def getMacros(self):
- from pyre.util import expandMacros
-
- macros = {
- 'fileRoot': self.fileRoot,
- }
-
- # Expand occurrences of '${fileRoot}'. (Expansion of other
- # macros is deferred until later.)
- macros['inputFileRoot'] = expandMacros(self.inputFileRoot, macros)
- macros['outputFileRoot'] = expandMacros(self.outputFileRoot, macros)
-
- return macros
-
-
-Pylith3d_scan = ScannerComponentHarness
-
-
# version
# $Id: Pylith3d_scan.py,v 1.19 2005/06/24 20:22:03 willic3 Exp $
More information about the cig-commits
mailing list