[cig-commits] r20685 - in short/3D/PyLith/branches/v1.7-stable: . examples/meshing examples/meshing/cubit_cellsize

brad at geodynamics.org brad at geodynamics.org
Tue Sep 4 17:37:39 PDT 2012


Author: brad
Date: 2012-09-04 17:37:39 -0700 (Tue, 04 Sep 2012)
New Revision: 20685

Added:
   short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/
   short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/Makefile.am
   short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/README
   short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/exodus_add_properties.py
   short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/geometry.jou
   short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/matprops.spatialdb
   short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_cellsize.jou
   short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_size_analyticfn.jou
   short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_size_spatialdb.jou
Modified:
   short/3D/PyLith/branches/v1.7-stable/configure.ac
   short/3D/PyLith/branches/v1.7-stable/examples/meshing/Makefile.am
Log:
Added example of setting cell size using ExodusII file.

Modified: short/3D/PyLith/branches/v1.7-stable/configure.ac
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/configure.ac	2012-09-05 00:11:31 UTC (rev 20684)
+++ short/3D/PyLith/branches/v1.7-stable/configure.ac	2012-09-05 00:37:39 UTC (rev 20685)
@@ -381,6 +381,7 @@
 		examples/meshing/surface_nurbs/dem/ulines/Makefile
 		examples/meshing/surface_nurbs/dem/vlines/Makefile
 		examples/meshing/surface_nurbs/triangles/Makefile
+		examples/meshing/cubit_cellsize/Makefile
 		templates/Makefile
 		share/Makefile
 		])

Modified: short/3D/PyLith/branches/v1.7-stable/examples/meshing/Makefile.am
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/examples/meshing/Makefile.am	2012-09-05 00:11:31 UTC (rev 20684)
+++ short/3D/PyLith/branches/v1.7-stable/examples/meshing/Makefile.am	2012-09-05 00:37:39 UTC (rev 20685)
@@ -17,7 +17,8 @@
 #
 
 SUBDIRS = \
-	surface_nurbs
+	surface_nurbs \
+	cubit_cellsize
 
 
 # End of file 

Added: short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/Makefile.am
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/Makefile.am	                        (rev 0)
+++ short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/Makefile.am	2012-09-05 00:37:39 UTC (rev 20685)
@@ -0,0 +1,28 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2012 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+
+dist_noinst_DATA = \
+	README \
+	exodus_add_properties.py \
+	geometry.jou \
+	mesh_cellsize.jou \
+	mesh_size_analyticfn.jou \
+	mesh_size_spatialdb.jou
+
+
+# End of file 

Added: short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/README
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/README	                        (rev 0)
+++ short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/README	2012-09-05 00:37:39 UTC (rev 20685)
@@ -0,0 +1,27 @@
+CUBIT example demonstrating how to use a field variable in an ExodusII
+file to specify the cell size in a CUBIT mesh. This technique only
+works for triangluar, quadrilateral, and tetrahedral cells.
+
+Steps:
+
+1. Generate a background mesh (ExodusII file) that will hold the field
+variable (computed at the vertices) for the cell size.
+
+  Run the CUBIT journal file mesh_cellsize.jou.
+
+2. Add the cell size field variable to the ExodusII file. In this case
+we add two cell size variables, one based upon an analytical function
+and one based upon a spatial database.
+
+  Run the Python script exodus_add_properties.py.
+
+3. Generate the CUBIT meshes using the cell size field variables.
+
+  Run the CUBIT journal file mesh_size_spatialdb.jou and
+  mesh_size_analyticfn.jou.
+
+NOTES:
+
+  The geometry in the background mesh used to specify the cell size
+  *must* be exactly the same geometry as that of the final mesh. CUBIT
+  will crash if the geometry is different.

Added: short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/exodus_add_properties.py
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/exodus_add_properties.py	                        (rev 0)
+++ short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/exodus_add_properties.py	2012-09-05 00:37:39 UTC (rev 20685)
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2012 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+# PREREQUISITES: numpy, netCDF4, spatialdata (PyLith)
+
+filenameExodus = "mesh_cellsize.exo"
+filenameDB = "matprops.spatialdb"
+minPeriod = 10.0
+
+# ======================================================================
+import sys
+import numpy
+import netCDF4
+
+# ----------------------------------------------------------------------
+# Cell size based on minimum wavelength with Vs from spatial database
+def getCellSizeDB(points):
+
+    from spatialdata.geocoords.CSCart import CSCart
+    from spatialdata.spatialdb.SimpleDB import SimpleDB
+    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+
+    # Coordinate system for mesh (must match coordsys in ExodusII file)
+    cs = CSCart()
+    cs._configure()
+    cs.initialize()
+
+    # Spatial database with physical properties (Vs)
+    dbIO = SimpleIOAscii()
+    dbIO.inventory.filename = filenameDB
+    dbIO._configure()
+    db = SimpleDB()
+    db.inventory.iohandler = dbIO
+    db.inventory.label = "Physical properties"
+    db.inventory.queryType = "linear"
+    db._configure()
+    
+    (npoints, spacedim) = points.shape
+
+    # Query database
+    db.open()
+    db.queryVals(["vs"])
+    data = numpy.zeros((npoints, 1), dtype=numpy.float64)
+    err = numpy.zeros((npoints,), dtype=numpy.int32)
+    db.multiquery(data, err, points, cs)
+    db.close()
+
+    vs = data[:,0]
+    cellSize = minPeriod*vs / 10.0
+    return cellSize
+
+
+# ----------------------------------------------------------------------
+# Cell size based on analytical function of vertex coordinates.
+def getCellSizeFn(points):
+    """
+    Cell size is based on distance from a target and grows at a
+    geometric rate.
+    """
+    # Coordinates of target
+    target = (5.0e+3, -10.0e+3, -10.0e+3)
+    
+    # Compute distance from target
+    dist = ((points[:,0] - target[0])**2 + \
+                (points[:,1] - target[1])**2 + \
+                (points[:,2] - target[2])**2)**0.5
+    bias_factor = 1.05 # Geometric rate
+    dxStart = 1.0e+3 # Discretization size at target
+    npts = numpy.ceil( numpy.log(1-dist/dxStart*(1-bias_factor))/numpy.log(bias_factor))
+    cellSize = dxStart*bias_factor**npts
+    return cellSize
+
+
+# ----------------------------------------------------------------------
+# Get coordinates of points from ExodusII file.
+exodus = netCDF4.Dataset(filenameExodus, 'a')
+points = exodus.variables['coord'][:].transpose()
+cellSizeDB = getCellSizeDB(points)
+cellSizeFn = getCellSizeFn(points)
+
+# Add cell size info to ExodusII file
+if not 'num_nod_var' in exodus.dimensions.keys():
+    exodus.createDimension('num_nod_var', 2)
+
+    name_nod_var = exodus.createVariable('name_nod_var', 'S1',
+                                       ('num_nod_var', 'len_string',))
+    name_nod_var[0,:] = netCDF4.stringtoarr("cell_size_db", 33)
+    name_nod_var[1,:] = netCDF4.stringtoarr("cell_size_fn", 33)
+    
+    vals_nod_var = exodus.createVariable('vals_nod_var', numpy.float64,
+                                       ('time_step', 'num_nod_var', 'num_nodes',))
+
+
+time_whole = exodus.variables['time_whole']
+time_whole[0] = 0.0
+vals_nod_var = exodus.variables['vals_nod_var']
+vals_nod_var[0,0,:] = cellSizeDB.transpose()
+vals_nod_var[0,1,:] = cellSizeFn.transpose()
+
+exodus.close()
+
+
+# End of file


Property changes on: short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/exodus_add_properties.py
___________________________________________________________________
Name: svn:executable
   + *

Added: short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/geometry.jou
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/geometry.jou	                        (rev 0)
+++ short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/geometry.jou	2012-09-05 00:37:39 UTC (rev 20685)
@@ -0,0 +1,83 @@
+# -*- Python -*- (syntax highlighting)
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2012 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+# CUBIT journal file with geometry for example showing how to specify
+# the discretization size using a field variable in an Exodus-II file.
+#
+# We also use the CUBIT support for APREPRO (the expressions in
+# braces), which includes units and mathematical functions. See the
+# APREPRO section in the appendix of the CUBIT documentation for more
+# information.
+#
+# ----------------------------------------------------------------------
+# Set units to SI.
+# ----------------------------------------------------------------------
+# {Units('si')}
+#
+# ----------------------------------------------------------------------
+# Reset geometry.
+# ----------------------------------------------------------------------
+reset
+
+# Make sure undo is off to prevent errors in stitching volumes.
+undo off
+
+# ----------------------------------------------------------------------
+# Create block
+# ----------------------------------------------------------------------
+# Block is 100 km x 100 km x 50 km
+#{blockLength=100.0*km}
+#{blockWidth=100.0*km}
+#{blockHeight=50.0*km}
+
+brick x {blockLength} y {blockWidth} z {blockHeight}
+#{idVol=Id("volume")}
+
+# Translate block so the top is at z=0
+volume {idVol} move x {domain_x} y {domain_y} z {-0.5*blockHeight}
+
+# ----------------------------------------------------------------------
+# Create interface surfaces
+# ----------------------------------------------------------------------
+create planar surface with plane xplane offset 0
+#{idFault=Id("surface")}
+surface {idFault} name "fault_surface"
+create planar surface with plane zplane offset {-20.0*km}
+#{idMoho=Id("surface")}
+surface {idMoho} name "material_interface"
+
+# ----------------------------------------------------------------------
+# Divide volumes using interface surfaces
+# ----------------------------------------------------------------------
+webcut volume 1 with plane surface material_interface
+webcut volume 1 with plane surface fault_surface
+volume 1 name "elastic_xpos"
+volume 5 name "elastic_xneg"
+volume 4 name "viscoelastic"
+
+# ----------------------------------------------------------------------
+# Imprint all volumes, merging surfaces
+# ----------------------------------------------------------------------
+delete body 2 3
+imprint all with volume all
+merge all
+compress ids all
+
+# End of file
+
+
+
+

Added: short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/matprops.spatialdb
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/matprops.spatialdb	                        (rev 0)
+++ short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/matprops.spatialdb	2012-09-05 00:37:39 UTC (rev 20685)
@@ -0,0 +1,29 @@
+// -*- C++ -*- (tell Emacs to use C++ mode for syntax highlighting)
+//
+// This spatial database specifies a piecewise linear depth variation
+// in the material properties.
+//
+#SPATIAL.ascii 1
+SimpleDB {
+  num-values = 3 // number of material property values
+  value-names =  density vs vp // names of the material property values
+  value-units =  kg/m**3  m/s  m/s // units
+  num-locs = 4 // number of locations
+  data-dim = 1
+  space-dim = 3
+  cs-data = cartesian {
+    to-meters = 1.0e+3  // use km
+    space-dim = 3
+  }
+}
+// Columns are
+// (1) x coordinate (m)
+// (2) y coordinate (m)
+// (3) z coordinate (m)
+// (4) density (kg/m^3)
+// (5) vs (m/s)
+// (6) vp (m/s)
+0.0  0.0   0.0   2500.0   2000.0  4874.8
+0.0  0.0 -10.0   2800.0   3000.0  6306.8
+0.0  0.0 -30.0   2900.0   3500.0  6321.9
+0.0  0.0 -50.0   2950.0   3500.0  6321.9

Added: short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_cellsize.jou
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_cellsize.jou	                        (rev 0)
+++ short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_cellsize.jou	2012-09-05 00:37:39 UTC (rev 20685)
@@ -0,0 +1,47 @@
+# -*- Python -*- (syntax highlighting)
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2012 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+# CUBIT journal file to create an ExodusII file with a mesh at uniform
+# resolution to which we will add a field specifying the cell size for
+# the real mesh.
+#
+# ----------------------------------------------------------------------
+# Generate geometry
+# ----------------------------------------------------------------------
+playback 'geometry.jou'
+
+# ----------------------------------------------------------------------
+# Create tet4 mesh at 4.0 km resolution.
+# ----------------------------------------------------------------------
+
+#{dx=4.0*km}
+volume all size {dx}
+volume all scheme tetmesh
+
+# ----------------------------------------------------------------------
+# Generate the mesh
+# ----------------------------------------------------------------------
+mesh surface all
+mesh volume all
+
+# ----------------------------------------------------------------------
+# Export exodus file
+# ----------------------------------------------------------------------
+set large exodus off
+export mesh "mesh_cellsize.exo" dimension 3 overwrite
+
+
+# End of file

Added: short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_size_analyticfn.jou
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_size_analyticfn.jou	                        (rev 0)
+++ short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_size_analyticfn.jou	2012-09-05 00:37:39 UTC (rev 20685)
@@ -0,0 +1,75 @@
+# -*- Python -*- (syntax highlighting)
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2012 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+# CUBIT journal file to create a mesh where the resolution is given as
+# a field variable in an ExodusII file. The field variable
+# 'cell_size_fn' is computed in a Python script using an analytic
+# function.
+#
+# ----------------------------------------------------------------------
+# Generate geometry
+# ----------------------------------------------------------------------
+playback 'geometry.jou'
+
+# ----------------------------------------------------------------------
+# Create tet4 mesh with resolution dictated by 'cell_size_fn'.
+# ----------------------------------------------------------------------
+volume all scheme tetmesh
+#{numvol=3}
+#{ivol=1}
+#{loop(numvol)}
+  import sizing Function "mesh_cellsize.exo" Block {ivol} Variable "cell_size_fn" Time 0.0
+  volume {ivol} sizing function type exodus
+  #{ivol++}
+#{endloop}
+surface all sizing function type exodus
+curve all scheme stride
+
+# ----------------------------------------------------------------------
+# Generate the mesh
+# ----------------------------------------------------------------------
+# Generate the volume mesh to insure cell sizes match desired
+# distribution, then delete volume cells, smooth the surface mesh, and
+# then generate the volume mesh again.
+mesh volume viscoelastic
+mesh volume elastic_xpos elastic_xneg
+delete mesh volume all
+surface all smooth scheme condition number beta 1.2 cpu 10
+smooth surface all
+mesh volume all
+
+# ----------------------------------------------------------------------
+# Smooth mesh to improve quality
+# ----------------------------------------------------------------------
+#{condnum=2.0}
+#{loop(4)}
+cleanup volume all
+volume all smooth scheme condition number beta {condnum} cpu 10
+smooth volume all
+#{condnum=condnum-0.1}
+#{endloop}
+
+# ----------------------------------------------------------------------
+# Export exodus file
+# ----------------------------------------------------------------------
+export mesh "mesh_size_analyticfn.exo" dimension 3 overwrite
+
+
+# End of file
+
+
+
+

Added: short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_size_spatialdb.jou
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_size_spatialdb.jou	                        (rev 0)
+++ short/3D/PyLith/branches/v1.7-stable/examples/meshing/cubit_cellsize/mesh_size_spatialdb.jou	2012-09-05 00:37:39 UTC (rev 20685)
@@ -0,0 +1,74 @@
+# -*- Python -*- (syntax highlighting)
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2012 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+# CUBIT journal file to create a mesh where the resolution is given as
+# the field variable 'cell_size_db' in an ExodusII file. The field
+# variable is computed in a Python script based upon a spatial
+# database file.
+#
+# ----------------------------------------------------------------------
+# Generate geometry
+# ----------------------------------------------------------------------
+playback 'geometry.jou'
+
+# ----------------------------------------------------------------------
+# Create tet4 mesh with resolution dictated by 'cell_size_db'.
+# ----------------------------------------------------------------------
+volume all scheme tetmesh
+#{numvol=3}
+#{ivol=1}
+#{loop(numvol)}
+  import sizing Function "mesh_cellsize.exo" Block {ivol} Variable "cell_size_db" Time 0.0
+  volume {ivol} sizing function type exodus
+  #{ivol++}
+#{endloop}
+surface all sizing function type exodus
+curve all scheme stride
+
+# ----------------------------------------------------------------------
+# Generate the mesh
+# ----------------------------------------------------------------------
+# Generate the volume mesh to insure cell sizes match desired
+# distribution, then delete volume cells, smooth the surface mesh, and
+# then generate the volume mesh again.
+mesh volume viscoelastic
+mesh volume elastic_xpos elastic_xneg
+delete mesh volume all
+surface all smooth scheme condition number beta 1.2 cpu 10
+smooth surface all
+mesh volume all
+
+# ----------------------------------------------------------------------
+# Smooth mesh to improve quality
+# ----------------------------------------------------------------------
+#{condnum=2.0}
+#{loop(4)}
+cleanup volume all
+volume all smooth scheme condition number beta {condnum} cpu 10
+smooth volume all
+#{condnum=condnum-0.1}
+#{endloop}
+
+# ----------------------------------------------------------------------
+# Export exodus file
+# ----------------------------------------------------------------------
+export mesh "mesh_size_spatialdb.exo" dimension 3 overwrite
+
+
+# End of file
+
+
+



More information about the CIG-COMMITS mailing list