def objective(fields, solver): U, T, p = fields mesh = solver.mesh.symMesh def _meshArgs(start=0): return [x[start] for x in mesh.getTensor()] patch = mesh.boundary['obstacle'] startFace, nFaces = patch['startFace'], patch['nFaces'] meshArgs = _meshArgs(startFace) test = tensor.Zeros((1, 1)) test = tensor.Kernel(objectiveTest)(nFaces, (test, ))(U, T, p, *meshArgs) inputs = (test, ) outputs = tuple([tensor.Zeros(x.shape) for x in inputs]) (test, ) = tensor.ExternalFunctionOp('mpi_allreduce', inputs, outputs).outputs return test
def objective(fields, solver): U, T, p = fields mesh = solver.mesh.symMesh def _meshArgs(start=0): return [x[start] for x in mesh.getTensor()] nPlaneCells, cells, areas = [x[0] for x in solver.extraArgs[:3]] w = tensor.Zeros((1, 1)) w = tensor.Kernel(objectivePressureLossWeighting)(nPlaneCells, (w, ))(U, T, p, cells, areas, solver=solver) weights = [x[0] for x in solver.extraArgs[3:]] w2 = tensor.Zeros((1, 1)) _heatTransferWeighting = tensor.Kernel(objectiveHeatTransferWeighting) for index, patchID in enumerate(patches): patch = mesh.boundary[patchID] startFace, nFaces = patch['startFace'], patch['nFaces'] meshArgs = _meshArgs(startFace) weight = weights[index] w2 = _heatTransferWeighting(nFaces, (w2, ))(weight, *meshArgs) inputs = (w, w2) outputs = tuple([tensor.Zeros(x.shape) for x in inputs]) w, w2 = tensor.ExternalFunctionOp('mpi_allreduce', inputs, outputs).outputs pl = tensor.Zeros((1, 1)) pl = tensor.Kernel(objectivePressureLoss)(nPlaneCells, (pl, ))(U, T, p, cells, areas, w, solver=solver) _heatTransfer = tensor.Kernel(objectiveHeatTransfer) ht = tensor.Zeros((1, 1)) for index, patchID in enumerate(patches): patch = mesh.boundary[patchID] startFace, nFaces = patch['startFace'], patch['nFaces'] meshArgs = _meshArgs(startFace) weight = weights[index] ht = _heatTransfer(nFaces, (ht, ))(U, T, p, weight, w2, *meshArgs, solver=solver) k = solver.mu(300) * solver.Cp / solver.Pr a = 0.4 #b = -0.71e-3/(120*k)/2000. b = 0. # MPI ALLREDUCE #if not config.gpu: # inputs = (pl, w, ht, w2) # outputs = tuple([tensor.Zeros(x.shape) for x in inputs]) # pl, w, ht, w2 = tensor.ExternalFunctionOp('mpi_allreduce', inputs, outputs).outputs inputs = (pl, ht) outputs = tuple([tensor.Zeros(x.shape) for x in inputs]) pl, ht = tensor.ExternalFunctionOp('mpi_allreduce', inputs, outputs).outputs # then elemwise def _combine(pl, ht): pl = pl.scalar() ht = ht.scalar() obj = pl obj2 = ht return a * obj + b * obj2 return tensor.Kernel(_combine)(1)(pl, ht)