1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 double *
 make_scalar_field_dofs(int edge_ct_x,   /*number of edges in X direction*/
                        int edge_ct_y    /*number of edges in Y direction*/
                        )
 {
    SAF_ENTER(make_scalar_field_dofs, NULL);

    int node_ct_x = edge_ct_x+1,       /* Number of nodes in x direction. */
        node_ct_y = edge_ct_y+1,       /* Number of nodes in y direction. */
        dofs_ub = node_ct_x*node_ct_y, /* Number of dofs. */
        i, j, node_id;
    double delx = 1.0,                 /* X increment between nodes in x. */
           dely = 1.0,                 /* Y increment between nodes in y. */
           *dofs,                      /* The array of dofs. */
           x, y;                       /* Used to compute dofs. */

    /* Preconditions */

    SAF_REQUIRE(edge_ct_x > 0, SAF_LOW_CHK_COST, NULL,
                _saf_errmsg("there must be at least 1 edge in the x direction"));
    SAF_REQUIRE(edge_ct_y > 0, SAF_LOW_CHK_COST, NULL,
                _saf_errmsg("there must be at least 1 edge in the y direction"));

    /* Body */


    /* allocate dofs as single index array,
     * but treat as dofs[nx+1][ny+1][2]; */
    dofs = (double*)malloc(dofs_ub*sizeof(double));

    for(i = 0; i < node_ct_x; i++)
    {
       x = i*delx;
       for(j = 0; j < node_ct_y; j++)
       {
          y = j*dely;
          node_id = NODE_ID(i,j);
          dofs[node_id] = x*x + y*y;
       }
    }

    /* Postconditions */

    /* Exit */

    SAF_LEAVE(dofs);
 }