Пример #1
0
  def _runTest(self, filenameIn, filenameOut, filenameOutE, faultGroup=None):

    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    io = MeshIOAscii()
    io.inventory.filename = filenameIn
    io.inventory.coordsys = cs
    io._configure()
    
    mesh = io.read(debug=False, interpolate=True)

    if not faultGroup is None:
      from pylith.faults.FaultCohesiveKin import FaultCohesiveKin
      fault = FaultCohesiveKin()
      fault.inventory.matId = 10
      fault.inventory.faultLabel = faultGroup
      fault._configure()

      nvertices = fault.numVerticesNoMesh(mesh)
      firstFaultVertex = 0
      firstLagrangeVertex = nvertices
      firstFaultCell      = 2*nvertices
      fault.adjustTopology(mesh, 
                           firstFaultVertex, 
                           firstLagrangeVertex,
                           firstFaultCell)

    from pylith.topology.RefineUniform import RefineUniform
    refiner = RefineUniform()
    meshRefined = refiner.refine(mesh)

    return
Пример #2
0
    def setUp(self):
        """
    Setup mesh and associated field.
    """
        from spatialdata.geocoords.CSCart import CSCart

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

        from spatialdata.units.Nondimensional import Nondimensional

        normalizer = Nondimensional()
        normalizer._configure()

        from pylith.meshio.MeshIOAscii import MeshIOAscii

        importer = MeshIOAscii()
        importer.inventory.filename = "data/tri3.mesh"
        importer.inventory.coordsys = cs
        importer._configure()
        self.mesh = importer.read(debug=False, interpolate=False)

        self.field = Field(self.mesh)
        self.field.allocate()
        return
Пример #3
0
  def test_readwrite(self):
    """
    Test write() and read().
    """
    filenameIn = "data/mesh2Din3D.txt"
    filenameOut = "data/mesh2Din3D_test.txt"

    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs._configure()

    io = MeshIOAscii()
    io.inventory.filename = filenameIn
    io.inventory.coordsys = cs
    io._configure()
    
    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()

    mesh = io.read(debug=False, interpolate=True)

    io.filename(filenameOut)
    io.write(mesh)

    fileE = open(filenameIn, "r")
    linesE = fileE.readlines()
    fileE.close()
    fileT = open(filenameOut, "r")
    linesT = fileT.readlines()
    fileT.close()

    self.assertEqual(len(linesE), len(linesT))
    for (lineE, lineT) in zip(linesE, linesT):
      self.assertEqual(lineE, lineT)
    return
Пример #4
0
    def test_databasemulti(self):
        locs = numpy.array([[2.3, -0.1, 1.8], [2.0, 0.4, -2.0]], numpy.float64)
        cs = CSCart()
        cs._configure()
        queryVals = ["two", "one"]
        dataE = numpy.array([[0.0207, 1.17], [0.0209, 1.15]], numpy.float64)
        errE = numpy.array([0, 0], numpy.int32)

        db = self._db
        db.open()
        db.queryVals(queryVals)
        data = numpy.zeros(dataE.shape, dtype=numpy.float64)
        err = numpy.zeros(errE.shape, dtype=numpy.int32)
        db.multiquery(data, err, locs, cs)
        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
Пример #5
0
  def setUp(self):
    """
    Setup mesh and associated field.
    """
    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()    

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    self.mesh = importer.read(debug=False, interpolate=False)

    from pylith.topology.SolutionFields import SolutionFields
    fields = SolutionFields(self.mesh)
    fields.add("disp t+dt", "displacement")
    fields.solutionName("disp t+dt")
    solution = fields.solution()
    solution.newSection(solution.VERTICES_FIELD, self.mesh.dimension())
    solution.allocate()
    solution.zero()

    self.fields = fields
    self.jacobian = Jacobian(solution)
    return
Пример #6
0
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
Пример #7
0
    def test_database(self):
        locs = numpy.array([[3.5, 0.1, 0.8], [8.0, -0.4, 1.8]], numpy.float64)
        cs = CSCart()
        cs._configure()
        queryVals = ["two", "one"]
        dataE = numpy.array([[0.0220, 1.04], [0.0222, 1.02]], numpy.float64)
        errE = [0, 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
Пример #8
0
  def test_preinitialize(self):
    """
    Test preinitialize().

    WARNING: This is not a rigorous test of initialize() because we
    don't verify the results.
    """
    from pylith.feassemble.FIATSimplex import FIATSimplex
    cell = FIATSimplex()
    cell.inventory.dimension = 2
    cell.inventory.order = 1
    cell.inventory.degree = 1
    cell._configure()

    from pylith.feassemble.Quadrature import Quadrature
    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature.inventory.minJacobian = 1.0e-4
    quadrature._configure()

    from spatialdata.spatialdb.SimpleDB import SimpleDB
    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    iohandler = SimpleIOAscii()
    iohandler.inventory.filename = "data/matinitialize.spatialdb"
    iohandler._configure()
    db = SimpleDB()
    db.inventory.label = "material properties"
    db.inventory.iohandler = iohandler
    db._configure()

    from pylith.materials.ElasticPlaneStrain import ElasticPlaneStrain
    material = ElasticPlaneStrain()
    material.inventory.quadrature = quadrature
    material.inventory.dbProperties = db
    material.inventory.label = "my material"
    material.inventory.id = 54
    material._configure()

    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/twoelems.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)
    
    material.preinitialize(mesh)

    # No test of result.
    return
  def _preinitialize(self):
    """
    Setup mesh and integrator and preinitialize integrator.
    """
    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    # Setup mesh
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()
    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)

    # Setup material
    from pylith.feassemble.FIATSimplex import FIATSimplex
    cell = FIATSimplex()
    cell.inventory.dimension = 2
    cell.inventory.degree = 1
    cell.inventory.order = 1
    cell._configure()
    from pylith.feassemble.Quadrature import Quadrature
    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature._configure()
    
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    iohandler = SimpleIOAscii()
    iohandler.inventory.filename = "data/elasticplanestrain.spatialdb"
    iohandler._configure()
    db = SimpleDB()
    db.inventory.label = "elastic plane strain"
    db.inventory.iohandler = iohandler
    db._configure()

    from pylith.materials.ElasticPlaneStrain import ElasticPlaneStrain
    material = ElasticPlaneStrain()
    material.inventory.label = "elastic plane strain"
    material.inventory.id = 0
    material.inventory.dbProperties = db
    material.inventory.quadrature = quadrature
    material._configure()
    
    from pylith.meshio.OutputMatElastic import OutputMatElastic
    material.output = OutputMatElastic()
    material.output._configure()
    material.output.writer._configure()

    # Setup integrator
    integrator = ElasticityImplicitLgDeform()
    integrator.preinitialize(mesh, material)
    return (mesh, integrator)
Пример #10
0
  def test(self):
    """
    Test GenSimpleDBApp with 1-D data in 2-D space.
    """
    from spatialdata.spatialdb.generator.GenSimpleDBApp import GenSimpleDBApp
    from spatialdata.geocoords.CSCart import CSCart
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    
    app = GenSimpleDBApp()
    app.run()

    # Test write using query
    db = SimpleDB()
    db.inventory.iohandler.inventory.filename = \
        "data/gen1Din2D.spatialdb"
    db.inventory.iohandler._configure()
    db.inventory.label = "test"
    db.inventory.queryType = "nearest"
    db._configure()

    qlocs = numpy.array( [[-2.0,  2.0],
                          [ 3.0, -4.0],
                          [ 0.0,  0.7]],
                         numpy.float64)
    
    dataE = numpy.array( [[-0.15, 3.45],
                          [2.4, 6.4],
                          [-0.6, 3.45]], numpy.float64)
    errE = [0, 0, 0]

    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    db.open()
    db.queryVals(["two", "one"])
    data = numpy.zeros(dataE.shape, dtype=numpy.float64)
    err = []
    nlocs = qlocs.shape[0]
    for i in xrange(nlocs):
      e = db.query(data[i,:], qlocs[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
Пример #11
0
  def test_initialize(self):
    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.units = "km"
    cs.inventory.spaceDim = 2
    cs._configure()
    cs.initialize()

    self.assertEqual(1.0e+3, cs.toMeters())
    self.assertEqual(2, cs.spaceDim())

    return
Пример #12
0
  def _initialize(self):
    """
    Initialize DirichletBoundary boundary condition.
    """
    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)
    
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    db = SimpleDB()
    db.inventory.label = "TestDirichletBoundary tri3"
    db.inventory.iohandler.inventory.filename = "data/tri3_disp.spatialdb"
    db.inventory.iohandler._configure()
    db._configure()

    from spatialdata.spatialdb.SimpleDB import SimpleDB
    dbRate = SimpleDB()
    dbRate.inventory.label = "TestDirichletBoundary tri3"
    dbRate.inventory.iohandler.inventory.filename = "data/tri3_vel.spatialdb"
    dbRate.inventory.iohandler._configure()
    dbRate._configure()

    from pylith.bc.DirichletBoundary import DirichletBoundary
    bc = DirichletBoundary()
    bc.inventory.output._configure()
    bc.inventory.output.writer._configure()
    bc.inventory.label = "bc"
    bc.inventory.bcDOF = [1]
    bc.inventory.dbInitial = db
    bc.inventory.dbRate = dbRate
    bc._configure()

    bc.preinitialize(mesh)
    bc.initialize(totalTime=0.0, numTimeSteps=1, normalizer=normalizer)

    # Setup field
    from pylith.topology.Field import Field
    field = Field(mesh)
    field.newSection(field.VERTICES_FIELD, cs.spaceDim())
    
    return (mesh, bc, field)
Пример #13
0
  def test_coordsys(self):
    """
    Test coordsys().
    """
    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    mesh = Mesh()
    mesh.coordsys(cs)
    self.assertEqual(cs.spaceDim(), mesh.coordsys().spaceDim())
    return
Пример #14
0
  def run(self):
    """
    Generate the database.
    """
    # Domain
    x = numpy.arange(-4000.0, 4000.1, 500.0)
    y = numpy.arange(-4000.0, 4000.1, 500.0)
    z = numpy.arange(-6000.0,    0.1, 500.0)
    nxpts = x.shape[0]
    nypts = y.shape[0]
    nzpts = z.shape[0]

    xx = numpy.tile(x, (1,nypts*nzpts))
    yy = numpy.tile(y, (nxpts,nzpts)).transpose()
    zz = numpy.tile(z, (nxpts*nypts,1)).transpose()

    xyz = numpy.zeros( (nxpts*nypts*nzpts, 3), dtype=numpy.float64)
    xyz[:,0] = numpy.ravel(xx)
    xyz[:,1] = numpy.ravel(yy)
    xyz[:,2] = numpy.ravel(zz)

    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 = {'points': xyz,
            'coordsys': cs,
            'data_dim': 3,
            'values': [{'name': "displacement-x",
                        'units': "m",
                        'data': numpy.ravel(disp[:,0])},
                       {'name': "displacement-y",
                        'units': "m",
                        'data': numpy.ravel(disp[:,1])},
                       {'name': "displacement-z",
                        'units': "m",
                        'data': numpy.ravel(disp[:,2])}]}

    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    io = SimpleIOAscii()
    io.inventory.filename = "axial_disp.spatialdb"
    io._configure()
    io.write(data)
    return
Пример #15
0
  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)
    z = numpy.arange(-6000.0, 0000.1, 1000.0)
    nptsX = x.shape[0]
    nptsY = y.shape[0]
    nptsZ = z.shape[0]

    xx = x * numpy.ones( (nptsY*nptsZ, 1), dtype=numpy.float64)
    yy0 = y * numpy.ones( (nptsZ, 1), dtype=numpy.float64)
    yy = yy0.ravel() * numpy.ones( (nptsX, 1), dtype=numpy.float64)
    zz = z * numpy.ones( (nptsX*nptsY, 1), dtype=numpy.float64)
    xyz = numpy.zeros( (nptsX*nptsY*nptsZ, 3), dtype=numpy.float64)
    xyz[:,0] = numpy.ravel(xx)
    xyz[:,1] = numpy.ravel(numpy.transpose(yy))
    xyz[:,2] = numpy.ravel(numpy.transpose(zz))

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

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

    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    io = SimpleIOAscii()
    io.inventory.filename = "rigidbody_disp.spatialdb"
    io._configure()
    io.write(data)
    return
Пример #16
0
  def run(self):
    """
    Generate the database.
    """
    from sheardisp_soln import AnalyticalSoln
    soln = AnalyticalSoln()

    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 3
    cs._configure()

    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    io = SimpleIOAscii()

    for component in ["x","y","z"]:
      if component == "y":
        xyz = numpy.array([[-40.0e+3, 0.0, 0.0],
                           [+40.0e+3, 0.0, 0.0]], dtype=numpy.float64)
        ic = 1
      elif component == "x":
        xyz = numpy.array([[0.0, -40.0e+3, 0.0],
                           [0.0, +40.0e+3, 0.0]], dtype=numpy.float64)
        ic = 0
      elif component == "z":
        xyz = numpy.array([[0.0, 0.0, -40.0e+3],
                           [0.0, 0.0,   0.0]], dtype=numpy.float64)
        ic = 2
      disp = soln.displacement(xyz)

      io.inventory.filename = "shear_disp%s.spatialdb" % component
      io._configure()
      data = {'points': xyz,
              'coordsys': cs,
              'data_dim': 1,
              'values': [{'name': "displacement-%s" % component,
                          'units': "m",
                          'data': numpy.ravel(disp[0,:,ic])},
                         ]}
      io.write(data)
    
    return
Пример #17
0
    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 sheardisp_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": "displacement-x", "units": "m", "data": numpy.ravel(disp[0, :, 0])},
                {"name": "displacement-y", "units": "m", "data": numpy.ravel(disp[0, :, 1])},
            ],
        }

        from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii

        io = SimpleIOAscii()
        io.inventory.filename = "shear_disp.spatialdb"
        io._configure()
        io.write(data)
        return
Пример #18
0
  def test_readwrite(self):
    """
    Test read().
    """
    filenameGmvIn = "data/cube2_ascii.gmv"
    filenamePsetIn = "data/cube2_ascii.pset"
    filenameOut = "data/cube2_test.txt"
    filenameE = "data/cube2.txt"

    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs._configure()

    # For now, we only test reading the file. We would like to write
    # the file and compare against the original.
    io = MeshIOLagrit()
    io.inventory.filenameGmv = filenameGmvIn
    io.inventory.filenamePset = filenamePsetIn
    io._configure()

    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()

    mesh = io.read(debug=False, interpolate=True)

    testhandler = MeshIOAscii()
    testhandler.filename(filenameOut)
    testhandler.coordsys = cs
    testhandler.write(mesh)

    fileE = open(filenameE, "r")
    linesE = fileE.readlines()
    fileE.close()
    fileT = open(filenameOut, "r")
    linesT = fileT.readlines()
    fileT.close()

    self.assertEqual(len(linesE), len(linesT))
    for (lineE, lineT) in zip(linesE, linesT):
      self.assertEqual(lineE, lineT)
    return
Пример #19
0
    def test_readwrite(self):
        """
    Test read().
    """
        filenameIn = "data/twohex8.exo"
        filenameOut = "data/twohex8_test.txt"
        filenameE = "data/twohex8.txt"

        from spatialdata.geocoords.CSCart import CSCart

        cs = CSCart()
        cs._configure()

        # For now, we only test reading the file.
        io = MeshIOCubit()
        io.inventory.filename = filenameIn
        io.inventory.useNames = False
        io._configure()

        from spatialdata.units.Nondimensional import Nondimensional

        normalizer = Nondimensional()

        mesh = io.read(debug=False, interpolate=False)

        testhandler = MeshIOAscii()
        testhandler.filename(filenameOut)
        testhandler.coordsys = cs
        testhandler.write(mesh)

        fileE = open(filenameE, "r")
        linesE = fileE.readlines()
        fileE.close()
        fileT = open(filenameOut, "r")
        linesT = fileT.readlines()
        fileT.close()

        self.assertEqual(len(linesE), len(linesT))
        for (lineE, lineT) in zip(linesE, linesT):
            self.assertEqual(lineE, lineT)
        return
Пример #20
0
  def run(self):
    """
    Generate the database.
    """
    # Domain
    dx = 200.0
    x = numpy.arange(-1000.0, 1000.1, dx)
    y = numpy.arange(-1000.0, 0.1, dx)
    nptsx = x.shape[0]
    nptsy = y.shape[0]

    xx = x * numpy.ones( (nptsy, 1), dtype=numpy.float64)
    yy = y * numpy.ones( (nptsx, 1), dtype=numpy.float64)
    xy = numpy.zeros( (nptsx*nptsy, 2), dtype=numpy.float64)
    xy[:,0] = numpy.ravel(xx)
    xy[:,1] = numpy.ravel(numpy.transpose(yy))

    from compressrotate_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': "displacement-x",
                        'units': "m",
                        'data': numpy.ravel(disp[0,:,0])},
                       {'name': "displacement-y",
                        'units': "m",
                        'data': numpy.ravel(disp[0,:,1])}]}

    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    io = SimpleIOAscii()
    io.inventory.filename = "compressrotate_disp.spatialdb"
    io._configure()
    io.write(data)
    return
Пример #21
0
  def _getMesh(self):
    """
    Get mesh from file.
    """
    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()    

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)
    
    return mesh
Пример #22
0
  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': "displacement-x",
                        'units': "m",
                        'data': numpy.ravel(disp[0,:,0])},
                       {'name': "displacement-y",
                        'units': "m",
                        'data': numpy.ravel(disp[0,:,1])}]}

    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    io = SimpleIOAscii()
    io.inventory.filename = "axial_disp.spatialdb"
    io._configure()
    io.write(data)
    return
Пример #23
0
    def test_readwrite(self):
        """
    Test read().
    """
        filenameIn = "data/twohex8.exo"
        filenameOut = "data/twohex8_test.txt"
        filenameE = "data/twohex8.txt"

        from spatialdata.geocoords.CSCart import CSCart
        cs = CSCart()
        cs._configure()

        # For now, we only test reading the file.
        io = MeshIOCubit()
        io.inventory.filename = filenameIn
        io.inventory.useNames = False
        io._configure()

        from spatialdata.units.Nondimensional import Nondimensional
        normalizer = Nondimensional()

        mesh = io.read(debug=False, interpolate=True)

        testhandler = MeshIOAscii()
        testhandler.filename(filenameOut)
        testhandler.coordsys = cs
        testhandler.write(mesh)

        fileE = open(filenameE, "r")
        linesE = fileE.readlines()
        fileE.close()
        fileT = open(filenameOut, "r")
        linesT = fileT.readlines()
        fileT.close()

        self.assertEqual(len(linesE), len(linesT))
        for (lineE, lineT) in zip(linesE, linesT):
            self.assertEqual(lineE, lineT)
        return
Пример #24
0
  def setUp(self):
    """
    Setup mesh and associated field.
    """
    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()    

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    self.mesh = importer.read(debug=False, interpolate=False)
    
    self.fields = Fields(self.mesh)
    return
Пример #25
0
  def test_adjustTopology(self):
    """
    Test adjustTopology().

    WARNING: This is not a rigorous test of adjustTopology() because we
    neither set the input fields or verify the results.
    """
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()
    
    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)

    fault = FaultCohesiveKin()
    fault.inventory.matId = 10
    fault.inventory.faultLabel = "fault"
    fault.inventory.faultEdge = "fault_edge"
    fault._configure()

    nvertices = fault.numVerticesNoMesh(mesh)
    firstFaultVertex = 0
    firstLagrangeVertex = nvertices
    firstFaultCell      = 2*nvertices
    fault.adjustTopology(mesh, firstFaultVertex, firstLagrangeVertex,
                         firstFaultCell)

    # We should really add something here to check to make sure things
    # actually initialized correctly    
    return
Пример #26
0
  def test_adjustTopology(self):
    """
    Test adjustTopology().

    WARNING: This is not a rigorous test of adjustTopology() because we
    neither set the input fields or verify the results.
    """
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()
    
    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)

    fault = FaultCohesiveKin()
    fault.inventory.matId = 10
    fault.inventory.faultLabel = "fault"
    fault.inventory.faultEdge = "fault_edge"
    fault._configure()

    nvertices = fault.numVerticesNoMesh(mesh)
    firstFaultVertex = 0
    firstLagrangeVertex = nvertices
    firstFaultCell      = 2*nvertices
    fault.adjustTopology(mesh, firstFaultVertex, firstLagrangeVertex,
                         firstFaultCell)

    # We should really add something here to check to make sure things
    # actually initialized correctly    
    return
Пример #27
0
  def run(self):
    """
    Generate the database.
    """
    # Domain
    x = numpy.arange(-4000.0, 4000.1, 500.0)
    y = numpy.arange(-4000.0, 4000.1, 500.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))

    disp = self.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': "displacement-x",
                        'units': "m",
                        'data': numpy.ravel(disp[0,:,0])},
                       {'name': "displacement-y",
                        'units': "m",
                        'data': numpy.ravel(disp[0,:,1])}]}

    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    io = SimpleIOAscii()
    io.inventory.filename = self.filename
    io._configure()
    io.write(data)
    return
Пример #28
0
  def _initialize(self):
    """
    Initialize fault.
    """
    dt = 2.4
    
    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    # Setup mesh
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)

    # Setup quadrature
    from pylith.feassemble.FIATSimplex import FIATSimplex
    cell = FIATSimplex()
    cell.inventory.dimension = 1
    cell.inventory.degree = 1
    cell.inventory.order = 1
    cell._configure()
    from pylith.feassemble.Quadrature import Quadrature
    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature._configure()

    # Setup earthquake source
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    ioFinalSlip = SimpleIOAscii()
    ioFinalSlip.inventory.filename = "data/tri3_finalslip.spatialdb"
    ioFinalSlip._configure()
    dbFinalSlip = SimpleDB()
    dbFinalSlip.inventory.iohandler = ioFinalSlip
    dbFinalSlip.inventory.label = "final slip"
    dbFinalSlip._configure()
    
    ioSlipTime = SimpleIOAscii()
    ioSlipTime.inventory.filename = "data/tri3_sliptime.spatialdb"
    ioSlipTime._configure()
    dbSlipTime = SimpleDB()
    dbSlipTime.inventory.iohandler = ioSlipTime
    dbSlipTime.inventory.label = "slip time"
    dbSlipTime._configure()
    
    from pylith.faults.StepSlipFn import StepSlipFn
    slipfn = StepSlipFn()
    slipfn.inventory.dbSlip = dbFinalSlip
    slipfn.inventory.dbSlipTime = dbSlipTime
    slipfn._configure()

    # Setup fault
    fault = FaultCohesiveKin()
    fault.inventory.output.inventory.writer._configure()
    fault.inventory.output._configure()
    fault.inventory.matId = 10
    fault.inventory.faultLabel = "fault"
    fault.inventory.upDir = [0, 0, 1]
    fault.inventory.faultQuadrature = quadrature
    fault._configure()
    eqsrc = fault.eqsrcs.components()[0]
    eqsrc.inventory.originTime = 1.23*second
    eqsrc.inventory.slipfn = slipfn
    eqsrc._configure()

    nvertices = fault.numVerticesNoMesh(mesh)
    firstFaultVertex = 0
    firstLagrangeVertex = nvertices
    firstFaultCell      = 2*nvertices
    fault.adjustTopology(mesh, firstFaultVertex, firstLagrangeVertex,
                         firstFaultCell)
    fault.preinitialize(mesh)
    fault.timeStep(dt)
    fault.verifyConfiguration()
    from pyre.units.time import s
    fault.initialize(totalTime=0.0*s, numTimeSteps=1, normalizer=normalizer)

    # Setup fields
    from pylith.topology.SolutionFields import SolutionFields
    fields = SolutionFields(mesh)
    fields.add("residual", "residual")
    fields.add("dispIncr(t->t+dt)", "displacement_increment")
    fields.add("disp(t)", "displacement")
    fields.solutionName("dispIncr(t->t+dt)")

    residual = fields.get("residual")
    residual.subfieldAdd("displacement", cs.spaceDim(), residual.VECTOR)
    residual.subfieldAdd("lagrange_multiplier", cs.spaceDim(), residual.VECTOR)
    residual.subfieldsSetup()
    residual.setupSolnChart()
    residual.setupSolnDof(cs.spaceDim())
    fault.setupSolnDof(residual)
    residual.allocate()
    residual.zero()

    fields.copyLayout("residual")
    
    return (mesh, fault, fields)
Пример #29
0
    def run(self):
        """Generate the database.
        """
        # Domain
        x1 = numpy.arange(-0.1, 10.1, 0.1)
        y1 = numpy.arange(-0.1, 1.01, 0.1)
        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 mandel_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': "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_pressure",
                'units': "Pa",
                'data': numpy.ravel(pres[0, :])
            }, {
                'name': "initial_trace_strain",
                'units': "none",
                'data': numpy.ravel(trace_strain[0, :])
            }]
        }

        from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii
        io = SimpleGridAscii()
        io.inventory.filename = "mandel_bc.spatialdb"
        io._configure()
        io.write(data)
        data["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, :])
        }]
        io.inventory.filename = "mandel_ic.spatialdb"
        io._configure()
        io.write(data)
        return
Пример #30
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
Пример #31
0
    def run(self):
        """Generate the database.
        """
        # Domain
        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 axialstrainrate_genmaxwell_soln import AnalyticalSoln
        soln = AnalyticalSoln()
        disp = soln.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':
            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()
            }, {
                '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 = "axialstrainrate_genmaxwell_bc.spatialdb"
        io._configure()
        io.write(data)
        return
Пример #32
0
    def _initialize(self):
        """
    Initialize AbsorbingDampers boundary condition.
    """
        from spatialdata.spatialdb.SimpleDB import SimpleDB
        db = SimpleDB()
        db.inventory.label = "TestAbsorbingDampers tri3"
        db.inventory.iohandler.inventory.filename = \
            "data/elasticplanestrain.spatialdb"
        db.inventory.iohandler._configure()
        db._configure()

        from pylith.feassemble.FIATSimplex import FIATSimplex
        cell = FIATSimplex()
        cell.inventory.dimension = 1
        cell.inventory.degree = 1
        cell.inventory.order = 1
        cell._configure()
        from pylith.feassemble.Quadrature import Quadrature
        quadrature = Quadrature()
        quadrature.inventory.cell = cell
        quadrature._configure()

        from pylith.bc.AbsorbingDampers import AbsorbingDampers
        bc = AbsorbingDampers()
        bc.inventory.quadrature = quadrature
        bc.inventory.db = db
        bc.inventory.id = 0
        bc.inventory.label = "bc"
        bc._configure()

        from spatialdata.geocoords.CSCart import CSCart
        cs = CSCart()
        cs.inventory.spaceDim = 2
        cs._configure()

        from spatialdata.units.Nondimensional import Nondimensional
        normalizer = Nondimensional()
        normalizer._configure()

        from pylith.meshio.MeshIOAscii import MeshIOAscii
        importer = MeshIOAscii()
        importer.inventory.filename = "data/tri3.mesh"
        importer.inventory.coordsys = cs
        importer._configure()
        mesh = importer.read(debug=False, interpolate=False)

        bc.preinitialize(mesh)
        bc.initialize(totalTime=0.0, numTimeSteps=1, normalizer=normalizer)
        bc.timeStep(0.01)

        # Setup fields
        from pylith.topology.SolutionFields import SolutionFields
        fields = SolutionFields(mesh)
        fields.add("residual", "residual")
        fields.add("dispIncr(t->t+dt)", "displacement")
        fields.add("disp(t)", "displacement")
        fields.add("disp(t-dt)", "displacement")
        fields.add("velocity(t)", "velocity")
        fields.solutionName("dispIncr(t->t+dt)")

        residual = fields.get("residual")
        residual.newSection(residual.VERTICES_FIELD, cs.spaceDim())
        residual.allocate()
        residual.zero()

        fields.copyLayout("residual")

        return (mesh, bc, fields)
Пример #33
0
    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
Пример #34
0
    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 sheartraction_rate_soln import AnalyticalSoln
        soln = AnalyticalSoln()
        disp = soln.bc_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("sheartraction_rate_disp.spatialdb")
        io.write(data)
        return
Пример #35
0
  def _initialize(self):
    """
    Initialize fault.
    """
    dt = 2.4
    
    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    # Setup mesh
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)

    # Setup quadrature
    from pylith.feassemble.FIATSimplex import FIATSimplex
    cell = FIATSimplex()
    cell.inventory.dimension = 1
    cell.inventory.degree = 1
    cell.inventory.order = 1
    cell._configure()
    from pylith.feassemble.Quadrature import Quadrature
    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature._configure()

    # Setup impulses
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    ioImpulseAmp = SimpleIOAscii()
    ioImpulseAmp.inventory.filename = "data/tri3_impulses.spatialdb"
    ioImpulseAmp._configure()
    dbImpulseAmp = SimpleDB()
    dbImpulseAmp.inventory.iohandler = ioImpulseAmp
    dbImpulseAmp.inventory.label = "impulse amplitude"
    dbImpulseAmp._configure()
    
    # Setup fault
    fault = FaultCohesiveImpulses()
    fault.inventory.output.inventory.writer._configure()
    fault.inventory.output._configure()
    fault.inventory.matId = 10
    fault.inventory.faultLabel = "fault"
    fault.inventory.upDir = [0, 0, 1]
    fault.inventory.faultQuadrature = quadrature
    fault.inventory.dbImpulseAmp = dbImpulseAmp
    fault._configure()

    nvertices = fault.numVerticesNoMesh(mesh)
    firstFaultVertex = 0
    firstLagrangeVertex = nvertices
    firstFaultCell      = 2*nvertices
    fault.adjustTopology(mesh, firstFaultVertex, firstLagrangeVertex,
                         firstFaultCell)
    fault.preinitialize(mesh)
    fault.timeStep(dt)
    fault.verifyConfiguration()
    from pyre.units.time import s
    fault.initialize(totalTime=0.0*s, numTimeSteps=1, normalizer=normalizer)

    # Setup fields
    from pylith.topology.SolutionFields import SolutionFields
    fields = SolutionFields(mesh)
    fields.add("residual", "residual")
    fields.add("dispIncr(t->t+dt)", "displacement_increment")
    fields.add("disp(t)", "displacement")
    fields.solutionName("dispIncr(t->t+dt)")

    residual = fields.get("residual")
    residual.subfieldAdd("displacement", cs.spaceDim(), residual.VECTOR)
    residual.subfieldAdd("lagrange_multiplier", cs.spaceDim(), residual.VECTOR)
    residual.subfieldsSetup()
    residual.setupSolnChart()
    residual.setupSolnDof(cs.spaceDim())
    fault.setupSolnDof(residual)
    residual.allocate()
    residual.zero()

    fields.copyLayout("residual")
    
    return (mesh, fault, fields)
Пример #36
0
    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
Пример #37
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
Пример #38
0
  def _initialize(self):
    """
    Initialize fault.
    """
    dt = 2.4
    
    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    # Setup mesh
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)

    # Setup quadrature
    from pylith.feassemble.FIATSimplex import FIATSimplex
    cell = FIATSimplex()
    cell.inventory.dimension = 1
    cell.inventory.degree = 1
    cell.inventory.order = 1
    cell._configure()
    from pylith.feassemble.Quadrature import Quadrature
    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature._configure()

    # Setup impulses
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    ioImpulseAmp = SimpleIOAscii()
    ioImpulseAmp.inventory.filename = "data/tri3_impulses.spatialdb"
    ioImpulseAmp._configure()
    dbImpulseAmp = SimpleDB()
    dbImpulseAmp.inventory.iohandler = ioImpulseAmp
    dbImpulseAmp.inventory.label = "impulse amplitude"
    dbImpulseAmp._configure()
    
    # Setup fault
    fault = FaultCohesiveImpulses()
    fault.inventory.output.inventory.writer._configure()
    fault.inventory.output._configure()
    fault.inventory.matId = 10
    fault.inventory.faultLabel = "fault"
    fault.inventory.upDir = [0, 0, 1]
    fault.inventory.faultQuadrature = quadrature
    fault.inventory.dbImpulseAmp = dbImpulseAmp
    fault._configure()

    nvertices = fault.numVerticesNoMesh(mesh)
    firstFaultVertex = 0
    firstLagrangeVertex = nvertices
    firstFaultCell      = 2*nvertices
    fault.adjustTopology(mesh, firstFaultVertex, firstLagrangeVertex,
                         firstFaultCell)
    fault.preinitialize(mesh)
    fault.timeStep(dt)
    fault.verifyConfiguration()
    from pyre.units.time import s
    fault.initialize(totalTime=0.0*s, numTimeSteps=1, normalizer=normalizer)

    # Setup fields
    from pylith.topology.SolutionFields import SolutionFields
    fields = SolutionFields(mesh)
    fields.add("residual", "residual")
    fields.add("dispIncr(t->t+dt)", "displacement_increment")
    fields.add("disp(t)", "displacement")
    fields.solutionName("dispIncr(t->t+dt)")
    residual = fields.get("residual")
    residual.newSection(residual.VERTICES_FIELD, cs.spaceDim())
    residual.allocate()
    residual.zero()
    fields.copyLayout("residual")
    
    return (mesh, fault, fields)
Пример #39
0
 def test_constructor(self):
     cs = CSCart()
     cs._configure()
     self.assertEqual(3, cs.getSpaceDim())
Пример #40
0
  def _initialize(self):
    """
    Initialize fault.
    """
    dt = 2.4
    
    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    # Setup mesh
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)

    # Setup quadrature
    from pylith.feassemble.FIATSimplex import FIATSimplex
    cell = FIATSimplex()
    cell.inventory.dimension = 1
    cell.inventory.degree = 1
    cell.inventory.order = 1
    cell._configure()
    from pylith.feassemble.Quadrature import Quadrature
    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature._configure()

    # Setup rupture info
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
    ioTractions = SimpleIOAscii()
    ioTractions.inventory.filename = "data/tri3_initialtractions.spatialdb"
    ioTractions._configure()
    dbTractions = SimpleDB()
    dbTractions.inventory.iohandler = ioTractions
    dbTractions.inventory.label = "initial tractions"
    dbTractions._configure()
    from pylith.faults.TractPerturbation import TractPerturbation
    tract = TractPerturbation()
    tract.inventory.dbInitial = dbTractions
    tract._configure()

    ioFriction = SimpleIOAscii()
    ioFriction.inventory.filename = "data/tri3_staticfriction.spatialdb"
    ioFriction._configure()
    dbFriction = SimpleDB()
    dbFriction.inventory.iohandler = ioFriction
    dbFriction.inventory.label = "friction"
    dbFriction._configure()
    
    from pylith.friction.StaticFriction import StaticFriction
    friction = StaticFriction()
    friction.inventory.label = "Static friction"
    friction.inventory.dbProperties = dbFriction
    friction._configure()

    # Setup fault
    fault = FaultCohesiveDyn()
    fault.inventory.output.inventory.writer._configure()
    fault.inventory.output._configure()
    fault.inventory.matId = 10
    fault.inventory.faultLabel = "fault"
    fault.inventory.upDir = [0, 0, 1]
    fault.inventory.faultQuadrature = quadrature
    fault.inventory.tract = tract
    fault.inventory.friction = friction
    fault._configure()

    nvertices = fault.numVerticesNoMesh(mesh)
    firstFaultVertex = 0
    firstLagrangeVertex = nvertices
    firstFaultCell      = 2*nvertices
    fault.adjustTopology(mesh, firstFaultVertex, firstLagrangeVertex,
                         firstFaultCell)
    from pylith.topology.topology import MeshOps_nondimensionalize
    MeshOps_nondimensionalize(mesh, normalizer)

    fault.preinitialize(mesh)
    fault.timeStep(dt)
    fault.verifyConfiguration()
    from pyre.units.time import s
    fault.initialize(totalTime=0.0*s, numTimeSteps=1, normalizer=normalizer)

    # Setup fields
    from pylith.topology.SolutionFields import SolutionFields
    fields = SolutionFields(mesh)
    fields.add("residual", "residual")
    fields.add("dispIncr(t->t+dt)", "displacement_increment")
    fields.add("disp(t)", "displacement")
    fields.add("velocity(t)", "velocity")
    fields.solutionName("dispIncr(t->t+dt)")

    residual = fields.get("residual")
    residual.subfieldAdd("displacement", cs.spaceDim(), residual.VECTOR)
    residual.subfieldAdd("lagrange_multiplier", cs.spaceDim(), residual.VECTOR)
    residual.subfieldsSetup()
    residual.setupSolnChart()
    residual.setupSolnDof(cs.spaceDim())
    fault.setupSolnDof(residual)
    residual.allocate()
    residual.zero()

    fields.copyLayout("residual")
    
    return (mesh, fault, fields)
Пример #41
0
#!/usr/bin/env python
"""
This script creates a spatial database for the initial stress and state
variables for a Maxwell plane strain material.
"""

material = "maxps"

import numpy
import h5py

from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
from spatialdata.geocoords.CSCart import CSCart
cs = CSCart()
cs._configure()
cs.setSpaceDim(2)

filenameH5 = "output/grav_static_%s-visco.h5" % material
filenameDB = "grav_statevars-%s.spatialdb" % 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)
stress = h5['cell_fields/stress'][0,:,:]
strain = h5['cell_fields/total_strain'][0,:,:]
strainViscous = h5['cell_fields/viscous_strain'][0,:,:]
h5.close()

# Get cell centers for output.
cellCoords = vertices[cells,:]
Пример #42
0
  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
Пример #43
0
  def _initialize(self):
    """
    Initialize AbsorbingDampers boundary condition.
    """
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    db = SimpleDB()
    db.inventory.label = "TestAbsorbingDampers tri3"
    db.inventory.iohandler.inventory.filename = \
        "data/elasticplanestrain.spatialdb"
    db.inventory.iohandler._configure()
    db._configure()

    from pylith.feassemble.FIATSimplex import FIATSimplex
    cell = FIATSimplex()
    cell.inventory.dimension = 1
    cell.inventory.degree = 1
    cell.inventory.order = 1
    cell._configure()
    from pylith.feassemble.Quadrature import Quadrature
    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature._configure()

    from pylith.bc.AbsorbingDampers import AbsorbingDampers
    bc = AbsorbingDampers()
    bc.inventory.quadrature = quadrature
    bc.inventory.db = db
    bc.inventory.id = 0
    bc.inventory.label = "bc"
    bc._configure()

    from spatialdata.geocoords.CSCart import CSCart
    cs = CSCart()
    cs.inventory.spaceDim = 2
    cs._configure()

    from spatialdata.units.Nondimensional import Nondimensional
    normalizer = Nondimensional()
    normalizer._configure()

    from pylith.meshio.MeshIOAscii import MeshIOAscii
    importer = MeshIOAscii()
    importer.inventory.filename = "data/tri3.mesh"
    importer.inventory.coordsys = cs
    importer._configure()
    mesh = importer.read(debug=False, interpolate=False)
    
    bc.preinitialize(mesh)
    bc.initialize(totalTime=0.0, numTimeSteps=1, normalizer=normalizer)
    bc.timeStep(0.01)

    # Setup fields
    from pylith.topology.SolutionFields import SolutionFields
    fields = SolutionFields(mesh)
    fields.add("residual", "residual")
    fields.add("dispIncr(t->t+dt)", "displacement")
    fields.add("disp(t)", "displacement")
    fields.add("disp(t-dt)", "displacement")
    fields.add("velocity(t)", "velocity")
    fields.solutionName("dispIncr(t->t+dt)")

    residual = fields.get("residual")
    residual.newSection(residual.VERTICES_FIELD, cs.spaceDim())
    residual.allocate()
    residual.zero()

    fields.copyLayout("residual")
    
    return (mesh, bc, fields)
Пример #44
0
    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
Пример #45
0
# Background normal tractions are overburden and compressive
# (negative, y is negative)
tractions_bg_normal = density*gacc*(vertices[:,1])

# 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
from spatialdata.geocoords.CSCart import CSCart
cs = CSCart()
cs._configure()
cs.setSpaceDim(2)

# Create writer for spatial database file
from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
writer = SimpleIOAscii()
writer.inventory.filename = "afterslip_tractions.spatialdb"
writer._configure()
writer.write({'points': vertices,
              'coordsys': cs,
              'data_dim': 1,
              'values': [{'name': "traction-shear",
                          'units': "Pa",
                          'data': tractions_shear},
                         {'name': "traction-normal",
                          'units': "Pa",
Пример #46
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