當前位置: 首頁>>代碼示例>>Python>>正文


Python Field.initialize方法代碼示例

本文整理匯總了Python中hysop.Field.initialize方法的典型用法代碼示例。如果您正苦於以下問題:Python Field.initialize方法的具體用法?Python Field.initialize怎麽用?Python Field.initialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hysop.Field的用法示例。


在下文中一共展示了Field.initialize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_analytical_field_8

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_analytical_field_8():
    box = Box(dimension=2, length=[1., 1.], origin=[0., 0.])
    topo = box.create_topology(d2d)
    coords = topo.mesh.coords
    caf = Field(box, name='f1', formula=func_vec_6, nb_components=nbc)
    theta = 0.3
    caf.set_formula_parameters(theta)
    ref = Field(box, name='f2', nb_components=nbc)
    refd = ref.discretize(topo)
    cafd = caf.discretize(topo)
    refd = ref.discretize(topo)
    ids = [0, ] * nbc
    for i in xrange(nbc):
        ids[i] = id(cafd.data[i])
    caf.initialize()
    refd.data = func_vec_6(refd.data, *(coords + (0., theta)))
    for i in xrange(caf.nb_components):
        assert allclose(cafd[i], refd.data[i])
        assert id(cafd.data[i]) == ids[i]
    time = 3.0
    caf.initialize(time=time)
    refd.data = func_vec_6(refd.data, *(coords + (time, theta)))
    for i in xrange(caf.nb_components):
        assert allclose(cafd[i], refd.data[i])
        assert id(cafd.data[i]) == ids[i]
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:27,代碼來源:test_field.py

示例2: hdf_dump_load

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def hdf_dump_load(discretisation, formula):
    dimension = len(discretisation.resolution)
    box = Box([1., ] * dimension)
    topo = box.create_topology(discretisation)
    fname = 'f1_' + str(dimension)
    ff = Field(box, name=fname, is_vector=True, formula=formula)
    iop = IOParams(ff.name)
    simu = Simulation(nbIter=4)
    simu.initialize()
    ff.initialize(time=simu.time, topo=topo)
    ff.hdf_dump(topo, simu)
    simu.advance()
    ff.initialize(time=simu.time, topo=topo)
    # Write ff for current time and topo
    ff.hdf_dump(topo, simu)
    assert iop.filepath == IO.default_path()
    assert os.path.isfile(iop.filename + '_00000.h5')
    assert os.path.isfile(iop.filename + '_00001.h5')
    assert os.path.isfile(iop.filename + '.xmf')
    fname2 = 'f2_' + str(dimension)
    gg = Field(box, name=fname2, is_vector=True)
    iop_in = IOParams(iop.filename + '_00001.h5')
    dsname = ff.name + '_' + str(topo.get_id())
    # Load gg from ff values at current time, on topo
    for i in xrange(gg.nb_components):
        assert not np.allclose(gg.discretize(topo)[i], ff.discretize(topo)[i])
    gg.hdf_load(topo, iop_in, dataset_name=dsname)
    for i in xrange(gg.nb_components):
        assert np.allclose(gg.discretize(topo)[i], ff.discretize(topo)[i])

    # reset ff with its values at time 'O', on topo
    ff.hdf_load(topo, restart=0)
    for i in xrange(gg.nb_components):
        assert not np.allclose(gg.discretize(topo)[i], ff.discretize(topo)[i])
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:36,代碼來源:test_field.py

示例3: test_analytical_field_6

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_analytical_field_6():
    box = Box()
    topo = box.create_topology(d3d)
    coords = topo.mesh.coords
    caf = Field(box, name='f1', formula=func_vec_4, is_vector=True,
                vectorize_formula=True)
    theta = 0.3
    caf.set_formula_parameters(theta)
    ref = Field(box, name='f2', is_vector=True)
    refd = ref.discretize(topo)
    cafd = caf.discretize(topo)
    refd = ref.discretize(topo)
    ids = [0, ] * 3
    for i in xrange(3):
        ids[i] = id(cafd.data[i])
    caf.initialize()
    refd.data = func_vec_3(refd.data, *(coords + (0., theta)))
    for i in xrange(caf.nb_components):
        assert allclose(cafd[i], refd.data[i])
        assert id(cafd.data[i]) == ids[i]
    time = 3.0
    caf.initialize(time=time)
    refd.data = func_vec_3(refd.data, *(coords + (time, theta)))
    for i in xrange(caf.nb_components):
        assert allclose(cafd[i], refd.data[i])
        assert id(cafd.data[i]) == ids[i]
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:28,代碼來源:test_field.py

示例4: test_cb_3d_fulldomain

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_cb_3d_fulldomain():
    """
    A cb defined on the whole domain.
    Integrals on upper surfaces must fail,
    because of periodic bc.
    """
    topo, cb = check_control_box(discr3D, orig, ldom)
    velo = Field(domain=topo.domain, is_vector=True, formula=v3d, name='velo')
    velo.discretize(topo)
    velo.initialize(topo=topo)
    i0 = cb.integrate_field_allc(velo, topo)
    vref = np.prod(cb.real_length[topo])
    assert (np.abs(i0 - vref) < 1e-6).all()
    nbc = velo.nb_components
    sref = npw.zeros(nbc)
    dirs = np.arange(nbc)
    for i in xrange(nbc):
        ilist = np.where(dirs != i)[0]
        sref = np.prod(cb.real_length[topo][ilist])
        isurf = cb.integrate_on_faces(velo, topo, [2 * i])
        assert np.abs(isurf - sref) < 1e-6
        res = False
        try:
            isurf = cb.integrate_on_faces(velo, topo, [2 * i + 1])
        except:
            res = True
        assert res
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:29,代碼來源:test_control_box.py

示例5: test_analytical_field_9

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_analytical_field_9():
    box = Box()
    topo = box.create_topology(d3d)
    res2 = Discretization([65, 33, 65], [1, 1, 1])
    topo2 = box.create_topology(res2, dim=2)
    coords = topo.mesh.coords
    coords2 = topo2.mesh.coords
    caf = Field(box, name='f1', formula=func_vec_1, is_vector=True)
    ref = Field(box, name='f2', is_vector=True)
    refd = ref.discretize(topo)
    cafd = caf.discretize(topo)
    cafd2 = caf.discretize(topo2)
    refd2 = ref.discretize(topo2)
    ids = [0, ] * 3
    for i in xrange(3):
        ids[i] = id(cafd2.data[i])
        # init on topo2
    caf.initialize(topo=topo2)
    refd2.data = func_vec_1(refd2.data, *(coords2 + (0.,)))
    refd.data = func_vec_1(refd.data, *(coords + (0.,)))
    for i in xrange(caf.nb_components):
        assert allclose(cafd2[i], refd2.data[i])
        assert id(cafd2.data[i]) == ids[i]
        assert not allclose(cafd[i], refd.data[i])
    caf.initialize(topo=topo)
    for i in xrange(caf.nb_components):
        assert allclose(cafd[i], refd.data[i])
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:29,代碼來源:test_field.py

示例6: test_integ

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_integ():
    topo, cub = check_subset(discr3D, xdef, ldef)
    velo = Field(domain=topo.domain, is_vector=True, formula=v3d, name='velo')
    vd = velo.discretize(topo)
    velo.initialize(topo=topo)
    i0 = cub.integrate_field_allc(velo, topo)
    i1 = cub.integrate_dfield_allc(vd)
    vref = np.prod(cub.real_length[topo])
    assert (np.abs(i0 - vref) < 1e-6).all()
    assert (np.abs(i1 - vref) < 1e-6).all()
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:12,代碼來源:test_regular_subset.py

示例7: test_write_read_vectors_3D

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_write_read_vectors_3D():
    dom, topo = init2()
    velo = Field(domain=dom, formula=vec3D, name='velo', is_vector=True)
    vorti = Field(domain=dom, formula=vort3D, name='vorti', is_vector=True)

    # Write a vector field, using default for output location
    # but with fixed names for datasets
    filename = working_dir + '/testIO_vec'
    iop = IOParams(filename, fileformat=IO.HDF5)
    op = HDF_Writer(variables={velo: topo, vorti: topo},
                    var_names={velo: 'io_1', vorti: 'io_2'}, io_params=iop)
    simu = Simulation(nbIter=3)
    op.discretize()
    op.setup()

    velo.initialize(simu.time, topo=topo)
    vorti.initialize(simu.time, topo=topo)
    simu.initialize()
    while not simu.isOver:
        op.apply(simu)
        simu.advance()

    op.finalize()

    # filename = ''
    # for v in op.input:
    #     filename += v.name
    #     filename += '_'
    fullpath = iop.filename
    assert os.path.exists(fullpath + '.xmf')
    assert os.path.exists(fullpath + '_00000.h5')
    assert os.path.exists(fullpath + '_00001.h5')

    v3d = velo.discretize(topo)
    w3d = vorti.discretize(topo)
    ind = topo.mesh.iCompute

    buff1 = Field(domain=dom, name='buff1', is_vector=True)
    buff2 = Field(domain=dom, name='buff2', is_vector=True)

    # Read vector fields, fixed filename, fixed dataset names.
    iop_read = IOParams(working_dir + '/testIO_vec_00001.h5',
                        fileformat=IO.HDF5)
    reader = HDF_Reader(variables={buff1: topo, buff2: topo},
                        io_params=iop_read,
                        var_names={buff1: 'io_2', buff2: 'io_1'})
    reader.discretize()
    reader.setup()
    reader.apply()
    reader.finalize()
    b1 = buff1.discretize(topo)
    b2 = buff2.discretize(topo)
    for d in xrange(v3d.nb_components):
        assert np.allclose(b2.data[d][ind], v3d.data[d][ind])
        assert np.allclose(b1.data[d][ind], w3d.data[d][ind])
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:57,代碼來源:test_hdf5_io.py

示例8: test_div_rho_v_2d

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_div_rho_v_2d():
    # Reference field
    ref = Field(domain=topo2.domain, formula=analyticalDivWV2D,
                name='Analytical', is_vector=False)
    rd = ref.discretize(topo2)
    ref.initialize(topo=topo2)
    op, result = build_op(diffop.DivRhoV, 1, topo2, work2)
    tol = np.max(topo2.mesh.space_step ** 4)
    result = op(v2d.data, w2d.data[0:1], result)
    # Numerical VS analytical
    assert np.allclose(rd[0][ic2], result[0][ic2], atol=tol)
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:13,代碼來源:test_diffOp.py

示例9: test_laplacian

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_laplacian():
    ref = Field(domain=topo3.domain, formula=laplacian_func,
                name='Analytical', is_vector=True)
    rd = ref.discretize(topo3)
    ref.initialize(topo=topo3)

    op, result = build_op(diffop.Laplacian, 3, topo3, work3)
    result = op(w3d.data, result)
    tol = np.max(topo3.mesh.space_step ** 2)
    for i in xrange(3):
        assert np.allclose(rd.data[i][ic3], result[i][ic3], rtol=tol)
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:13,代碼來源:test_diffOp.py

示例10: test_integ_2

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_integ_2():
    topo, cub = check_subset(discr3D, xdef, ldef)
    velo = Field(domain=topo.domain, is_vector=True, formula=v3d, name='velo')
    vd = velo.discretize(topo)
    velo.initialize(topo=topo)
    vref = np.prod(cub.real_length[topo])
    for i in xrange(velo.nb_components):
        i0 = cub.integrate_field(velo, topo, component=i)
        assert np.abs(i0 - vref) < 1e-6
        i1 = cub.integrate_dfield(vd, component=i)
        assert np.abs(i1 - vref) < 1e-6
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:13,代碼來源:test_regular_subset.py

示例11: test_copy

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_copy():
    box = Box()
    topo = box.create_topology(d3d)
    f1 = Field(box, name='source', is_vector=True, formula=func_vec_1)
    f2 = Field(box, name='target', is_vector=True)
    f1d = f1.discretize(topo)
    f1.initialize(topo=topo)
    f2.copy(f1, topo)
    f2d = f2.discretize(topo)
    for d in xrange(f2.nb_components):
        assert np.allclose(f2d[d], f1d[d])
        assert f2d[d].flags.f_contiguous == f1d[d].flags.f_contiguous
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:14,代碼來源:test_field.py

示例12: test_div_advection

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_div_advection():
    # Reference scalar field
    ref = Field(domain=topo3.domain, formula=analyticalDivAdvection,
                name='Analytical')
    rd = ref.discretize(topo3)
    ref.initialize(topo=topo3)
    op, result = build_op(diffop.DivAdvection, 1, topo3, work3)
    result = op(v3d.data, result)

    # Numerical VS analytical
    errx = (topo3.domain.length[0] / (Nx - 1)) ** 4
    assert np.allclose(rd[0][ic3], result[0][ic3], rtol=errx)
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:14,代碼來源:test_diffOp.py

示例13: test_div_rho_v

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_div_rho_v():
    # Reference field
    ref = Field(domain=topo3.domain, formula=analyticalDivWV,
                name='Analytical', is_vector=True)
    rd = ref.discretize(topo3)
    ref.initialize(topo=topo3)
    op, result = build_op(diffop.DivRhoV, 3, topo3, work3)
    tol = np.max(topo3.mesh.space_step ** 4)
    for i in xrange(3):
        result[i:i + 1] = op(v3d.data, w3d.data[i:i + 1], result[i:i + 1])
        # Numerical VS analytical
        assert np.allclose(rd[i][ic3], result[i][ic3], atol=tol)
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:14,代碼來源:test_diffOp.py

示例14: test_write_read_subset_2

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_write_read_subset_2():
    dom, topo = init2()
    velo = Field(domain=dom, formula=vec3D, name='velo', is_vector=True)

    # A subset of the current domain
    # a plane ...
    mybox = SubBox(origin=[-0.5, 2.3, 4.1], length=[Lx / 2, Lx / 3, 0.0],
                   parent=dom)
    # Write a vector field, using default for output location
    # but with fixed names for datasets
    op = HDF_Writer(variables={velo: topo}, var_names={velo: 'io_1'},
                    subset=mybox)
    simu = Simulation(nbIter=3)
    op.discretize()
    op.setup()
    velo.initialize(simu.time, topo=topo)
    simu.initialize()
    while not simu.isOver:
        op.apply(simu)
        simu.advance()
    op.finalize()

    filename = ''
    for v in op.input:
        filename += v.name
        filename += '_'
    filename = filename[:-1]
    fullpath = os.path.join(IO.default_path(), filename)

    assert os.path.exists(fullpath + '.xmf')
    assert os.path.exists(fullpath + '_00000.h5')
    assert os.path.exists(fullpath + '_00001.h5')

    v3d = velo.discretize(topo)
    ind = topo.mesh.iCompute
    indsubset = mybox.mesh[topo].iCompute

    buff1 = Field(domain=dom, name='buff1', is_vector=True)

    # Read vector fields, fixed filename, fixed dataset names.
    iop = IOParams(filename + '_00000.h5', fileformat=IO.HDF5)
    reader = HDF_Reader(variables={buff1: topo},
                        io_params=iop,
                        var_names={buff1: 'io_1'}, subset=mybox)
    reader.discretize()
    reader.setup()
    reader.apply()
    reader.finalize()
    b1 = buff1.discretize(topo)
    for d in xrange(v3d.nb_components):
        assert not np.allclose(b1.data[d][ind], v3d.data[d][ind])
        assert np.allclose(b1.data[d][indsubset], v3d.data[d][indsubset])
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:54,代碼來源:test_hdf5_io.py

示例15: test_2d_subbox

# 需要導入模塊: from hysop import Field [as 別名]
# 或者: from hysop.Field import initialize [as 別名]
def test_2d_subbox():
    """
    subset in 2D domain
    """
    topo, cub = check_subset(discr2D, xdef[:2], ldef[:2])
    velo = Field(domain=topo.domain, is_vector=True, formula=v2d, name='velo')
    vd = velo.discretize(topo)
    velo.initialize(topo=topo)
    i0 = cub.integrate_field_allc(velo, topo)
    vref = np.prod(cub.real_length[topo])
    assert (np.abs(i0 - vref) < 1e-6).all()
    i1 = cub.integrate_dfield_allc(vd)
    assert (np.abs(i1 - vref) < 1e-6).all()
開發者ID:ljktest,項目名稱:tmp-tests,代碼行數:15,代碼來源:test_regular_subset.py


注:本文中的hysop.Field.initialize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。