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
48
49
50
51
52
53
54
55
56
 double *
 make_stress_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_stress_field_dofs, NULL);

     int dofs_ub = edge_ct_x*edge_ct_y*2*3, /* Number of dofs. */
        tri_ct = 0,                        /* Triangle counter. */
        i, j;
    double *dofs;                          /* The array of 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[edge_ct_x][edge_ct_y][3]; */
    dofs = (double*)malloc(dofs_ub*sizeof(double));

    for(i=0; i<edge_ct_x; i++)
    {
       for(j=0; j<edge_ct_y; j++)
       {
          /* Each (i,j) pair is the lower-left-hand node in
           * a quad containing two triangles. */

          /* Stress for lower triangle in quad, */

          dofs[3*tri_ct]   = tri_ct+0.0; /* xx component */
          dofs[3*tri_ct+1] = tri_ct+0.1; /* xy component */
          dofs[3*tri_ct+2] = tri_ct+0.2; /* yy component */

          tri_ct++;

          /* Stress for upper triangle in quad, */

          dofs[3*tri_ct]   = tri_ct+0.0; /* xx component */
          dofs[3*tri_ct+1] = tri_ct+0.1; /* xy component */
          dofs[3*tri_ct+2] = tri_ct+0.2; /* yy component */

          tri_ct++;
       }
    }

    /* Postconditions */

    /* Exit */

    SAF_LEAVE(dofs);
 }