[cig-commits] [commit] knepley/upgrade-petsc-interface: Converted shell script for running examples to Python script. (6fe83b0)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Wed Nov 27 11:10:16 PST 2013
Repository : ssh://geoshell/pylith
On branch : knepley/upgrade-petsc-interface
Link : https://github.com/geodynamics/pylith/compare/a0bd2c33efdb067cee19f14bac8d4aa4e31c8c8e...6fe83b00085ca5cd29c3a38d94c45f83f91be7f0
>---------------------------------------------------------------
commit 6fe83b00085ca5cd29c3a38d94c45f83f91be7f0
Author: Brad Aagaard <baagaard at usgs.gov>
Date: Wed Nov 27 11:13:08 2013 -0800
Converted shell script for running examples to Python script.
Added ability to run subsets of the examples.
>---------------------------------------------------------------
6fe83b00085ca5cd29c3a38d94c45f83f91be7f0
examples/run_examples.py | 203 +++++++++++++++++++++++++++++++++++++++++++++++
examples/run_examples.sh | 127 -----------------------------
2 files changed, 203 insertions(+), 127 deletions(-)
diff --git a/examples/run_examples.py b/examples/run_examples.py
new file mode 100755
index 0000000..dcb1a9e
--- /dev/null
+++ b/examples/run_examples.py
@@ -0,0 +1,203 @@
+#!/usr/bin/env python
+
+# Run all of the examples. Execute this script from the examples
+# directory.
+
+
+import os
+import glob
+import sys
+
+targets = ["all"]
+if len(sys.argv) > 1:
+ targets = sys.argv
+
+examplesDir = os.getcwd()
+
+# ======================================================================
+def clean(dir):
+ for pattern in ["*.vtk",
+ "output/*.vtk",
+ "output/*.h5",
+ "output/*.xmf",
+ ]:
+ trash = glob.glob(pattern)
+ for f in trash:
+ os.remove(f)
+ return
+
+
+def run_pylith(dir, examples, nprocs=1):
+ """
+ Run pylith on examples in a given directory.
+
+ @param dir Name of directory with input files.
+ @param examples List or tuple of .cfg files for examples.
+ @param nprocs Number of processes to use.
+ """
+ wkd = os.path.join(examplesDir, dir)
+ os.chdir(wkd)
+ clean(dir)
+ for simfiles in examples:
+ cmd = "pylith --nodes=%d %s" % (nprocs, simfiles)
+ print "WORKDIR: %s, RUNNING %s" % (wkd, cmd)
+ os.system(cmd)
+
+# ======================================================================
+if "twocells" in targets or "all" in targets:
+ dir = "twocells/twotri3"
+ examples = ("axialdisp.cfg",
+ "sheardisp.cfg",
+ "dislocation.cfg",
+ )
+ run_pylith(dir, examples)
+
+
+ dir = "twocells/twoquad4"
+ examples = ("axialdisp.cfg",
+ "sheardisp.cfg",
+ "axialtract.cfg",
+ "dislocation.cfg",
+ )
+ run_pylith(dir, examples)
+
+
+ dir = "twocells/twotet4"
+ examples = ("axialdisp.cfg",
+ "dislocation.cfg",
+ )
+ run_pylith(dir, examples)
+
+
+ dir = "twocells/twohex8"
+ examples = ("axialdisp.cfg",
+ "sheardisp.cfg",
+ "dislocation.cfg",
+ )
+ run_pylith(dir, examples)
+
+
+ dir = "twocells/twotet4-geoproj"
+ examples = ("dislocation.cfg",
+ )
+ run_pylith(dir, examples)
+
+
+# ----------------------------------------------------------------------
+if "3d/tet4" in targets or "all" in targets:
+ dir = "3d/tet4"
+ examples = ("step01.cfg",
+ "step02.cfg",
+ "step03.cfg",
+ "step04.cfg",
+ )
+ run_pylith(dir, examples, nprocs=1)
+ run_pylith(dir, examples, nprocs=2)
+ run_pylith(dir, examples, nprocs=3)
+ run_pylith(dir, examples, nprocs=4)
+ run_pylith(dir, examples, nprocs=5)
+
+
+# ----------------------------------------------------------------------
+if "3d/hex8" in targets or "all" in targets:
+ dir = "3d/hex8"
+ examples = ("step01.cfg",
+ "step02.cfg",
+ "step03.cfg",
+ "step04.cfg",
+ "step05.cfg",
+ "step06.cfg",
+ "step07.cfg",
+ "step08.cfg",
+ "step09.cfg",
+ "step10.cfg",
+ "step11.cfg",
+ "step12.cfg",
+ "step13.cfg",
+ "step14.cfg",
+ "step15.cfg",
+ "step16.cfg",
+ "step17.cfg",
+ "step18.cfg",
+ "step19.cfg",
+ "step20.cfg",
+ "step21.cfg --problem=pylith.problems.GreensFns",
+ )
+ run_pylith(dir, examples, nprocs=1)
+
+ examples = ("step01.cfg",
+ "step03.cfg",
+ "step06.cfg",
+ "step15.cfg",
+ "step19.cfg",
+ "step20.cfg",
+ "step21.cfg --problem=pylith.problems.GreensFns",
+ )
+ run_pylith(dir, examples, nprocs=2)
+ run_pylith(dir, examples, nprocs=4)
+
+
+# ----------------------------------------------------------------------
+if "2d/subduction" in targets or "all" in targets:
+ dir = "2d/subduction"
+ examples = ("step01.cfg",
+ "step02.cfg",
+ "step03.cfg",
+ "step04.cfg",
+ )
+ run_pylith(dir, examples, nprocs=1)
+ run_pylith(dir, examples, nprocs=2)
+ run_pylith(dir, examples, nprocs=4)
+ run_pylith(dir, examples, nprocs=5)
+
+
+# ----------------------------------------------------------------------
+if "bar_shearwave" in targets or "all" in targets:
+ dir = "bar_shearwave/tri3"
+ examples = ("pylithapp.cfg",
+ )
+ run_pylith(dir, examples, nprocs=1)
+ run_pylith(dir, examples, nprocs=3)
+
+
+ dir = "bar_shearwave/quad4"
+ examples = ("prescribedrup.cfg",
+ "spontaneousrup.cfg spontaneousrup_staticfriction.cfg",
+ "spontaneousrup.cfg spontaneousrup_slipweakening.cfg",
+ "spontaneousrup.cfg spontaneousrup_ratestateageing.cfg",
+ )
+ run_pylith(dir, examples, nprocs=1)
+ run_pylith(dir, examples, nprocs=3)
+
+
+ dir = "bar_shearwave/tet4"
+ examples = ("pylithapp.cfg",
+ )
+ run_pylith(dir, examples, nprocs=1)
+ run_pylith(dir, examples, nprocs=3)
+
+
+ dir = "bar_shearwave/hex8"
+ examples = ("pylithapp.cfg",
+ )
+ run_pylith(dir, examples, nprocs=1)
+ run_pylith(dir, examples, nprocs=3)
+
+
+# ----------------------------------------------------------------------
+if "2d/greensfns" in targets or "all" in targets:
+ dir = "2d/greensfns/strikeslip"
+ examples = ("eqsim.cfg",
+ "--problem=pylith.problems.GreensFns",
+ )
+ run_pylith(dir, examples, nprocs=1)
+ run_pylith(dir, examples, nprocs=2)
+ run_pylith(dir, examples, nprocs=4)
+
+ dir = "2d/greensfns/reverse"
+ examples = ("eqsim.cfg",
+ "--problem=pylith.problems.GreensFns",
+ )
+ run_pylith(dir, examples, nprocs=1)
+ run_pylith(dir, examples, nprocs=2)
+ run_pylith(dir, examples, nprocs=4)
diff --git a/examples/run_examples.sh b/examples/run_examples.sh
deleted file mode 100755
index 33d8292..0000000
--- a/examples/run_examples.sh
+++ /dev/null
@@ -1,127 +0,0 @@
-#!/bin/bash
-
-# Run all of the examples. Execute this script from the examples
-# directory.
-
-examples_dir=`pwd`
-
-# Run specified list of examples (single .cfg file)
-run_examples() {
- nprocs=1
- if [ $# == 1 ]; then
- nprocs=$1
- fi
- cd ${examples_dir}/$dir
- rm *.vtk
- if [ -d output ]; then rm output/*.vtk; fi
- for example in $examples; do
- echo "RUNNING $dir/$example"
- pylith --nodes=$nprocs $example
- done
-}
-
-# Run specified list of examples (additional common .cfg files)
-run_examples2() {
- commoncfg=$1
- cd ${examples_dir}/$dir
- for example in $examples; do
- echo "RUNNING $dir/$example"
- pylith $commoncfg $example
- done
-}
-
-# ----------------------------------------------------------------------
-# twotri3
-dir="twocells/twotri3"
-examples="axialdisp.cfg sheardisp.cfg dislocation.cfg"
-run_examples
-
-# twoquad4
-dir="twocells/twoquad4"
-examples="axialdisp.cfg sheardisp.cfg axialtract.cfg dislocation.cfg"
-run_examples
-
-# twotet4
-dir="twocells/twotet4"
-examples="axialdisp.cfg dislocation.cfg"
-run_examples
-
-# twohex8
-dir="twocells/twohex8"
-examples="axialdisp.cfg sheardisp.cfg dislocation.cfg"
-run_examples
-
-# twotet4-geoproj
-dir="twocells/twotet4-geoproj"
-examples="dislocation.cfg"
-run_examples
-
-# ----------------------------------------------------------------------
-# 3d/tet4
-dir="3d/tet4"
-examples="step01.cfg step02.cfg step03.cfg step04.cfg"
-run_examples
-run_examples 2
-run_examples 3
-run_examples 4
-run_examples 5
-
-# 3d/hex8
-dir="3d/hex8"
-examples="step01.cfg step02.cfg step03.cfg step04.cfg step05.cfg step06.cfg step07.cfg step08.cfg step09.cfg step10.cfg step11.cfg step12.cfg step13.cfg step14.cfg step15.cfg step16.cfg step17.cfg step18.cfg step19.cfg step20.cfg"
-run_examples
-
-examples="step21.cfg"
-run_examples2 "--problem=pylith.problems.GreensFns"
-
-examples="step01.cfg step03.cfg step06.cfg step15.cfg step19.cfg step20.cfg"
-run_examples 2
-
-# ----------------------------------------------------------------------
-# subduction
-dir="2d/subduction"
-examples="step01.cfg step02.cfg step03.cfg step04.cfg"
-run_examples
-run_examples 2
-run_examples 4
-run_examples 5
-
-# ----------------------------------------------------------------------
-# bar_shearwave/tri3
-dir="bar_shearwave/tri3"
-examples="pylithapp.cfg"
-run_examples
-
-# bar_shearwave/quad4
-dir="bar_shearwave/quad4"
-examples="prescribedrup.cfg"
-run_examples
-examples="spontaneousrup_staticfriction.cfg spontaneousrup_slipweakening.cfg spontaneousrup_ratestateageing.cfg"
-run_examples2 "spontaneousrup.cfg"
-
-# bar_shearwave/tet4
-dir="bar_shearwave/tet4"
-examples="pylithapp.cfg"
-run_examples
-
-# bar_shearwave/hex8
-dir="bar_shearwave/hex8"
-examples="pylithapp.cfg"
-run_examples
-
-
-# ----------------------------------------------------------------------
-# greensfns
-dir="2d/greensfns/strikeslip"
-examples="eqsim.cfg --problem=pylith.problems.GreensFns"
-run_examples
-
-dir="2d/greensfns/reverse"
-examples="eqsim.cfg --problem=pylith.problems.GreensFns"
-run_examples
-
-# ----------------------------------------------------------------------
-# Return to examples dir
-cd ${examples_dir}
-
-exit 0
More information about the CIG-COMMITS
mailing list