예제 #1
0
    public static double[] local_fem_1d(int order, double[] node_x, double[] node_v,
                                        int sample_num, double[] sample_x)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LOCAL_FEM_1D evaluates a local finite element function.
    //
    //  Discussion:
    //
    //    A local finite element function is a finite element function
    //    defined over a single element.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    19 March 2011
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int ORDER, the order of the element.
    //    0 <= ORDER.  ORDER = 1 means piecewise linear.
    //
    //    Input, double NODE_X[ORDER], the element nodes.
    //    These must be distinct.  Basis function I is 1 when X = NODE_X(I) and 0
    //    when X is equal to any other node.
    //
    //    Input, double NODE_V[ORDER], the value of the finite element
    //    function at each node.
    //
    //    Input, int SAMPLE_NUM, the number of sample points.
    //
    //    Input, double SAMPLE_X[SAMPLE_NUM], the sample points at which
    //    the local finite element function is to be evaluated.
    //
    //    Output, double LOCAL_FEM_1D[SAMPLE_NUM], the values of the local
    //    finite element basis functions.
    //
    {
        double[] sample_v = new double[sample_num];

        for (int sample = 0; sample < sample_num; sample++)
        {
            double   x   = sample_x[sample];
            double[] phi = LocalBasis.local_basis_1d(order, node_x, x);
            sample_v[sample] = typeMethods.r8vec_dot_product(order, node_v, phi);
        }

        return(sample_v);
    }
예제 #2
0
    private static void test01()
//****************************************************************************80
//
//  Purpose:
//
//    TEST01 verifies LOCAL_BASIS_1D.
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license.
//
//  Modified:
//
//    03 June 2011
//
//  Author:
//
//    John Burkardt
//
//  Parameters:
//
//    None
//
    {
        const int NODE_NUM = 4;

        double[] node_x =
        {
            1.0, 2.0, 4.0, 4.5
        }

        ;
        double[] phi;
        double[] phi_matrix = new double[NODE_NUM * NODE_NUM];
        double   x;

        Console.WriteLine("");
        Console.WriteLine("TEST01:");
        Console.WriteLine("  LOCAL_BASIS_1D evaluates the local basis functions");
        Console.WriteLine("  for a 1D element.");
        Console.WriteLine("");
        Console.WriteLine("  Test that the basis functions, evaluated at the nodes,");
        Console.WriteLine("  form the identity matrix.");
        Console.WriteLine("");
        Console.WriteLine("  Number of nodes = " + NODE_NUM + "");

        Console.WriteLine("");
        Console.WriteLine("  Node coordinates:");
        Console.WriteLine("");
        for (int j = 0; j < NODE_NUM; j++)
        {
            Console.WriteLine("  " + j.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + node_x[j].ToString(CultureInfo.InvariantCulture).PadLeft(7) + "");
        }

        for (int j = 0; j < NODE_NUM; j++)
        {
            x   = node_x[j];
            phi = LocalBasis.local_basis_1d(NODE_NUM, node_x, x);
            for (int i = 0; i < NODE_NUM; i++)
            {
                phi_matrix[i + j * NODE_NUM] = phi[i];
            }
        }

        typeMethods.r8mat_print(NODE_NUM, NODE_NUM, phi_matrix, "  A(I,J) = PHI(I) at node (J):");

        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("  The PHI functions should sum to 1 at random X values:");
        Console.WriteLine("");
        Console.WriteLine("       X        Sum ( PHI(:)(X) )");
        Console.WriteLine("");

        for (int j = 1; j <= 5; j++)
        {
            x   = UniformRNG.r8_uniform(1.0, 4.5, ref seed);
            phi = LocalBasis.local_basis_1d(NODE_NUM, node_x, x);
            double s = typeMethods.r8vec_sum(NODE_NUM, phi);
            Console.WriteLine("  " + x.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + s.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
    }