예제 #1
0
def jacobi_test_function_derivatives(n_test_functions, x):
    d1test_total = [((1 + 2) / 2) * jacobi_polynomial(1, 1, 1, x),
                    ((2 + 2) / 2) * jacobi_polynomial(2, 1, 1, x) -
                    ((2) / 2) * jacobi_polynomial(2 - 2, 1, 1, x)]
    d2test_total = [
        ((1 + 2) * (1 + 3) / (2 * 2)) * jacobi_polynomial(0, 2, 2, x),
        ((2 + 2) * (2 + 3) / (2 * 2)) * jacobi_polynomial(1, 2, 2, x)
    ]
    for n in range(3, n_test_functions + 1):
        d1test = ((n + 2) / 2) * jacobi_polynomial(n, 1, 1, x) - (
            (n) / 2) * jacobi_polynomial(n - 2, 1, 1, x)
        d2test = ((n + 2) * (n + 3) /
                  (2 * 2)) * jacobi_polynomial(n - 1, 2, 2, x) - (
                      (n) * (n + 1) /
                      (2 * 2)) * jacobi_polynomial(n - 3, 2, 2, x)
        d1test_total.append(d1test)
        d2test_total.append(d2test)
    return np.array(d1test_total), np.array(d2test_total)
예제 #2
0
    def train(self, n_iterations, treshold, total_record):
        start_time = time.time()
        for it in range(n_iterations):
            self.sess.run(self.train_op_adam)

            if it % 10 == 0:
                loss_value = self.sess.run(self.loss)
                loss_valueb = self.sess.run(self.loss_boundary)
                loss_valuev = self.sess.run(self.varloss_total)
                l2_errorv = self.sess.run(self.l2_error,
                                          {self.x_prediction: self.x_test})
                total_record.append(np.array([it, loss_value, l2_errorv]))

                if loss_value < treshold:
                    print('It: %d, Loss: %.3e' % (it, loss_value))
                    return total_record

            if it % 100 == 0:
                elapsed = time.time() - start_time
                str_print = 'It: %d, Lossb: %.3e, Lossv: %.3e, ErrL2: %.3e, Time: %.2f'
                print(str_print %
                      (it, loss_valueb, loss_valuev, l2_errorv, elapsed))
                start_time = time.time()
        return total_record
예제 #3
0
def jacobi_test_function(n_test_functions, x):
    test_total = [
        jacobi_polynomial(n + 1, 0, 0, x) - jacobi_polynomial(n - 1, 0, 0, x)
        for n in range(1, n_test_functions + 1)
    ]
    return np.array(test_total)
예제 #4
0
            r1 * x)) / ((np.cosh(r1 * x))**2)
        return -amp * gtemp

    def test_function(n, x):
        return jacobi_test_function(n, x)

    x_quad, w_quad = gauss_lobatto_jacobi_weights(n_quadrature_points, 0, 0)

    grid = create_grid(n_elements)

    elements = [
        Element(x_quad, w_quad, test_functions_per_element, test_function, f,
                grid[i], grid[i + 1]) for i in range(n_elements)
    ]

    x_boundary = np.array([-1.0, 1.0])[:, None]
    u_boundary = u_exact(x_boundary)

    x_quad_train = x_quad[:, None]
    w_quad_train = w_quad[:, None]

    x_test = np.linspace(-1, 1, test_points)
    x_prediction = x_test[:, None]
    u_correct = u_exact(x_test)[:, None]

    model = VPINN(net_layers)
    model.boundary(x_boundary, u_boundary)
    model.element_losses(x_quad_train, w_quad_train, variational_form,
                         boundary_loss_weight, elements)
    model.optimizer(learning_rate)
    model.exact(x_test, u_exact(x_test))
예제 #5
0
파일: grid.py 프로젝트: coinator/hp-VPINNs
def create_grid(n_elements, x_left=-1, x_right=1):
    delta_x = (x_right - x_left) / n_elements
    return np.array([x_left + i * delta_x for i in range(n_elements + 1)])