Ejemplo n.º 1
0
def test_field_io_mpi(case):
    mesh = Mesh.create(case)
    Field.setMesh(mesh)

    time = 1.0

    config.hdf5 = False
    with IOField.handle(time):
        U = IOField.read('U')
        U.partialComplete()

    config.hdf5 = True
    with IOField.handle(time, case=case):
        Uh = IOField.read('U')
        Uh.partialComplete()
Ejemplo n.º 2
0
def test_mpi_comm_method(case_path):
    mesh = Mesh.create(case_path)
    IOField.setMesh(mesh)
    with IOField.handle(1.):
        U = IOField.read('U')
        U.partialComplete()
    with IOField.handle(2.):
        U.write()
    return
Ejemplo n.º 3
0
def diffAllTimes():
    case1, case2, field = sys.argv[1:]
    mesh1 = Mesh.create(case1)
    mesh2 = Mesh.create(case2)

    times1 = mesh1.getTimes()
    times2 = mesh2.getTimes()

    for time1, time2 in zip(times1, times2):
        Field.setMesh(mesh1)
        with IOField.handle(time1):
            phi1 = IOField.read(field)
        Field.setMesh(mesh2)
        with IOField.handle(time2):
            phi2 = IOField.read(field)
        diff = np.abs(phi1.field-phi2.field)
        norm = np.sqrt(parallel.sum(diff**2*mesh1.volumes))
        pprint(parallel.min(diff))
        pprint('norm:', norm)
Ejemplo n.º 4
0
def test_mpi_comm():
    case_path = os.path.join(cases_path, 'forwardStep')
    mesh = Mesh.create(case_path)
    IOField.setMesh(mesh)
    with IOField.handle(0.):
        U = IOField.read('U')
        U.partialComplete()
    U.field = np.random.rand(*U.field.shape)

    try:
        with IOField.handle(1.):
            U.write()
        time.sleep(1)
        subprocess.check_output(
            ['decomposePar', '-case', case_path, '-time', '1'])
        subprocess.check_output([
            'mpirun', '-np', '4', 'python2', __file__, 'RUN',
            'test_mpi_comm_method', case_path
        ])
        checkFields(case_path, 'U', '1.0', '2.0', relThres=1e-12, nProcs=4)
    finally:
        shutil.rmtree(os.path.join(case_path, '1'))
        map(shutil.rmtree, glob.glob(os.path.join(case_path, 'processor*')))
Ejemplo n.º 5
0
#!/usr/bin/python2
import sys, os
import numpy as np

from adFVM import config
from adFVM.field import Field, IOField
from adFVM.mesh import Mesh

case1, case2 = sys.argv[1:]
mesh = Mesh.create(case1)
times = mesh.getTimes()
Field.setMesh(mesh)

fields = ['p', 'T', 'U']
for name in fields:
    phimax = -1
    for time in times:
        mesh.case = case1
        phi1 = IOField.read(name, mesh, time)
        phi1.partialComplete()
        if phimax < 0:
            phimax = phi1.field.max()
        mesh.case = case2
        phi2 = IOField.read(name, mesh, time)
        phi2.partialComplete()
        phi1.name += '_diff'
        phi1.field = (phi2.field-phi1.field)/phimax
        phi1.write(time)

Ejemplo n.º 6
0
#from mms import source, solution

    # analytical inviscid comparison
def test_shockTube(self):
    case = '../cases/shockTube/'
    t = 0.0
    solver = RCF(case, mu=lambda T: T*0., faceReconstructor='AnkitENO', CFL=0.6)
    solver.readFields(t)
    solver.compile()
    timeRef = 0.006
    solver.run(startTime=t, endTime=timeRef, dt=1e-5)

    f = open(case + '/output')
    f.readline()
    f.readline()
    data = np.loadtxt(f)
    with IOField.handle(timeRef):
        rho = IOField.read('rho')
        p = IOField.read('p')
        U = IOField.read('U')
    #rho.complete()
    #p.complete()
    #U.complete()
    self.mesh = solver.mesh
    checkVolSum(self, rho.getInternalField(), data[:, 2].reshape((-1,1)), relThres=0.02)
    checkVolSum(self, p.getInternalField(), data[:, 3].reshape((-1,1)), relThres=0.02)
    checkVolSum(self, U.getInternalField()[:,0].reshape((-1,1)), data[:, 4].reshape((-1,1)),relThres=0.05)

if __name__ == "__main__":
    unittest.main(verbosity=2, buffer=True)
Ejemplo n.º 7
0
    plt.savefig(saveFile)
    plt.clf()


if __name__ == '__main__':
    from adFVM.mesh import Mesh
    from adFVM.field import Field, IOField
    import sys

    case, time = sys.argv[1:3]
    time = float(time)
    mesh = Mesh.create(case)
    Field.setMesh(mesh)

    with IOField.handle(time):
        htc = IOField.read('htc')
        htc.partialComplete()
        Ma = IOField.read('Ma')
        Ma.partialComplete()

    #nLayers = 1
    nLayers = 200
    from postpro import surface
    patches = [surface + '_pressure', surface + '_suction']
    get_profile(surface)

    htc_args = []
    Ma_args = []

    mesh = mesh.origMesh
    for patchID in patches:
Ejemplo n.º 8
0
#!/usr/bin/python2
import sys
import numpy as np

from adFVM.density import RCF
from adFVM.field import IOField

case, time = sys.argv[1:3]
time = float(time)
rcf = RCF(case)
with IOField.handle(time):
    U = IOField.read('U')
    T = IOField.read('T')
    p = IOField.read('p')
rho, rhoU, rhoE = rcf.conservative(U, T, p)
fields = [U, T, p, rho, rhoU, rhoE]

for phi in fields:
    phi.info()
Ejemplo n.º 9
0
        continue
    boundaryFile = boundaryDir + 'boundary'
    shutil.copyfile(boundaryFile, boundaryDir + 'boundary.cyclic')
    # intersection_master on the right, intersection_slave on the left (x-axis)
    patch = mesh.origMesh.boundary['intersection_master']
    patch['type'] = 'slidingPeriodic1D'
    patch['periodicPatch'] = 'mid1plane'
    patch['velocity'] = '(0 252 0)'
    patch['nLayers'] = '1'
    #patch['nLayers'] = '10'
    patch.pop('movingCellCentres', None)
    patch = mesh.origMesh.boundary['intersection_slave']
    patch['type'] = 'slidingPeriodic1D'
    patch['periodicPatch'] = 'mid2plane'
    patch['velocity'] = '(0 -252 0)'
    patch['nLayers'] = '1'
    #patch['nLayers'] = '10'
    patch.pop('movingCellCentres', None)
    mesh.writeFoamBoundary(boundaryFile, mesh.origMesh.boundary)

fields = os.listdir(timeDir)
for phi in fields:
    if phi == 'polyMesh':
        continue
    with IOField.handle(user.time):
        field = IOField.read(phi)
        field.boundary['intersection_master']['type'] = 'slidingPeriodic1D'
        field.boundary['intersection_slave']['type'] = 'slidingPeriodic1D'
        field.partialComplete()
        field.write(skipProcessor=True)
Ejemplo n.º 10
0
            phi2 = IOField.read(field)
        diff = np.abs(phi1.field-phi2.field)
        norm = np.sqrt(parallel.sum(diff**2*mesh1.volumes))
        pprint(parallel.min(diff))
        pprint('norm:', norm)


def diffSingleTime():
    case, field, time1, time2 = sys.argv[1:]
    time1 = float(time1)
    time2 = float(time2)
    mesh = Mesh.create(case)
    Field.setMesh(mesh)

    with IOField.handle(time1):
        phi1 = IOField.read(field)
        phi1.partialComplete()
    with IOField.handle(time2):
        phi2 = IOField.read(field)
        phi2.partialComplete()

    diff = abs(phi1.field-phi2.field)
    ref = parallel.max(phi1.field)
    pprint('ref:', ref)
    pprint('absolute:', parallel.max(diff))
    pprint('relative:', parallel.max(diff)/ref)
    pprint('close:', np.allclose(phi1.field, phi2.field))

diffSingleTime()
#diffAllTimes()
Ejemplo n.º 11
0
Field.setMesh(mesh)

times = mesh.getTimes()
times = filter(lambda x: x > 3.00049, times)
pprint(times)

nLayers = 200
#nLayers = 1

for field in fields:
    # time avg: no dt
    avg = 0.
    not_nan_times = 0.
    for time in times:
        with IOField.handle(time):
            phi = IOField.read(field)
        phi.partialComplete()
        not_nan_times += 1. - np.isnan(phi.field)
        avg += np.nan_to_num(phi.field)
    avg /= not_nan_times

    # spanwise avg: structured
    nDims = avg.shape[1]

    #nLayers = 1
    def average(start, end):
        nCellsPerLayer = (end - start) / nLayers
        spanAvg = avg[start:end].reshape(
            (nCellsPerLayer, nLayers, nDims)).sum(axis=1, keepdims=1) / nLayers
        spanAvg = np.tile(spanAvg, (1, nLayers, 1)).reshape(
            (end - start, nDims))
Ejemplo n.º 12
0
#!/usr/bin/python2
import sys, os
import numpy as np

from adFVM import config
from adFVM.field import Field, IOField
from adFVM.mesh import Mesh

case = sys.argv[1]
time1, time2 = sys.argv[2:4]
mesh = Mesh.create(case)
Field.setMesh(mesh)

fields = ['p', 'T', 'U']
fieldsRef = [2e5, 300, 100]
for name, ref in zip(fields, fieldsRef):
    with IOField.handle(float(time1)):
        phi = IOField.read(name)
        phi.partialComplete()
    with IOField.handle(float(time2)):
        mid = np.array([-0.02, 0.01, 0.005])
        G = 1e0 * np.exp(-3e3 * np.linalg.norm(
            mid - mesh.cellCentres[:mesh.nInternalCells], axis=1, keepdims=1)**
                         2)
        phi.field[:mesh.nInternalCells] = G * ref

        phi = IOField(name, phi.field, phi.dimensions, phi.boundary)
        phi.write()
Ejemplo n.º 13
0
import os
import numpy as np

from adFVM import config
from adFVM.field import Field, IOField
from adFVM.mesh import Mesh

case, field = sys.argv[1:3]
#times = sys.argv[3:]
mesh = Mesh.create(case)
Field.setMesh(mesh)

# time avg: no dt
times = mesh.getTimes()
with IOField.handle(times[0]):
    phiAvg = IOField.read(field + '_avg')
    phiAvg.partialComplete()

std = 0.
for time in times:
    with IOField.handle(time):
        phi = IOField.read(field)
        phi.partialComplete()
    std += (phiAvg.field-phi.field)**2

# spanwise avg: structured
nLayers = 200
nDims = std.shape[1]
#nLayers = 1
def average(start, end):
    nCellsPerLayer = (end-start)/nLayers
Ejemplo n.º 14
0
    U.partialComplete()

    field = np.random.rand(mesh.nInternalCells, 1)
    boundary = copy.deepcopy(mesh.defaultBoundary)
    T = IOField('T', field, (1,), boundary)
    boundary['outlet'] = {
            'type':'fixedValue',
            'value': 'uniform 10'
            }

    with IOField.handle(time):
        U.write()
        T.write()

    with IOField.handle(time):
        Tn = IOField.read('T')
        Un = IOField.read('U')
        Un.partialComplete()

    config.hdf5 = False
    assert (deep_eq(Tn.boundary, T.boundary))
    assert (deep_eq(Un.boundary, U.boundary))
    np.allclose(Tn.field, T.field)
    np.allclose(Un.field, U.field)

@pytest.mark.skip
def test_field_io_mpi(case):
    mesh = Mesh.create(case)
    Field.setMesh(mesh)

    time = 1.0
Ejemplo n.º 15
0
Archivo: match.py Proyecto: qiqi/adFVM
pklFile = 'match_args.pkl'
if __name__ == '__main__':
    if 0:  #os.path.exists(pklFile):
        htc_args, Ma_args = pkl.load(open(pklFile))
    else:
        from adFVM import config
        from adFVM.mesh import Mesh
        from adFVM.field import Field, IOField
        case, time = sys.argv[1:3]
        time = float(time)
        mesh = Mesh.create(case)
        Field.setMesh(mesh)

        with IOField.handle(time):
            htc = IOField.read('htc_avg')
            Ma = IOField.read('Ma_avg')
            #htc = IOField.read('htc')
            #Ma = IOField.read('Ma')

            htc.partialComplete()
            Ma.partialComplete()
            #join = '/'
            #if config.hdf5:
            #    join = '_'
            #with open(mesh.getTimeDir(time) + join + 'wake_avg', 'r') as f:
            #    data = load(f)
            #    wakeCells, pl = data['arr_0'], data['arr_1']

        patches = ['pressure', 'suction']