Example #1
0
def test_writenek():
    import pymech.neksuite as ns

    fname = './tests/nek/channel3D_0.f00001'
    time0 = time.perf_counter()
    field = ns.readnek(fname)
    time1 = time.perf_counter()

    fnamew = './test_0.f00001'
    status = ns.writenek(fnamew, field)
    time2 = time.perf_counter()
    print('readnek: {:.6e} s; writenek: {:.6e} s'.format(
        time1 - time0, time2 - time1))

    assert status == 0

    fieldw = ns.readnek(fnamew)

    assert field.endian == fieldw.endian
    assert field.istep == fieldw.istep
    assert field.lr1 == fieldw.lr1
    assert field.ndim == fieldw.ndim
    assert field.nel == fieldw.nel
    assert field.var == fieldw.var
    assert field.wdsz == fieldw.wdsz
    assert (field.time - fieldw.time) < 1e-3
    assert field.lims.pos.all() == fieldw.lims.pos.all()
    assert field.lims.vel.all() == fieldw.lims.vel.all()
    assert field.lims.pres.all() == fieldw.lims.pres.all()
    assert field.lims.scal.all() == fieldw.lims.scal.all()
    assert np.abs(field.elem[123].vel - fieldw.elem[123].vel).max() < 1e-9
    assert np.abs(field.elem[-1].pos - fieldw.elem[-1].pos).max() < 1e-9
    assert np.abs(field.elem[-1].pres - fieldw.elem[-1].pres).max() < 1e-9
Example #2
0
def test_writenek_scalars():
    import pymech.neksuite as ns

    fname = './tests/nek/stsabl0.f00001'
    field = ns.readnek(fname)

    fnamew = './test_sts_0.f00001'
    status = ns.writenek(fnamew, field)

    assert status == 0

    fieldw = ns.readnek(fnamew)
    npt.assert_array_equal(field.lims.scal, fieldw.lims.scal)
Example #3
0
def test_readnek():
    import pymech.neksuite as ns

    fname = "./tests/nek/channel3D_0.f00001"
    field = ns.readnek(fname)

    assert field.endian == "little"
    assert field.istep == 10
    assert field.lr1 == [8, 8, 8]
    assert field.ndim == 3
    assert field.nel == 512
    assert field.var == [3, 3, 1, 0, 0]
    assert field.wdsz == 4
    assert (field.time - 0.2) < 1e-3
    representation = dedent(
        """\
    <pymech.exadata.exadata>
    Dimensions:    3
    Precision:     4 bytes
    Mesh limits:
      * x:         (0.0, 6.2831854820251465)
      * y:         (-1.0, 1.0)
      * z:         (0.0, 3.1415927410125732)
    Time:
      * time:      0.2
      * istep:     10
    Elements:
      * nel:       512
      * elem:      [<elem centered at [ 0.39269908 -0.98        0.19634954]>
                    ...
                    <elem centered at [5.89048618 0.98       2.94524309]>]"""
    )
    assert repr(field).splitlines() == representation.splitlines()
Example #4
0
def test_lims():
    from pymech.neksuite import readnek

    fld = readnek("tests/nek/channel3D_0.f00001")

    with pytest.raises(AttributeError):
        fld.lims = ()

    with pytest.raises(AttributeError):
        fld.lims.pos = ((0, 3.14), (0, 1), (-1, 1))

    with pytest.raises(TypeError):
        fld.lims.pos[0, 1] = 3.14

    npt.assert_array_equal(
        fld.lims.pos,
        (
            (0.0, 6.2831854820251465),
            (-1.0, 1.0),
            (0.0, 3.1415927410125732),
        ),
    )
    npt.assert_array_equal(
        fld.lims.vel,
        (
            (-0.0001499584031989798, 1.2596282958984375),
            (-0.024550313130021095, 0.021655898541212082),
            (-0.022412149235606194, 0.020889850333333015),
        ),
    )
    npt.assert_array_equal(fld.lims.pres,
                           ((-0.2145293802022934, 0.2344336062669754), ))
    npt.assert_array_equal(fld.lims.temp, ())
    npt.assert_array_equal(fld.lims.scal, ())
Example #5
0
def test_readnek_scalars():
    import pymech.neksuite as ns

    # 2D statistics file
    fname = './tests/nek/stsabl0.f00001'
    field = ns.readnek(fname)

    ux_min, ux_max = field.lims.scal[0]
    assert math.isclose(ux_max, 5.3, abs_tol=0.1)
Example #6
0
def test_readnek():
    import pymech.neksuite as ns

    fname = './tests/nek/channel3D_0.f00001'
    field = ns.readnek(fname)

    assert field.endian == 'little'
    assert field.istep == 10
    assert field.lr1 == [8, 8, 8]
    assert field.ndim == 3
    assert field.nel == 512
    assert field.var == [3, 3, 1, 0, 0]
    assert field.wdsz == 4
    assert (field.time - 0.2) < 1e-3
Example #7
0
def test_writenek():
    import pymech.neksuite as ns

    fname = "./tests/nek/channel3D_0.f00001"
    time0 = time.perf_counter()
    field = ns.readnek(fname)
    time1 = time.perf_counter()

    fnamew = "./test_0.f00001"
    status = ns.writenek(fnamew, field)
    time2 = time.perf_counter()
    logger.info(
        "readnek: {:.6e} s; writenek: {:.6e} s".format(time1 - time0, time2 - time1)
    )

    assert status == 0

    fieldw = ns.readnek(fnamew)

    assert field.endian == fieldw.endian
    assert field.istep == fieldw.istep
    assert field.lr1 == fieldw.lr1
    assert field.ndim == fieldw.ndim
    assert field.nel == fieldw.nel
    assert field.var == fieldw.var
    assert field.wdsz == fieldw.wdsz
    assert (field.time - fieldw.time) < 1e-3
    npt.assert_array_equal(field.lims.pos, fieldw.lims.pos)
    npt.assert_array_equal(field.lims.vel, fieldw.lims.vel)
    npt.assert_array_equal(field.lims.pres, fieldw.lims.pres)
    npt.assert_array_equal(field.lims.scal, fieldw.lims.scal)

    for elem, elemw in zip(field.elem, fieldw.elem):
        npt.assert_array_equal(elem.pos, elemw.pos)
        npt.assert_array_equal(elem.vel, elemw.vel)
        npt.assert_array_equal(elem.pres, elemw.pres)
        npt.assert_array_equal(elem.scal, elemw.scal)
Example #8
0
def test_writenek_big_endian():
    import pymech.neksuite as ns

    fname = './tests/nek/channel3D_0.f00001'
    field = ns.readnek(fname)

    field.endian = "big"
    fnamew = './test_0_big.f00001'
    status = ns.writenek(fnamew, field)
    assert status == 0

    fieldw = ns.readnek(fnamew)
    assert field.endian == fieldw.endian == "big"

    npt.assert_array_equal(field.lims.pos, fieldw.lims.pos)
    npt.assert_array_equal(field.lims.vel, fieldw.lims.vel)
    npt.assert_array_equal(field.lims.pres, fieldw.lims.pres)
    npt.assert_array_equal(field.lims.scal, fieldw.lims.scal)

    for elem, elemw in zip(field.elem, fieldw.elem):
        npt.assert_array_equal(elem.pos, elemw.pos)
        npt.assert_array_equal(elem.vel, elemw.vel)
        npt.assert_array_equal(elem.pres, elemw.pres)
        npt.assert_array_equal(elem.scal, elemw.scal)
Example #9
0
import numpy as np
from tqdm import tqdm
from pymech.exadata import exadata, elem
import pandas as pd
import quadpy
from pymech.neksuite import readnek
from pymech.neksuite import writenek

def stacked_sum(var, zyx):
        z,y,x = zyx
        return np.sum(np.sum(np.sum(var*z,axis=0)*y,axis=0)*x)

filename='..\\Mesh0110_1p50.f00008'
field=readnek(filename)
nel=field.nel
lr1=field.lr1

scheme = quadpy.c1.gauss_lobatto(field.lr1[2])
gausslobattopoints=scheme.points
gausslobattoweights=scheme.weights
w=gausslobattoweights

TotalVol=0.0
TotalMass=0.0
TotalPotentialEnergy=0.0
TotalKineticEnergy=0.0

for n in np.arange(nel):
        ax=field.elem[n].pos[0,0,0,0]
        bx=field.elem[n].pos[0,0,0,-1]
        wxprime=w*((bx-ax)/2.0)