def test_namespacewriter_simple(): f = Frame() f.addfield("Y", 1.) f.addgroup("A") f.A.addfield("B", 0.) def dYdx(f, x, Y): return -Y f.Y.differentiator = dYdx f.addintegrationvariable("x", 0.) def dx(f): return 1. f.x.updater = dx f.x.snapshots = [1.] f.integrator = Integrator(f.x) f.integrator.instructions = [Instruction(schemes.expl_1_euler, f.Y)] f.writer = writers.namespacewriter() f.writer.dumping = True f.run() Y = f.writer.read.sequence("Y") assert np.all(Y == [1., 0.]) x = f.writer.read.sequence("x") assert np.all(x == [0., 1.]) data = f.writer.read.all() assert np.all(data.Y == [1., 0.]) assert np.all(data.x == [0., 1.]) f.writer.reset()
def test_simple_read_files(): f = Frame() f.addgroup("A") f.A.addfield("B", [0., 0.]) f.addfield("Y", 1.) def dYdx(f, x, Y): return -Y f.Y.differentiator = dYdx f.addintegrationvariable("x", 0.) def dx(f): return 1. f.x.updater = dx f.x.snapshots = [1.] f.integrator = Integrator(f.x) f.integrator.instructions = [Instruction(schemes.expl_1_euler, f.Y)] f.writer = writers.hdf5writer() f.run() x = f.writer.read.sequence("x") assert np.all(x == [0., 1.]) Y = f.writer.read.sequence("Y") assert np.all(Y == [1., 0.]) B = f.writer.read.sequence("A.B") assert np.all(B == [0., 0.]) with pytest.raises(TypeError): f.writer.read.sequence(1) data = f.writer.read.all() assert np.all(data.x == [0., 1.]) assert np.all(data.Y == [1., 0.]) assert np.all(data.A.B == [0., 0.]) data0000 = f.writer.read.output(0) assert np.all(data0000.x == 0.) assert np.all(data0000.Y == 1.) assert np.all(data0000.A.B == 0.) with pytest.raises(RuntimeError): f.writer.read.output(2) shutil.rmtree(f.writer.datadir) with pytest.raises(RuntimeError): f.writer.datadir = "temp" f.writer.read.all() with pytest.raises(RuntimeError): f.writer.read.sequence("x") f.writer.datadir = "data"
def test_group_repr_str(): f = Frame() assert isinstance(repr(f), str) assert isinstance(str(f), str) f.addintegrationvariable("x", 0) f.addfield("Y", 1.) f.addfield("abcdefghijklm", 0.) f.addgroup("A") f.addgroup("BCDEFGHIJKLMN") f.C = None f.abcdef1234567 = None f.A.addfield("k", 0.) assert isinstance(repr(f), str) assert isinstance(str(f), str) assert isinstance(repr(f.A), str) assert isinstance(str(f.A), str) f.integrator = Integrator(f.x) f.writer = writers.namespacewriter() assert isinstance(repr(f), str) assert isinstance(str(f), str)
def test_group_toc(): f = Frame() f.addgroup("A") f.addfield("x", 1.) f.toc f.toc = None