Esempio n. 1
0
    outputs = tuple([tensor.Zeros(x.shape) for x in inputs])
    pl, w, ht, w2 = tensor.ExternalFunctionOp('mpi_allreduce', inputs,
                                              outputs).outputs

    # then elemwise
    def _combine(pl, w, ht, w2):
        pl, w = pl.scalar(), w.scalar()
        ht, w2 = ht.scalar(), w2.scalar()
        obj = pl / w
        obj2 = ht / w2
        return a * obj + b * obj2

    return tensor.Kernel(_combine)(1)(pl, w, ht, w2)[0]


primal = RCF('./', objective=objective, fixedTimeStep=True)
#primal = RCF('/home/talnikar/adFVM/cases/vane/3d_10/', objective=objective)
#primal = RCF('/home/talnikar/adFVM/cases/vane/les/', objective=objective)
getPlane(primal)
getWeights(primal)


def makePerturb(index):
    def perturbMesh(fields, mesh, t):
        if not hasattr(perturbMesh, 'perturbation'):
            perturbMesh.perturbation = mesh.getPerturbation(
                caseDir + 'grad{}/'.format(index))
        return perturbMesh.perturbation

    return perturbMesh
Esempio n. 2
0
    pl, w, ht, w2 = tensor.ExternalFunctionOp('mpi_allreduce', inputs,
                                              outputs).outputs

    # then elemwise
    def _combine(pl, w, ht, w2):
        pl, w = pl.scalar(), w.scalar()
        ht, w2 = ht.scalar(), w2.scalar()
        obj = pl / w
        obj2 = ht / w2
        return a * obj + b * obj2

    return tensor.Kernel(_combine)(1)(pl, w, ht, w2)[0]


primal = RCF('./',
             objective=objective,
             fixedTimeStep=True,
             timeSeriesAppend='0')
#primal = RCF('/home/talnikar/adFVM/cases/vane/3d_10/', objective=objective)
#primal = RCF('/home/talnikar/adFVM/cases/vane/les/', objective=objective)
getPlane(primal)
getWeights(primal)


def makePerturb(index):
    def perturbMesh(fields, mesh, t):
        if not hasattr(perturbMesh, 'perturbation'):
            perturbMesh.perturbation = mesh.getPerturbation(
                caseDir + 'grad{}/'.format(index))
        return perturbMesh.perturbation

    return perturbMesh
Esempio n. 3
0
import numpy as np

from adFVM import config, parallel
from adFVM.config import ad
from adFVM.compat import norm
from adFVM.density import RCF

primal = RCF(
    '/home/talnikar/adFVM/cases/periodic_wake/')  #, timeIntegrator='euler')


def objective(fields, mesh):
    rho, rhoU, rhoE = fields
    solver = rho.solver
    mesh = mesh.origMesh

    center = np.array([0.015, 0.01, 0.01])
    dist = (mesh.cellCentres - center)**2
    dist = dist.sum(axis=1)
    index = parallel.argmin(dist)
    indices = ad.ivector()
    solver.postpro.append((indices, index))

    U = rhoU.field[indices] / rho.field[indices]
    return (U[:, 1]**2).sum() / 2


def source(fields, mesh, t):
    n = mesh.nInternalCells
    U = fields[1].field[:n] / fields[0].field[:n]
    x = mesh.cellCentres[:n, 0]
Esempio n. 4
0

def objective(fields, solver):
    U, T, p = fields
    mesh = solver.mesh.symMesh

    # then elemwise
    def _combine(T):
        return (T * 1).sum()

    return tensor.Kernel(_combine)(mesh.nInternalCells)(T)


#primal = RCF('./', objective=objective, fixedTimeStep=True)
primal = RCF('/home/talnikar/adFVM/cases/box/box_4/',
             objective=objective,
             fixedTimeStep=True)


def makePerturb(param, eps=1e-6):
    def perturbMesh(fields, mesh, t):
        if not hasattr(perturbMesh, 'perturbation'):
            ## do the perturbation based on param and eps
            #perturbMesh.perturbation = mesh.getPerturbation()
            points = np.zeros_like(mesh.points)
            #points[param] = eps
            points[:] = eps * mesh.points
            #points[:] = eps
            perturbMesh.perturbation = mesh.getPointsPerturbation(points)
        return perturbMesh.perturbation
Esempio n. 5
0
import numpy as np

from adFVM import config
from adFVM.compat import intersectPlane
from adFVM.density import RCF
from adpy import tensor
from adFVM.mesh import Mesh

from adFVM.objectives.vane import objective, getPlane, getWeights

primal = RCF('/home/talnikar/adFVM/cases/vane/laminar/test_matop/',
             objective=objective,
             fixedTimeStep=True)
#primal = RCF('/home/talnikar/adFVM/cases/vane/3d_10/', objective=objective, fixedTimeStep=True)
#primal = RCF('/home/talnikar/adFVM/cases/vane/les/', objective=objective, fixedTimeStep=True)
getPlane(primal)
getWeights(primal)

parameters = 'mesh'


def makePerturb(mid):
    def perturb(fields, mesh, t):
        G = 1e0 * np.exp(-1e2 * np.linalg.norm(
            mid - mesh.cellCentres[:mesh.nInternalCells], axis=1, keepdims=1)**
                         2)
        #rho
        rho = G
        rhoU = np.zeros((mesh.nInternalCells, 3), config.precision)
        rhoU[:, 0] = G.flatten() * 100
        rhoE = G * 2e5
Esempio n. 6
0
    inputs = (drag, )
    outputs = tuple([tensor.Zeros(x.shape) for x in inputs])
    (drag, ) = tensor.ExternalFunctionOp('mpi_allreduce', inputs,
                                         outputs).outputs

    return drag


#primal = RCF('cases/cylinder_chaos_test/', CFL=1.2, mu=lambda T: Field('mu', T.field/T.field*2.5e-5, (1,)), boundaryRiemannSolver='eulerLaxFriedrichs')
primal = RCF(
    '/home/talnikar/adFVM/cases/3d_cylinder/Re_525/',
    #primal = RCF('/home/talnikar/adFVM/cases/cylinder/Re_500/',
    #primal = RCF('/home/talnikar/adFVM/cases/cylinder/chaotic/testing/',
    #mu=lambda T: 2.5e-5*T/T,
    mu=lambda T: 1.81e-5,
    #mu=lambda T: 0.9e-5,
    #boundaryRiemannSolver='eulerLaxFriedrichs',
    objective=objective,
    fixedTimeStep=True,
)

#def makePerturb(param, eps=1e-4):
#    def perturbMesh(fields, mesh, t):
#        if not hasattr(perturbMesh, 'perturbation'):
#            ## do the perturbation based on param and eps
#            #perturbMesh.perturbation = mesh.getPerturbation()
#            points = np.zeros_like(mesh.points)
#            #points[param] = eps
#            points[:] = eps*mesh.points
#            perturbMesh.perturbation = mesh.getPointsPerturbation(points)
Esempio n. 7
0
    drag = tensor.Kernel(objectiveDrag)(nFaces, (drag, ))(U,
                                                          T,
                                                          p,
                                                          *meshArgs,
                                                          solver=solver)

    inputs = (drag, )
    outputs = tuple([tensor.Zeros(x.shape) for x in inputs])
    (drag, ) = tensor.ExternalFunctionOp('mpi_allreduce', inputs,
                                         outputs).outputs

    return drag


#primal = RCF('/home/talnikar/adFVM/cases/lpt_t106/', objective=objective, fixedTimeStep=True)
primal = RCF('/home/talnikar/adFVM/cases/lpt_t106/', objective=objective)

#def makePerturb(param, eps=1e-6):
#    def perturbMesh(fields, mesh, t):
#        if not hasattr(perturbMesh, 'perturbation'):
#            ## do the perturbation based on param and eps
#            #perturbMesh.perturbation = mesh.getPerturbation()
#            points = np.zeros_like(mesh.points)
#            #points[param] = eps
#            points[:] = eps*mesh.points
#            #points[:] = eps
#            perturbMesh.perturbation = mesh.getPointsPerturbation(points)
#        return perturbMesh.perturbation
#    return perturbMesh
#perturb = [makePerturb(1)]
##perturb = []
Esempio n. 8
0
import numpy as np

from adFVM import config
from adFVM.config import ad
from adFVM.compat import norm, intersectPlane
from adFVM.density import RCF

#primal = RCF('.')
primal = RCF('/home/talnikar/foam/stator-rotor/laminar/',
             timeIntegrator='euler',
             faceReconstructor='SecondOrder')

#primal = RCF('/master/home/talnikar/foam/stator-rotor/les/')
#primal = RCF('/lustre/atlas/proj-shared/tur103/stator-rotor/les/')
#primal.dynamicMesh = True


# heat transfer
def objectiveHeatTransfer(fields, mesh):
    rho, rhoU, rhoE = fields
    solver = rhoE.solver
    U, T, p = solver.primitive(rho, rhoU, rhoE)

    res = 0
    for patchID in ['nozzle_suction', 'nozzle_pressure']:
        startFace, endFace, _ = mesh.getPatchFaceRange(patchID)
        internalIndices = mesh.owner[startFace:endFace]

        areas = mesh.areas[startFace:endFace]
        deltas = mesh.deltas[startFace:endFace]
Esempio n. 9
0
from adFVM.density import RCF 
import sys
import os
sys.path.append(os.path.expanduser('~/adFVM/templates'))
from adFVM.objectives.vane import objective, getPlane, getWeights

#config.hdf5 = True
caseDir = './'
nParam = 4
#primal = RCF(caseDir, objective='pressureLoss', objectivePLInfo={})
#primal = RCF(caseDir, objective='heatTransfer', objectiveDragInfo="pressure|suction")
primal = RCF(caseDir, timeSeriesAppend='2', fixedTimeStep=True, objective=objective)

#primal = RCF('/home/talnikar/adFVM/cases/vane/3d_10/', objective=objective)
#primal = RCF('/home/talnikar/adFVM/cases/vane/les/', objective=objective)
getPlane(primal)
getWeights(primal)


def makePerturb(index):
    def perturbMesh(fields, mesh, t):
        if not hasattr(perturbMesh, 'perturbation'):
            perturbMesh.perturbation = mesh.getPerturbation(caseDir + 'grad{}/'.format(index))
        return perturbMesh.perturbation
    return perturbMesh
perturb = []
for index in range(0, nParam):
    perturb.append(makePerturb(index))

parameters = 'mesh'
reportInterval = 100
Esempio n. 10
0
                                                          solver=solver)

    inputs = (drag, )
    outputs = tuple([tensor.Zeros(x.shape) for x in inputs])
    (drag, ) = tensor.ExternalFunctionOp('mpi_allreduce', inputs,
                                         outputs).outputs

    return drag


primal = RCF(
    '/home/talnikar/adFVM/cases/naca0012/Re_12000/',
    #primal = RCF('/master/home/talnikar/adFVM-tf/cases/naca0012/adjoint_entropy/',
    mu=lambda T: 3.4e-5,
    #mu=lambda T: 1e-9,
    #faceReconstructor='SecondOrder',
    #faceReconstructor='AnkitWENO',
    #boundaryRiemannSolver='eulerLaxFriedrichs',
    objective=objective,
    #fixedTimeStep=True
)


def makePerturb(pt_per):
    def perturb(fields, mesh, t):
        return pt_per

    return perturb


#perturb = [makePerturb(0.1), makePerturb(0.2), makePerturb(0.4)]
Esempio n. 11
0
                                                          p,
                                                          *meshArgs,
                                                          solver=solver)

    inputs = (drag, )
    outputs = tuple([tensor.Zeros(x.shape) for x in inputs])
    (drag, ) = tensor.ExternalFunctionOp('mpi_allreduce', inputs,
                                         outputs).outputs

    return drag


primal = RCF(
    '../cases/cylinder/',
    #primal = RCF('cases/cylinder/',
    mu=lambda T: 2.5e-5,
    boundaryRiemannSolver='eulerLaxFriedrichs',
    objective=objective,
    fixedTimeStep=True,
)


def perturb(fields, mesh, t):
    #mid = np.array([-0.012, 0.0, 0.])
    #G = 100*np.exp(-3e4*norm(mid-mesh.cellCentres[:mesh.nInternalCells], axis=1)**2)
    mid = np.array([-0.001, 0.0, 0.])
    G = 1e5 * np.exp(-1e5 * np.linalg.norm(
        mid - mesh.cellCentres[:mesh.nInternalCells], axis=1, keepdims=1)**2)
    rho = G
    rhoU = np.zeros((mesh.nInternalCells, 3))
    rhoU[:, 0] += G.flatten() * 100
    rhoE = G * 2e5
Esempio n. 12
0
import numpy as np
import sys, os

from adFVM import config
from adFVM.compat import norm, intersectPlane
from adFVM.density import RCF

config.hdf5 = True
caseDir = './'
#primal = RCF(caseDir, objective='pressureLoss', objectivePLInfo={})
#primal = RCF(caseDir, objective='heatTransfer', objectiveDragInfo="pressure|suction")
primal = RCF(caseDir,
             timeSeriesAppend='2',
             fixedTimeStep=True,
             objective='optim',
             objectivePLInfo={})
nParam = 4


# pressure loss
def getPlane(solver):
    point = np.array([0.052641, -0.1, 0.005])
    normal = np.array([1., 0., 0.])
    ptin = 175158.
    interCells, interArea = intersectPlane(solver.mesh, point, normal)
    return {
        'cells': interCells.astype(np.int32),
        'areas': interArea,
        'normal': normal,
        'ptin': ptin
    }
                                                          p,
                                                          *meshArgs,
                                                          solver=solver)
    inputs = (drag, )
    outputs = tuple([tensor.Zeros(x.shape) for x in inputs])
    (drag, ) = tensor.ExternalFunctionOp('mpi_allreduce', inputs,
                                         outputs).outputs
    return drag


#primal = RCF('cases/cylinder_chaos_test/', CFL=1.2, mu=lambda T: Field('mu', T.field/T.field*2.5e-5, (1,)), boundaryRiemannSolver='eulerLaxFriedrichs')
primal = RCF(
    '/master/home/nishac/adFVM/cases/slab_60_fds/temp/adjoint',
    #primal = RCF('/home/talnikar/adFVM/cases/cylinder/Re_500/',
    #primal = RCF('/home/talnikar/adFVM/cases/cylinder/chaotic/testing/',
    #mu=lambda T: 2.5e-5*T/T,
    mu=lambda T: 3.4e-5,
    boundaryRiemannSolver='eulerLaxFriedrichs',
    objective=objective,
    fixedTimeStep=True,
    readConservative=False)

#def makePerturb(param, eps=1e-4):
#    def perturbMesh(fields, mesh, t):
#        if not hasattr(perturbMesh, 'perturbation'):
#            ## do the perturbation based on param and eps
#            #perturbMesh.perturbation = mesh.getPerturbation()
#            points = np.zeros_like(mesh.points)
#            #points[param] = eps
#            points[:] = eps*mesh.points
#            perturbMesh.perturbation = mesh.getPointsPerturbation(points)
#        return perturbMesh.perturbation
Esempio n. 14
0
    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


primal = RCF('../cases/forwardStep/',
             timeIntegrator='SSPRK',
             CFL=1.2,
             Cp=2.5,
             mu=lambda T: 0.,
             objective=objective,
             fixedTimeStep=True)


def perturb(fields, mesh, t):
    patchID = 'inlet'
    startFace, endFace, _ = mesh.getPatchFaceRange(patchID)
    rho = np.zeros((mesh.nInternalCells, 1))
    rhoU = np.zeros((mesh.nInternalCells, 3))
    rhoE = np.zeros((mesh.nInternalCells, 1))
    rhoU[mesh.owner[startFace:endFace], 0] += 0.1
    return rho, rhoU, rhoE