Esempio n. 1
0
    def updateControl(self):
        """ The optimal continuous control in this example depends on the
        gradient. """

        x, y = SpatialCoordinate(self.mesh)
        # Dxu = project(Dx(self.u,0),FunctionSpace(self.mesh, "DG", 0))
        Dxxu = Dx(Dx(self.u, 0), 0)
        Dxxu = self.H[0, 0]
        self.gamma[0] = .5 * (x**2) * Dxxu
    def initControl(self):

        # Initialize control spaces
        self.controlSpace = [FunctionSpace(self.mesh, "DG", 0)]

        # Initialize controls
        u_x = Dx(self.u, 0)
        u_y = Dx(self.u, 1)
        u_lapl = Dx(u_x, 0) + Dx(u_y, 1)
        self.gamma = [conditional(u_lapl >= 0, self.alpha0, self.alpha1)]
Esempio n. 3
0
    def initControl(self):

        # Initialize control spaces
        self.controlSpace = [FunctionSpace(self.mesh, "DG", 0)]

        # Initialize controls
        u_lapl = Dx(Dx(self.u, 0), 0) + Dx(Dx(self.u, 1), 1)

        # Method 1:
        self.gamma = [conditional(u_lapl >= 0, self.alpha0, self.alpha1)]
    def initControl(self):

        # Initialize control spaces
        self.controlSpace = [FunctionSpace(self.mesh, "DG", 1)]

        # Initialize controls
        x = SpatialCoordinate(self.mesh)[0]

        u_x = Dx(self.u, 0)
        u_xx = Dx(u_x, 0)
        g1 = conditional(
            x > 0, -(self.mu - self.r) * u_x / (x * self.sigmax**2 * u_xx), 0)
        self.gamma = [g1]
Esempio n. 5
0
    def initControl(self):
        self.controlSpace = [FunctionSpace(self.mesh, "DG", 0)]

        x, y = SpatialCoordinate(self.mesh)
        u_ = (2*x-1.) \
            * (exp(1 - abs(2*x-1.)) - 1) \
            * (y + (1 - exp(y/self.delta))/(exp(1/self.delta)-1))
        cs = self.controlSpace[0]
        du = self.u - u_

        du_xx = Dx(Dx(du, 0), 0)
        du_xy = Dx(Dx(du, 0), 1)
        du_yx = Dx(Dx(du, 1), 0)
        du_yy = Dx(Dx(du, 1), 1)

        du_xx_proj = project(du_xx, cs)
        du_xy_proj = project(du_xy, cs)
        du_yx_proj = project(du_yx, cs)
        du_yy_proj = project(du_yy, cs)

        # Use the UserExpression
        gamma_star = Gallistl_Sueli_1_optControl(du_xx_proj, du_xy_proj,
                                                 du_yx_proj, du_yy_proj,
                                                 self.alphamin, self.alphamax)
        # Interpolate evaluates expression in centers of mass
        # Project evaluates expression in vertices
        self.gamma = [gamma_star]
Esempio n. 6
0
    def initControl(self):
        self.controlSpace = [
            FunctionSpace(self.mesh, "DG", 1),
            FunctionSpace(self.mesh, "DG", 1)
        ]

        u_x = Dx(self.u, 0)
        u_y = Dx(self.u, 1)
        # phi = atan(u_y/u_x) <==> sin(phi) / cos(phi) = u_y / u_x

        self.gamma = []
        phi = ufl.atan_2(u_y, u_x)
        self.gamma.append(1. / self.alpha * (cos(phi) * u_x + sin(phi) * u_y))
        self.gamma.append(phi)
    def initControl(self):

        # Initialize control spaces
        self.controlSpace = [
            FunctionSpace(self.mesh, "DG", 1),
            FunctionSpace(self.mesh, "DG", 1)
        ]

        # Initialize controls
        u_x = Dx(self.u, 0)
        u_y = Dx(self.u, 1)
        u_norm = sqrt(u_x**2 + u_y**2)

        self.gamma = []
        self.gamma.append(u_x / u_norm)
        self.gamma.append(u_y / u_norm)
Esempio n. 8
0
    def updateControl(self):
        """ The optimal continuous control in this example depends on the
        gradient. """

        x, y = SpatialCoordinate(self.mesh)
        # Dxu = project(Dx(self.u,0),FunctionSpace(self.mesh, "DG", 0))
        # Dxxu = Dx(Dx(self.u, 0), 0)
        if hasattr(self, 'H'):
            print('Use FE Hessian')
            Dxxu = self.H[0, 0]
        else:
            print('Use piecewise Hessian')
            Dxxu = Dx(Dx(self.u, 0), 0)

        # print('Use piecewise Hessian')
        # Dxxu = Dx(Dx(self.u, 0), 0)
        self.gamma[0] = .5 * (x**2) * Dxxu
    def initControl(self):

        # Initialize control spaces
        self.controlSpace = []
        self.controlSpace.append(FunctionSpace(self.mesh, "DG", 0))
        self.controlSpace.append(FunctionSpace(self.mesh, "DG", 0))
        # self.controlSpace.append(FunctionSpace(self.mesh, "CG", 1))
        # self.controlSpace.append(FunctionSpace(self.mesh, "CG", 1))

        self.gamma = []

        # Initialize controls
        Dxu = Dx(self.u, 0)
        spx = Dxu + self.beta
        smx = Dxu - self.beta

        Dyu = Dx(self.u, 1)
        spy = Dyu + self.beta
        smy = Dyu - self.beta

        if self.alpha < 1e-15:
            self.gamma.append(
                conditional(spx < 0, self.cmax,
                            conditional(smx > 0, self.cmin, 0)))
            self.gamma.append(
                conditional(spy < 0, self.cmax,
                            conditional(smy > 0, self.cmin, 0)))
        else:
            self.gamma.append(
                conditional(
                    spx < 0, ufl.Min(-1.0 * spx / self.alpha, self.cmax),
                    conditional(smx > 0,
                                ufl.Max(-1.0 * smx / self.alpha, self.cmin),
                                0)))

            self.gamma.append(
                conditional(
                    spy < 0, ufl.Min(-1.0 * spy / self.alpha, self.cmax),
                    conditional(smy > 0,
                                ufl.Max(-1.0 * smy / self.alpha, self.cmin),
                                0)))
Esempio n. 10
0
def bulk_electrostriction(E, e_r, p, direction, q_b):
    """ calculate the bulk electrostriction force """
    pp = as_matrix(p)  # photoelestic tensor is stored as as numpy array
    if direction == 'backward':
        EE_6vec_r = as_vector([
            E[0] * E[0], E[1] * E[1], -E[2] * E[2], 0.0, 0.0, 2.0 * E[0] * E[1]
        ])
        EE_6vec_i = as_vector(
            [0.0, 0.0, 0.0, 2.0 * E[1] * E[2], 2.0 * E[0] * E[2], 0.0])
        sigma_r = -0.5 * epsilon_0 * e_r**2 * pp * EE_6vec_r
        sigma_i = -0.5 * epsilon_0 * e_r**2 * pp * EE_6vec_i
        f_r = f_elst_r(sigma_r, sigma_i, q_b)
        f_i = f_elst_i(sigma_r, sigma_i, q_b)

    elif direction == 'forward':
        EE_6vec_r = as_vector([
            E[0] * E[0], E[1] * E[1], E[2] * E[2], 0.0, 0.0, 2.0 * E[0] * E[1]
        ])
        # EE_6vec_i, sigma_i, q_b is zero
        sigma_r = -0.5 * epsilon_0 * e_r**2 * pp * EE_6vec_r
        # no need to multiply zeros ...
        f_r = as_vector([
            -Dx(sigma_r[0], 0) - Dx(sigma_r[5], 1),
            -Dx(sigma_r[5], 0) - Dx(sigma_r[1], 1),
            -Dx(sigma_r[4], 0) - Dx(sigma_r[3], 1)
        ])
        f_i = Constant((0.0, 0.0, 0.0), cell=triangle)
        #f_i = as_vector([ - q_b*sigma_r[4],- q_b*sigma_r[3],- q_b*sigma_r[2]])

    else:
        raise ValueError('Specify scattering direction as forward or backward')

    return (f_r, f_i)
    def initControl(self):

        # Initialize control spaces
        self.controlSpace = []
        self.controlSpace.append(FunctionSpace(self.mesh, "DG", 0))
        self.controlSpace.append(FunctionSpace(self.mesh, "DG", 1))
        self.controlSpace.append(FunctionSpace(self.mesh, "DG", 1))

        # Initialize controls
        u_x = Dx(self.u, 0)
        u_y = Dx(self.u, 1)
        u_lapl = Dx(u_x, 0) + Dx(u_y, 1)

        g_a = conditional(u_lapl >= 0, self.alpha0, self.alpha1)

        u_norm = sqrt(u_x**2 + u_y**2)
        g_x = conditional(u_norm > 0, u_x / u_norm, 0)
        g_y = conditional(u_norm > 0, u_y / u_norm, 0)
        self.gamma = []
        self.gamma.append(g_a)
        self.gamma.append(g_x)
        self.gamma.append(g_y)
Esempio n. 12
0
    def initControl(self):
        self.controlSpace = [
            FunctionSpace(self.mesh, "DG", 1),
            FunctionSpace(self.mesh, "DG", 1)
        ]

        self.gamma = []
        # Dxu = project(Dx(self.u,0),FunctionSpace(self.mesh, "DG", 0))
        Dxu = Dx(self.u, 0)
        spx = Dxu + self.beta
        smx = Dxu - self.beta

        # Dyu = project(Dx(self.u,1),FunctionSpace(self.mesh, "DG", 0))
        Dyu = Dx(self.u, 1)
        spy = Dyu + self.beta
        smy = Dyu - self.beta

        if self.alpha < 1e-15:
            self.gamma.append(
                conditional(spx < 0, self.cmax,
                            conditional(smx > 0, self.cmin, 0)))
            self.gamma.append(
                conditional(spy < 0, self.cmax,
                            conditional(smy > 0, self.cmin, 0)))
        else:

            self.gamma.append(
                conditional(
                    spx < 0, ufl.Min(-1.0 * spx / self.alpha, self.cmax),
                    conditional(smx > 0,
                                ufl.Max(-1.0 * smx / self.alpha, self.cmin),
                                0)))

            self.gamma.append(
                conditional(
                    spy < 0, ufl.Min(-1.0 * spy / self.alpha, self.cmax),
                    conditional(smy > 0,
                                ufl.Max(-1.0 * smy / self.alpha, self.cmin),
                                0)))
Esempio n. 13
0
def f_elst_i(sigma_r, sigma_i, q_b):
    # assumes sigma is a 6 vector and sigma exp(i*q_b*z)
    f = as_vector([
        -Dx(sigma_i[0], 0) - Dx(sigma_i[5], 1) - q_b * sigma_r[4],
        -Dx(sigma_i[5], 0) - Dx(sigma_i[1], 1) - q_b * sigma_r[3],
        -Dx(sigma_i[4], 0) - Dx(sigma_i[3], 1) - q_b * sigma_r[2]
    ])
    return f
    def updateCoefficients(self):

        x, y = SpatialCoordinate(self.mesh)

        # Init coefficient matrix
        self.a = as_matrix([[1., 0], [0, self.eps]])
        self.b = as_vector([0.0, -10 * (y - 0.5) * x])
        self.c = Constant(0.0)

        # self.u_T = Constant(0)
        self.u_ = 0.5 * (self.t**2 + 1) * sin(2 * x * pi) * sin(2 * y * pi)
        self.u_T = ufl.replace(self.u_, {self.t: self.T[1]})

        # Init right-hand side
        self.f = +self.t * sin(2*pi*x) * sin(2*pi*y) \
            + inner(self.a[0][0], Dx(Dx(self.u_, 0), 0)) \
            + inner(self.b, grad(self.u_)) \
            + self.c * self.u_
        # self.f = +self.t * sin(2*pi*x) * sin(2*pi*y) \
        # + inner(self.a, grad(grad(self.u_))) \
        # + inner(self.b, grad(self.u_)) \
        # + self.c * self.u_

        self.g = Constant(0.0)
    def initControl(self):

        # Initialize control spaces
        self.controlSpace = [FunctionSpace(self.mesh, "DG", 1)]

        # Initialize controls

        P, Inv = SpatialCoordinate(self.mesh)

        cmax = self.k1 * sqrt(Inv)
        cmin = -self.k2 * sqrt(1 / (Inv + self.k3) - 1 / self.k4)
        ui = Dx(self.u, 1)
        u1 = self.Gamma(cmin, P, ui)
        u2 = self.Gamma(-Constant(self.k5), P, ui)
        u3 = self.Gamma(Constant(0.0), P, ui)
        u4 = self.Gamma(cmax, P, ui)
        umax = ufl.Max(u1, ufl.Max(u2, ufl.Max(u3, u4)))
        # self.gamma[0] = cmin
        g1 = conditional(
            u1 >= umax, cmin,
            conditional(u2 >= umax, -self.k5,
                        conditional(u3 >= umax, 0.0, cmax)))
        self.gamma = [g1]
Esempio n. 16
0
def curl_t(w):
    return Dx(w[1], 0) - Dx(w[0], 1)