1#pragma once
2
3#include <atomic>
4
5#include "taichi/ir/type.h"
6#include "taichi/ir/snode.h"
7#include "taichi/ir/scratch_pad.h"
8
9#include <unordered_set>
10
11namespace taichi::lang {
12
13class Stmt;
14
15namespace mesh {
16
17enum class MeshTopology { Triangle = 3, Tetrahedron = 4 };
18
19enum class MeshElementType { Vertex = 0, Edge = 1, Face = 2, Cell = 3 };
20
21std::string element_type_name(MeshElementType type);
22
23enum class MeshRelationType {
24 VV = 0,
25 VE = 1,
26 VF = 2,
27 VC = 3,
28 EV = 4,
29 EE = 5,
30 EF = 6,
31 EC = 7,
32 FV = 8,
33 FE = 9,
34 FF = 10,
35 FC = 11,
36 CV = 12,
37 CE = 13,
38 CF = 14,
39 CC = 15,
40};
41
42std::string relation_type_name(MeshRelationType type);
43
44enum class ConvType { l2g, l2r, g2r };
45
46std::string conv_type_name(ConvType type);
47
48int element_order(MeshElementType type);
49int from_end_element_order(MeshRelationType rel);
50int to_end_element_order(MeshRelationType rel);
51MeshRelationType relation_by_orders(int from_order, int to_order);
52MeshRelationType inverse_relation(MeshRelationType rel);
53
54struct MeshLocalRelation {
55 MeshLocalRelation(SNode *value_, SNode *patch_offset_, SNode *offset_)
56 : value(value_), patch_offset(patch_offset_), offset(offset_) {
57 fixed = false;
58 }
59
60 explicit MeshLocalRelation(SNode *value_) : value(value_) {
61 fixed = true;
62 }
63
64 bool fixed;
65 SNode *value{nullptr};
66 SNode *patch_offset{nullptr};
67 SNode *offset{nullptr};
68};
69
70class Mesh {
71 public:
72 Mesh() = default;
73
74 template <typename T>
75 using MeshMapping = std::unordered_map<MeshElementType, T>;
76
77 int num_patches{0};
78 MeshMapping<int> num_elements{};
79 MeshMapping<int>
80 patch_max_element_num{}; // the max number of mesh element in each patch
81
82 MeshMapping<SNode *> owned_offset{}; // prefix of owned element
83 MeshMapping<SNode *> total_offset{}; // prefix of total element
84 std::map<std::pair<MeshElementType, ConvType>, SNode *>
85 index_mapping{}; // mapping from one index space to another index space
86
87 std::map<MeshRelationType, MeshLocalRelation> relations;
88};
89
90struct MeshPtr { // Mesh wrapper in python
91 std::shared_ptr<Mesh> ptr;
92};
93
94} // namespace mesh
95} // namespace taichi::lang
96