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
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()
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)
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()
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()
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*')))
#!/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)
def objectiveHeatTransferWeighting(weight, *mesh): mesh = Mesh.container(mesh) return (mesh.areas * weight).sum()
def interpolate(U, *meshArgs): mesh = Mesh.container(meshArgs) return central(U, mesh)
def interpolate(U, gradU, *meshArgs): mesh = Mesh.container(meshArgs) return secondOrder(U, gradU, mesh, 0)
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
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:
def objectiveTest(U, T, p, *mesh, **options): mesh = Mesh.container(mesh) p0 = p.extract(mesh.neighbour) return (p0 * mesh.areas).sum()