def test_timehistory(self): timeQ = numpy.array([0.5, 0.0, 0.6, 2.0, 5.0, 20.0, 8.0], dtype=numpy.float64) amplitudeE = numpy.array([1.0, 0.0, 1.2, 4.0, 2.5, 0.0, 1.0], dtype=numpy.float64) errE = numpy.array([0, 0, 0, 0, 0, 1, 0], dtype=numpy.float64) from spatialdata.spatialdb.TimeHistory import TimeHistory th = TimeHistory() th.inventory.label = "test" th.inventory.filename = "data/timehistory.timedb" th._configure() th.open() nlocs = timeQ.shape[0] amplitude = numpy.zeros((nlocs, ), dtype=numpy.float64) err = numpy.zeros((nlocs, ), dtype=numpy.int32) for i in range(nlocs): (e, amplitude[i]) = th.query(timeQ[i]) err[i] = e th.close() self.assertEqual(len(errE), len(err)) for vE, v in zip(errE, err): self.assertEqual(vE, v) self.assertEqual(len(amplitudeE.shape), len(amplitude.shape)) for dE, d in zip(amplitudeE.shape, amplitude.shape): self.assertEqual(dE, d) for vE, v in zip(numpy.reshape(amplitudeE, -1), numpy.reshape(amplitude, -1)): self.assertAlmostEqual(vE, v, 6)
def test_configure(self): """ Test constructor. """ from spatialdata.spatialdb.SimpleDB import SimpleDB db = SimpleDB() db.inventory.label = "simple database" db._configure() from spatialdata.spatialdb.TimeHistory import TimeHistory th = TimeHistory() th._configure() from pylith.bc.DirichletBC import DirichletBC bc = DirichletBC() bc.inventory.label = "abc" bc.inventory.dbInitial = db bc.inventory.dbRate = db bc.inventory.dbChange = db bc.inventory.thChange = th bc._configure() return
def test_initialize(self): """ Test initialize(). """ from spatialdata.spatialdb.SimpleDB import SimpleDB from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii from spatialdata.spatialdb.TimeHistory import TimeHistory ioFinalSlip = SimpleIOAscii() ioFinalSlip.inventory.filename = "finalslip.spatialdb" ioFinalSlip._configure() dbFinalSlip = SimpleDB() dbFinalSlip.inventory.iohandler = ioFinalSlip dbFinalSlip.inventory.label = "slip amplitude" dbFinalSlip._configure() ioSlipTime = SimpleIOAscii() ioSlipTime.inventory.filename = "sliptime.spatialdb" ioSlipTime._configure() dbSlipTime = SimpleDB() dbSlipTime.inventory.iohandler = ioSlipTime dbSlipTime.inventory.label = "slip time" dbSlipTime._configure() dbTimeHistory = TimeHistory() dbTimeHistory.inventory.filename = "slipfn.timedb" dbTimeHistory.inventory.label = "time history" dbTimeHistory._configure() slipFn = TimeHistorySlipFn() slipFn.inventory.dbslip = dbFinalSlip slipFn.inventory.dbSlipTime = dbSlipTime slipFn.inventory.dbTimeHistory = dbTimeHistory slipFn._configure() slipFn.preinitialize() slipFn.verifyConfiguration() slipFn.initialize() return