Debian Codegraph @

packages/seacas/libraries/exodus/test/test-field-utils.c

raw
1 #include <exodusII.h>
2 #include <stdio.h>
3 #undef NDEBUG
4 #include <assert.h>
5
6 #define SIZE(X) sizeof(X) / sizeof(X[0])
7
8 int main(int argc, char **argv)
9 {
10 ex_field_type types[] = {EX_FIELD_TYPE_USER_DEFINED,
11 EX_FIELD_TYPE_SEQUENCE,
12 EX_QUADRATURE,
13 EX_BASIS,
14 EX_SCALAR,
15 EX_VECTOR_1D,
16 EX_VECTOR_2D,
17 EX_VECTOR_3D,
18 EX_QUATERNION_2D,
19 EX_QUATERNION_3D,
20 EX_FULL_TENSOR_12,
21 EX_FULL_TENSOR_16,
22 EX_FULL_TENSOR_22,
23 EX_FULL_TENSOR_32,
24 EX_FULL_TENSOR_36,
25 EX_SYM_TENSOR_10,
26 EX_SYM_TENSOR_11,
27 EX_SYM_TENSOR_13,
28 EX_SYM_TENSOR_21,
29 EX_SYM_TENSOR_31,
30 EX_SYM_TENSOR_33,
31 EX_ASYM_TENSOR_01,
32 EX_ASYM_TENSOR_02,
33 EX_ASYM_TENSOR_03,
34 EX_MATRIX_2X2,
35 EX_MATRIX_3X3,
36 EX_FIELD_TYPE_INVALID};
37
38 int num_enum = SIZE(types);
39 for (int i = 0; i < num_enum; i++) {
40 const char *string_type = ex_field_type_enum_to_string(types[i]);
41 ex_field_type return_type = ex_string_to_field_type_enum(string_type);
42 assert(return_type == types[i]);
43 }
44
45 for (int i = 0; i < num_enum; i++) {
46 struct ex_field field = (ex_field){.entity_type = EX_ELEM_BLOCK,
47 .entity_id = 100,
48 .name = "Testing",
49 .type = {types[i]},
50 .nesting = 1,
51 .component_separator[0] = '_'};
52
53 int cardinality = ex_field_cardinality(types[i]);
54 // Make sure the numeric suffices are formatted correctly "00", "01", ... "10" -- all same
55 // width.
56 if (cardinality == -1 && (types[i] == EX_FIELD_TYPE_SEQUENCE || types[i] == EX_BASIS)) {
57 field.cardinality[0] = 10;
58 cardinality = 10;
59 }
60 if (cardinality > 0 && types[i] != EX_SCALAR) {
61 fprintf(stderr, "%s (%s) components: ", ex_field_type_enum_to_string(field.type[0]),
62 ex_field_type_name(field.type[0]));
63 for (int j = 1; j <= cardinality; j++) {
64 fprintf(stderr, "%s%c", ex_field_component_suffix(&field, 0, j),
65 j == cardinality ? ' ' : ',');
66 }
67 fprintf(stderr, "\n");
68 }
69 else {
70 fprintf(stderr, "%s (%s)\n", ex_field_type_enum_to_string(field.type[0]),
71 ex_field_type_name(field.type[0]));
72 }
73 }
74 }