[cig-commits] [commit] devel: updates create_mesh.py for homogeneous halfspace example; adds argument check in ascii2sac.csh (0ed834c)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Tue Dec 23 14:29:24 PST 2014
Repository : https://github.com/geodynamics/specfem3d
On branch : devel
Link : https://github.com/geodynamics/specfem3d/compare/c3b9c7ef07feb7d057fa71da18323d53b9c27233...9d3bd7538f7fce31e575efb67ada184321dcd807
>---------------------------------------------------------------
commit 0ed834ca6f6f9e03be8764879f3d42d219e1414d
Author: daniel peter <peterda at ethz.ch>
Date: Tue Dec 23 16:20:40 2014 +0100
updates create_mesh.py for homogeneous halfspace example; adds argument check in ascii2sac.csh
>---------------------------------------------------------------
0ed834ca6f6f9e03be8764879f3d42d219e1414d
.../create_mesh.py | 132 ++++++++++++++-------
utils/seis_process/ascii2sac.csh | 6 +
2 files changed, 98 insertions(+), 40 deletions(-)
diff --git a/EXAMPLES/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/create_mesh.py b/EXAMPLES/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/create_mesh.py
index eeac372..fc88a72 100755
--- a/EXAMPLES/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/create_mesh.py
+++ b/EXAMPLES/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/create_mesh.py
@@ -4,11 +4,31 @@
# i.e., a uniform mesh of 134 km x 134 km x 60 km with an element size 3.75 km.
# It is not applicable to other examples.
-import cubit
import os
import sys
+# to run this script from command line, python must have its PATH environment set such that it
+# includes the path to CUBIT/Trelis (cubit.py).
+#
+# you can also explicitly set it here e.g. like:
+#sys.path.append('/opt/Trelis-15.0/bin/')
+
+try:
+ import cubit
+except ImportError:
+ print "Error: Importing cubit as python module failed"
+ print "could not import cubit, please check your PYTHONPATH settings..."
+ print ""
+ print "current path: "
+ print sys.path
+ print ""
+ print "try to include path to directory which includes file cubit.py, e.g. /opt/Trelis-15.0/bin/"
+ print ""
+ sys.exit("Import cubit failed")
+
+cubit.init([""])
+
# Creating the volumes
cubit.cmd('reset')
@@ -41,53 +61,85 @@ print "path: "
print sys.path
print ""
-from geocubitlib import boundary_definition,cubit2specfem3d
+##
+from geocubitlib import boundary_definition,cubit2specfem3d,exportlib
# bounding faces
boundary_definition.entities=['face']
boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-# sets the id of the volume block
-# (volume block starts at id 4)
-id_block = 4
-print "cubit block:"
-print " volume block id = " + str(id_block)
-print ""
-
-# Define material properties
-print "#### DEFINE MATERIAL PROPERTIES #######################"
-
-# elastic material
-cubit.cmd('block '+str(id_block)+' name "elastic 1" ') # elastic material region
-cubit.cmd('block '+str(id_block)+' attribute count 7')
-cubit.cmd('block '+str(id_block)+' attribute index 1 1') # flag for material: 1 for 1. material
-cubit.cmd('block '+str(id_block)+' attribute index 2 2800') # vp
-cubit.cmd('block '+str(id_block)+' attribute index 3 1500') # vs
-cubit.cmd('block '+str(id_block)+' attribute index 4 2300') # rho
-cubit.cmd('block '+str(id_block)+' attribute index 5 9999.0') # Qkappa
-cubit.cmd('block '+str(id_block)+' attribute index 6 9000.0') # Qmu
-cubit.cmd('block '+str(id_block)+' attribute index 7 0') # anisotropy_flag
-
-# acoustic material
-#cubit.cmd('block '+str(id_block)+' name "acoustic 1" ') # acoustic material region
-#cubit.cmd('block '+str(id_block)+' attribute count 4')
-#cubit.cmd('block '+str(id_block)+' attribute index 1 1 ') # material 1
-#cubit.cmd('block '+str(id_block)+' attribute index 2 1480 ') # vp
-#cubit.cmd('block '+str(id_block)+' attribute index 3 0 ') # vs
-#cubit.cmd('block '+str(id_block)+' attribute index 4 1028 ') # rho (ocean salt water density:
-
# creates MESH/ directory for file output
os.system('mkdir -p MESH')
+
+# conversion to specfem-format
+# use_explicit will explicitly assign material properties as block attributes
+use_explicit=0
+
+if use_explicit == 1:
+ from geocubitlib import cubit2specfem3d
+ print ""
+ print "material properties: assigned as block attributes"
+ print ""
+ # sets the id of the volume block
+ # (volume block starts at id 4)
+ id_block = 4
+ print "cubit block:"
+ print " volume block id = " + str(id_block)
+ print ""
+ # Define material properties
+ print "#### DEFINE MATERIAL PROPERTIES #######################"
+ # elastic material
+ cubit.cmd('block '+str(id_block)+' name "elastic 1" ') # elastic material region
+ cubit.cmd('block '+str(id_block)+' attribute count 7')
+ cubit.cmd('block '+str(id_block)+' attribute index 1 1') # flag for material: 1 for 1. material
+ cubit.cmd('block '+str(id_block)+' attribute index 2 2800') # vp
+ cubit.cmd('block '+str(id_block)+' attribute index 3 1500') # vs
+ cubit.cmd('block '+str(id_block)+' attribute index 4 2300') # rho
+ cubit.cmd('block '+str(id_block)+' attribute index 5 9999.0') # Qkappa
+ cubit.cmd('block '+str(id_block)+' attribute index 6 9000.0') # Qmu
+ cubit.cmd('block '+str(id_block)+' attribute index 7 0') # anisotropy_flag
+ # acoustic material
+ #cubit.cmd('block '+str(id_block)+' name "acoustic 1" ') # acoustic material region
+ #cubit.cmd('block '+str(id_block)+' attribute count 4')
+ #cubit.cmd('block '+str(id_block)+' attribute index 1 1 ') # material 1
+ #cubit.cmd('block '+str(id_block)+' attribute index 2 1480 ') # vp
+ #cubit.cmd('block '+str(id_block)+' attribute index 3 0 ') # vs
+ #cubit.cmd('block '+str(id_block)+' attribute index 4 1028 ') # rho (ocean salt water density:
+ print ""
+ print "exporting to SPECFEM3D-format:"
+ print ""
+ # Export to SPECFEM3D format
+ cubit2specfem3d.export2SPECFEM3D('MESH/')
+else:
+ from geocubitlib import exportlib
+ print ""
+ print "exporting to SPECFEM3D-format:"
+ print ""
+ # Export to SPECFEM3D format
+ # note: exportlib-commands will overwrite material properties
+ exportlib.collect(outdir='MESH/')
+ # Define material properties
+ print "#### DEFINE MATERIAL PROPERTIES #######################"
+ # elastic material
+ material_cfg=[{'material region':'2','id_block':'1','vp':'2800','vs':'1500','rho':'2300','Qkappa':'9990.0','Qmu':'9000.0','anisotropy_flag':'0'}]
+ # modifies material file
+ nummaterial_velocity_file='MESH/nummaterial_velocity_file'
+ f=open(nummaterial_velocity_file,'w')
+ for block in material_cfg:
+ print block
+ s=block['material region']+' '
+ s=s+block['id_block']+' '
+ s=s+block['rho']+' '
+ s=s+block['vp']+' '
+ s=s+block['vs']+' '
+ s=s+block['Qkappa']+' '
+ s=s+block['Qmu']+' '
+ s=s+block['anisotropy_flag']
+ f.write(s+'\n')
+ f.close()
+
+# backup cubit
cubit.cmd('export mesh "MESH/top.e" dimension 3 overwrite')
cubit.cmd('save as "MESH/meshing.cub" overwrite')
-# Export to SPECFEM3D format
-
-#note: exportlib-commands will overwrite the above material properties
-# exportlib.collect(outdir='MESH/')
-# exportlib.e2SEM(outdir='MESH/')
-
-cubit2specfem3d.export2SPECFEM3D('MESH/')
-
-
# all files needed by xdecompose_mesh are now in directory MESH/
diff --git a/utils/seis_process/ascii2sac.csh b/utils/seis_process/ascii2sac.csh
index eb2872e..f67563e 100755
--- a/utils/seis_process/ascii2sac.csh
+++ b/utils/seis_process/ascii2sac.csh
@@ -1,5 +1,11 @@
#!/bin/csh
+# checks arguments
+if( $1 =~ "" ) then
+ echo "Usage: ascii2sac.csh filenames"
+ exit 1
+endif
+
foreach file ($*)
./asc2sac $file
end
More information about the CIG-COMMITS
mailing list