1 | #include "taichi/ir/mesh.h" |
---|---|
2 | |
3 | namespace taichi::lang { |
4 | namespace mesh { |
5 | |
6 | std::string element_type_name(MeshElementType type) { |
7 | if (type == MeshElementType::Vertex) |
8 | return "verts"; |
9 | else if (type == MeshElementType::Edge) |
10 | return "edges"; |
11 | else if (type == MeshElementType::Face) |
12 | return "faces"; |
13 | else if (type == MeshElementType::Cell) |
14 | return "cells"; |
15 | else { |
16 | TI_NOT_IMPLEMENTED; |
17 | } |
18 | } |
19 | |
20 | std::string relation_type_name(MeshRelationType type) { |
21 | return element_type_name(MeshElementType(from_end_element_order(type))) + |
22 | "-"+ element_type_name(MeshElementType(to_end_element_order(type))); |
23 | } |
24 | |
25 | std::string conv_type_name(ConvType type) { |
26 | if (type == mesh::ConvType::l2g) |
27 | return "local to global"; |
28 | else if (type == mesh::ConvType::l2r) |
29 | return "local to reordered"; |
30 | else if (type == mesh::ConvType::g2r) { |
31 | return "global to reordered"; |
32 | } else { |
33 | TI_NOT_IMPLEMENTED; |
34 | } |
35 | } |
36 | |
37 | int element_order(MeshElementType type) { |
38 | return int(type); |
39 | } |
40 | |
41 | int from_end_element_order(MeshRelationType rel) { |
42 | return int(rel) >> 0x2; |
43 | } |
44 | |
45 | int to_end_element_order(MeshRelationType rel) { |
46 | return int(rel) & 0x3; |
47 | } |
48 | |
49 | MeshRelationType relation_by_orders(int from_order, int to_order) { |
50 | return MeshRelationType((from_order << 2) | to_order); |
51 | } |
52 | |
53 | MeshRelationType inverse_relation(MeshRelationType rel) { |
54 | return relation_by_orders(to_end_element_order(rel), |
55 | from_end_element_order(rel)); |
56 | } |
57 | |
58 | } // namespace mesh |
59 | } // namespace taichi::lang |
60 |