File: test_face_transform3.c

package info (click to toggle)
p4est 2.3.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,536 kB
  • sloc: ansic: 87,528; makefile: 855; sh: 635; perl: 272; python: 226; awk: 40; javascript: 23
file content (153 lines) | stat: -rw-r--r-- 5,613 bytes parent folder | download | duplicates (2)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
  This file is part of p4est.
  p4est is a C library to manage a collection (a forest) of multiple
  connected adaptive quadtrees or octrees in parallel.

  Copyright (C) 2010 The University of Texas System
  Additional copyright (C) 2011 individual authors
  Written by Carsten Burstedde, Lucas C. Wilcox, and Tobin Isaac

  p4est is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  p4est is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with p4est; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/*
 * Purpose of this program is to verify the face transformation codes
 * that are computed in a fast but cryptic way in p8est_find_face_transform.
 */

#include <p8est.h>
#include <p4est_to_p8est.h>

int
main (int argc, char **argv)
{
  int                 my_face, target_face, orientation;
  int                 face_ref, face_perm;
  int                 low[2], high[2], swap;
  int                 i, reverse;
  int                 ft[9], gt[9];
  int                *my_axis = &ft[0];
  int                *target_axis = &ft[3];
  int                *edge_reverse = &ft[6];

  sc_init (sc_MPI_COMM_NULL, 1, 1, NULL, SC_LP_DEFAULT);
  p4est_init (NULL, SC_LP_DEFAULT);

  for (my_face = 0; my_face < 2 * P4EST_DIM; ++my_face) {
    for (target_face = 0; target_face < 2 * P4EST_DIM; ++target_face) {
      for (orientation = 0; orientation < 4; ++orientation) {

        /* find if my edges 0 and 2 are parallel to the x, y, or z-axis */
        my_axis[0] = p8est_face_edges[my_face][0] / 4;
        my_axis[1] = p8est_face_edges[my_face][2] / 4;
        target_axis[0] = target_axis[1] = -1;
        edge_reverse[0] = edge_reverse[1] = 0;

        /* find matching target vertices */
        face_ref = p8est_face_permutation_refs[my_face][target_face];
        face_perm = p8est_face_permutation_sets[face_ref][orientation];
        low[0] = low[1] =
          p8est_face_corners[target_face][p8est_face_permutations[face_perm]
                                          [0]];
        high[0] =
          p8est_face_corners[target_face][p8est_face_permutations[face_perm]
                                          [1]];
        high[1] =
          p8est_face_corners[target_face][p8est_face_permutations[face_perm]
                                          [2]];
        if (low[0] > high[0]) {
          swap = low[0];
          low[0] = high[0];
          high[0] = swap;
          edge_reverse[0] = 1;
        }
        if (low[1] > high[1]) {
          swap = low[1];
          low[1] = high[1];
          high[1] = swap;
          edge_reverse[1] = 1;
        }

        /* find matching target edges */
        for (i = 0; i < 12; ++i) {
          if (low[0] == p8est_edge_corners[i][0] &&
              high[0] == p8est_edge_corners[i][1]) {
            P4EST_ASSERT (target_axis[0] == -1);
            target_axis[0] = i / 4;
#ifndef P4EST_ENABLE_DEBUG
            if (target_axis[1] >= 0)
              break;
#endif
          }
          else if (low[1] == p8est_edge_corners[i][0] &&
                   high[1] == p8est_edge_corners[i][1]) {
            P4EST_ASSERT (target_axis[1] == -1);
            target_axis[1] = i / 4;
#ifndef P4EST_ENABLE_DEBUG
            if (target_axis[0] >= 0)
              break;
#endif
          }
        }

        /* find what axis is normal to the faces */
        my_axis[2] = my_face / 2;
        target_axis[2] = target_face / 2;
        edge_reverse[2] = 2 * (my_face % 2) + target_face % 2;

#ifdef P4EST_ENABLE_DEBUG
        for (i = 0; i < 3; ++i) {
          P4EST_ASSERT (0 <= my_axis[i] && my_axis[i] < 3);
          P4EST_ASSERT (0 <= target_axis[i] && target_axis[i] < 3);
        }
        P4EST_ASSERT (my_axis[0] != my_axis[1] &&
                      my_axis[0] != my_axis[2] && my_axis[1] != my_axis[2]);
        P4EST_ASSERT (target_axis[0] != target_axis[1] &&
                      target_axis[0] != target_axis[2] &&
                      target_axis[1] != target_axis[2]);
#endif

        /* output the results */
        P4EST_LDEBUGF
          ("Results for %d %d %d are %d %d %d %d %d %d %d %d %d\n",
           my_face, target_face, orientation, ft[0], ft[1], ft[2],
           ft[3], ft[4], ft[5], ft[6], ft[7], ft[8]);

        /* compute the transformation code in a faster way and compare */
        gt[0] = my_face < 2 ? 1 : 0;
        gt[1] = my_face < 4 ? 2 : 1;
        gt[2] = my_face / 2;
        reverse =
          p8est_face_permutation_refs[0][my_face] ^
          p8est_face_permutation_refs[0][target_face] ^
          (orientation == 0 || orientation == 3);
        gt[3 + reverse] = target_face < 2 ? 1 : 0;
        gt[3 + !reverse] = target_face < 4 ? 2 : 1;
        gt[5] = target_face / 2;
        reverse = p8est_face_permutation_refs[my_face][target_face] == 1;
        gt[6 + reverse] = orientation % 2;
        gt[6 + !reverse] = orientation / 2;
        gt[8] = 2 * (my_face % 2) + target_face % 2;

        /* ensure that both computations yield the same result */
        SC_CHECK_ABORT (!memcmp (ft, gt, 9 * sizeof (int)), "Mismatch");
      }
    }
  }

  sc_finalize ();

  return 0;
}