Wildmeshing Toolkit
Loading...
Searching...
No Matches
HarmonicTet.hpp
1#pragma once
2
3#include <wmtk/TetMesh.h>
4#include <wmtk/AttributeCollection.hpp>
5
6// clang-format off
7#include <wmtk/utils/DisableWarnings.hpp>
8#include <tbb/enumerable_thread_specific.h>
9#include <wmtk/utils/EnableWarnings.hpp>
10// clang-format on
11
12#include <wmtk/utils/partition_utils.hpp>
13#include "wmtk/utils/Logger.hpp"
14
15#include <Eigen/Core>
16#include <atomic>
17#include <memory>
18
19namespace harmonic_tet {
20
22{
23public:
25 {
26 Eigen::Vector3d pos;
27 size_t partition_id = 0;
28 };
30 {
31 double quality = -1.;
32 };
35
37 const std::vector<Eigen::Vector3d>& _vertex_attribute,
38 const std::vector<std::array<size_t, 4>>& tets,
39 int num_threads = 1)
40 {
41 p_vertex_attrs = &vertex_attrs;
42 p_tet_attrs = &tet_attrs;
43
44 vertex_attrs.resize(_vertex_attribute.size());
45
46 NUM_THREADS = num_threads;
47 init(_vertex_attribute.size(), tets);
48
49 for_each_vertex([&](auto& v) {
50 auto i = v.vid(*this);
51 vertex_attrs[i].pos = _vertex_attribute[i];
52 });
53 for_each_tetra([&](auto& t) {
54 auto i = t.tid(*this);
55 tet_attrs[i].quality = get_quality(t);
56 });
57
58 compute_vertex_partition_morton();
59 }
60 HarmonicTet() {};
61 ~HarmonicTet() {};
62
64 // TODO: this should not be exposed in the application
65 void compute_vertex_partition_morton()
66 {
67 if (NUM_THREADS == 0) return;
68 wmtk::logger().info("Number of parts: {} by morton", NUM_THREADS);
69 std::vector<size_t> par;
70 wmtk::partition_vertex_morton(
72 [&](auto vid) { return vertex_attrs[vid].pos; },
73 NUM_THREADS,
74 par);
75 for_each_vertex([&](auto& v) {
76 auto vid = v.vid(*this);
77 vertex_attrs[vid].partition_id = par[vid];
78 });
79 }
80
81 void output_mesh(std::string file) const;
82
83 size_t get_partition_id(const Tuple& loc) const
84 {
85 return vertex_attrs[loc.vid(*this)].partition_id;
86 }
87
88 // parallel containers
90
92 {
93 double total_energy = 0.;
94 };
95 tbb::enumerable_thread_specific<SwapInfoCache> edgeswap_cache, faceswap_cache;
96
97 void smooth_all_vertices(bool interior_only = false);
98 bool smooth_after(const Tuple& t) override;
99
100 void swap_all_edges(bool parallel = false);
101 bool swap_edge_before(const Tuple& t) override;
102 bool swap_edge_after(const Tuple& t) override;
103
104 int swap_all();
105 void swap_all_faces(bool parallel = false);
106 bool swap_face_before(const Tuple& t) override;
107 bool swap_face_after(const Tuple& t) override;
108
109 bool is_inverted(const Tuple& loc);
110 double get_quality(const Tuple& loc) const;
111 double get_quality(const std::array<size_t, 4>& vids) const;
112
113 bool invariants(const std::vector<Tuple>&) override;
114};
115
116} // namespace harmonic_tet
Definition HarmonicTet.hpp:22
bool swap_face_after(const Tuple &t) override
User specified modifications and desideratas for after a 2-3 face swap.
Definition HarmonicTet.cpp:138
bool swap_face_before(const Tuple &t) override
User specified preparations and desideratas for an 2-3 face swap befroe changing the geometry.
Definition HarmonicTet.cpp:206
bool swap_edge_after(const Tuple &t) override
User specified modifications and desideratas for after a 3-2 edge swap.
Definition HarmonicTet.cpp:118
bool swap_edge_before(const Tuple &t) override
User specified preparations and desideratas for an 3-2 edge swap before changing the conenctivity.
Definition HarmonicTet.cpp:105
bool smooth_after(const Tuple &t) override
User specified modifications and desideratas for after smoothing a vertex.
Definition HarmonicTet.cpp:53
a Tuple refers to a global vid and a global tet id, and a local edge id and local face id
Definition TetMesh.h:49
Definition TetMesh.h:24
size_t vert_capacity() const
get the current largest global vid
Definition TetMesh.h:355
void for_each_vertex(const std::function< void(const TetMesh::Tuple &)> &)
perform the given function for each vertex
Definition TetMesh.cpp:1355
void init(size_t n_vertices, const std::vector< std::array< size_t, 4 > > &tets)
Definition TetMesh.cpp:77
void for_each_tetra(const std::function< void(const TetMesh::Tuple &)> &)
perform the given function for each tet
Definition TetMesh.cpp:1327
Definition HarmonicTet.hpp:92
Definition HarmonicTet.hpp:30
Definition HarmonicTet.hpp:25
Definition AttributeCollection.hpp:37