Ejemplo n.º 1
0
def test_readrea():
    import pymech.neksuite as ns

    fname = './tests/nek/2D_section_R360.rea'
    field = ns.readrea(fname)

    assert field.lr1 == [2, 2, 1]
    assert field.ndim == 2
    assert field.nel == 1248
    assert abs(field.elem[0].pos[0][0][0][0] - 0.048383219999999998) < 1e-3
    assert abs(field.elem[887].curv[1, 0] - 1.21664) < 1e-3
    assert field.elem[887].ccurv[1] == 'C'

    fname = './tests/nek/m3j_bf_test.rea'
    field = ns.readrea(fname)
    assert field.elem[790].ccurv[0] == 'm'
    assert abs(field.elem[790].curv[0][1] + 0.05258981) < 1e-7
    assert field.elem[0].bcs[0, 0][0] == 'W'
    assert field.elem[0].bcs[0, 1][0] == 'o'
    assert field.elem[0].bcs[0, 2][0] == 'E'
    assert field.elem[0].bcs[0, 2][1] == 1
    assert field.elem[0].bcs[0, 2][2] == 3
    assert int(field.elem[0].bcs[0, 2][3]) == 2
    assert int(field.elem[0].bcs[0, 2][4]) == 1
    assert int(field.elem[799].bcs[1, 1][3]) == 790
    assert field.elem[799].bcs[1, 2][0] == 't'
    assert field.elem[799].bcs[1, 3][0] == 'I'
    assert int(field.elem[799].bcs[2, 1][3]) == 790
    assert field.elem[799].bcs[2, 2][0] == 'P'
    assert field.elem[799].bcs[2, 3][0] == 'P'
Ejemplo n.º 2
0
def test_writerea():
    import pymech.neksuite as ns

    fname = './tests/nek/2D_section_R360.rea'
    field = ns.readrea(fname)

    fnamew = 'test.rea'
    status = ns.writerea(fnamew, field)

    assert status == 0

    fieldw = ns.readrea(fnamew)

    assert field.endian == fieldw.endian
    assert field.lr1 == fieldw.lr1
    assert field.ndim == fieldw.ndim
    assert field.nel == fieldw.nel
    assert field.wdsz == fieldw.wdsz
    assert (field.elem[0].pos[0][0][0][0] -
            fieldw.elem[0].pos[0][0][0][0]) < 1e-3
    assert abs(field.elem[887].curv[1, 0] - 1.21664) < 1e-3
    assert field.elem[887].ccurv[1] == 'C'

    fname = './tests/nek/m3j_bf_test.rea'
    fnamew = 'test.rea'

    field = ns.readrea(fname)
    status = ns.writerea(fnamew, field)

    assert status == 0

    fieldw = ns.readrea(fnamew)

    assert fieldw.elem[790].ccurv[0] == 'm'
    assert abs(fieldw.elem[790].curv[0][1] + 0.05258981) < 1e-7
    assert fieldw.elem[0].bcs[0, 0][0] == 'W'
    assert fieldw.elem[0].bcs[0, 1][0] == 'o'
    assert fieldw.elem[0].bcs[0, 2][0] == 'E'
    assert fieldw.elem[0].bcs[0, 2][1] == 1
    assert fieldw.elem[0].bcs[0, 2][2] == 3
    assert int(fieldw.elem[0].bcs[0, 2][3]) == 2
    assert int(fieldw.elem[0].bcs[0, 2][4]) == 1
    assert int(field.elem[799].bcs[1, 1][3]) == 790
    assert fieldw.elem[799].bcs[1, 2][0] == 't'
    assert fieldw.elem[799].bcs[1, 3][0] == 'I'
    assert int(fieldw.elem[799].bcs[2, 1][3]) == 790
    assert fieldw.elem[799].bcs[2, 2][0] == 'P'
    assert fieldw.elem[799].bcs[2, 3][0] == 'P'
Ejemplo n.º 3
0
def test_readre2_3d():
    import pymech.neksuite as ns

    # same test as test_readre2(), but with a 3D mesh.

    frea = './tests/nek/box3d.rea'
    fre2 = './tests/nek/box3d.re2'
    meshrea = ns.readrea(frea)
    meshre2 = ns.readre2(fre2)
    # remove the 'E' conditions from the .rea data
    for el in meshrea.elem:
        for iface in range(6):
            if el.bcs[0, iface][0] == 'E':
                el.bcs[0, iface][0] = ''
                for j in range(1, 8):
                    el.bcs[0, iface][j] = 0

    assert meshre2.ndim == meshrea.ndim
    assert meshre2.nel == meshrea.nel
    assert meshre2.ncurv == meshrea.ncurv
    assert meshre2.nbc == meshrea.nbc
    assert meshre2.var == meshrea.var
    assert meshre2.lr1 == meshrea.lr1
    assert meshre2.wdsz == 8
    for (el, elw) in zip(meshrea.elem, meshre2.elem):
        npt.assert_allclose(elw.pos, el.pos)
        npt.assert_array_equal(elw.bcs, el.bcs)
        npt.assert_allclose(elw.curv, el.curv)
        npt.assert_array_equal(elw.ccurv, el.ccurv)
Ejemplo n.º 4
0
def test_readre2():
    import pymech.neksuite as ns

    # The .re2 has been generated with reatore2 and contains the same data
    # except for the internal boundary conditions.
    # Assuming that `readrea` is correct, this checks id the .re2 file is read correctly too.
    #
    frea = './tests/nek/2D_section_R360.rea'
    fre2 = './tests/nek/2D_section_R360.re2'
    meshrea = ns.readrea(frea)
    meshre2 = ns.readre2(fre2)

    # remove the 'E' conditions from the .rea data
    for el in meshrea.elem:
        for iface in range(4):
            if el.bcs[0, iface][0] == 'E':
                el.bcs[0, iface][0] = ''
                for j in range(1, 8):
                    el.bcs[0, iface][j] = 0

    assert meshre2.ndim == meshrea.ndim
    assert meshre2.nel == meshrea.nel
    assert meshre2.ncurv == meshrea.ncurv
    assert meshre2.nbc == meshrea.nbc
    assert meshre2.var == meshrea.var
    assert meshre2.lr1 == meshrea.lr1
    assert meshre2.wdsz == 8
    for (el, elw) in zip(meshrea.elem, meshre2.elem):
        npt.assert_allclose(elw.pos, el.pos)
        npt.assert_array_equal(elw.bcs, el.bcs)
        npt.assert_allclose(elw.curv, el.curv)
        npt.assert_array_equal(elw.ccurv, el.ccurv)
Ejemplo n.º 5
0
def test_merge():
    import pymech.neksuite as ns
    import copy

    fname = './tests/nek/box3d.rea'
    mesh = ns.readrea(fname)
    mesh1 = copy.deepcopy(mesh)
    mesh2 = copy.deepcopy(mesh)
    mesh3 = copy.deepcopy(mesh)
    # mesh and mesh1 will be connected along the 'v' and 'O' BCs
    for el in mesh1.elem:
        el.pos[0, ...] = el.pos[0, ...] + 2
    # mesh and mesh2 will be connected along 'P' BCs
    for el in mesh2.elem:
        el.pos[1, ...] = el.pos[1, ...] + 2
    for el in mesh3.elem:
        el.pos[2, ...] = el.pos[2, ...] + 2
    n1 = mesh1.merge(mesh)
    n2 = mesh2.merge(mesh)
    n3 = mesh3.merge(mesh)
    assert mesh.check_connectivity()
    assert mesh1.check_connectivity()
    assert mesh2.check_connectivity()
    assert mesh3.check_connectivity()
    assert mesh1.nel == 2 * mesh.nel
    assert n1 == 9
    assert n2 == 9
    assert n3 == 9
    # check if the element/faces indices in the boundary conditions are right too, even if it may not matter
    assert mesh1.nbc > 0
    for ibc in range(mesh1.nbc):
        for (iel, el) in enumerate(mesh1.elem):
            for iface in range(6):
                assert el.bcs[ibc, iface][1] == iel + 1
                assert el.bcs[ibc, iface][2] == iface + 1
Ejemplo n.º 6
0
import pymech.neksuite as ns
import pymech.exadata as exa
import meshtools as mst

path = '../examples/'
meshI = 'in_mesh_2d.rea'
meshO = 'out_mesh_3d'
#meshI = 'boxmix.rea'

## defining paths to files
fnameI = path + meshI
fnameO = path + meshO

# Reading 2D mesh
if fnameI[-3:]=='rea':
    mesh2D = ns.readrea(fnameI)
elif fnameI[-3:]=='re2':
    mesh2D = ns.readre2(fnameI)
else:
    print('Assuming mesh has .rea format')
    mesh2D = ns.readrea(fnameI+'.rea')

#Input parameters
z = [-1.0,1.0]
n = 32
bc1='v'
bc2='O'

imesh_high=1 #index of mesh with higher discretization. Example: for imesh_high=0, the mesh with higher discretization is the most internal mesh (for for imesh_high=1, it is the second most internal mesh)
funpar=[0.53, 1.25, 2.0, 3.6]