def run(self): """Generate the database. """ # Domain x = numpy.arange(-4000.0, 4000.1, 1000.0) y = numpy.arange(-4000.0, 4000.1, 1000.0) npts = x.shape[0] xx = x * numpy.ones((npts, 1), dtype=numpy.float64) yy = y * numpy.ones((npts, 1), dtype=numpy.float64) xy = numpy.zeros((npts**2, 2), dtype=numpy.float64) xy[:, 0] = numpy.ravel(xx) xy[:, 1] = numpy.ravel(numpy.transpose(yy)) from axialstrainrate_genmaxwell_soln import AnalyticalSoln soln = AnalyticalSoln() disp = soln.initial_displacement(xy) velocity_time = soln.bc_rate_time(xy)/year.value velocity = soln.bc_velocity(xy)*year.value from spatialdata.geocoords.CSCart import CSCart cs = CSCart() cs.inventory.spaceDim = 2 cs._configure() data = {'points': xy, 'coordsys': cs, 'data_dim': 2, 'values': [{'name': "initial_amplitude_x", 'units': "m", 'data': disp[0, :, 0].ravel()}, {'name': "initial_amplitude_y", 'units': "m", 'data': disp[0, :, 1].ravel()}, {'name': "rate_amplitude_x", 'units': "m/year", 'data': velocity[0, :, 0].ravel()}, {'name': "rate_amplitude_y", 'units': "m/year", 'data': velocity[0, :, 1].ravel()}, {'name': "rate_start_time", 'units': "year", 'data': velocity_time[0, :, 0].ravel()}, ]} from spatialdata.spatialdb.SimpleIOAscii import createWriter io = createWriter("axialstrainrate_genmaxwell_disp.spatialdb") io.write(data) io = createWriter("axialstrainrate_genmaxwell_bc.spatialdb") io.write(data) return
def run(self): """Generate the database. """ # Domain x = numpy.arange(-4000.0, 4000.1, 1000.0) y = numpy.arange(-4000.0, 4000.1, 1000.0) npts = x.shape[0] xx = x * numpy.ones((npts, 1), dtype=numpy.float64) yy = y * numpy.ones((npts, 1), dtype=numpy.float64) xy = numpy.zeros((npts**2, 2), dtype=numpy.float64) xy[:, 0] = numpy.ravel(xx) xy[:, 1] = numpy.ravel(numpy.transpose(yy)) from axialdisp_soln import AnalyticalSoln soln = AnalyticalSoln() disp = soln.displacement(xy) from spatialdata.geocoords.CSCart import CSCart cs = CSCart() cs.inventory.spaceDim = 2 cs._configure() data = { 'points': xy, 'coordsys': cs, 'data_dim': 2, 'values': [{ 'name': "initial_amplitude_x", 'units': "m", 'data': numpy.ravel(disp[0, :, 0]) }, { 'name': "initial_amplitude_y", 'units': "m", 'data': numpy.ravel(disp[0, :, 1]) }] } from spatialdata.spatialdb.SimpleIOAscii import createWriter io = createWriter("axialdisp_bc.spatialdb") io.write(data) data["values"][0]["name"] = "displacement_x" data["values"][1]["name"] = "displacement_y" io = createWriter("axialdisp_ic.spatialdb") io.write(data) return
def main(self, *args, **kwds): """ Application driver. """ from spatialdata.spatialdb.SimpleIOAscii import createWriter self._info.log("Reading geometry.") self.geometry.read() points = self.geometry.vertices coordsys = self.geometry.coordsys data = { 'points': points, 'coordsys': coordsys, 'data_dim': self.geometry.dataDim, 'values': [], } for value in self.values.components(): self._info.log("Creating value '%s'" % value.name) data['values'].append({ 'name': value.vname, 'units': value.units, 'data': value.calculate(points, coordsys), }) self._info.log("Writing database.") writer = createWriter(self.filename) writer.write(data)
def generate(sim, fileRoot, materials): from coordsys import cs_mesh for material in materials: filenameH5 = "../output/%s-%s.h5" % (sim, material) filenameDB = "%s-%s.spatialdb" % (fileRoot, material) # Open HDF5 file and get coordinates, cells, and stress. h5 = h5py.File(filenameH5, "r") vertices = h5['geometry/vertices'][:] cells = numpy.array(h5['topology/cells'][:], dtype=numpy.int) # Get stresses from final time step. stress = h5['cell_fields/stress'][-1, :, :] h5.close() # Compute coordinates of quadrature points. quadCoords = getCellCenters(vertices, cells) # Create writer for spatial database file values = [ { 'name': "stress-xx", 'units': "Pa", 'data': stress[:, 0] }, { 'name': "stress-yy", 'units': "Pa", 'data': stress[:, 1] }, { 'name': "stress-zz", 'units': "Pa", 'data': stress[:, 2] }, { 'name': "stress-xy", 'units': "Pa", 'data': stress[:, 3] }, { 'name': "stress-yz", 'units': "Pa", 'data': stress[:, 4] }, { 'name': "stress-xz", 'units': "Pa", 'data': stress[:, 5] }, ] writer = createWriter(filenameDB) writer.write({ 'points': quadCoords, 'coordsys': cs_mesh(), 'data_dim': 3, 'values': values })
def run(self): """Generate the database. """ # Domain z = numpy.arange(-9000.0, 0.1, 9000.0) x = numpy.zeros(z.shape) y = numpy.zeros(z.shape) npts = z.shape[0] xyz = numpy.vstack((x, y, z)).transpose() from gravity_refstate_soln import AnalyticalSoln from gravity_refstate_soln import p_density, p_vs, p_vp soln = AnalyticalSoln() stress = soln.stress(xyz) strain = soln.strain(xyz) from spatialdata.geocoords.CSCart import CSCart cs = CSCart() cs.inventory.spaceDim = 3 cs._configure() data = { 'points': xyz, 'coordsys': cs, 'data_dim': 1, 'values': [ { 'name': "density", 'units': "kg/m**3", 'data': p_density * numpy.ones((npts,)), }, { 'name': "vs", 'units': "m/s", 'data': p_vs * numpy.ones((npts,)), }, { 'name': "vp", 'units': "m/s", 'data': p_vp * numpy.ones((npts,)), }, { 'name': "reference_stress_xx", 'units': "Pa", 'data': numpy.ravel(stress[0, :, 0]), }, { 'name': "reference_stress_yy", 'units': "Pa", 'data': numpy.ravel(stress[0, :, 1]), }, { 'name': "reference_stress_zz", 'units': "Pa", 'data': numpy.ravel(stress[0, :, 2]), }, { 'name': "reference_stress_yz", 'units': "Pa", 'data': numpy.ravel(stress[0, :, 4]), }, { 'name': "reference_stress_xz", 'units': "Pa", 'data': numpy.ravel(stress[0, :, 5]), }, { 'name': "reference_stress_xy", 'units': "Pa", 'data': numpy.ravel(stress[0, :, 3]), }, { 'name': "reference_strain_xx", 'units': "none", 'data': numpy.ravel(strain[0, :, 0]), }, { 'name': "reference_strain_yy", 'units': "none", 'data': numpy.ravel(strain[0, :, 1]), }, { 'name': "reference_strain_zz", 'units': "none", 'data': numpy.ravel(strain[0, :, 2]), }, { 'name': "reference_strain_xy", 'units': "none", 'data': numpy.ravel(strain[0, :, 3]), }, { 'name': "reference_strain_yz", 'units': "none", 'data': numpy.ravel(strain[0, :, 4]), }, { 'name': "reference_strain_xz", 'units': "none", 'data': numpy.ravel(strain[0, :, 5]), } ] } from spatialdata.spatialdb.SimpleIOAscii import createWriter io = createWriter("gravity_refstate_matfields.spatialdb") io.write(data) return
# Background shear tractions are reverse (in 2-D right-lateral is negative) # because the normal tractions are negative. tractions_bg_shear = coef_friction * tractions_bg_normal # Combine traction changes and background tractions tractions_shear = tractions_bg_shear + tractions_change[:, 0] tractions_normal = tractions_bg_normal + tractions_change[:, 1] # Create coordinate system for spatial database cs = CSCart() cs._configure() cs.setSpaceDim(2) # Create writer for spatial database file writer = createWriter("afterslip_tractions.spatialdb") writer.write({ 'points': vertices, 'coordsys': cs, 'data_dim': 1, 'values': [{ 'name': "initial_amplitude_tangential", 'units': "Pa", 'data': tractions_shear }, { 'name': "initial_amplitude_normal", 'units': "Pa", 'data': tractions_normal
def test_write(self): """ Test write(). """ # Database info cs = CSCart() cs._configure() filename = "data/test.spatialdb" data = { 'points': numpy.array([[1.0, 2.0, 3.0], [0.5, 3.0, -3.0]], numpy.float64), 'coordsys': cs, 'data_dim': 1, 'values': [{ 'name': "One", 'units': "m", 'data': numpy.array([2.0, 8.0], numpy.float64) }, { 'name': "Two", 'units': "m", 'data': numpy.array([-2.0, 3.0], numpy.float64) }] } dataDim = 1 qlocs = numpy.array( [[0.875, 2.25, 1.5], [0.6, 2.8, -1.8], [1.0, 2.0, 3.0]], numpy.float64) valsE = numpy.array([[-0.75, 3.5], [2.0, 6.8], [-2.0, 2.0]], numpy.float64) errE = [0, 0, 0] # Write database from spatialdata.spatialdb.SimpleIOAscii import createWriter writer = createWriter(filename) writer.write(data) # Test write using query from spatialdata.spatialdb.SimpleDB import SimpleDB db = SimpleDB() db.inventory.label = "test" db.inventory.queryType = "linear" db.inventory.iohandler.inventory.filename = filename db.inventory.iohandler._configure() db._configure() db.open() db.setQueryValues(["two", "one"]) vals = numpy.zeros(valsE.shape, dtype=numpy.float64) err = [] nlocs = qlocs.shape[0] for i in range(nlocs): e = db.query(vals[i, :], qlocs[i, :], cs) err.append(e) db.close() self.assertEqual(len(valsE.shape), len(vals.shape)) for dE, d in zip(valsE.shape, vals.shape): self.assertEqual(dE, d) for vE, v in zip(numpy.reshape(valsE, -1), numpy.reshape(vals, -1)): self.assertAlmostEqual(vE, v, 6) return