[cig-commits] r18709 - in short/3D/PyLith/branches/v1.6-stable/pylith: bc faults friction materials meshio

brad at geodynamics.org brad at geodynamics.org
Thu Jul 7 13:38:33 PDT 2011


Author: brad
Date: 2011-07-07 13:38:33 -0700 (Thu, 07 Jul 2011)
New Revision: 18709

Modified:
   short/3D/PyLith/branches/v1.6-stable/pylith/bc/BoundaryCondition.py
   short/3D/PyLith/branches/v1.6-stable/pylith/faults/Fault.py
   short/3D/PyLith/branches/v1.6-stable/pylith/friction/FrictionModel.py
   short/3D/PyLith/branches/v1.6-stable/pylith/materials/Material.py
   short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOAscii.py
   short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOCubit.py
   short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOLagrit.py
   short/3D/PyLith/branches/v1.6-stable/pylith/meshio/OutputSolnSubset.py
Log:
Improved validation of input and added more descriptive error messages.

Modified: short/3D/PyLith/branches/v1.6-stable/pylith/bc/BoundaryCondition.py
===================================================================
--- short/3D/PyLith/branches/v1.6-stable/pylith/bc/BoundaryCondition.py	2011-07-07 15:47:18 UTC (rev 18708)
+++ short/3D/PyLith/branches/v1.6-stable/pylith/bc/BoundaryCondition.py	2011-07-07 20:38:33 UTC (rev 18709)
@@ -31,6 +31,16 @@
 from pylith.utils.PetscComponent import PetscComponent
 from bc import BoundaryCondition as ModuleBoundaryCondition
 
+# Validator for label
+def validateLabel(value):
+  """
+  Validate label for group/nodeset/pset.
+  """
+  if 0 == len(value):
+    raise ValueError("Label for group/nodeset/pset in mesh not specified.")
+  return value
+
+
 # Validator for direction
 def validateDir(value):
   """
@@ -76,7 +86,7 @@
 
     import pyre.inventory
 
-    label = pyre.inventory.str("label", default="")
+    label = pyre.inventory.str("label", default="", validator=validateLabel)
     label.meta['tip'] = "Label identifier for boundary."
 
     upDir = pyre.inventory.list("up_dir", default=[0, 0, 1],
@@ -132,10 +142,16 @@
     """
     Setup members using inventory.
     """
-    PetscComponent._configure(self)
-    ModuleBoundaryCondition.label(self, self.inventory.label)
-    self.upDir = map(float, self.inventory.upDir)
-    self.perfLogger = self.inventory.perfLogger
+    try:
+      PetscComponent._configure(self)
+      ModuleBoundaryCondition.label(self, self.inventory.label)
+      self.upDir = map(float, self.inventory.upDir)
+      self.perfLogger = self.inventory.perfLogger
+    except ValueError as err:
+      aliases = ", ".join(self.aliases)
+      raise ValueError("Error while configuring boundary condition "
+                       "(%s):\n%s" % (aliases, err.message))
+                         
     return
 
 

Modified: short/3D/PyLith/branches/v1.6-stable/pylith/faults/Fault.py
===================================================================
--- short/3D/PyLith/branches/v1.6-stable/pylith/faults/Fault.py	2011-07-07 15:47:18 UTC (rev 18708)
+++ short/3D/PyLith/branches/v1.6-stable/pylith/faults/Fault.py	2011-07-07 20:38:33 UTC (rev 18709)
@@ -29,6 +29,16 @@
 from pylith.utils.PetscComponent import PetscComponent
 from faults import Fault as ModuleFault
 
+# Validator for label
+def validateLabel(value):
+  """
+  Validate label for group/nodeset/pset.
+  """
+  if 0 == len(value):
+    raise ValueError("Label for group/nodeset/pset in mesh not specified.")
+  return value
+
+
 # Validator for direction
 def validateDir(value):
   """
@@ -77,8 +87,8 @@
   matId.meta['tip'] = "Fault identifier (must be unique across all faults " \
       "and materials)."
   
-  faultLabel = pyre.inventory.str("label", default="")
-  faultLabel.meta['tip'] = "Name of fault."
+  faultLabel = pyre.inventory.str("label", default="", validator=validateLabel)
+  faultLabel.meta['tip'] = "Label identifier for fault."
   
   upDir = pyre.inventory.list("up_dir", default=[0, 0, 1],
                               validator=validateDir)
@@ -216,12 +226,17 @@
     """
     Setup members using inventory.
     """
-    PetscComponent._configure(self)
-    self.faultQuadrature = self.inventory.faultQuadrature
-    self.upDir = map(float, self.inventory.upDir)
-    ModuleFault.id(self, self.inventory.matId)
-    ModuleFault.label(self, self.inventory.faultLabel)
-    self.perfLogger = self.inventory.perfLogger
+    try:
+      PetscComponent._configure(self)
+      self.faultQuadrature = self.inventory.faultQuadrature
+      self.upDir = map(float, self.inventory.upDir)
+      ModuleFault.id(self, self.inventory.matId)
+      ModuleFault.label(self, self.inventory.faultLabel)
+      self.perfLogger = self.inventory.perfLogger
+    except ValueError as err:
+      aliases = ", ".join(self.aliases)
+      raise ValueError("Error while configuring fault "
+                       "(%s):\n%s" % (aliases, err.message))
     return
 
   

Modified: short/3D/PyLith/branches/v1.6-stable/pylith/friction/FrictionModel.py
===================================================================
--- short/3D/PyLith/branches/v1.6-stable/pylith/friction/FrictionModel.py	2011-07-07 15:47:18 UTC (rev 18708)
+++ short/3D/PyLith/branches/v1.6-stable/pylith/friction/FrictionModel.py	2011-07-07 20:38:33 UTC (rev 18709)
@@ -63,8 +63,8 @@
 
     import pyre.inventory
 
-    label = pyre.inventory.str("label", default="")
-    label.meta['tip'] = "Name of the friction model."
+    label = pyre.inventory.str("label", default="", validator=validateLabel)
+    label.meta['tip'] = "Descriptive label for friction model."
 
     from spatialdata.spatialdb.SimpleDB import SimpleDB
     dbProperties = pyre.inventory.facility("db_properties",
@@ -109,14 +109,19 @@
     """
     Setup members using inventory.
     """
-    PetscComponent._configure(self)
-    self.label(self.inventory.label)
-    self.dbProperties(self.inventory.dbProperties)
-    from pylith.utils.NullComponent import NullComponent
-    if not isinstance(self.inventory.dbInitialState, NullComponent):
-      self.dbInitialState(self.inventory.dbInitialState)
+    try:
+      PetscComponent._configure(self)
+      self.label(self.inventory.label)
+      self.dbProperties(self.inventory.dbProperties)
+      from pylith.utils.NullComponent import NullComponent
+      if not isinstance(self.inventory.dbInitialState, NullComponent):
+        self.dbInitialState(self.inventory.dbInitialState)
 
-    self.perfLogger = self.inventory.perfLogger
+      self.perfLogger = self.inventory.perfLogger
+    except ValueError as err:
+      aliases = ", ".join(self.aliases)
+      raise ValueError("Error while configuring friction model "
+                       "(%s):\n%s" % (aliases, err.message))
     return
 
   

Modified: short/3D/PyLith/branches/v1.6-stable/pylith/materials/Material.py
===================================================================
--- short/3D/PyLith/branches/v1.6-stable/pylith/materials/Material.py	2011-07-07 15:47:18 UTC (rev 18708)
+++ short/3D/PyLith/branches/v1.6-stable/pylith/materials/Material.py	2011-07-07 20:38:33 UTC (rev 18709)
@@ -32,6 +32,16 @@
 
 from pylith.utils.PetscComponent import PetscComponent
 
+# Validator for label
+def validateLabel(value):
+  """
+  Validate descriptive label.
+  """
+  if 0 == len(value):
+    raise ValueError("Descriptive label for material not specified.")
+  return value
+
+
 # Material class
 class Material(PetscComponent):
   """
@@ -56,7 +66,7 @@
     ##
     ## \b Properties
     ## @li \b id Material identifier (from mesh generator)
-    ## @li \b name Name of material
+    ## @li \b label Descriptive label for material.
     ##
     ## \b Facilities
     ## @li \b db_properties Database of material property parameters
@@ -68,8 +78,8 @@
     id = pyre.inventory.int("id", default=0)
     id.meta['tip'] = "Material identifier (from mesh generator)."
 
-    label = pyre.inventory.str("label", default="")
-    label.meta['tip'] = "Name of material."
+    label = pyre.inventory.str("label", default="", validator=validateLabel)
+    label.meta['tip'] = "Descriptive label for material."
 
     from spatialdata.spatialdb.SimpleDB import SimpleDB
     dbProperties = pyre.inventory.facility("db_properties",
@@ -169,16 +179,21 @@
     """
     Setup members using inventory.
     """
-    PetscComponent._configure(self)
-    self.id(self.inventory.id)
-    self.label(self.inventory.label)
-    self.dbProperties(self.inventory.dbProperties)
-    from pylith.utils.NullComponent import NullComponent
-    if not isinstance(self.inventory.dbInitialState, NullComponent):
-      self.dbInitialState(self.inventory.dbInitialState)
+    try:
+      PetscComponent._configure(self)
+      self.id(self.inventory.id)
+      self.label(self.inventory.label)
+      self.dbProperties(self.inventory.dbProperties)
+      from pylith.utils.NullComponent import NullComponent
+      if not isinstance(self.inventory.dbInitialState, NullComponent):
+        self.dbInitialState(self.inventory.dbInitialState)
 
-    self.quadrature = self.inventory.quadrature
-    self.perfLogger = self.inventory.perfLogger
+      self.quadrature = self.inventory.quadrature
+      self.perfLogger = self.inventory.perfLogger
+    except ValueError as err:
+      aliases = ", ".join(self.aliases)
+      raise ValueError("Error while configuring material "
+                       "(%s):\n%s" % (aliases, err.message))
     return
 
   

Modified: short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOAscii.py
===================================================================
--- short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOAscii.py	2011-07-07 15:47:18 UTC (rev 18708)
+++ short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOAscii.py	2011-07-07 20:38:33 UTC (rev 18709)
@@ -26,6 +26,16 @@
 from MeshIOObj import MeshIOObj
 from meshio import MeshIOAscii as ModuleMeshIOAscii
 
+# Validator for filename
+def validateFilename(value):
+  """
+  Validate filename.
+  """
+  if 0 == len(value):
+    raise ValueError("Filename for ASCII input mesh not specified.")
+  return value
+
+
 # MeshIOAscii class
 class MeshIOAscii(MeshIOObj, ModuleMeshIOAscii):
   """
@@ -53,7 +63,8 @@
 
     import pyre.inventory
 
-    filename = pyre.inventory.str("filename", default="")
+    filename = pyre.inventory.str("filename", default="", 
+                                  validator=validateFilename)
     filename.meta['tip'] = "Name of mesh file"
 
     from spatialdata.geocoords.CSCart import CSCart

Modified: short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOCubit.py
===================================================================
--- short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOCubit.py	2011-07-07 15:47:18 UTC (rev 18708)
+++ short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOCubit.py	2011-07-07 20:38:33 UTC (rev 18709)
@@ -26,6 +26,16 @@
 from MeshIOObj import MeshIOObj
 from meshio import MeshIOCubit as ModuleMeshIOCubit
 
+# Validator for filename
+def validateFilename(value):
+  """
+  Validate filename.
+  """
+  if 0 == len(value):
+    raise ValueError("Filename for CUBIT input mesh not specified.")
+  return value
+
+
 # MeshIOCubit class
 class MeshIOCubit(MeshIOObj, ModuleMeshIOCubit):
   """
@@ -53,7 +63,8 @@
 
     import pyre.inventory
 
-    filename = pyre.inventory.str("filename", default="mesh.exo")
+    filename = pyre.inventory.str("filename", default="mesh.exo",
+                                  validator=validateFilename)
     filename.meta['tip'] = "Name of Cubit Exodus file."
 
     useNames = pyre.inventory.bool("use_nodeset_names", default=True)

Modified: short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOLagrit.py
===================================================================
--- short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOLagrit.py	2011-07-07 15:47:18 UTC (rev 18708)
+++ short/3D/PyLith/branches/v1.6-stable/pylith/meshio/MeshIOLagrit.py	2011-07-07 20:38:33 UTC (rev 18709)
@@ -26,6 +26,26 @@
 from MeshIOObj import MeshIOObj
 from meshio import MeshIOLagrit as ModuleMeshIOLagrit
 
+# Validator for filename
+def validateFilenameGmv(value):
+  """
+  Validate filename.
+  """
+  if 0 == len(value):
+    raise ValueError("Filename for LaGriT input mesh not specified.")
+  return value
+
+
+# Validator for filename
+def validateFilenamePset(value):
+  """
+  Validate filename.
+  """
+  if 0 == len(value):
+    raise ValueError("Filename for LaGriT pset file not specified.")
+  return value
+
+
 # MeshIOLagrit class
 class MeshIOLagrit(MeshIOObj, ModuleMeshIOLagrit):
   """
@@ -56,10 +76,12 @@
 
     import pyre.inventory
 
-    filenameGmv = pyre.inventory.str("filename_gmv", default="mesh.gmv")
+    filenameGmv = pyre.inventory.str("filename_gmv", default="mesh.gmv",
+                                     validator=validateFilenameGmv)
     filenameGmv.meta['tip'] = "Name of mesh GMV file."
 
-    filenamePset = pyre.inventory.str("filename_pset", default="mesh.pset")
+    filenamePset = pyre.inventory.str("filename_pset", default="mesh.pset",
+                                      validator=validateFilenamePset)
     filenamePset.meta['tip'] = "Name of mesh PSET file."
 
     flipEndian = pyre.inventory.bool("flip_endian", default=False)

Modified: short/3D/PyLith/branches/v1.6-stable/pylith/meshio/OutputSolnSubset.py
===================================================================
--- short/3D/PyLith/branches/v1.6-stable/pylith/meshio/OutputSolnSubset.py	2011-07-07 15:47:18 UTC (rev 18708)
+++ short/3D/PyLith/branches/v1.6-stable/pylith/meshio/OutputSolnSubset.py	2011-07-07 20:38:33 UTC (rev 18709)
@@ -26,6 +26,16 @@
 from OutputManager import OutputManager
 from meshio import OutputSolnSubset as ModuleOutputSolnSubset
 
+# Validator for label
+def validateLabel(value):
+  """
+  Validate label for group/nodeset/pset.
+  """
+  if 0 == len(value):
+    raise ValueError("Label for group/nodeset/pset in mesh not specified.")
+  return value
+
+
 # OutputSolnSubset class
 class OutputSolnSubset(OutputManager, ModuleOutputSolnSubset):
   """
@@ -53,7 +63,7 @@
                                          default=["displacement"])
   vertexDataFields.meta['tip'] = "Names of vertex data fields to output."
   
-  label = pyre.inventory.str("label", default="")
+  label = pyre.inventory.str("label", default="", validator=validateLabel)
   label.meta['tip'] = "Label identifier for subdomain."
 
   from DataWriterVTKSubMesh import DataWriterVTKSubMesh
@@ -138,15 +148,21 @@
     """
     Set members based using inventory.
     """
-    OutputManager._configure(self)
-    ModuleOutputSolnSubset.label(self, self.label)
-    ModuleOutputSolnSubset.coordsys(self, self.inventory.coordsys)
-    ModuleOutputSolnSubset.writer(self, self.inventory.writer)
-    from pylith.utils.NullComponent import NullComponent
-    if not isinstance(self.inventory.vertexFilter, NullComponent):
-      ModuleOutputSolnSubset.vertexFilter(self, self.inventory.vertexFilter)
-    if not isinstance(self.inventory.cellFilter, NullComponent):
-      ModuleOutputSolnSubset.cellFilter(self, self.inventory.cellFilter)
+    try:
+      OutputManager._configure(self)
+      ModuleOutputSolnSubset.label(self, self.label)
+      ModuleOutputSolnSubset.coordsys(self, self.inventory.coordsys)
+      ModuleOutputSolnSubset.writer(self, self.inventory.writer)
+      from pylith.utils.NullComponent import NullComponent
+      if not isinstance(self.inventory.vertexFilter, NullComponent):
+        ModuleOutputSolnSubset.vertexFilter(self, self.inventory.vertexFilter)
+      if not isinstance(self.inventory.cellFilter, NullComponent):
+        ModuleOutputSolnSubset.cellFilter(self, self.inventory.cellFilter)
+    except ValueError as err:
+      aliases = ", ".join(self.aliases)
+      raise ValueError("Error while configuring output over boundary "
+                       "(%s):\n%s" % (aliases, err.message))
+
     return
 
 



More information about the CIG-COMMITS mailing list