-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtriangle_mesh_area.cpp
More file actions
48 lines (37 loc) · 1.33 KB
/
triangle_mesh_area.cpp
File metadata and controls
48 lines (37 loc) · 1.33 KB
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
#include "examples_main.h"
#include <symx>
using namespace symx;
void triangle_mesh_area()
{
std::cout << "\n=================== triangle_mesh_area() ===================" << std::endl;
struct Data
{
std::vector<Eigen::Vector3d> vertices;
std::vector<std::array<int, 3>> triangles;
} data;
auto mesh = generate_triangle_grid(Eigen::Vector2d{0.5, 0.5}, {10, 10});
data.vertices = mesh.vertices;
data.triangles = mesh.triangles;
// Create MappedWorkspace
auto [mws, element] = MappedWorkspace<double>::create(data.triangles);
// Spawn symbols from data
std::vector<Vector> v = mws->make_vectors(data.vertices, element);
// Expression
Vector cross = (v[1] - v[0]).cross3(v[2] - v[0]);
Scalar area = 0.5*cross.norm();
// Compilation
const std::string codegen_dir = symx::get_codegen_dir();
auto loop = CompiledInLoop<double>::create(mws, {area}, "tri_area", codegen_dir);
// Evaluation
double total_area = 0.0;
const int n_threads = 1;
loop->run(n_threads,
[&](const View<double> out, const int32_t elem_idx, const int32_t thread_id, const View<int32_t> elem_conn)
{
total_area += out[0];
}
);
// Print
std::cout << "Total triangle mesh area: " << total_area << std::endl;
loop->get_info().print();
}