Esempio n. 1
0
def generatePerturbation():
    PERT_DX = 500.0
    PERT_AMPLITUDE = 1.0e-2

    x = numpy.arange(XLIM[0],
                     XLIM[1] + 0.1 * PERT_DX,
                     PERT_DX,
                     dtype=numpy.float64)
    y = numpy.arange(YLIM[0],
                     YLIM[1] + 0.1 * PERT_DX,
                     PERT_DX,
                     dtype=numpy.float64)
    xgrid, ygrid = numpy.meshgrid(x, y)
    points = numpy.vstack((xgrid.ravel(), ygrid.ravel())).transpose()
    npts = points.shape[0]

    disp = PERT_AMPLITUDE * (numpy.random.rand(npts, 2) - 0.5)
    disp_dot = 0 * disp

    # Create writer for spatial database file
    writer = createWriter(
        "IsotropicLinearMaxwellPlaneStrain_VarStrain_pert.spatialdb")
    writer.write({
        'points':
        points,
        'x':
        x,
        'y':
        y,
        'coordsys':
        cs,
        'data_dim':
        2,
        'values': [
            {
                'name': "displacement_x",
                'units': "m",
                'data': disp[:, 0]
            },
            {
                'name': "displacement_y",
                'units': "m",
                'data': disp[:, 1]
            },
            {
                'name': "displacement_dot_x",
                'units': "m/s",
                'data': disp_dot[:, 0]
            },
            {
                'name': "displacement_dot_y",
                'units': "m/s",
                'data': disp_dot[:, 1]
            },
        ]
    })

    return
Esempio n. 2
0
def generateSolution():

    disp = numpy.zeros((npts, 2))
    disp[:, 0] = (A * PX**2 + 2.0 * B * PX * PY + C * PY**2) * \
        math.exp(-TIME / maxwellTime)
    disp[:, 1] = (A * PY**2 + 2.0 * B * PX * PY + C * PX**2) * \
        math.exp(-TIME / maxwellTime)

    disp_dot = numpy.zeros((npts, 2))
    disp_dot[:, 0] = -(A * PX**2 + 2.0 * B * PX * PY + C * PY**2) * math.exp(
        -TIME / maxwellTime) / maxwellTime
    disp_dot[:, 1] = -(A * PY**2 + 2.0 * B * PX * PY + C * PX**2) * math.exp(
        -TIME / maxwellTime) / maxwellTime

    # Create writer for spatial database file
    writer = createWriter(
        "IsotropicLinearMaxwellPlaneStrain_VarStrain_soln.spatialdb")
    writer.write({
        'points':
        points,
        'x':
        x,
        'y':
        y,
        'coordsys':
        cs,
        'data_dim':
        2,
        'values': [
            {
                'name': "displacement_x",
                'units': "m",
                'data': disp[:, 0]
            },
            {
                'name': "displacement_y",
                'units': "m",
                'data': disp[:, 1]
            },
            {
                'name': "displacement_dot_x",
                'units': "m/s",
                'data': disp_dot[:, 0]
            },
            {
                'name': "displacement_dot_y",
                'units': "m/s",
                'data': disp_dot[:, 1]
            },
        ]
    })

    return
Esempio n. 3
0
    def _writeSpatialdb(self):
        """Write spatial database with fault slip.
        """
        llSlipInfo = {
            'name': "left-lateral-slip",
            'units': "m",
            'data': self.faultSlip[:, 0]
        }

        udSlipInfo = {
            'name': "reverse-slip",
            'units': "m",
            'data': self.faultSlip[:, 1]
        }

        openInfo = {
            'name': "fault-opening",
            'units': "m",
            'data': self.faultSlip[:, 2]
        }

        data = {
            'num-x': self.lon.shape[0],
            'num-y': self.lat.shape[0],
            'num-z': 1,
            'points': self.grid,
            'x': self.lon,
            'y': self.lat,
            'z': self.z,
            'coordsys': self.coordsys,
            'data_dim': 2,
            'values': [llSlipInfo, udSlipInfo, openInfo]
        }

        writer = createWriter(self.dbFilename)
        writer.write(data)
Esempio n. 4
0
def generateAuxSubfields():
    totalStrain_11 = (2.0 * A * PX + B * PY) * math.exp(-TIME / maxwellTime)
    totalStrain_12 = (B * PX / 2.0 + B * PY / 2.0 + C * PX +
                      C * PY) * math.exp(-TIME / maxwellTime)
    totalStrain_22 = (2.0 * A * PY + B * PX) * math.exp(-TIME / maxwellTime)
    totalStrain_33 = numpy.zeros_like(totalStrain_22)

    visStrain_11 = (math.exp(TIME / maxwellTime) - 1.0) * (A * PX - A * PY - B * PX + B * PY) * \
        math.exp(-2.0 * TIME / maxwellTime)
    visStrain_12 = (math.exp(TIME / maxwellTime) - 1.0) * (B * PX + B * PY + C * PX + C * PY) * \
        math.exp(-2.0 * TIME / maxwellTime)
    visStrain_22 = -(math.exp(TIME / maxwellTime) - 1.0) * (A * PX - A * PY - B * PX + B * PY) * \
        math.exp(-2.0 * TIME / maxwellTime)
    visStrain_33 = -(math.exp(TIME / maxwellTime) - 1.0) * (A * PX + A * PY + B * PX + B * PY) * \
        math.exp(-2.0 * TIME / maxwellTime)

    equil_1 = 4.0 * bulkModulus * \
        (A + B) * math.exp(-TIME / maxwellTime) * \
        numpy.ones(npts, dtype=numpy.float64)
    equil_2 = 4.0 * bulkModulus * \
        (A + B) * math.exp(-TIME / maxwellTime) * \
        numpy.ones(npts, dtype=numpy.float64)

    writer = createWriter(
        "IsotropicLinearMaxwellPlaneStrain_VarStrain_aux.spatialdb")
    writer.write({
        'points':
        points,
        'x':
        x,
        'y':
        y,
        'coordsys':
        cs,
        'data_dim':
        2,
        'values': [
            {
                'name': "vs",
                'units': "m/s",
                'data': vs
            },
            {
                'name': "vp",
                'units': "m/s",
                'data': vp
            },
            {
                'name': "density",
                'units': "kg/m**3",
                'data': density
            },
            {
                'name': "viscosity",
                'units': "Pa*s",
                'data': viscosity
            },
            {
                'name': "total_strain_xx",
                'units': "None",
                'data': totalStrain_11
            },
            {
                'name': "total_strain_yy",
                'units': "None",
                'data': totalStrain_22
            },
            {
                'name': "total_strain_zz",
                'units': "None",
                'data': totalStrain_33
            },
            {
                'name': "total_strain_xy",
                'units': "None",
                'data': totalStrain_12
            },
            {
                'name': "vis_strain_xx",
                'units': "None",
                'data': visStrain_11
            },
            {
                'name': "vis_strain_yy",
                'units': "None",
                'data': visStrain_22
            },
            {
                'name': "vis_strain_zz",
                'units': "None",
                'data': visStrain_33
            },
            {
                'name': "vis_strain_xy",
                'units': "None",
                'data': visStrain_12
            },
            {
                'name': "body_force_x",
                'units': "N",
                'data': equil_1
            },
            {
                'name': "body_force_y",
                'units': "N",
                'data': equil_2
            },
        ]
    })
    return
Esempio n. 5
0
    def test_io_3d(self):
        from spatialdata.spatialdb.SimpleGridAscii import createWriter

        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()

        writer = createWriter(filename)
        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.setQueryValues(queryVals)
        data = numpy.zeros(dataE.shape, dtype=numpy.float64)
        err = []
        nlocs = locs.shape[0]
        for i in range(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)