Пример #1
0
def main():
    def pde(x, y):
        dy_r = dde.grad.jacobian(y, x, i=0, j=0)
        dy_rr = dde.grad.hessian(y, x, i=0, j=0)
        dy_thetatheta = dde.grad.hessian(y, x, i=1, j=1)
        return x[:, 0:1] * dy_r + x[:, 0:1]**2 * dy_rr + dy_thetatheta

    def solution(x):
        r, theta = x[:, 0:1], x[:, 1:]
        return r * np.cos(theta)

    geom = dde.geometry.Rectangle(xmin=[0, 0], xmax=[1, 2 * np.pi])
    bc_rad = dde.DirichletBC(
        geom,
        lambda x: np.cos(x[:, 1:2]),
        lambda x, on_boundary: on_boundary and np.isclose(x[0], 1),
    )
    data = dde.data.PDE(geom,
                        pde,
                        bc_rad,
                        num_domain=2540,
                        num_boundary=80,
                        solution=solution)

    net = dde.maps.FNN([2] + [20] * 3 + [1], "tanh", "Glorot normal")
    # Use [r*sin(theta), r*cos(theta)] as features,
    # so that the network is automatically periodic along the theta coordinate.
    net.apply_feature_transform(lambda x: tf.concat(
        [x[:, 0:1] * tf.sin(x[:, 1:2]), x[:, 0:1] * tf.cos(x[:, 1:2])], axis=1)
                                )

    model = dde.Model(data, net)
    model.compile("adam", lr=1e-3, metrics=["l2 relative error"])
    losshistory, train_state = model.train(epochs=15000)
    dde.saveplot(losshistory, train_state, issave=True, isplot=True)
Пример #2
0
 def feature_transform(t):
     t = 0.01 * t
     return tf.concat(
         (t, tf.sin(t), tf.sin(2 * t), tf.sin(3 * t), tf.sin(
             4 * t), tf.sin(5 * t)),
         axis=1,
     )
Пример #3
0
def feature_transform(inputs):
    # Periodic BC in x
    P = BOX[1][0] - BOX[0][0] + 2 * DPML
    w = 2 * np.pi / P
    x, y = w * inputs[:, :1], inputs[:, 1:]
    return tf.concat(
        (
            tf.math.cos(x),
            tf.math.sin(x),
            tf.math.cos(2 * x),
            tf.math.sin(2 * x),
            tf.math.cos(3 * x),
            tf.math.sin(3 * x),
            tf.math.cos(4 * x),
            tf.math.sin(4 * x),
            tf.math.cos(5 * x),
            tf.math.sin(5 * x),
            tf.math.cos(6 * x),
            tf.math.sin(6 * x),
            # tf.math.cos(7 * x),
            # tf.math.sin(7 * x),
            # tf.math.cos(8 * x),
            # tf.math.sin(8 * x),
            # tf.math.cos(9 * x),
            # tf.math.sin(9 * x),
            # tf.math.cos(10 * x),
            # tf.math.sin(10 * x),
            y,
            tf.math.cos(OMEGA * y),
            tf.math.sin(OMEGA * y),
        ),
        axis=1,
    )
Пример #4
0
 def modify_inv_heter(self, x, y):
     domain_space = x[:, 0:2]
     D = tf.layers.dense(tf.layers.dense(
         tf.layers.dense(
             tf.layers.dense(
                 tf.layers.dense(
                     tf.layers.dense(domain_space, 60, tf.nn.tanh), 60,
                     tf.nn.tanh), 60, tf.nn.tanh), 60, tf.nn.tanh), 60,
         tf.nn.tanh),
                         1,
                         activation=None)
     return tf.concat((y[:, 0:2], D), axis=1)
Пример #5
0
 def feature_transform(t):
     return tf.concat(
         (
             t,
             tf.sin(t),
             tf.sin(2 * t),
             tf.sin(3 * t),
             tf.sin(4 * t),
             tf.sin(5 * t),
             tf.sin(6 * t),
         ),
         axis=1,
     )
Пример #6
0
def initialState_tf(X, wei=-1, sample_output=None):
    """
    initial state for the rho 2020/12/25 wodnering
    ρ(q,0)=1/[〖(2π)〗^(1/4) √σ]^N |├ UP⟩⟨UP┤|∙∏_(s=1)^N▒〖ψ_((α_s=0)) (q_s)〗
    
    ρ(q,0)=1/[〖(2π)〗^(1/4) √σ]^N  ∑_(i=1)^(N+1)▒∑_(j=1)^(N+1)▒〖ρ_ij (0)〗|├ i⟩⟨j┤|∙∏_(s=1)^N▒〖ψ_((α_s=0)) (q_s)〗

    ρ_ij (0)=1/2N (1-δ_(i,N+1) )(1-δ_(j,N+1) )+1/2 δ_(i,N+1) δ_(j,N+1)
                        +1/(2√N) [(1-δ_(i,N+1) ) δ_(j,N+1)+δ_(i,N+1) (1-δ_(j,N+1) )]
    ψ_((α_s=0) ) (q_s )=e^(-q_s^2/2σ^2 )/(〖(2π)〗^(1/4) √σ) H_0 (q_s/(√2 σ))
    """
    def rhoij(i, j):
        """
        get the rho(i,j) for inital state
        """
        assert (i >= j)
        if i == j:
            if i == N + 1:
                Rhoij = 1 / 2
            else:
                Rhoij = 1 / 2 / Ntf
        elif i == N + 1:
            Rhoij = 1 / 2 / (Ntf)**0.5
        else:
            Rhoij = 1 / 2 / Ntf
        return Rhoij

    if sample_output is None:
        NUM_initial, _ = np.shape(X)
        Rho0 = np.zeros([NUM_initial, C.sizeRho])
    else:
        Rho0 = []
        for i in range(0, C.sizeRho):
            Rho0.append(sample_output[:, i:i + 1] * 0)
    N = C.N
    ConstantNumber = 1 / ((2 * pi)**(1 / 4) * (sigma)**0.5)**Ntf
    Phi0_multi = 1
    for s in range(1, N):
        Phi0_multi = Phi0_multi * phi(X[:, s:s + 1], 0)
    for j in range(1, C.N + 2):
        for i in range(j + 1, C.N + 2):
            Xnum = getXHalf_real(i, j, C.N)
            X_imag = getXHalf_imag(i, j, C.N)
            Rho0[Xnum] = Rho0[Xnum] + ConstantNumber * Phi0_multi * rhoij(i, j)

    for n in range(1, N + 2):
        Rho0[n - 1] = Rho0[n - 1] + ConstantNumber * Phi0_multi * rhoij(n, n)
    if wei == -1:
        return tf.concat(Rho0, axis=1)
    else:
        return Rho0[:, wei:wei + 1]
Пример #7
0
    def modify_heter(self, x, y):

        x_space, y_space = x[:, 0:1], x[:, 1:2]

        x_upper = tf.less_equal(x_space, 54 * 0.1)
        x_lower = tf.greater(x_space, 32 * 0.1)
        cond_1 = tf.logical_and(x_upper, x_lower)

        y_upper = tf.less_equal(y_space, 54 * 0.1)
        y_lower = tf.greater(y_space, 32 * 0.1)
        cond_2 = tf.logical_and(y_upper, y_lower)

        D0 = tf.ones_like(x_space) * 0.02
        D1 = tf.ones_like(x_space) * 0.1
        D = tf.where(tf.logical_and(cond_1, cond_2), D0, D1)
        return tf.concat((y[:, 0:2], D), axis=1)
Пример #8
0
def output_transform(inputs, outputs):
    x, y = inputs[:, :1], inputs[:, 1:]

    # 1 <= eps <= 12
    eps = 1 + 11 * tf.math.sigmoid(outputs[:, -1:])

    # Zero Dirichlet BC
    a, b = BOX[0][1] - DPML, BOX[1][1] + DPML
    E = (1 - tf.math.exp(a - y)) * (1 - tf.math.exp(y - b)) * outputs[:, :2]

    # Zero Dirichlet and Neumann BC
    # a, b = BOX[0][1] - DPML, BOX[1][1] + DPML
    # E = 0.01 * (a - y) ** 2 * (y - b) ** 2 * outputs[:, :2]

    # return E
    return tf.concat((E, eps), axis=1)
Пример #9
0
def initial_condition(x, y):
    """
        main function for differential function with q
    """
    def rhoij(i, j):
        """
        get the rho(i,j) for inital state
        """
        assert (i >= j)
        if i == j:
            if i == C.N + 1:
                Rhoij = 1 / 2
            else:
                Rhoij = 1 / 2 / Ntf
        elif i == C.N + 1:
            Rhoij = 1 / 2 / (Ntf)**0.5
        else:
            Rhoij = 1 / 2 / Ntf
        return Rhoij

    Rho0 = []
    for i in range(0, C.sizeRho):
        Rho0.append(y[:, i:i + 1] * 0)

    Phi0_multi = etf**(-x[:, 0:1]**2 /
                       (2 * sigma**2)) / ((2 * pi)**0.5 * sigma)**0.5
    for s in range(1, C.N):
        Phi0_multi = Phi0_multi * etf**(-x[:, s:s + 1]**2 / (2 * sigma**2)) / (
            (2 * pi)**0.5 * sigma)**0.5
    for n in range(1, C.N + 2):
        Rho0[n - 1] = Rho0[n - 1] + ConstantNumber * Phi0_multi * rhoij(n, n)
    for j in range(1, C.N + 1):
        for i in range(j + 1, C.N + 1):
            Xnum = getXHalf_real(i, j, C.N)
            Rho0[Xnum] = Rho0[Xnum] * ConstantNumber * Phi0_multi * rhoij(i, j)
    result = []
    for i in range(0, C.sizeRho):
        result.append(x[:, C.N:] * y[:, i:i + 1] + Rho0[i])
        for j in range(0, C.N):
            result[i] = result[i] * (x[:, j:j + 1] - QmaxTF) * (x[:, j:j + 1] +
                                                                QmaxTF)
    return tf.concat(result, axis=1)
Пример #10
0
def output_transform(inputs, outputs):
    x, y = inputs[:, :1], inputs[:, 1:]
    bc = 16 * x * (1 - x) * y * (1 - y)

    # u
    u0 = 1
    u = tf.math.abs(u0 + bc * outputs[:, :1])
    # v
    v = bc * outputs[:, 1:2]
    # p
    p = (1 - x) * outputs[:, 2:3]
    # rho
    # rho = tf.math.exp(-bc * tf.math.square(outputs[:, 3:]))
    # rho = 1 + bc * outputs[:, 3:]
    center = tf.math.square(x - 0.5) + tf.math.square(y - 0.5)
    # rho = center * outputs[:, 3:]
    rho = center * (bc * outputs[:, 3:] + (1 - bc) * (1 + 1e-6 / 0.25) /
                    (center + 1e-6))
    rho = tf.math.maximum(0.0, tf.math.minimum(1.0, rho))
    return tf.concat((u, v, p, rho), axis=1)
Пример #11
0
 def feature_transform(t):
     t = 0.1 * t
     return tf.concat((t, tf.exp(-t)), axis=1,)
Пример #12
0
def SLE_q(x, y, C):
    """
    SLE function with q
    """
    Drho = []

    for allindex in range(0, C.sizeRho):
        DrhoQ = Gamma / 2 * y[:, allindex:allindex + 1] * Ntf
        for qs in range(0, C.N):
            DrhoQ = DrhoQ + Gamma / 2 * (
                x[:, qs:qs + 1] * dde.grad.jacobian(y, x, i=allindex, j=qs) +
                (0.5 + n_bar) *
                dde.grad.hessian(y, x, i=qs, j=qs, component=allindex))

        DrhoT = dde.grad.jacobian(y, x, i=allindex, j=C.N)
        Drho.append(DrhoQ - DrhoT)
        # Drho.append(DrhoT)
    # for n in range(1 ,C.N + 1):
    #         #  n = 1: N
    #     for m in range(n + 1 , C.N + 2 ):
    #         # m = n + 1: N + 1
    #         X_imag = getXHalf_imag(m,n, C.N)
    #         X_real = getXHalf_real(m,n, C.N)

    #         # real part
    #         indexAA =  getXHalf_imag(C.N + 1, m , C.N)
    #         AA = - (
    #             y[:,X_imag:X_imag+1] * ( w - v -lamb * w_vib * x[:,n-1:n] )
    #             - G * y[:,indexAA:indexAA+1]
    #         )
    #         DD = AA *x[:,n-1:n] *0
    #         if m == C.N+1:
    #             for k in range(1,C.N+1):
    #                 if k >n:
    #                     indexDD = getXHalf_imag(k,n,C.N)
    #                     DD = DD + G * y[:,indexDD:indexDD+1]
    #                 elif k < n:
    #                     indexDD = getXHalf_imag(n,k,C.N)
    #                     DD = DD - G * y[:,indexDD:indexDD+1]
    #         else:
    #             indexDD = getXHalf_imag(C.N+1, n ,C.N)
    #             DD = y[:,X_imag:X_imag+1] * \
    #                 (w - v - lamb * w_vib * x[:,m-1:m] ) \
    #                     + G * y[:, indexDD:indexDD+1]

    #         # imag part
    #         indexEE = getXHalf_real(C.N+1,m,C.N )
    #         EE = y[:,X_real:X_real+1] * (w - v - lamb * w_vib * x[:, n-1:n]) \
    #             + G * y[:,indexEE:indexEE+1 ]
    #         HH = EE * 0
    #         if m == C.N +1 :
    #             for k in range(1,C.N + 1):
    #                 if k > n:
    #                     indexEE = getXHalf_real(k,n,C.N)
    #                     HH = HH - G * y[:,indexEE :indexEE +1]
    #                 elif k < n:
    #                     indexEE = getXHalf_real(n,k,C.N)
    #                     HH = HH - G * y[:,indexEE:indexEE+1]
    #                 elif k == n:
    #                     HH = HH - G * y[:,n-1:n]
    #         else:
    #             indexEE = getXHalf_real(C.N + 1,n,C.N)
    #             HH = - y[:, X_real:X_real+1]* \
    #                 (w - v - lamb * w_vib * x[:, m-1:m]) \
    #                     - G * y[:,indexEE:indexEE+1]
    #         Drho[X_real] = Drho[X_real] + AA + DD
    #         Drho[X_imag] = Drho[X_imag] + EE + HH

    return tf.concat(Drho, axis=1)
Пример #13
0
def feature_transform(x):
    return tf.concat(
        [x[:, 0:1] * tf.sin(x[:, 1:2]), x[:, 0:1] * tf.cos(x[:, 1:2])], axis=1)