示例#1
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
示例#2
0
def objectiveHeatTransfer(U, T, p, weight, *mesh, **options):
    solver = options['solver']
    mesh = Mesh.container(mesh)
    Ti = T.extract(mesh.owner)
    Tw = 300.
    dtdn = (Tw - Ti) / mesh.deltas
    k = solver.Cp * solver.mu(Tw) / solver.Pr
    ht = k * dtdn * mesh.areas * weight
    w = mesh.areas * weight
    return ht.sum(), w.sum()
示例#3
0
文件: diff_fields.py 项目: qiqi/adFVM
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)
示例#4
0
文件: lpt_t106.py 项目: qiqi/adFVM
def objectiveDrag(U, T, p, *mesh, **options):
    solver = options['solver']
    mesh = Mesh.container(mesh)
    U0 = U.extract(mesh.neighbour)[0]
    U0i = U.extract(mesh.owner)[0]
    p0 = p.extract(mesh.neighbour)
    T0 = T.extract(mesh.neighbour)
    nx = mesh.normals[0]
    mungUx = solver.mu(T0) * (U0 - U0i) / mesh.deltas
    drag = (p0 * nx - mungUx) * mesh.areas
    return drag.sum()
示例#5
0
def objectiveDrag(U, T, p, *mesh, **options):
    solver = options['solver']
    mesh = Mesh.container(mesh)
    U0 = U.extract(mesh.neighbour)
    Ui = U.extract(mesh.owner)
    p0 = p.extract(mesh.neighbour)
    T0 = T.extract(mesh.neighbour)
    nx = mesh.normals[0]
    mungUx = solver.mu(T0) * (U0[0] - Ui[0]) / mesh.deltas
    drag = (p0 * nx - mungUx) * mesh.areas
    # rescaled version
    rho0 = p0 / (solver.R * T0)
    D = diameter
    z = 2 * D
    drag = drag * 2. / (rho0 * (U0.dot(U0) * z * D))
    return drag.sum()
示例#6
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*')))
示例#7
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)

示例#8
0
文件: vane.py 项目: qiqi/adFVM
def objectiveHeatTransferWeighting(weight, *mesh):
    mesh = Mesh.container(mesh)
    return (mesh.areas * weight).sum()
示例#9
0
 def interpolate(U, *meshArgs):
     mesh = Mesh.container(meshArgs)
     return central(U, mesh)
示例#10
0
 def interpolate(U, gradU, *meshArgs):
     mesh = Mesh.container(meshArgs)
     return secondOrder(U, gradU, mesh, 0)
示例#11
0
文件: map_fields.py 项目: qiqi/adFVM
import numpy as np

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

#config.hdf5 = True
case1, case2, time1, time2 = sys.argv[1:5]
if len(sys.argv) > 5:
    skipZ = True
else:
    skipZ = False
time1 = float(time1)
time2 = float(time2)

mesh1 = Mesh.create(case1)
mesh2 = Mesh.create(case2)

from scipy.spatial import cKDTree as KDTree


def mapNearest(centres1, centres2):
    if skipZ:
        centres1 = centres1[:, :2]
        centres2 = centres2[:, :2]
    tree = KDTree(centres1)
    indices = tree.query(centres2)[1]
    #print centres1.shape, centres2.shape, indices.shape
    return indices

示例#12
0
文件: hdf5serial.py 项目: qiqi/adFVM
        fields.append(field)
        boundaries.append(boundary)

    fieldGroup = fieldsFile.create_group(name)

    genParallel(parallelInfo, fieldGroup)
    fieldGroup.create_dataset('field', data=np.vstack(fields))
    fieldGroup.create_dataset('boundary', data=np.vstack(boundaries))


config.hdf5 = False
meshes = []
for rank, processor in enumerate(processorDirs):
    print processor
    mesh = Mesh()
    mesh.points, mesh.faces, mesh.owner, \
            mesh.neighbour, mesh.addressing, mesh.boundary = mesh.readFoam(processor, 'constant')
    mesh.buildBeforeWrite()

    meshes.append(mesh)

meshFile = h5py.File(case + '/mesh.hdf5', 'w')
meshWriteHDF5(meshes)
meshFile.close()

for index, time in enumerate(times):
    print 'writing time', time
    if time.is_integer():
        stime = int(time)
    else:
示例#13
0
def objectiveTest(U, T, p, *mesh, **options):
    mesh = Mesh.container(mesh)
    p0 = p.extract(mesh.neighbour)
    return (p0 * mesh.areas).sum()