[cig-commits] r22418 - in seismo/3D/SPECFEM3D/trunk: CUBIT examples examples/CPML_examples examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides examples/Mount_StHelens examples/fault_examples examples/fault_examples/tpv15 examples/fault_examples/tpv5 examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides examples/homogeneous_halfspace_HEX8_elastic_no_absorbing examples/homogeneous_poroelastic examples/layered_halfspace examples/meshfem3D_examples examples/tomographic_model examples/waterlayered_halfspace

danielpeter at geodynamics.org danielpeter at geodynamics.org
Tue Jun 25 07:13:49 PDT 2013


Author: danielpeter
Date: 2013-06-25 07:13:49 -0700 (Tue, 25 Jun 2013)
New Revision: 22418

Added:
   seismo/3D/SPECFEM3D/trunk/CUBIT/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/CUBIT/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/CPML_realistic_mesh_with_topography/
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/README
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/README
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/splay_faults/
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv102/
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv103/
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/absorbing_boundary.py
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/save_fault_nodes_elements.py
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv16/
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/save_fault_nodes_elements.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/meshfem3D_examples/README
   seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/cubit2specfem3d.py
Removed:
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_realistic_mesh_with_topography/
   seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/layered_halfspace/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/layered_halfspace/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/splay_faults/
   seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/run_boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/run_cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/tpv102/
   seismo/3D/SPECFEM3D/trunk/examples/tpv103/
   seismo/3D/SPECFEM3D/trunk/examples/tpv15/
   seismo/3D/SPECFEM3D/trunk/examples/tpv16/
   seismo/3D/SPECFEM3D/trunk/examples/tpv5/
   seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/cubit2specfem3d.py
Modified:
   seismo/3D/SPECFEM3D/trunk/CUBIT/boundary_definition.py
   seismo/3D/SPECFEM3D/trunk/CUBIT/cubit2specfem3d.py
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/process.sh
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/process.sh
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/process.sh
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/process.sh
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/process.sh
   seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/process.sh
   seismo/3D/SPECFEM3D/trunk/examples/view_all_parameter_files_to_modify_them.csh
Log:
moves CPML examples to subdirectory examples/CPML_examples/; moves fault examples to examples/fault_examples/; updates scripts cubit2specfem3d.py and boundary_definition.py in CUBIT/ directory to be usable with Q_kappa; links examples scripts cubit2specfem3d.py and boundary_definition.py to the ones in CUBIT/ directory; adds some README files to example subdirectories

Modified: seismo/3D/SPECFEM3D/trunk/CUBIT/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/CUBIT/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/CUBIT/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -49,25 +49,19 @@
     absorbing_surf_ymax=[]
     absorbing_surf_bottom=[]
     top_surf=[]
-    
-    
+
+
     list_vol=cubit.parse_cubit_list("volume","all")
     init_n_vol=len(list_vol)
     zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...    
+    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
     xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
     xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
     ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
     ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
+    
+    
     list_surf=cubit.parse_cubit_list("surface","all")
-    print '##boundary box: '
-    print '##  x min: ' + str(xmin_box)
-    print '##  y min: ' + str(ymin_box)
-    print '##  z min: ' + str(zmin_box)
-    print '##  x max: ' + str(xmax_box)
-    print '##  y max: ' + str(ymax_box)
-    print '##  z max: ' + str(zmax_box)
-
 #    for k in list_surf:
 #        center_point = cubit.get_center_point("surface", k)
 #        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
@@ -98,47 +92,78 @@
     x_len = abs( xmax_box - xmin_box)
     y_len = abs( ymax_box - ymin_box)
     z_len = abs( zmax_box - zmin_box)
-    
+
     print '##boundary box: '
     print '##  x length: ' + str(x_len)
     print '##  y length: ' + str(y_len)
     print '##  z length: ' + str(z_len)
-    
-    # tolerance parameters 
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-        
+
+    # debug
+    print '##  xmin: ' + str(xmin_box)
+    print '##  xmax: ' + str(xmax_box)
+    print '##  ymin: ' + str(ymin_box)
+    print '##  ymax: ' + str(ymax_box)
+    print '##  zmin: ' + str(zmin_box)
+    print '##  zmax: ' + str(zmax_box)
+
+    ############################################
+    ##
+    ## tolerance parameters
+    ##
+    ## modified for surface topography
+    ############################################
+    absorbing_surface_distance_tolerance=0.1
+    topographic_surface_distance_tolerance=0.1
+    topographic_surface_normal_tolerance=0.3
+
     for k in list_surf:
         center_point = cubit.get_center_point("surface", k)
+        
+        #debug
+        print '##surface: ' + str(k)
+        print '## center point: ' + str(center_point)
+
         if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
+          #debug 
+          print '## xmin surface: ' + str(k)
+          absorbing_surf_xmin.append(k)
+          absorbing_surf.append(k)
         elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
+          #debug 
+          print '## xmax surface: ' + str(k)
+          absorbing_surf_xmax.append(k)
+          absorbing_surf.append(k)
         elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
+          #debug 
+          print '## ymin surface: ' + str(k)
+          absorbing_surf_ymin.append(k)
+          absorbing_surf.append(k)
         elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
+          #debug 
+          print '## ymax surface: ' + str(k)
+          absorbing_surf_ymax.append(k)
+          absorbing_surf.append(k)
         elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             print 'center_point[2]' + str(center_point[2])
-             print 'kz:' + str(k)
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-                       
-   
+          #debug 
+          print '## bottom surface: ' + str(k)
+          absorbing_surf_bottom.append(k)
+          absorbing_surf.append(k)
         else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
+          sbox=cubit.get_bounding_box('surface',k)
+          dz=abs((sbox[7] - zmax_box)/z_len)
+          normal=cubit.get_surface_normal(k)
+          zn=normal[2]
+          dn=abs(abs(zn)-1)
+          #debug 
+          #print '## surface element: ' + str(k)
+          #print '## surface element: zn ' + str(zn)
+          #print '## surface element: dn ' + str(dn)
+          #print '## surface element: dz ' + str(dz)
+          if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
+            #debug 
+            print '## topo surface: ' + str(k)          
+            top_surf.append(k)
+    
     return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
 
 def define_absorbing_surf_nopar():
@@ -177,7 +202,7 @@
     list_vol=cubit.parse_cubit_list("volume","all")
     init_n_vol=len(list_vol)
     zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...    
+    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
     xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
     xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
     ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
@@ -208,7 +233,7 @@
         if len(c) == 1:
             p=cubit.get_center_point("curve",list(c)[0])
             lp.append(p)
-    for k in list_surf: 
+    for k in list_surf:
         center_point = cubit.get_center_point("surface", k)
         for p in lp:
             if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
@@ -274,7 +299,7 @@
        #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
        command= 'block '+str(id_block)+' hex in vol '+str(v)
        command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command) 
+       cubit.cmd(command)
        command = "block "+str(id_block)+" name '"+n+"'"
        cubit.cmd(command)
 
@@ -289,10 +314,11 @@
                 print 'error importing cubit'
                 import sys
                 sys.exit()
+                
     id_nodeset=cubit.get_next_nodeset_id()
     id_block=cubit.get_next_block_id()
 
-    
+    # creates command string
     if obj == 'hex':
         txt='hex in node in surface'
         txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
@@ -314,7 +340,9 @@
         print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
         txt2=''
 
-    
+    # executes commands
+    print "# command: " + txt1
+    print "# command: " + txt2
     cubit.cmd(txt1)
     cubit.cmd(txt2)
 
@@ -323,48 +351,114 @@
     closed=keys.get('closed',False)
     if not closed:
         print "##open region"
+
+        # model with parallel sides (e.g. a block)
         if parallel:
-            print 'Parallel absorbing boundaries'
             surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
         else:
-            print 'Not parallel absorbing' 
+            # arbitrary geometry
             surf,topo=define_absorbing_surf_nopar()
+
         v_list,name_list=define_block()
         build_block(v_list,name_list)
         entities=args[0]
         print entities
         for entity in entities:
-            print "##entity: "+str(entity) 
-            build_block_side(topo,entity+'_topo',obj=entity)
-            build_block_side(surf,entity+'_abs',obj=entity)
-            if parallel: 
+            print "##entity: "+str(entity)
+
+            # block for free surface (w/ topography)
+            #print '## topo surface block: ' + str(topo)
+            if len(topo) == 0:
+              print ""
+              print "no topo surface found, please create block face_topo manually..."
+              print ""
+            else:
+              build_block_side(topo,entity+'_topo',obj=entity)
+
+            # model has parallel sides (e.g. a block model )
+            if parallel:
+            
+              # blocks for each side
+              if len(xmin) == 0:
+                print ""
+                print "no abs_xmin surface found, please create block manually..."
+                print ""
+              else:
                 build_block_side(xmin,entity+'_abs_xmin',obj=entity)
+                
+              # blocks for each side
+              if len(xmax) == 0:
+                print ""
+                print "no abs_xmax surface found, please create block manually..."
+                print ""
+              else:
                 build_block_side(xmax,entity+'_abs_xmax',obj=entity)
+
+              # blocks for each side
+              if len(ymin) == 0:
+                print ""
+                print "no abs_xmin surface found, please create block manually..."
+                print ""
+              else:
                 build_block_side(ymin,entity+'_abs_ymin',obj=entity)
+
+              # blocks for each side
+              if len(ymax) == 0:
+                print ""
+                print "no abs_ymax surface found, please create block manually..."
+                print ""
+              else:
                 build_block_side(ymax,entity+'_abs_ymax',obj=entity)
+
+              # blocks for each side
+              if len(bottom) == 0:
+                print ""
+                print "no abs_bottom surface found, please create block manually..."
+                print ""
+              else:
                 build_block_side(bottom,entity+'_abs_bottom',obj=entity)
+
+              # block for all sides together
+              # NOTE:
+              #    this might fail in some CUBIT versions, when elements are already
+              #    assigned to other blocks
+              try:
+                build_block_side(surf,entity+'_abs',obj=entity)
+              except:
+                print "no combined surface with all sides created"
+
+            else:
+                # arbitrary geometry
+                # puts all elements in single block
+                build_block_side(surf,entity+'_abs',obj=entity)
+
     else:
         print "##closed region"
-        
+
+        # model without absorbing boundaries, only one surface, e.g. a sphere
         surf=define_absorbing_surf_sphere()
+
         v_list,name_list=define_block()
         build_block(v_list,name_list)
+
         entities=args[0]
         for entity in entities:
+            # puts all elements in single block
             build_block_side(surf,entity+'_closedvol',obj=entity)
 
 
 
-#entities=['surface','face','edge','node','hex']
+
+
+## calling example:
+
+#entities=['face']
 #define_bc(entities,parallel=True)
 #define_bc(entities,parallel=False)
 #define_bc(entities,parallel=False,closed=True)
 
+## block material assigning example:
 
-# call
-#entities=['surface','face']
-#define_bc(entities,parallel=True)
-
 #block 1  attribute count 5
 #block 2  attribute count 0
 #block 2  name '/prova/interface1'
@@ -385,6 +479,16 @@
 #block 2  attribute index 2 1
 #block 2  attribute index 3 2
 
+# to create block manually:
+#
+# use a commands like:
+#
+# e.g. surface with topography
+# block 2 face in surface 6 
+# block 2 name "face_topo"
+#
+# e.g. all surface which are absorbing
+# block 3 face in surface 1 2 3 4 5
+# block 2 name "face_abs"
 
 
-

Modified: seismo/3D/SPECFEM3D/trunk/CUBIT/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/CUBIT/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/CUBIT/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -25,30 +25,30 @@
 #
 #for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
 #
-#USAGE 
+#USAGE
 #
 #############################################################################
 #PREREQUISITE
-#The mesh must be prepared 
+#The mesh must be prepared
 #   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or 
+#or
 #   manually following the convention:
 #     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity 
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be 
+#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
+#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
 #       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography), 
+#     - each mesh should have the block definition for the face on the free_surface (topography),
 #       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries, 
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of 
+#     - each mesh should have the block definition for the faces on the absorbing boundaries,
+#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
 #       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
 #
 #############################################################################
 #RUN
 #In a python script or in the cubit python tab call:
-#           
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME) 
 #
+#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
+#
 #the modele create a python class for the mesh: ex. profile=mesh()
 #and it export the files of the mesh needed by the partitioner of SESAME
 #
@@ -62,39 +62,39 @@
 #        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
 #        .....
 #
-#__________________________________________________________________________________________        
+#__________________________________________________________________________________________
 ##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
 #    format:
 #        number of nodes
 #        id_node x_coordinate y_coordinate z_coordinate
 #        .....
 #
-#__________________________________________________________________________________________        
+#__________________________________________________________________________________________
 ##material_name='materials_file' -> the file that contains the material flag of the elements
 #    format:
 #        id_element flag
 #        .....
 #
-#__________________________________________________________________________________________        
+#__________________________________________________________________________________________
 ##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
 #    format:
 #        flag rho vp vs 0 0 #full definition of the properties, flag > 0
 #        .....
 #        flag 'tomography' file_name #for interpolation with tomography
 #        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface 
+#        flag 'interface' file_name flag_for_the_gll_below_the_interface
 #        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________        
+#__________________________________________________________________________________________
 ##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the 
+##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
 #                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the 
+##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
 #                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the 
+##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
 #                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the 
+##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
 #                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the 
+##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
 #                                                                                     absorbing  boundary defined by z=bottom
 #    format:
 #        number of faces
@@ -108,7 +108,7 @@
 #        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
 #
 #__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file 
+# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
 # call the module mesh.nodescoord_write(full path name)
 #
 #############################################################################
@@ -129,7 +129,7 @@
         txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
         for surf,vp in zip(self.list_surf,self.list_vp):
             txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n' 
+                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
         return txt
     def freq2meshsize(self,vp):
         velocity=vp*.5
@@ -191,16 +191,16 @@
     """Tools for the mesh
     #########
     dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt 
+        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
         required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number 
+        Furthermore, given the number of gll point in the element (ngll) and the number
         of GLL point for wavelength, it provide the maximum resolved frequency.
     #########
     length=edge_length(edge)
         return the length of a edge
     #########
     edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length 
+        given the cubit id of a surface, it return the edge with minimun length
     #########
     """
     def __int__(self):
@@ -208,9 +208,9 @@
     def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
         """
         dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt 
+            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
             required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number 
+            Furthermore, given the number of gll point in the element (ngll) and the number
             of GLL point for wavelength, it provide the maximum resolved frequency.
         """
         ratiostore=1e10
@@ -251,7 +251,7 @@
     def edge_min_length(self,surface):
         """
         edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length 
+            given the cubit id of a surface, it return the edge with minimun length
         """
         from math import sqrt
         self.dmin=99999
@@ -279,8 +279,8 @@
         a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
         b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
         axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0 
-        for i in (0,1,2): 
+        dot=0.0
+        for i in (0,1,2):
             dot=dot+axb[i]*normal[i]
         if  dot > 0:
             return nodes
@@ -308,7 +308,7 @@
             cubit.cmd(command)
             command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
             cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()            
+        nend=cubit.get_next_sideset_id()
         sidelist=range(nstart,nend)
         for block in self.block_mat:
             name=cubit.get_exodus_entity_name('block',block)
@@ -393,13 +393,13 @@
                   print "  could not find appropriate material for this block..."
                   print ""
                   break
-                  
+
                 nattrib=cubit.get_block_attribute_count(block)
                 if nattrib != 0:
-                    # material flag: 
-                    #   positive => material properties, 
+                    # material flag:
+                    #   positive => material properties,
                     #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))                    
+                    flag=int(cubit.get_block_attribute_value(block,0))
                     if flag > 0 and nattrib >= 2:
                       # vp
                       vel=cubit.get_block_attribute_value(block,1)
@@ -410,22 +410,33 @@
                           #density
                           rho=cubit.get_block_attribute_value(block,3)
                           if nattrib >= 5:
-                            #Q_flag
+                            #Q_mu
                             q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be an integer flag between 1 and 13 
-                            # (see constants.h for IATTENUATION_SEDIMENT_40, etc. )
-                            if q < 0 or q > 13:
-                              print 'error, q flag invalid:', q
-                              print '  check with constants.h for IATTENUATION flags'
-                              break                                                                      
+                            # for q to be valid: it must be positive
+                            if q < 0 :
+                              print 'error, q value invalid:', q
+                              break
                             if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)                                      
+                              # only 6 parameters given (skipping Q_kappa ), old format style
+                              #Q_kappa is 10 times stronger than Q_mu
+                              q2 = q * 10
+                              # last entry is anisotropic flag
+                              ani=cubit.get_block_attribute_value(block,5)
+                            elif nattrib > 6:
+                               #Q_kappa
+                               q2=cubit.get_block_attribute_value(block,5)
+                               # for q to be valid: it must be positive
+                               if q2 < 0 :
+                                  print 'error, q value invalid:', q2
+                                  break
+                               if nattrib == 7:
+                                  #anisotropy_flag
+                                  ani=cubit.get_block_attribute_value(block,6)
                     elif flag < 0:
                         # velocity model
                         vel=name
                         attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1: 
+                        if attrib == 1:
                             kind='interface'
                             flag_down=cubit.get_block_attribute_value(block,2)
                             flag_up=cubit.get_block_attribute_value(block,3)
@@ -433,11 +444,11 @@
                             kind='tomography'
                 else:
                     flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
+                    vel,vs,rho,q,q2,ani=(name,0,0,0,0,0)
                 block_flag.append(int(flag))
                 block_mat.append(block)
                 if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
+                    par=tuple([imaterial,flag,vel,vs,rho,q,q2,ani])
                 elif flag < 0:
                     if kind=='interface':
                         par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
@@ -446,14 +457,14 @@
                 elif flag==0:
                     par=tuple([imaterial,flag,name])
                 material[block]=par
-            elif (type == self.face) or (type == self.face2) : 
-                # block has surface elements (QUAD4 or SHELL4)                
+            elif (type == self.face) or (type == self.face2) :
+                # block has surface elements (QUAD4 or SHELL4)
                 block_bc_flag.append(4)
                 block_bc.append(block)
                 bc[block]=4 #face has connectivity = 4
                 if name == self.topo: topography_face=block
             else:
-                # block elements differ from HEX8/QUAD4/SHELL4    
+                # block elements differ from HEX8/QUAD4/SHELL4
                 print '****************************************'
                 print 'block not properly defined:'
                 print '  name:',name
@@ -467,7 +478,7 @@
                 print '  SHELL4 for surface'
                 print '****************************************'
                 continue
-                
+
         nsets=cubit.get_nodeset_id_list()
         if len(nsets) == 0: self.receivers=None
         for nset in nsets:
@@ -495,8 +506,8 @@
             print material
             print bc
             print topography
-            print '****************************************'            
-    def mat_parameter(self,properties): 
+            print '****************************************'
+    def mat_parameter(self,properties):
         #note: material property acoustic/elastic/poroelastic are defined by the block's name
         print "#material properties:"
         print properties
@@ -512,12 +523,12 @@
                     m2km=1.
                 vp=vel/m2km
                 rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)     
-            elif type(vel) != str:   
+                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
+            elif type(vel) != str:
                 # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_flag #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %2i %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
+                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
+                txt='%1i %3i %20f %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
+                         properties[2],properties[3],properties[5],properties[6],properties[7])
             else:
                 txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
         elif flag < 0:
@@ -539,7 +550,7 @@
         meshfile=open(mesh_name,'w')
         print 'Writing '+mesh_name+'.....'
         num_elems=cubit.get_hex_count()
-        print num_elems
+        print '  number of elements:',str(num_elems)
         meshfile.write(str(num_elems)+'\n')
         num_write=0
         for block,flag in zip(self.block_mat,self.block_flag):
@@ -554,7 +565,7 @@
                 txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
                 meshfile.write(txt)
         meshfile.close()
-        print 'Ok',str(num_elems)
+        print 'Ok'
     def material_write(self,mat_name):
         mat=open(mat_name,'w')
         print 'Writing '+mat_name+'.....'
@@ -569,6 +580,7 @@
         print 'Writing '+nodecoord_name+'.....'
         node_list=cubit.parse_cubit_list('node','all')
         num_nodes=len(node_list)
+        print '  number of nodes:',str(num_nodes)
         nodecoord.write('%10i\n' % num_nodes)
         #
         for node in node_list:
@@ -578,14 +590,14 @@
         nodecoord.close()
         print 'Ok'
     def free_write(self,freename=None):
-        # free surface 
+        # free surface
         cubit.cmd('set info off')
         cubit.cmd('set echo off')
         cubit.cmd('set journal off')
         from sets import Set
         normal=(0,0,1)
         if not freename: freename=self.freename
-        # writes free surface file  
+        # writes free surface file
         print 'Writing '+freename+'.....'
         freehex=open(freename,'w')
         # searches block definition with name face_topo
@@ -594,7 +606,7 @@
                 name=cubit.get_exodus_entity_name('block',block)
                 print '  block name:',name,'id:',block
                 quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
+                print '  number of faces = ',len(quads_all)
                 dic_quads_all=dict(zip(quads_all,quads_all))
                 freehex.write('%10i\n' % len(quads_all))
                 list_hex=cubit.parse_cubit_list('hex','all')
@@ -608,7 +620,7 @@
                             txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
                                          nodes_ok[1],nodes_ok[2],nodes_ok[3])
                             freehex.write(txt)
-        freehex.close()   
+        freehex.close()
         print 'Ok'
         cubit.cmd('set info on')
         cubit.cmd('set echo on')
@@ -635,25 +647,27 @@
                     filename=absname+'_xmax'
                     normal=(1,0,0)
                 elif re.search('ymin',name):
-                    filename=absname+'_ymin'                    
+                    filename=absname+'_ymin'
                     normal=(0,-1,0)
                 elif re.search('ymax',name):
-                    filename=absname+'_ymax'                    
+                    filename=absname+'_ymax'
                     normal=(0,1,0)
                 elif re.search('bottom',name):
-                    filename=absname+'_bottom'                    
+                    filename=absname+'_bottom'
                     normal=(0,0,-1)
-                elif re.search('abs',name):                
-                    print "  ...face_abs - not used so far..."
-                    continue
+                elif re.search('abs',name):
+                    #print "  ...face_abs - not used so far..."
+                    filename=absname+'_all'
+                    absflag=True          
                 else:
                     continue
                 # opens file
-                print 'Writing '+filename+'.....'                  
+                print 'Writing '+filename+'.....'
                 abshex_local=open(filename,'w')
                 # gets face elements
                 quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))                
+                dic_quads_all=dict(zip(quads_all,quads_all))
+                print '  number of faces = ',len(quads_all)
                 abshex_local.write('%10i\n' % len(quads_all))
                 #command = "group 'list_hex' add hex in face "+str(quads_all)
                 #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
@@ -667,7 +681,7 @@
                     for f in faces:
                         if dic_quads_all.has_key(f):
                             nodes=cubit.get_connectivity('Face',f)
-                            if not absflag: 
+                            if not absflag:
                                 # checks with specified normal
                                 nodes_ok=self.normal_check(nodes,normal)
                                 txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
@@ -677,16 +691,16 @@
                                              nodes[1],nodes[2],nodes[3])
                             abshex_local.write(txt)
                 # closes file
-                abshex_local.close()   
+                abshex_local.close()
         print 'Ok'
         cubit.cmd('set info on')
         cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):    
+    def surface_write(self,pathdir=None):
         # optional surfaces, e.g. moho_surface
-        # should be created like e.g.: 
+        # should be created like e.g.:
         #  > block 10 face in surface 2
         #  > block 10 name 'moho_surface'
-        import re            
+        import re
         from sets import Set
         for block in self.block_bc :
             if block != self.topography:
@@ -706,10 +720,10 @@
                 print '  face = ',len(quads_all)
                 if len(quads_all) == 0 :
                   continue
-                # writes out surface infos to file                
-                print 'Writing '+filename+'.....'  
+                # writes out surface infos to file
+                print 'Writing '+filename+'.....'
                 surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))                
+                dic_quads_all=dict(zip(quads_all,quads_all))
                 # writes number of surface elements
                 surfhex_local.write('%10i\n' % len(quads_all))
                 # writes out element node ids
@@ -722,8 +736,8 @@
                             txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
                                              nodes[1],nodes[2],nodes[3])
                             surfhex_local.write(txt)
-                # closes file            
-                surfhex_local.close()   
+                # closes file
+                surfhex_local.close()
         print 'Ok'
     def rec_write(self,recname):
         print 'Writing '+self.recname+'.....'
@@ -740,9 +754,9 @@
         cubit.cmd('set journal off')
         if len(path) != 0:
             if path[-1] != '/': path=path+'/'
-        # mesh file    
+        # mesh file
         self.mesh_write(path+self.mesh_name)
-        # mesh material 
+        # mesh material
         self.material_write(path+self.material_name)
         # mesh coordinates
         self.nodescoord_write(path+self.nodecoord_name)
@@ -754,7 +768,7 @@
         self.abs_write(path+self.absname)
         # any other surfaces: ***surface***
         self.surface_write(path)
-        # receivers            
+        # receivers
         if self.receivers: self.rec_write(path+self.recname)
         cubit.cmd('set info on')
         cubit.cmd('set echo on')
@@ -764,12 +778,12 @@
     cubit.cmd('set echo on')
     sem_mesh=mesh()
     sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-    
 
+
 if __name__ == '__main__':
     path='MESH/'
-    export2SESAME(path)    
-    
+    export2SESAME(path)
+
 # call by:
 # import cubit2specfem3d
 # cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/CUBIT/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/CUBIT/run_boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/CUBIT/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1,18 @@
+#!python
+#!/usr/bin/env python
+
+import cubit
+import boundary_definition
+import cubit2specfem3d 
+
+import os
+import sys
+
+
+###### This is boundary_definition.py of GEOCUBIT
+#..... which extracts the bounding faces and defines them into blocks
+reload(boundary_definition)
+boundary_definition.entities=['face']
+boundary_definition.define_bc(boundary_definition.entities,parallel=True)
+
+


Property changes on: seismo/3D/SPECFEM3D/trunk/CUBIT/run_boundary_definition.py
___________________________________________________________________
Added: svn:executable
   + *

Added: seismo/3D/SPECFEM3D/trunk/CUBIT/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/CUBIT/run_cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/CUBIT/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1,26 @@
+#!python
+#!/usr/bin/env python
+
+import cubit
+import boundary_definition
+import cubit2specfem3d 
+
+import os
+import sys
+
+
+###### This is boundary_definition.py of GEOCUBIT
+#..... which extracts the bounding faces and defines them into blocks
+#reload(boundary_definition)
+#boundary_definition.entities=['face']
+#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
+
+
+#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
+os.system('mkdir -p MESH')
+
+reload(cubit2specfem3d)
+cubit2specfem3d.export2SESAME('MESH') 
+
+# all files needed by SCOTCH are now in directory MESH
+


Property changes on: seismo/3D/SPECFEM3D/trunk/CUBIT/run_cubit2specfem3d.py
___________________________________________________________________
Added: svn:executable
   + *

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/README
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/README	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/README	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1,10 @@
+----------------------------------------------------------------------
+README
+----------------------------------------------------------------------
+
+Examples contained in this folder help to familiarize yourself with simulations using
+Convolutional Perfectly Match Layer (CPML) absorbing boundaries.
+
+please consider submitting your own example to this package! 
+email us: cig-seismo AT geodynamics.org
+

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Modified: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/process.sh
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/process.sh	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/process.sh	2013-06-25 14:13:49 UTC (rev 22418)
@@ -34,13 +34,13 @@
 rm -rf OUTPUT_FILES/DATABASES_MPI/*
 
 # compiles executables in root directory
-cd ../../
+cd ../../../
 
 rm -fr DATA/*
 cd $currentdir
-cp -fr DATA/* ../../DATA/.
+cp -fr DATA/* ../../../DATA/.
 
-cd ../../
+cd ../../../
 
 make clean
 ./configure
@@ -50,9 +50,9 @@
 # links executables
 cd bin/
 rm -f *
-cp ../../../bin/xdecompose_mesh .
-cp ../../../bin/xgenerate_databases .
-cp ../../../bin/xspecfem3D .
+cp ../../../../bin/xdecompose_mesh .
+cp ../../../../bin/xgenerate_databases .
+cp ../../../../bin/xspecfem3D .
 cd ../
 
 # stores setup

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Modified: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/process.sh
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/process.sh	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/process.sh	2013-06-25 14:13:49 UTC (rev 22418)
@@ -34,13 +34,13 @@
 rm -rf OUTPUT_FILES/DATABASES_MPI/*
 
 # compiles executables in root directory
-cd ../../
+cd ../../../
 
 rm -fr DATA/*
 cd $currentdir
-cp -fr DATA/* ../../DATA/.
+cp -fr DATA/* ../../../DATA/.
 
-cd ../../
+cd ../../../
 
 make clean
 ./configure
@@ -50,9 +50,9 @@
 # links executables
 cd bin/
 rm -f *
-cp ../../../bin/xdecompose_mesh .
-cp ../../../bin/xgenerate_databases .
-cp ../../../bin/xspecfem3D .
+cp ../../../../bin/xdecompose_mesh .
+cp ../../../../bin/xgenerate_databases .
+cp ../../../../bin/xspecfem3D .
 cd ../
 
 # stores setup

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Modified: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/process.sh
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/process.sh	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/process.sh	2013-06-25 14:13:49 UTC (rev 22418)
@@ -34,13 +34,13 @@
 rm -rf OUTPUT_FILES/DATABASES_MPI/*
 
 # compiles executables in root directory
-cd ../../
+cd ../../../
 
 rm -fr DATA/*
 cd $currentdir
-cp -fr DATA/* ../../DATA/.
+cp -fr DATA/* ../../../DATA/.
 
-cd ../../
+cd ../../../
 
 make clean
 ./configure
@@ -50,9 +50,9 @@
 # links executables
 cd bin/
 rm -f *
-cp ../../../bin/xdecompose_mesh .
-cp ../../../bin/xgenerate_databases .
-cp ../../../bin/xspecfem3D .
+cp ../../../../bin/xdecompose_mesh .
+cp ../../../../bin/xgenerate_databases .
+cp ../../../../bin/xspecfem3D .
 cd ../
 
 # stores setup

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Modified: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/process.sh
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/process.sh	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/process.sh	2013-06-25 14:13:49 UTC (rev 22418)
@@ -34,13 +34,13 @@
 rm -rf OUTPUT_FILES/DATABASES_MPI/*
 
 # compiles executables in root directory
-cd ../../
+cd ../../../
 
 rm -fr DATA/*
 cd $currentdir
-cp -fr DATA/* ../../DATA/.
+cp -fr DATA/* ../../../DATA/.
 
-cd ../../
+cd ../../../
 
 make clean
 ./configure
@@ -50,9 +50,9 @@
 # links executables
 cd bin/
 rm -f *
-cp ../../../bin/xdecompose_mesh .
-cp ../../../bin/xgenerate_databases .
-cp ../../../bin/xspecfem3D .
+cp ../../../../bin/xdecompose_mesh .
+cp ../../../../bin/xgenerate_databases .
+cp ../../../../bin/xspecfem3D .
 cd ../
 
 # stores setup

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Modified: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/process.sh
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/process.sh	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/process.sh	2013-06-25 14:13:49 UTC (rev 22418)
@@ -34,13 +34,13 @@
 rm -rf OUTPUT_FILES/DATABASES_MPI/*
 
 # compiles executables in root directory
-cd ../../
+cd ../../../
 
 rm -fr DATA/*
 cd $currentdir
-cp -fr DATA/* ../../DATA/.
+cp -fr DATA/* ../../../DATA/.
 
-cd ../../
+cd ../../../
 
 make clean
 ./configure
@@ -50,9 +50,9 @@
 # links executables
 cd bin/
 rm -f *
-cp ../../../bin/xdecompose_mesh .
-cp ../../../bin/xgenerate_databases .
-cp ../../../bin/xspecfem3D .
+cp ../../../../bin/xdecompose_mesh .
+cp ../../../../bin/xgenerate_databases .
+cp ../../../../bin/xspecfem3D .
 cd ../
 
 # stores setup

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Modified: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/process.sh
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/process.sh	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/process.sh	2013-06-25 14:13:49 UTC (rev 22418)
@@ -34,13 +34,13 @@
 rm -rf OUTPUT_FILES/DATABASES_MPI/*
 
 # compiles executables in root directory
-cd ../../
+cd ../../../
 
 rm -fr DATA/*
 cd $currentdir
-cp -fr DATA/* ../../DATA/.
+cp -fr DATA/* ../../../DATA/.
 
-cd ../../
+cd ../../../
 
 make clean
 ./configure
@@ -50,9 +50,9 @@
 # links executables
 cd bin/
 rm -f *
-cp ../../../bin/xdecompose_mesh .
-cp ../../../bin/xgenerate_databases .
-cp ../../../bin/xspecfem3D .
+cp ../../../../bin/xdecompose_mesh .
+cp ../../../../bin/xgenerate_databases .
+cp ../../../../bin/xspecfem3D .
 cd ../
 
 # stores setup

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,494 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    
-    
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # debug
-    print '##  xmin: ' + str(xmin_box)
-    print '##  xmax: ' + str(xmax_box)
-    print '##  ymin: ' + str(ymin_box)
-    print '##  ymax: ' + str(ymax_box)
-    print '##  zmin: ' + str(zmin_box)
-    print '##  zmax: ' + str(zmax_box)
-
-    ############################################
-    ##
-    ## tolerance parameters
-    ##
-    ## modified for surface topography
-    ############################################
-    absorbing_surface_distance_tolerance=0.1
-    topographic_surface_distance_tolerance=0.1
-    topographic_surface_normal_tolerance=0.3
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        
-        #debug
-        print '##surface: ' + str(k)
-        print '## center point: ' + str(center_point)
-
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-          #debug 
-          print '## xmin surface: ' + str(k)
-          absorbing_surf_xmin.append(k)
-          absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-          #debug 
-          print '## xmax surface: ' + str(k)
-          absorbing_surf_xmax.append(k)
-          absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-          #debug 
-          print '## ymin surface: ' + str(k)
-          absorbing_surf_ymin.append(k)
-          absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-          #debug 
-          print '## ymax surface: ' + str(k)
-          absorbing_surf_ymax.append(k)
-          absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-          #debug 
-          print '## bottom surface: ' + str(k)
-          absorbing_surf_bottom.append(k)
-          absorbing_surf.append(k)
-        else:
-          sbox=cubit.get_bounding_box('surface',k)
-          dz=abs((sbox[7] - zmax_box)/z_len)
-          normal=cubit.get_surface_normal(k)
-          zn=normal[2]
-          dn=abs(abs(zn)-1)
-          #debug 
-          #print '## surface element: ' + str(k)
-          #print '## surface element: zn ' + str(zn)
-          #print '## surface element: dn ' + str(dn)
-          #print '## surface element: dz ' + str(dz)
-          if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-            #debug 
-            print '## topo surface: ' + str(k)          
-            top_surf.append(k)
-    
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-                
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-    # creates command string
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-    # executes commands
-    print "# command: " + txt1
-    print "# command: " + txt2
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            #print '## topo surface block: ' + str(topo)
-            if len(topo) == 0:
-              print ""
-              print "no topo surface found, please create block face_topo manually..."
-              print ""
-            else:
-              build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-            
-              # blocks for each side
-              if len(xmin) == 0:
-                print ""
-                print "no abs_xmin surface found, please create block manually..."
-                print ""
-              else:
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                
-              # blocks for each side
-              if len(xmax) == 0:
-                print ""
-                print "no abs_xmax surface found, please create block manually..."
-                print ""
-              else:
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-
-              # blocks for each side
-              if len(ymin) == 0:
-                print ""
-                print "no abs_xmin surface found, please create block manually..."
-                print ""
-              else:
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-
-              # blocks for each side
-              if len(ymax) == 0:
-                print ""
-                print "no abs_ymax surface found, please create block manually..."
-                print ""
-              else:
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-
-              # blocks for each side
-              if len(bottom) == 0:
-                print ""
-                print "no abs_bottom surface found, please create block manually..."
-                print ""
-              else:
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-              # block for all sides together
-              # NOTE:
-              #    this might fail in some CUBIT versions, when elements are already
-              #    assigned to other blocks
-              try:
-                build_block_side(surf,entity+'_abs',obj=entity)
-              except:
-                print "no combined surface with all sides created"
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-# to create block manually:
-#
-# use a commands like:
-#
-# e.g. surface with topography
-# block 2 face in surface 6 
-# block 2 name "face_topo"
-#
-# e.g. all surface which are absorbing
-# block 3 face in surface 1 2 3 4 5
-# block 2 name "face_abs"
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,776 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    #print "  ...face_abs - not used so far..."
-                    filename=absname+'_all'
-                    absflag=True
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/Mount_StHelens/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Added: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/README
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/fault_examples/README	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/fault_examples/README	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1,33 @@
+----------------------------------------------------------------------
+README
+----------------------------------------------------------------------
+
+Examples contained in this folder help to familiarize yourself with simulations using
+dynamic and kinematic sources defined along fault surfaces. We suggest to start with:
+
+SCEC 3D benchmark examples (http://scecdata.usc.edu/cvws/):
+
+- tpv5/: Nucleation followed by spontaneous rupture on a slightly stress-heterogeneous 
+         vertical strike-slip fault in a homogeneous halfspace
+
+- tpv15/: Nucleation followed by spontaneous rupture on a left-lateral, vertical, strike-slip fault 
+          with a rightward branch forming a 30 degree angle.
+
+- tpv16/: Nucleation followed by spontaneous rupture on a vertical strike-slip fault in a homogeneous halfspace. 
+          There are randomly-generated heterogeneous initial stress conditions.
+
+- tpv102/: Nucleation followed by spontaneous rupture on a vertical strike-slip fault in a homogeneous halfspace. 
+           Rate-state friction, using an ageing law.
+
+- tpv103/: Nucleation followed by spontaneous rupture on a vertical strike-slip fault in a homogeneous fullspace. 
+           Rate-state friction, using a slip law with strong rate-weakening.
+
+
+additional examples:
+
+- splay_faults/: two models based on Wendt et al. (2009) "Tsunamis and splay fault dynamics" paper
+
+
+please consider submitting your own example to this package! 
+email us: cig-seismo AT geodynamics.org
+

Added: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/absorbing_boundary.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/absorbing_boundary.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/absorbing_boundary.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/absorbing_boundary.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/absorbing_boundary.py
___________________________________________________________________
Added: svn:special
   + *

Added: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Added: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/save_fault_nodes_elements.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/save_fault_nodes_elements.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/save_fault_nodes_elements.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/save_fault_nodes_elements.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv15/save_fault_nodes_elements.py
___________________________________________________________________
Added: svn:special
   + *

Added: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Added: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Added: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/save_fault_nodes_elements.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/save_fault_nodes_elements.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/save_fault_nodes_elements.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../../CUBIT/save_fault_nodes_elements.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/fault_examples/tpv5/save_fault_nodes_elements.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,782 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-			    if nattrib >= 6:
-                               #Q_kappa
-                               q2=cubit.get_block_attribute_value(block,5)
-                               # for q to be valid: it must be positive
-                               if q2 < 0 :
-                                  print 'error, q value invalid:', q2
-                                  break
-                               if nattrib == 7:
-                                  #anisotropy_flag
-                                  ani=cubit.get_block_attribute_value(block,6)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,q2,ani=(name,0,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,q2,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6],properties[7])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_halfspace_HEX8_elastic_no_absorbing/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,378 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    
-    
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...    
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-    
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-    
-    # tolerance parameters 
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-        
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...    
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf: 
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command) 
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-    
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-    
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            surf,topo=define_absorbing_surf_nopar()
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-            
-            build_block_side(topo,entity+'_topo',obj=entity)
-            build_block_side(surf,entity+'_abs',obj=entity)
-            if parallel: 
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-    else:
-        print "##closed region"
-        
-        surf=define_absorbing_surf_sphere()
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        for entity in entities:
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-#entities=['surface','face','edge','node','hex']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-
-# call
-#entities=['surface','face']
-#define_bc(entities,parallel=True)
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/homogeneous_poroelastic/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/layered_halfspace/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/layered_halfspace/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/layered_halfspace/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/layered_halfspace/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/layered_halfspace/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/layered_halfspace/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/meshfem3D_examples/README
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/meshfem3D_examples/README	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/meshfem3D_examples/README	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1,20 @@
+----------------------------------------------------------------------
+README
+----------------------------------------------------------------------
+
+Examples contained in this folder help to familiarize yourself with the new 
+in-house mesher xmeshfem3D (no CUBIT needed). We suggest to start with:
+
+simple examples:
+
+- simple_model/: a model with topography, an internal interface and a mesh doubling layer
+
+- socal1D/: a 1D standard velocity model for Southern California
+
+more complex example are provided in:
+
+- many_interfaces/: a model with topography and several internal interfaces defined
+
+please consider submitting your own example to this package! 
+email us: cig-seismo AT geodynamics.org
+

Deleted: seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/run_boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/run_boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/run_boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,18 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-reload(boundary_definition)
-boundary_definition.entities=['face']
-boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-

Deleted: seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/run_cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/run_cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/tomographic_model/run_cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,26 +0,0 @@
-#!python
-#!/usr/bin/env python
-
-import cubit
-import boundary_definition
-import cubit2specfem3d 
-
-import os
-import sys
-
-
-###### This is boundary_definition.py of GEOCUBIT
-#..... which extracts the bounding faces and defines them into blocks
-#reload(boundary_definition)
-#boundary_definition.entities=['face']
-#boundary_definition.define_bc(boundary_definition.entities,parallel=True)
-
-
-#### Export to SESAME format using cubit2specfem3d.py of GEOCUBIT
-os.system('mkdir -p MESH')
-
-reload(cubit2specfem3d)
-cubit2specfem3d.export2SESAME('MESH') 
-
-# all files needed by SCOTCH are now in directory MESH
-

Modified: seismo/3D/SPECFEM3D/trunk/examples/view_all_parameter_files_to_modify_them.csh
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/view_all_parameter_files_to_modify_them.csh	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/view_all_parameter_files_to_modify_them.csh	2013-06-25 14:13:49 UTC (rev 22418)
@@ -3,5 +3,5 @@
 # this list of files is obtained using " find . -iname \*Par_file\* -exec ls -1 {} \; | grep -v Mesh_Par_file | grep -v Par_file_faults "
 # and adding ../DATA/Par_file manually to the list
 
-vi ../DATA/Par_file ./noise_tomography/DATA/Par_file_step3 ./noise_tomography/DATA/Par_file_step2 ./noise_tomography/DATA/Par_file_step1 ./tpv15/DATA/Par_file ./tpv16/DATA/Par_file ./homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/DATA/Par_file ./homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/DATA/Par_file ./tpv102/DATA/Par_file ./tpv5/DATA/Par_file ./homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/DATA/Par_file ./homogeneous_halfspace_HEX27_elastic_no_absorbing/DATA/Par_file ./splay_faults/DATA/Par_file ./homogeneous_poroelastic/DATA/Par_file ./tpv103/DATA/Par_file ./homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/DATA/Par_file ./homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/DATA/Par_file ./BENCHMARK_CLAERBOUT_ADJOINT/ACOUSTIC/DATA/Par_file ./BENCHMARK_CLAERBOUT_ADJOINT/ELASTIC/DATA/Par_file ./layered_halfspace/DATA/Par_file ./meshfem3D_examples/simple_model/DATA/Par_file ./meshfem3D_examples/socal1D/example_utm/Par_file_utm ./meshfem3D_examples/socal1D/DATA/Par_file ./meshfem3D_examples/many_interfaces/DATA/Par_file ./tomographic_model/DATA/Par_file ./homogeneous_halfspace_HEX8_elastic_no_absorbing/DATA/Par_file ./homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/DATA/Par_file ./waterlayered_halfspace/DATA/Par_file ./Mount_StHelens/DATA/Par_file ./homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/DATA/Par_file
+vi ../DATA/Par_file ./noise_tomography/DATA/Par_file_step3 ./noise_tomography/DATA/Par_file_step2 ./noise_tomography/DATA/Par_file_step1 ./fault_examples/tpv15/DATA/Par_file ./fault_examples/tpv16/DATA/Par_file ./CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_6sides/DATA/Par_file ./CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_5sides/DATA/Par_file ./fault_examples/tpv102/DATA/Par_file ./fault_examples/tpv5/DATA/Par_file ./CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_6sides/DATA/Par_file ./homogeneous_halfspace_HEX27_elastic_no_absorbing/DATA/Par_file ./fault_examples/splay_faults/DATA/Par_file ./homogeneous_poroelastic/DATA/Par_file ./fault_examples/tpv103/DATA/Par_file ./CPML_examples/homogeneous_halfspace_HEX8_elastic_absorbing_CPML_5sides/DATA/Par_file ./CPML_examples/homogeneous_halfspace_HEX8_acoustic_elastic_absorbing_CPML_5sides/DATA/Par_file ./BENCHMARK_CLAERBOUT_ADJOINT/ACOUSTIC/DATA/Par_file ./BENCHMARK_CLAERBOUT_ADJOINT/ELASTIC/DATA/Par_file ./layered_halfspace/DATA/Par_file ./meshfem3D_examples/simple_model/DATA/Par_file ./meshfem3D_examples/socal1D/example_utm/Par_file_utm ./meshfem3D_examples/socal1D/DATA/Par_file ./meshfem3D_examples/many_interfaces/DATA/Par_file ./tomographic_model/DATA/Par_file ./homogeneous_halfspace_HEX8_elastic_no_absorbing/DATA/Par_file ./CPML_examples/homogeneous_halfspace_HEX8_acoustic_absorbing_CPML_6sides/DATA/Par_file ./waterlayered_halfspace/DATA/Par_file ./Mount_StHelens/DATA/Par_file ./homogeneous_halfspace_HEX8_elastic_absorbing_Stacey_5sides/DATA/Par_file
 

Deleted: seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/boundary_definition.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,401 +0,0 @@
-#############################################################################
-# boundary_definition.py                                                    #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-
-def define_absorbing_surf():
-    """
-    define the absorbing surfaces for a layered topological box where boundary are surfaces parallel to the axis.
-    it returns absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    absorbing_surf_xmin is the list of the absorbing boundary surfaces that correnspond to x=xmin
-    ...
-    absorbing_surf_bottom is the list of the absorbing boundary surfaces that correspond to z=zmin
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-
-
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-#    for k in list_surf:
-#        center_point = cubit.get_center_point("surface", k)
-#        if abs((center_point[0] - xmin_box)/xmin_box) <= 0.005:
-#             absorbing_surf_xmin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[0] - xmax_box)/xmax_box) <= 0.005:
-#             absorbing_surf_xmax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymin_box)/ymin_box) <= 0.005:
-#             absorbing_surf_ymin.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[1] - ymax_box)/ymax_box) <= 0.005:
-#             absorbing_surf_ymax.append(k)
-#             absorbing_surf.append(k)
-#        elif abs((center_point[2] - zmin_box)/zmin_box) <= 0.005:
-#             absorbing_surf_bottom.append(k)
-#             absorbing_surf.append(k)
-#        else:
-#            sbox=cubit.get_bounding_box('surface',k)
-#            dz=abs((sbox[7] - zmax_box)/zmax_box)
-#            normal=cubit.get_surface_normal(k)
-#            zn=normal[2]
-#            dn=abs(zn-1)
-#            if dz <= 0.001 and dn < 0.2:
-#                top_surf.append(k)
-
-    #box lengths
-    x_len = abs( xmax_box - xmin_box)
-    y_len = abs( ymax_box - ymin_box)
-    z_len = abs( zmax_box - zmin_box)
-
-    print '##boundary box: '
-    print '##  x length: ' + str(x_len)
-    print '##  y length: ' + str(y_len)
-    print '##  z length: ' + str(z_len)
-
-    # tolerance parameters
-    absorbing_surface_distance_tolerance=0.005
-    topographic_surface_distance_tolerance=0.001
-    topographic_surface_normal_tolerance=0.2
-
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        if abs((center_point[0] - xmin_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[0] - xmax_box)/x_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_xmax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymin_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymin.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[1] - ymax_box)/y_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_ymax.append(k)
-             absorbing_surf.append(k)
-        elif abs((center_point[2] - zmin_box)/z_len) <= absorbing_surface_distance_tolerance:
-             absorbing_surf_bottom.append(k)
-             absorbing_surf.append(k)
-        else:
-            sbox=cubit.get_bounding_box('surface',k)
-            dz=abs((sbox[7] - zmax_box)/z_len)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            dn=abs(zn-1)
-            if dz <= topographic_surface_distance_tolerance and dn < topographic_surface_normal_tolerance:
-                top_surf.append(k)
-
-    return absorbing_surf,absorbing_surf_xmin,absorbing_surf_xmax,absorbing_surf_ymin,absorbing_surf_ymax,absorbing_surf_bottom,top_surf
-
-def define_absorbing_surf_nopar():
-    """
-    define the absorbing surfaces for a layered topological box where boundary surfaces are not parallel to the axis.
-    it returns absorbing_surf,topo_surf
-    where
-    absorbing_surf is the list of all the absorbing boundary surf
-    """
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    from sets import Set
-    def product(*args, **kwds):
-        # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
-        # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
-        pools = map(tuple, args) * kwds.get('repeat', 1)
-        result = [[]]
-        for pool in pools:
-            result = [x+[y] for x in result for y in pool]
-        return result
-    absorbing_surf=[]
-    absorbing_surf_xmin=[]
-    absorbing_surf_xmax=[]
-    absorbing_surf_ymin=[]
-    absorbing_surf_ymax=[]
-    absorbing_surf_bottom=[]
-    top_surf=[]
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    zmax_box=cubit.get_total_bounding_box("volume",list_vol)[7]
-    zmin_box=cubit.get_total_bounding_box("volume",list_vol)[6] #it is the z_min of the box ... box= xmin,xmax,d,ymin,ymax,d,zmin...
-    xmin_box=cubit.get_total_bounding_box("volume",list_vol)[0]
-    xmax_box=cubit.get_total_bounding_box("volume",list_vol)[1]
-    ymin_box=cubit.get_total_bounding_box("volume",list_vol)[3]
-    ymax_box=cubit.get_total_bounding_box("volume",list_vol)[4]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    lv=[]
-    for k in list_surf:
-            sbox=cubit.get_bounding_box('surface',k)
-            dzmax=abs((sbox[7] - zmax_box)/zmax_box)
-            dzmin=abs((sbox[6] - zmin_box)/zmin_box)
-            normal=cubit.get_surface_normal(k)
-            zn=normal[2]
-            if dzmax <= 0.001 and zn > 0.7:
-                top_surf.append(k)
-                list_vertex=cubit.get_relatives('surface',k,'vertex')
-                for v in list_vertex:
-                    valence=cubit.get_valence(v)
-                    if valence <= 4: #valence 3 is a corner, 4 is a vertex between 2 volumes, > 4 is a vertex not in the boundaries
-                        lv.append(v)
-            elif dzmin <= 0.001 and zn < -0.7:
-                absorbing_surf.append(k)
-    lp=[]
-    combs=product(lv,lv)
-    for comb in combs:
-        v1=comb[0]
-        v2=comb[1]
-        c=Set(cubit.get_relatives("vertex",v1,"curve")) & Set(cubit.get_relatives("vertex",v2,"curve"))
-        if len(c) == 1:
-            p=cubit.get_center_point("curve",list(c)[0])
-            lp.append(p)
-    for k in list_surf:
-        center_point = cubit.get_center_point("surface", k)
-        for p in lp:
-            if abs((center_point[0] - p[0])/p[0]) <= 0.005 and abs((center_point[1] - p[1])/p[1]) <= 0.005:
-             absorbing_surf.append(k)
-             break
-    return absorbing_surf,top_surf
-
-def define_absorbing_surf_sphere():
-    try:
-        cubit.cmd('comment')
-    except:
-        try:
-            import cubit
-            cubit.init([""])
-        except:
-            print 'error importing cubit'
-            import sys
-            sys.exit()
-    surf=[]
-    list_surf=cubit.parse_cubit_list("surface","all")
-    for s in list_surf:
-       v=cubit.get_relatives('surface',s,'volume')
-       if len(v) == 1:
-           surf.append(s)
-    return surf
-
-def define_block():
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    list_vol=cubit.parse_cubit_list("volume","all")
-    init_n_vol=len(list_vol)
-    list_name=map(lambda x: 'vol'+x,map(str,list_vol))
-    return list_vol,list_name
-
-def build_block(vol_list,name):
-    from sets import Set
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    block_list=cubit.get_block_id_list()
-    if len(block_list) > 0:
-        id_block=max(block_list)
-    else:
-        id_block=0
-    for v,n in zip(vol_list,name):
-       id_block+=1
-       v_other=Set(vol_list)-Set([v])
-       #command= 'block '+str(id_block)+' hex in node in vol '+str(v)+' except hex in vol '+str(list(v_other))
-       command= 'block '+str(id_block)+' hex in vol '+str(v)
-       command = command.replace("["," ").replace("]"," ")
-       cubit.cmd(command)
-       command = "block "+str(id_block)+" name '"+n+"'"
-       cubit.cmd(command)
-
-def build_block_side(surf_list,name,obj='surface'):
-    try:
-            cubit.cmd('comment')
-    except:
-            try:
-                import cubit
-                cubit.init([""])
-            except:
-                print 'error importing cubit'
-                import sys
-                sys.exit()
-    id_nodeset=cubit.get_next_nodeset_id()
-    id_block=cubit.get_next_block_id()
-
-
-    if obj == 'hex':
-        txt='hex in node in surface'
-        txt1='block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt2="block "+str(id_block)+" name '"+name+"'"
-        txt1=txt1.replace("["," ").replace("]"," ")
-    elif obj == 'node':
-         txt=obj+' in surface'
-         txt1= 'nodeset '+str(id_nodeset)+ ' '+ txt +' '+str(list(surf_list))
-         txt1 = txt1.replace("["," ").replace("]"," ")
-         txt2 = "nodeset "+str(id_nodeset)+" name '"+name+"'"
-    elif obj == 'face' or obj == 'edge':
-        txt=obj+' in surface'
-        txt1= 'block '+str(id_block)+ ' '+ txt +' '+str(list(surf_list))
-        txt1 = txt1.replace("["," ").replace("]"," ")
-        txt2 = "block "+str(id_block)+" name '"+name+"'"
-    else:
-        txt1=''
-        # do not execute: block id might be wrong
-        print "##block "+str(id_block)+" name '"+name+"_notsupported (only hex,face,edge,node)'"
-        txt2=''
-
-
-    cubit.cmd(txt1)
-    cubit.cmd(txt2)
-
-def define_bc(*args,**keys):
-    parallel=keys.get('parallel',True)
-    closed=keys.get('closed',False)
-    if not closed:
-        print "##open region"
-
-        # model with parallel sides (e.g. a block)
-        if parallel:
-            surf,xmin,xmax,ymin,ymax,bottom,topo=define_absorbing_surf()
-        else:
-            # arbitrary geometry
-            surf,topo=define_absorbing_surf_nopar()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-        entities=args[0]
-        print entities
-        for entity in entities:
-            print "##entity: "+str(entity)
-
-            # block for free surface (w/ topography)
-            build_block_side(topo,entity+'_topo',obj=entity)
-
-            # model has parallel sides (e.g. a block model )
-            if parallel:
-                # blocks for each side
-                build_block_side(xmin,entity+'_abs_xmin',obj=entity)
-                build_block_side(xmax,entity+'_abs_xmax',obj=entity)
-                build_block_side(ymin,entity+'_abs_ymin',obj=entity)
-                build_block_side(ymax,entity+'_abs_ymax',obj=entity)
-                build_block_side(bottom,entity+'_abs_bottom',obj=entity)
-
-                # block for all sides together
-                # NOTE:
-                #    this might fail in some CUBIT versions, when elements are already
-                #    assigned to other blocks
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-            else:
-                # arbitrary geometry
-                # puts all elements in single block
-                build_block_side(surf,entity+'_abs',obj=entity)
-
-    else:
-        print "##closed region"
-
-        # model without absorbing boundaries, only one surface, e.g. a sphere
-        surf=define_absorbing_surf_sphere()
-
-        v_list,name_list=define_block()
-        build_block(v_list,name_list)
-
-        entities=args[0]
-        for entity in entities:
-            # puts all elements in single block
-            build_block_side(surf,entity+'_closedvol',obj=entity)
-
-
-
-
-
-## calling example:
-
-#entities=['face']
-#define_bc(entities,parallel=True)
-#define_bc(entities,parallel=False)
-#define_bc(entities,parallel=False,closed=True)
-
-## block material assigning example:
-
-#block 1  attribute count 5
-#block 2  attribute count 0
-#block 2  name '/prova/interface1'
-#block 2  attribute count 3
-#block 3  attribute count 5
-#block 1  attribute index 2 1500
-#block 1  attribute count 2
-#block 3  attribute index 1 2
-#block 3  attribute index 2 5800
-#block 3  attribute index 3 3900
-#block 3  attribute index 4 1500
-#block 3  attribute index 5 3.5
-#block 1  name 'top'
-#block 3  name 'bottom'
-#block 2  attribute index 1 -1
-#block 2  attribute index 2 2
-#block 2  attribute count 4
-#block 2  attribute index 2 1
-#block 2  attribute index 3 2
-
-
-
-

Added: seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/boundary_definition.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/boundary_definition.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/boundary_definition.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/boundary_definition.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/boundary_definition.py
___________________________________________________________________
Added: svn:special
   + *

Deleted: seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/cubit2specfem3d.py	2013-06-25 12:15:59 UTC (rev 22417)
+++ seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -1,775 +0,0 @@
-#!python
-#############################################################################
-# cubit2specfem3d.py                                                           #
-# this file is part of GEOCUBIT                                             #
-#                                                                           #
-# Created by Emanuele Casarotti                                             #
-# Copyright (c) 2008 Istituto Nazionale di Geofisica e Vulcanologia         #
-#                                                                           #
-#############################################################################
-#                                                                           #
-# GEOCUBIT is free software: you can redistribute it and/or modify          #
-# it under the terms of the GNU General Public License as published by      #
-# the Free Software Foundation, either version 3 of the License, or         #
-# (at your option) any later version.                                       #
-#                                                                           #
-# GEOCUBIT is distributed in the hope that it will be useful,               #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of            #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
-# GNU General Public License for more details.                              #
-#                                                                           #
-# You should have received a copy of the GNU General Public License         #
-# along with GEOCUBIT.  If not, see <http://www.gnu.org/licenses/>.         #
-#                                                                           #
-#############################################################################
-#
-#for a complete definition of the format of the mesh in SPECFEM3D_SESAME check the manual (http:/):
-#
-#USAGE
-#
-#############################################################################
-#PREREQUISITE
-#The mesh must be prepared
-#   automatically using the module boundary_definition (see boundary_definition.py for more information)
-#or
-#   manually following the convention:
-#     - each material should have a block defined by:
-#         material domain_flag (acoustic/elastic/poroelastic)name,flag of the material (integer),p velocity
-#       (or the full description: name, flag, vp, vs, rho, Q ... if not present these last 3 parameters will be
-#       interpolated by module mat_parameter)
-#     - each mesh should have the block definition for the face on the free_surface (topography),
-#       the name of this block must be 'face_topo' or you can change the default name in mesh.topo defined in profile.
-#     - each mesh should have the block definition for the faces on the absorbing boundaries,
-#       one block for each surface with x=Xmin,x=Xmax,y=Ymin,y=Ymax and z=bottom. The names of
-#       the blocks should contain the strings "xmin,xmax,ymin,ymax,bottom"
-#
-#############################################################################
-#RUN
-#In a python script or in the cubit python tab call:
-#
-#           export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME)
-#
-#the modele create a python class for the mesh: ex. profile=mesh()
-#and it export the files of the mesh needed by the partitioner of SESAME
-#
-#############################################################################
-#OUTPUT
-#The default output are 11 ASCII files:
-#__________________________________________________________________________________________
-#mesh_name='mesh_file' -> the file that contains the connectity of the all mesh
-#    format:
-#        number of elements
-#        id_elements id_node1 id_node2 id_node3 id_node4 id_node5 id_node6 id_node7 id_node8
-#        .....
-#
-#__________________________________________________________________________________________
-##nodecoord_name='nodes_coords_file' -> the file that contains the coordinates of the nodes of the all mesh
-#    format:
-#        number of nodes
-#        id_node x_coordinate y_coordinate z_coordinate
-#        .....
-#
-#__________________________________________________________________________________________
-##material_name='materials_file' -> the file that contains the material flag of the elements
-#    format:
-#        id_element flag
-#        .....
-#
-#__________________________________________________________________________________________
-##nummaterial_name='nummaterial_velocity_file' -> table of the material properties
-#    format:
-#        flag rho vp vs 0 0 #full definition of the properties, flag > 0
-#        .....
-#        flag 'tomography' file_name #for interpolation with tomography
-#        .....
-#        flag 'interface' file_name flag_for_the_gll_below_the_interface
-#        flag_for_the_gll_above_the_interface #for interpolation with interface
-#__________________________________________________________________________________________
-##absname='absorbing_surface_file' -> this file contains all the face in all the absorbing  boundaries
-##absname_local='absorbing_surface_file'+'_xmin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmin
-##absname_local='absorbing_surface_file'+'_xmax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by x=Xmax
-##absname_local='absorbing_surface_file'+'_ymin' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymin
-##absname_local='absorbing_surface_file'+'_ymax' -> this file contains all the face in the
-#                                                                                    absorbing  boundary defined by y=Ymax
-##absname_local='absorbing_surface_file'+'_bottom' -> this file contains all the face in the
-#                                                                                     absorbing  boundary defined by z=bottom
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#        ....
-#
-#__________________________________________________________________________________________
-##freename='free_surface_file' -> file with the hex on the free surface (usually the topography)
-#    format:
-#        number of faces
-#        id_(element containg the face) id_node1_face id_node2_face id_node3_face id_node4_face
-#
-#__________________________________________________________________________________________
-# it is possible save only one (or more) file singularly: for example if you want only the nodecoord_file
-# call the module mesh.nodescoord_write(full path name)
-#
-#############################################################################
-
-import cubit
-
-class mtools(object):
-    """docstring for ciao"""
-    def __init__(self,frequency,list_surf,list_vp):
-        super(mtools, self).__init__()
-        self.frequency = frequency
-        self.list_surf = list_surf
-        self.list_vp = list_vp
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-    def __repr__(self):
-        txt='Meshing for frequency up to '+str(self.frequency)+'Hz\n'
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            txt=txt+'surface '+str(surf)+', vp ='+str(vp)+'  -> size '+str(self.freq2meshsize(vp)[0])\
-                                                      +' -> dt '+str(self.freq2meshsize(vp)[0])+'\n'
-        return txt
-    def freq2meshsize(self,vp):
-        velocity=vp*.5
-        self.size=(1/2.5)*velocity/self.frequency*(self.ngll-1)/self.point_wavelength
-        self.dt=.4*self.size/vp*self.percent_gll
-        return self.size,self.dt
-    def mesh_it(self):
-        for surf,vp in zip(self.list_surf,self.list_vp):
-            command = "surface "+str(surf)+" size "+str(self.freq2meshsize(vp)[0])
-            cubit.cmd(command)
-            command = "surface "+str(surf)+ 'scheme pave'
-            cubit.cmd(command)
-            command = "mesh surf "+str(surf)
-            cubit.cmd(command)
-
-class block_tools:
-    def __int__(self):
-        pass
-    def create_blocks(self,mesh_entity,list_entity=None,):
-        if mesh_entity =='surface':
-            txt=' face in surface '
-        elif mesh_entity == 'curve':
-            txt=' edge in curve '
-        elif mesh_entity == 'group':
-            txt=' face in group '
-        if list_entity:
-            if not isinstance(list_entity,list):
-                list_entity=[list_entity]
-        for entity in list_entity:
-            iblock=cubit.get_next_block_id()
-            command = "block "+str(iblock)+ txt +str(entity)
-            cubit.cmd(command)
-    def material_file(self,filename):
-        matfile=open(filename,'w')
-        material=[]
-        for record in matfile:
-            mat_name,vp_str=record.split()
-            vp=float(vp_str)
-            material.append([mat_name,vp])
-        self.material=dict(material)
-    def assign_block_material(self,id_block,mat_name,vp=None):
-        try:
-            material=self.material
-        except:
-            material=None
-        cubit.cmd('block '+str(id_block)+' attribute count 2')
-        cubit.cmd('block '+str(id_block)+'  attribute index 1 '+str(id_block))
-        if material:
-            if material.has_key(mat_name):
-                cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(material[mat_name]))
-                print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(material[mat_name])+' from database'
-        elif vp:
-            cubit.cmd('block '+str(id_block)+'  attribute index 2 '+str(vp))
-            print 'block '+str(id_block)+' - material '+mat_name+' - vp '+str(vp)
-        else:
-            print 'assignment impossible: check if '+mat_name+' is in the database or specify vp'
-
-class mesh_tools(block_tools):
-    """Tools for the mesh
-    #########
-    dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-        Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-        required for the stability condition (and the corrisponding edge).
-        Furthermore, given the number of gll point in the element (ngll) and the number
-        of GLL point for wavelength, it provide the maximum resolved frequency.
-    #########
-    length=edge_length(edge)
-        return the length of a edge
-    #########
-    edge_min,length=edge_min_length(surface)
-        given the cubit id of a surface, it return the edge with minimun length
-    #########
-    """
-    def __int__(self):
-        pass
-    def seismic_resolution(self,edges,velocity,bins_d=None,bins_u=None,sidelist=None):
-        """
-        dt,edge_dt,freq,edge_freq=seismic_resolution(edges,velocity,bins_d=None,bins_u=None,sidelist=None,ngll=5,np=8)
-            Given the velocity of a list of edges, seismic_resolution provides the minimum Dt
-            required for the stability condition (and the corrisponding edge).
-            Furthermore, given the number of gll point in the element (ngll) and the number
-            of GLL point for wavelength, it provide the maximum resolved frequency.
-        """
-        ratiostore=1e10
-        dtstore=1e10
-        edgedtstore=-1
-        edgeratiostore=-1
-        for edge in edges:
-            d=self.edge_length(edge)
-            ratio=(1/2.5)*velocity/d*(self.ngll-1)/self.point_wavelength
-            dt=.4*d/velocity*self.percent_gll
-            if dt<dtstore:
-               dtstore=dt
-               edgedtstore=edge
-            if ratio < ratiostore:
-                ratiostore=ratio
-                edgeratiostore=edge
-            try:
-                for bin_d,bin_u,side in zip(bins_d,bins_u,sidelist):
-                    if ratio >= bin_d and ratio < bin_u:
-                        command = "sideset "+str(side)+" edge "+str(edge)
-                        cubit.cmd(command)
-                        #print command
-                        break
-            except:
-                pass
-        return dtstore,edgedtstore,ratiostore,edgeratiostore
-    def edge_length(self,edge):
-        """
-        length=edge_length(edge)
-            return the length of a edge
-        """
-        from math import sqrt
-        nodes=cubit.get_connectivity('Edge',edge)
-        x0,y0,z0=cubit.get_nodal_coordinates(nodes[0])
-        x1,y1,z1=cubit.get_nodal_coordinates(nodes[1])
-        d=sqrt((x1-x0)**2+(y1-y0)**2+(z1-z0)**2)
-        return d
-    def edge_min_length(self,surface):
-        """
-        edge_min,length=edge_min_length(surface)
-            given the cubit id of a surface, it return the edge with minimun length
-        """
-        from math import sqrt
-        self.dmin=99999
-        edge_store=0
-        command = "group 'list_edge' add edge in surf "+str(surface)
-        command = command.replace("["," ").replace("]"," ")
-        #print command
-        cubit.cmd(command)
-        group=cubit.get_id_from_name("list_edge")
-        edges=cubit.get_group_edges(group)
-        command = "delete group "+ str(group)
-        cubit.cmd(command)
-        for edge in edges:
-            d=self.edge_length(edge)
-            if d<dmin:
-                self.dmin=d
-                edge_store=edge
-        self.edgemin=edge_store
-        return self.edgemin,self.dmin
-    def normal_check(self,nodes,normal):
-        tres=.2
-        p0=cubit.get_nodal_coordinates(nodes[0])
-        p1=cubit.get_nodal_coordinates(nodes[1])
-        p2=cubit.get_nodal_coordinates(nodes[2])
-        a=[p1[0]-p0[0],p1[1]-p0[1],p1[2]-p0[2]]
-        b=[p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]]
-        axb=[a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0]]
-        dot=0.0
-        for i in (0,1,2):
-            dot=dot+axb[i]*normal[i]
-        if  dot > 0:
-            return nodes
-        elif dot < 0:
-            return nodes[0],nodes[3],nodes[2],nodes[1]
-        else:
-            print 'error: surface normal, dot=0', axb,normal,dot,p0,p1,p2
-    def mesh_analysis(self,frequency):
-        from sets import Set
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        bins_d=[0.0001]+range(0,int(frequency)+1)+[1000]
-        bins_u=bins_d[1:]
-        dt=[]
-        ed_dt=[]
-        r=[]
-        ed_r=[]
-        nstart=cubit.get_next_sideset_id()
-        command = "del sideset all"
-        cubit.cmd(command)
-        for bin_d,bin_u in zip(bins_d,bins_u):
-            nsideset=cubit.get_next_sideset_id()
-            command='create sideset '+str(nsideset)
-            cubit.cmd(command)
-            command = "sideset "+str(nsideset)+ " name "+ "'ratio-["+str(bin_d)+"_"+str(bin_u)+"['"
-            cubit.cmd(command)
-        nend=cubit.get_next_sideset_id()
-        sidelist=range(nstart,nend)
-        for block in self.block_mat:
-            name=cubit.get_exodus_entity_name('block',block)
-            velocity=self.material[name][1]
-            if velocity > 0:
-                faces=cubit.get_block_faces(block)
-                edges=[]
-                for face in faces:
-                    es=cubit.get_sub_elements("face", face, 1)
-                    edges=edges+list(es)
-                edges=Set(edges)
-                dtstore,edgedtstore,ratiostore,edgeratiostore=self.seismic_resolution(edges,\
-                                                              velocity,bins_d,bins_u,sidelist)
-                dt.append(dtstore)
-                ed_dt.append(edgedtstore)
-                r.append(ratiostore)
-                ed_r.append(edgeratiostore)
-        self.ddt=zip(ed_dt,dt)
-        self.dr=zip(ed_r,r)
-        def sorter(x, y):
-            return cmp(x[1],y[1])
-        self.ddt.sort(sorter)
-        self.dr.sort(sorter)
-        print self.ddt,self.dr
-        print 'Deltat minimum => edge:'+str(self.ddt[0][0])+' dt: '+str(self.ddt[0][1])
-        print 'minimum frequency resolved => edge:'+str(self.dr[0][0])+' frequency: '+str(self.dr[0][1])
-        return self.ddt[0],self.dr[0]
-
-class mesh(object,mesh_tools):
-    def __init__(self):
-        super(mesh, self).__init__()
-        self.mesh_name='mesh_file'
-        self.nodecoord_name='nodes_coords_file'
-        self.material_name='materials_file'
-        self.nummaterial_name='nummaterial_velocity_file'
-        self.absname='absorbing_surface_file'
-        self.freename='free_surface_file'
-        self.recname='STATIONS'
-        self.face='QUAD4'
-        self.face2='SHELL4'
-        self.hex='HEX8'
-        self.edge='BAR2'
-        self.topo='face_topo'
-        self.rec='receivers'
-        self.ngll=5
-        self.percent_gll=0.172
-        self.point_wavelength=5
-        self.block_definition()
-        cubit.cmd('compress')
-    def __repr__(self):
-        pass
-    def block_definition(self):
-        block_flag=[]
-        block_mat=[]
-        block_bc=[]
-        block_bc_flag=[]
-        material={}
-        bc={}
-        blocks=cubit.get_block_id_list()
-        for block in blocks:
-            name=cubit.get_exodus_entity_name('block',block)
-            type=cubit.get_block_element_type(block)
-            print block,name,blocks,type,self.hex,self.face
-            # block has hexahedral elements (HEX8)
-            if type == self.hex:
-                flag=None
-                vel=None
-                vs=None
-                rho=None
-                q=0
-                ani=0
-                # material domain id
-                if name.find("acoustic") >= 0 :
-                  imaterial = 1
-                elif name.find("elastic") >= 0 :
-                  imaterial = 2
-                elif name.find("poroelastic") >= 0 :
-                  imaterial = 3
-                else :
-                  imaterial = 0
-                  print "block: ",name
-                  print "  could not find appropriate material for this block..."
-                  print ""
-                  break
-
-                nattrib=cubit.get_block_attribute_count(block)
-                if nattrib != 0:
-                    # material flag:
-                    #   positive => material properties,
-                    #   negative => interface/tomography domain
-                    flag=int(cubit.get_block_attribute_value(block,0))
-                    if flag > 0 and nattrib >= 2:
-                      # vp
-                      vel=cubit.get_block_attribute_value(block,1)
-                      if nattrib >= 3:
-                        # vs
-                        vs=cubit.get_block_attribute_value(block,2)
-                        if nattrib >= 4:
-                          #density
-                          rho=cubit.get_block_attribute_value(block,3)
-                          if nattrib >= 5:
-                            #Q_mu
-                            q=cubit.get_block_attribute_value(block,4)
-                            # for q to be valid: it must be positive
-                            if q < 0 :
-                              print 'error, q value invalid:', q
-                              break
-                            if nattrib == 6:
-                              #anisotropy_flag
-                              ani=cubit.get_block_attribute_value(block,5)
-                    elif flag < 0:
-                        # velocity model
-                        vel=name
-                        attrib=cubit.get_block_attribute_value(block,1)
-                        if attrib == 1:
-                            kind='interface'
-                            flag_down=cubit.get_block_attribute_value(block,2)
-                            flag_up=cubit.get_block_attribute_value(block,3)
-                        elif attrib == 2:
-                            kind='tomography'
-                else:
-                    flag=block
-                    vel,vs,rho,q,ani=(name,0,0,0,0)
-                block_flag.append(int(flag))
-                block_mat.append(block)
-                if flag > 0:
-                    par=tuple([imaterial,flag,vel,vs,rho,q,ani])
-                elif flag < 0:
-                    if kind=='interface':
-                        par=tuple([imaterial,flag,kind,name,flag_down,flag_up])
-                    elif kind=='tomography':
-                        par=tuple([imaterial,flag,kind,name])
-                elif flag==0:
-                    par=tuple([imaterial,flag,name])
-                material[block]=par
-            elif (type == self.face) or (type == self.face2) :
-                # block has surface elements (QUAD4 or SHELL4)
-                block_bc_flag.append(4)
-                block_bc.append(block)
-                bc[block]=4 #face has connectivity = 4
-                if name == self.topo: topography_face=block
-            else:
-                # block elements differ from HEX8/QUAD4/SHELL4
-                print '****************************************'
-                print 'block not properly defined:'
-                print '  name:',name
-                print '  type:',type
-                print
-                print 'please check your block definitions!'
-                print
-                print 'only supported types are:'
-                print '  HEX8  for volumes'
-                print '  QUAD4 for surface'
-                print '  SHELL4 for surface'
-                print '****************************************'
-                continue
-
-        nsets=cubit.get_nodeset_id_list()
-        if len(nsets) == 0: self.receivers=None
-        for nset in nsets:
-            name=cubit.get_exodus_entity_name('nodeset',nset)
-            if name == self.rec:
-                self.receivers=nset
-            else:
-                print 'nodeset '+name+' not defined'
-                self.receivers=None
-        try:
-            self.block_mat=block_mat
-            self.block_flag=block_flag
-            self.block_bc=block_bc
-            self.block_bc_flag=block_bc_flag
-            self.material=material
-            self.bc=bc
-            self.topography=topography_face
-        except:
-            print '****************************************'
-            print 'sorry, no blocks or blocks not properly defined'
-            print block_mat
-            print block_flag
-            print block_bc
-            print block_bc_flag
-            print material
-            print bc
-            print topography
-            print '****************************************'
-    def mat_parameter(self,properties):
-        #note: material property acoustic/elastic/poroelastic are defined by the block's name
-        print "#material properties:"
-        print properties
-        imaterial=properties[0]
-        flag=properties[1]
-        if flag > 0:
-            vel=properties[2]
-            if properties[3] is None and type(vel) != str:
-                # velocity model scales with given vp value
-                if vel >= 30:
-                    m2km=1000.
-                else:
-                    m2km=1.
-                vp=vel/m2km
-                rho=(1.6612*vp-0.472*vp**2+0.0671*vp**3-0.0043*vp**4+0.000106*vp**4)*m2km
-                txt='%1i %3i %20f %20f %20f %1i %1i\n' % (properties[0],properties[1],rho,vel,vel/(3**.5),0,0)
-            elif type(vel) != str:
-                # velocity model given as vp,vs,rho,..
-                #format nummaterials file: #material_domain_id #material_id #rho #vp #vs #Q_mu #anisotropy_flag
-                txt='%1i %3i %20f %20f %20f %20f %2i\n' % (properties[0],properties[1],properties[4], \
-                         properties[2],properties[3],properties[5],properties[6])
-            else:
-                txt='%1i %3i %s \n' % (properties[0],properties[1],properties[2])
-        elif flag < 0:
-            if properties[2] == 'tomography':
-                txt='%1i %3i %s %s\n' % (properties[0],properties[1],properties[2],properties[3])
-            elif properties[2] == 'interface':
-                txt='%1i %3i %s %s %1i %1i\n' % (properties[0],properties[1],properties[2],properties[3],\
-                                            properties[4],properties[5])
-        return txt
-    def nummaterial_write(self,nummaterial_name):
-        print 'Writing '+nummaterial_name+'.....'
-        nummaterial=open(nummaterial_name,'w')
-        for block in self.block_mat:
-            #name=cubit.get_exodus_entity_name('block',block)
-            nummaterial.write(self.mat_parameter(self.material[block]))
-        nummaterial.close()
-        print 'Ok'
-    def mesh_write(self,mesh_name):
-        meshfile=open(mesh_name,'w')
-        print 'Writing '+mesh_name+'.....'
-        num_elems=cubit.get_hex_count()
-        print '  number of elements:',str(num_elems)
-        meshfile.write(str(num_elems)+'\n')
-        num_write=0
-        for block,flag in zip(self.block_mat,self.block_flag):
-            #print block,flag
-            hexes=cubit.get_block_hexes(block)
-            #print len(hexes)
-            for hexa in hexes:
-                #print hexa
-                nodes=cubit.get_connectivity('Hex',hexa)
-                #nodes=self.jac_check(nodes) #is it valid for 3D? TODO
-                txt=('%10i ')% hexa
-                txt=txt+('%10i %10i %10i %10i %10i %10i %10i %10i\n')% nodes[:]
-                meshfile.write(txt)
-        meshfile.close()
-        print 'Ok'
-    def material_write(self,mat_name):
-        mat=open(mat_name,'w')
-        print 'Writing '+mat_name+'.....'
-        for block,flag in zip(self.block_mat,self.block_flag):
-                hexes=cubit.get_block_hexes(block)
-                for hexa in hexes:
-                    mat.write(('%10i %10i\n') % (hexa,flag))
-        mat.close()
-        print 'Ok'
-    def nodescoord_write(self,nodecoord_name):
-        nodecoord=open(nodecoord_name,'w')
-        print 'Writing '+nodecoord_name+'.....'
-        node_list=cubit.parse_cubit_list('node','all')
-        num_nodes=len(node_list)
-        print '  number of nodes:',str(num_nodes)
-        nodecoord.write('%10i\n' % num_nodes)
-        #
-        for node in node_list:
-            x,y,z=cubit.get_nodal_coordinates(node)
-            txt=('%10i %20f %20f %20f\n') % (node,x,y,z)
-            nodecoord.write(txt)
-        nodecoord.close()
-        print 'Ok'
-    def free_write(self,freename=None):
-        # free surface
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        normal=(0,0,1)
-        if not freename: freename=self.freename
-        # writes free surface file
-        print 'Writing '+freename+'.....'
-        freehex=open(freename,'w')
-        # searches block definition with name face_topo
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block == self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print '  block name:',name,'id:',block
-                quads_all=cubit.get_block_faces(block)
-                print '  number of faces = ',len(quads_all)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                freehex.write('%10i\n' % len(quads_all))
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            #print f
-                            nodes=cubit.get_connectivity('Face',f)
-                            nodes_ok=self.normal_check(nodes,normal)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                         nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            freehex.write(txt)
-        freehex.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def abs_write(self,absname=None):
-        # absorbing boundaries
-        import re
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        from sets import Set
-        if not absname: absname=self.absname
-        #
-        # loops through all block definitions
-        list_hex=cubit.parse_cubit_list('hex','all')
-        for block,flag in zip(self.block_bc,self.block_bc_flag):
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                print name,block
-                absflag=False
-                if re.search('xmin',name):
-                    filename=absname+'_xmin'
-                    normal=(-1,0,0)
-                elif re.search('xmax',name):
-                    filename=absname+'_xmax'
-                    normal=(1,0,0)
-                elif re.search('ymin',name):
-                    filename=absname+'_ymin'
-                    normal=(0,-1,0)
-                elif re.search('ymax',name):
-                    filename=absname+'_ymax'
-                    normal=(0,1,0)
-                elif re.search('bottom',name):
-                    filename=absname+'_bottom'
-                    normal=(0,0,-1)
-                elif re.search('abs',name):
-                    print "  ...face_abs - not used so far..."
-                    continue
-                else:
-                    continue
-                # opens file
-                print 'Writing '+filename+'.....'
-                abshex_local=open(filename,'w')
-                # gets face elements
-                quads_all=cubit.get_block_faces(block)
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                print '  number of faces = ',len(quads_all)
-                abshex_local.write('%10i\n' % len(quads_all))
-                #command = "group 'list_hex' add hex in face "+str(quads_all)
-                #command = command.replace("["," ").replace("]"," ").replace("("," ").replace(")"," ")
-                #cubit.cmd(command)
-                #group=cubit.get_id_from_name("list_hex")
-                #list_hex=cubit.get_group_hexes(group)
-                #command = "delete group "+ str(group)
-                #cubit.cmd(command)
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            if not absflag:
-                                # checks with specified normal
-                                nodes_ok=self.normal_check(nodes,normal)
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes_ok[0],\
-                                             nodes_ok[1],nodes_ok[2],nodes_ok[3])
-                            else:
-                                txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            abshex_local.write(txt)
-                # closes file
-                abshex_local.close()
-        print 'Ok'
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-    def surface_write(self,pathdir=None):
-        # optional surfaces, e.g. moho_surface
-        # should be created like e.g.:
-        #  > block 10 face in surface 2
-        #  > block 10 name 'moho_surface'
-        import re
-        from sets import Set
-        for block in self.block_bc :
-            if block != self.topography:
-                name=cubit.get_exodus_entity_name('block',block)
-                # skips block names like face_abs**, face_topo**
-                if re.search('abs',name):
-                  continue
-                elif re.search('topo',name):
-                  continue
-                elif re.search('surface',name):
-                  filename=pathdir+name+'_file'
-                else:
-                  continue
-                # gets face elements
-                print '  surface block name: ',name,'id: ',block
-                quads_all=cubit.get_block_faces(block)
-                print '  face = ',len(quads_all)
-                if len(quads_all) == 0 :
-                  continue
-                # writes out surface infos to file
-                print 'Writing '+filename+'.....'
-                surfhex_local=open(filename,'w')
-                dic_quads_all=dict(zip(quads_all,quads_all))
-                # writes number of surface elements
-                surfhex_local.write('%10i\n' % len(quads_all))
-                # writes out element node ids
-                list_hex=cubit.parse_cubit_list('hex','all')
-                for h in list_hex:
-                    faces=cubit.get_sub_elements('hex',h,2)
-                    for f in faces:
-                        if dic_quads_all.has_key(f):
-                            nodes=cubit.get_connectivity('Face',f)
-                            txt='%10i %10i %10i %10i %10i\n' % (h,nodes[0],\
-                                             nodes[1],nodes[2],nodes[3])
-                            surfhex_local.write(txt)
-                # closes file
-                surfhex_local.close()
-        print 'Ok'
-    def rec_write(self,recname):
-        print 'Writing '+self.recname+'.....'
-        recfile=open(self.recname,'w')
-        nodes=cubit.get_nodeset_nodes(self.receivers)
-        for i,n in enumerate(nodes):
-            x,y,z=cubit.get_nodal_coordinates(n)
-            recfile.write('ST%i XX %20f %20f 0.0 0.0 \n' % (i,x,z))
-        recfile.close()
-        print 'Ok'
-    def write(self,path=''):
-        cubit.cmd('set info off')
-        cubit.cmd('set echo off')
-        cubit.cmd('set journal off')
-        if len(path) != 0:
-            if path[-1] != '/': path=path+'/'
-        # mesh file
-        self.mesh_write(path+self.mesh_name)
-        # mesh material
-        self.material_write(path+self.material_name)
-        # mesh coordinates
-        self.nodescoord_write(path+self.nodecoord_name)
-        # material definitions
-        self.nummaterial_write(path+self.nummaterial_name)
-        # free surface: face_top
-        self.free_write(path+self.freename)
-        # absorbing surfaces: abs_***
-        self.abs_write(path+self.absname)
-        # any other surfaces: ***surface***
-        self.surface_write(path)
-        # receivers
-        if self.receivers: self.rec_write(path+self.recname)
-        cubit.cmd('set info on')
-        cubit.cmd('set echo on')
-
-def export2SESAME(path_exporting_mesh_SPECFEM3D_SESAME):
-    cubit.cmd('set info on')
-    cubit.cmd('set echo on')
-    sem_mesh=mesh()
-    sem_mesh.write(path=path_exporting_mesh_SPECFEM3D_SESAME)
-
-
-if __name__ == '__main__':
-    path='MESH/'
-    export2SESAME(path)
-
-# call by:
-# import cubit2specfem3d
-# cubit2specfem3d.export2SESAME('MESH')

Added: seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/cubit2specfem3d.py
===================================================================
--- seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/cubit2specfem3d.py	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/cubit2specfem3d.py	2013-06-25 14:13:49 UTC (rev 22418)
@@ -0,0 +1 @@
+link ../../CUBIT/cubit2specfem3d.py
\ No newline at end of file


Property changes on: seismo/3D/SPECFEM3D/trunk/examples/waterlayered_halfspace/cubit2specfem3d.py
___________________________________________________________________
Added: svn:special
   + *



More information about the CIG-COMMITS mailing list