'value': np.random.rand(nFaces, 3) } U = IOField('U', field, (3,), boundary) 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)
#!/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()
for patchID in mesh1.boundary: startFace, endFace, indices1 = getPatchInfo(mesh1, patchID) centres1 = mesh1.faceCentres[startFace:endFace] startFace, endFace, indices2 = getPatchInfo(mesh2, patchID) centres2 = mesh2.faceCentres[startFace:endFace] patchIndices[patchID] = mapNearest(centres1, centres2) #for field in mesh1.getFields(time1): for field in ['U', 'T', 'p', 'rho', 'rhoU', 'rhoE']: print 'interpolating', field Field.setMesh(mesh1) with IOField.handle(time1): phi1 = IOField.read(field) phi1.partialComplete() dims = phi1.dimensions phi2 = np.zeros((mesh2.nCells, ) + dims) phi2 = IOField(field, phi2, dims) phi2.field[:mesh2.nInternalCells] = phi1.field[internalIndices] for patchID in phi1.boundary: startFace, endFace, indices1 = getPatchInfo(mesh1, patchID) startFace, endFace, indices2 = getPatchInfo(mesh2, patchID) phi2.field[indices2] = phi1.field[indices1][patchIndices[patchID]] phi2.boundary = copy.deepcopy(phi1.boundary) Field.setMesh(mesh2) with IOField.handle(time2): phi2.write() print