Exemple #1
0
    def run(self):
        """Generate the database.
        """
        # Domain
        # Extend beyond mesh boundaries to avoid problems with linear interpolations.
        x = numpy.arange(-6000.0, 6000.1, 2000.0)
        y = numpy.arange(-6000.0, 6000.1, 2000.0)
        z = numpy.arange(-10000.0, 2000.1, 2000.0)
        (x3, y3, z3) = numpy.meshgrid(x, y, z)
        nptsX = x.shape[0]
        nptsY = y.shape[0]
        nptsZ = z.shape[0]

        xyz = numpy.zeros((nptsX * nptsY * nptsZ, 3), dtype=numpy.float64)
        xyz[:, 0] = x3.ravel()
        xyz[:, 1] = y3.ravel()
        xyz[:, 2] = z3.ravel()

        from axialstrain_genmaxwell_soln import AnalyticalSoln
        soln = AnalyticalSoln()
        disp = soln.initial_displacement(xyz)

        from spatialdata.geocoords.CSCart import CSCart
        cs = CSCart()
        cs.inventory.spaceDim = 3
        cs._configure()
        data = {
            'x':
            x,
            'y':
            y,
            'z':
            z,
            'points':
            xyz,
            'coordsys':
            cs,
            'data_dim':
            3,
            'values': [{
                'name': "initial_amplitude_x",
                'units': "m",
                'data': disp[0, :, 0].ravel()
            }, {
                'name': "initial_amplitude_y",
                'units': "m",
                'data': disp[0, :, 1].ravel()
            }, {
                'name': "initial_amplitude_z",
                'units': "m",
                'data': disp[0, :, 2].ravel()
            }]
        }

        from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii
        io = SimpleGridAscii()
        io.inventory.filename = "axialstrain_genmaxwell_bc.spatialdb"
        io._configure()
        io.write(data)
        return
Exemple #2
0
    def run(self):
        """Generate the database.
        """
        # Domain
        x1 = numpy.arange(-1.0, 11.01, 1.0)
        y1 = numpy.arange(-1.0, 11.01, 1.0)
        x, y = numpy.meshgrid(x1, y1)

        xy = numpy.zeros((len(x1) * len(y1), 2), dtype=numpy.float64)
        xy[:, 0] = x.ravel()
        xy[:, 1] = y.ravel()

        from terzaghi_soln import AnalyticalSoln
        soln = AnalyticalSoln()
        disp = soln.initial_displacement(xy)
        pres = soln.initial_pressure(xy)
        trace_strain = soln.initial_trace_strain(xy)

        from spatialdata.geocoords.CSCart import CSCart
        cs = CSCart()
        cs.inventory.spaceDim = 2
        cs._configure()
        data = {
            'x':
            x1,
            'y':
            y1,
            'points':
            xy,
            'coordsys':
            cs,
            'data_dim':
            2,
            'values': [{
                'name': "displacement_x",
                'units': "m",
                'data': numpy.ravel(disp[0, :, 0])
            }, {
                'name': "displacement_y",
                'units': "m",
                'data': numpy.ravel(disp[0, :, 1])
            }, {
                'name': "pressure",
                'units': "Pa",
                'data': numpy.ravel(pres[0, :])
            }, {
                'name': "trace_strain",
                'units': "none",
                'data': numpy.ravel(trace_strain[0, :])
            }]
        }

        from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii
        io = SimpleGridAscii()
        io.inventory.filename = "terzaghi_ic.spatialdb"
        io._configure()
        io.write(data)

        return
Exemple #3
0
    def run(self):
        """Generate the database.
        """
        # Domain
        x = numpy.arange(-1.0e+4, 1.01e+4, 5.0e+3)
        y = numpy.arange(-1.0e+4, 1.01e+4, 5.0e+3)
        z = numpy.array([0])
        x3, y3, z3 = numpy.meshgrid(x, y, z)
        nptsX = x.shape[0]
        nptsY = y.shape[0]
        nptsZ = z.shape[0]

        xyz = numpy.zeros((nptsX * nptsY * nptsZ, 3), dtype=numpy.float64)
        xyz[:, 0] = x3.ravel()
        xyz[:, 1] = y3.ravel()
        xyz[:, 2] = z3.ravel()

        from sheartraction_rate_soln import AnalyticalSoln
        soln = AnalyticalSoln()
        disp = soln.bc_initial_displacement(xyz)
        velocity_time = soln.bc_rate_time(xyz) / year.value
        velocity = soln.bc_velocity(xyz) * year.value

        from spatialdata.geocoords.CSCart import CSCart
        cs = CSCart()
        cs.inventory.spaceDim = 3
        cs._configure()
        data = {
            "x":
            x,
            "y":
            y,
            "z":
            z,
            'points':
            xyz,
            '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': "initial_amplitude_z",
                    'units': "m",
                    'data': disp[0, :, 2].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_amplitude_z",
                    'units': "m/year",
                    'data': velocity[0, :, 2].ravel()
                },
                {
                    'name': "rate_start_time",
                    'units': "year",
                    'data': velocity_time[0, :, 0].ravel()
                },
            ]
        }

        from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii
        io = SimpleGridAscii()
        io.inventory.filename = "sheartraction_rate_disp.spatialdb"
        io._configure()
        io.write(data)
        return
Exemple #4
0
    def run(self):
        """Generate the database.
        """
        # Domain
        x = numpy.arange(-4.0e+3, 4.01e+3, 1.0e+3)
        y = numpy.arange(-4.0e+3, 4.01e+3, 1.0e+3)
        z = numpy.arange(-8.0e+3, 0.01e+3, 1.0e+3)
        x3, y3, z3 = numpy.meshgrid(x, y, z)
        nptsX = x.shape[0]
        nptsY = y.shape[0]
        nptsZ = z.shape[0]

        xyz = numpy.zeros((nptsX * nptsY * nptsZ, 3), dtype=numpy.float64)
        xyz[:, 0] = x3.ravel()
        xyz[:, 1] = y3.ravel()
        xyz[:, 2] = z3.ravel()

        from axialdisp_soln import AnalyticalSoln
        soln = AnalyticalSoln()
        disp = soln.displacement(xyz)

        from spatialdata.geocoords.CSCart import CSCart
        cs = CSCart()
        cs.inventory.spaceDim = 3
        cs._configure()
        data = {
            "x":
            x,
            "y":
            y,
            "z":
            z,
            "points":
            xyz,
            "coordsys":
            cs,
            "data_dim":
            3,
            "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])
                },
                {
                    "name": "initial_amplitude_z",
                    "units": "m",
                    "data": numpy.ravel(disp[0, :, 2])
                },
            ]
        }

        from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii
        io = SimpleGridAscii()
        io.inventory.filename = "axialdisp_bc.spatialdb"
        io._configure()
        io.write(data)
        return
    def test_io(self):
        from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii

        filename = "data/gridio.spatialdb"
        x = numpy.array([-2.0, 0.0, 3.0], dtype=numpy.float64)
        y = numpy.array([0.0, 1.0], dtype=numpy.float64)
        z = numpy.array([-2.0, -1.0, 2.0], dtype=numpy.float64)

        points = numpy.array(
            [
                [-2.0, 0.0, -2.0],
                [-2.0, 1.0, -2.0],
                [-2.0, 0.0, -1.0],
                [-2.0, 1.0, -1.0],
                [-2.0, 0.0, 2.0],
                [-2.0, 1.0, 2.0],
                [0.0, 0.0, -2.0],
                [0.0, 1.0, -2.0],  # query (5.7, 8.2)
                [0.0, 0.0, -1.0],
                [0.0, 1.0, -1.0],
                [0.0, 0.0, 2.0],
                [0.0, 1.0, 2.0],
                [3.0, 0.0, -2.0],
                [3.0, 1.0, -2.0],
                [3.0, 0.0, -1.0],
                [3.0, 1.0, -1.0],
                [3.0, 0.0, 2.0],
                [3.0, 1.0, 2.0],
            ],
            dtype=numpy.float64,
        )
        one = numpy.array(
            [6.6, 5.5, 2.3, 5.7, 6.3, 3.4, 7.2, 5.7, 3.4, 5.7, 9.4, 7.2, 4.8, 9.2, 5.8, 4.7, 7.8, 2.9],
            dtype=numpy.float64,
        )
        two = numpy.array(
            [3.4, 6.7, 4.1, 2.0, 6.7, 6.4, 6.8, 8.2, 9.8, 2.3, 8.5, 9.3, 7.5, 8.3, 8.5, 8.9, 6.2, 8.3],
            dtype=numpy.float64,
        )

        cs = CSCart()
        cs.initialize()

        writer = SimpleGridAscii()
        writer.inventory.filename = filename
        writer._configure()
        writer.write(
            {
                "points": points,
                "x": x,
                "y": y,
                "z": z,
                "coordsys": cs,
                "data_dim": 3,
                "values": [{"name": "one", "units": "m", "data": one}, {"name": "two", "units": "m", "data": two}],
            }
        )

        db = SimpleGridDB()
        db.inventory.label = "test"
        db.inventory.queryType = "nearest"
        db.inventory.filename = filename
        db._configure()
        self._db = db

        locs = numpy.array([[0.1, 0.95, -1.8]], numpy.float64)
        cs = CSCart()
        cs._configure()
        queryVals = ["two", "one"]
        dataE = numpy.array([[8.2, 5.7]], numpy.float64)
        errE = [0]

        db = self._db
        db.open()
        db.queryVals(queryVals)
        data = numpy.zeros(dataE.shape, dtype=numpy.float64)
        err = []
        nlocs = locs.shape[0]
        for i in xrange(nlocs):
            e = db.query(data[i, :], locs[i, :], cs)
            err.append(e)
        db.close()

        self.assertEqual(len(errE), len(err))
        for vE, v in zip(errE, err):
            self.assertEqual(vE, v)

        self.assertEqual(len(dataE.shape), len(data.shape))
        for dE, d in zip(dataE.shape, data.shape):
            self.assertEqual(dE, d)
        for vE, v in zip(numpy.reshape(dataE, -1), numpy.reshape(data, -1)):
            self.assertAlmostEqual(vE, v, 6)

        return
Exemple #6
0
    def test_io_3d(self):
        from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii

        filename = "data/gridio3d.spatialdb"
        x = numpy.array([-2.0, 0.0, 3.0], dtype=numpy.float64)
        y = numpy.array([0.0, 1.0], dtype=numpy.float64)
        z = numpy.array([-2.0, -1.0, 2.0], dtype=numpy.float64)

        points = numpy.array(
            [
                [-2.0, 0.0, -2.0],
                [-2.0, 1.0, -2.0],
                [-2.0, 0.0, -1.0],
                [-2.0, 1.0, -1.0],
                [-2.0, 0.0, 2.0],
                [-2.0, 1.0, 2.0],
                [0.0, 0.0, -2.0],
                [0.0, 1.0, -2.0],  # query (5.7, 8.2)
                [0.0, 0.0, -1.0],
                [0.0, 1.0, -1.0],
                [0.0, 0.0, 2.0],
                [0.0, 1.0, 2.0],
                [3.0, 0.0, -2.0],
                [3.0, 1.0, -2.0],
                [3.0, 0.0, -1.0],
                [3.0, 1.0, -1.0],
                [3.0, 0.0, 2.0],
                [3.0, 1.0, 2.0],
            ],
            dtype=numpy.float64)
        one = numpy.array([
            6.6, 5.5, 2.3, 5.7, 6.3, 3.4, 7.2, 5.7, 3.4, 5.7, 9.4, 7.2, 4.8,
            9.2, 5.8, 4.7, 7.8, 2.9
        ],
                          dtype=numpy.float64)
        two = numpy.array([
            3.4, 6.7, 4.1, 2.0, 6.7, 6.4, 6.8, 8.2, 9.8, 2.3, 8.5, 9.3, 7.5,
            8.3, 8.5, 8.9, 6.2, 8.3
        ],
                          dtype=numpy.float64)

        cs = CSCart()
        cs.initialize()

        writer = SimpleGridAscii()
        writer.inventory.filename = filename
        writer._configure()
        writer.write({
            'points':
            points,
            'x':
            x,
            'y':
            y,
            'z':
            z,
            'coordsys':
            cs,
            'data_dim':
            3,
            'values': [
                {
                    'name': "one",
                    'units': "m",
                    'data': one
                },
                {
                    'name': "two",
                    'units': "m",
                    'data': two
                },
            ]
        })

        db = SimpleGridDB()
        db.inventory.label = "test"
        db.inventory.queryType = "nearest"
        db.inventory.filename = filename
        db._configure()
        self._db = db

        locs = numpy.array([[0.1, 0.95, -1.8]], numpy.float64)
        cs = CSCart()
        cs._configure()
        queryVals = ["two", "one"]
        dataE = numpy.array([[8.2, 5.7]], numpy.float64)
        errE = [0]

        db = self._db
        db.open()
        db.queryVals(queryVals)
        data = numpy.zeros(dataE.shape, dtype=numpy.float64)
        err = []
        nlocs = locs.shape[0]
        for i in xrange(nlocs):
            e = db.query(data[i, :], locs[i, :], cs)
            err.append(e)
        db.close()

        self.assertEqual(len(errE), len(err))
        for vE, v in zip(errE, err):
            self.assertEqual(vE, v)

        self.assertEqual(len(dataE.shape), len(data.shape))
        for dE, d in zip(dataE.shape, data.shape):
            self.assertEqual(dE, d)
        for vE, v in zip(numpy.reshape(dataE, -1), numpy.reshape(data, -1)):
            self.assertAlmostEqual(vE, v, 6)

        return
npts = nx*ny*nz
xyz = numpy.zeros( (npts, 3), dtype=numpy.float64)
xyz[:,0] = x
for iy in xrange(ny):
    xyz[iy*nz:(iy+1)*nz,1] = y[iy]
    xyz[iy*nz:(iy+1)*nz,2] = z

zero = numpy.zeros( (npts,), dtype=numpy.float64)

r = ((xyz[:,0]-hypoX)**2 + (xyz[:,1]-hypoY)**2 + (xyz[:,2]-hypoZ)**2)**0.5
tractionLL = dTshear*fnF(r)

cs = CSCart()
cs.initialize()

writer = SimpleGridAscii()
writer.inventory.filename = "traction_change.spatialdb"
writer._configure()
writer.write({'points': xyz,
              'x': x,
              'y': y,
              'z': z,
              'coordsys': cs,
              'data_dim': 2,
              'values': [{'name': "traction-shear-leftlateral",
                          'units': "MPa",
                          'data': tractionLL},
                         {'name': "traction-shear-updip",
                          'units': "MPa",
                          'data': zero},
                         {'name': "traction-normal",
  def test_io_2d(self):
    from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii

    filename = "data/gridio2d.spatialdb"
    x = numpy.array([-2.0, 0.0, 3.0], dtype=numpy.float64)
    y = numpy.array([0.0, 1.0], dtype=numpy.float64)

    points = numpy.array([
        [-2.0,  0.0],
        [-2.0,  1.0],
        [ 0.0,  0.0],
        [ 0.0,  1.0], # query (5.7, 8.2)
        [ 3.0,  0.0],
        [ 3.0,  1.0],
        ], dtype=numpy.float64)
    one = numpy.array([6.6, 5.5, 7.2, 5.7, 4.8, 9.2], dtype=numpy.float64)
    two = numpy.array([3.4, 6.7, 6.8, 8.2, 7.5, 8.3], dtype=numpy.float64)

    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()
    cs.initialize()

    writer = SimpleGridAscii()
    writer.inventory.filename = filename
    writer._configure()
    writer.write({'points': points,
                  'x': x,
                  'y': y,
                  'coordsys': cs,
                  'data_dim': 2,
                  'values': [{'name': "one",
                              'units': "m",
                              'data': one},
                             {'name': "two",
                              'units': "m",
                              'data': two},
                             ]})

    db = SimpleGridDB()
    db.inventory.label = "test"
    db.inventory.queryType = "nearest"
    db.inventory.filename = filename
    db._configure()
    self._db = db

    locs = numpy.array( [[0.1, 0.95]], numpy.float64)
    queryVals = ["two", "one"]
    dataE = numpy.array( [[8.2, 5.7]], numpy.float64)
    errE = [0]

    db = self._db
    db.open()
    db.queryVals(queryVals)
    data = numpy.zeros(dataE.shape, dtype=numpy.float64)
    err = []
    nlocs = locs.shape[0]
    for i in xrange(nlocs):
      e = db.query(data[i,:], locs[i,:], cs)
      err.append(e)
    db.close()    

    self.assertEqual(len(errE), len(err))
    for vE, v in zip(errE, err):
      self.assertEqual(vE, v)

    self.assertEqual(len(dataE.shape), len(data.shape))
    for dE, d in zip(dataE.shape, data.shape):
      self.assertEqual(dE, d)
    for vE, v in zip(numpy.reshape(dataE, -1), numpy.reshape(data, -1)):
      self.assertAlmostEqual(vE, v, 6)

    return
Exemple #9
0
xyz = numpy.zeros((npts, 3), dtype=numpy.float64)
xyz[:, 0] = x
for iy in xrange(ny):
    xyz[iy * nz:(iy + 1) * nz, 1] = y[iy]
    xyz[iy * nz:(iy + 1) * nz, 2] = z

zero = numpy.zeros((npts, ), dtype=numpy.float64)

r = ((xyz[:, 0] - hypoX)**2 + (xyz[:, 1] - hypoY)**2 +
     (xyz[:, 2] - hypoZ)**2)**0.5
tractionLL = dTshear * fnF(r)

cs = CSCart()
cs.initialize()

writer = SimpleGridAscii()
writer.inventory.filename = "traction_change.spatialdb"
writer._configure()
writer.write({
    'points':
    xyz,
    'x':
    x,
    'y':
    y,
    'z':
    z,
    'coordsys':
    cs,
    'data_dim':
    2,
f0 = 0.6*numpy.ones( (npts,), dtype=numpy.float64)
v0 = 1.0e-6*numpy.ones( (npts,), dtype=numpy.float64)
a = 0.008 + 0.008*(1.0 - fnB(xyz[:,1], W, taperW)*fnB(-xyz[:,2]-7.5e+3,0.5*W,taperW))
b = 0.012*numpy.ones( (npts,), dtype=numpy.float64)
L = 0.02*numpy.ones( (npts,), dtype=numpy.float64)
cohesion = numpy.zeros( (npts,), dtype=numpy.float64)
vi = 1.0e-12
Tshear = 75.0e+6
Tnormal = -120.0e+6

theta0 = L/v0*numpy.exp(1.0/b*(-Tshear/Tnormal - f0 - a*numpy.log(vi/v0)))

cs = CSCart()
cs.initialize()

writer = SimpleGridAscii()
writer.inventory.filename = "friction.spatialdb"
writer._configure()
writer.write({'points': xyz,
              'x': x,
              'y': y,
              'z': z,
              'coordsys': cs,
              'data_dim': 2,
              'values': [{'name': "reference-friction-coefficient",
                          'units': "none",
                          'data': f0},
                         {'name': "reference-slip-rate",
                          'units': "m/s",
                          'data': v0},
                         {'name': "characteristic-slip-distance",