PolyFEM
Loading...
Searching...
No Matches
NodeCompositeParametrizations.cpp
Go to the documentation of this file.
2
4#include <map>
5#include <polyfem/State.hpp>
6
7namespace polyfem::solver
8{
10 {
11 dim = state.mesh->dimension();
12 }
13
14 void VariableToNodes::set_output_indexing(const std::vector<int> &node_ids)
15 {
16 output_indexing_.resize(node_ids.size() * dim);
17 for (int i = 0; i < node_ids.size(); ++i)
18 for (int k = 0; k < dim; ++k)
19 output_indexing_(i * dim + k) = node_ids[i] * dim + k;
20 }
21
22 VariableToInteriorNodes::VariableToInteriorNodes(const State &state, const std::vector<int> &volume_selection) : VariableToNodes(state)
23 {
24 const auto &mesh = state.mesh;
25
26 std::set<int> node_ids;
27 for (int e = 0; e < mesh->n_elements(); e++)
28 {
29 const int body_id = mesh->get_body_id(e);
30 if (volume_selection.size() == 0 || std::find(volume_selection.begin(), volume_selection.end(), body_id) != volume_selection.end())
31 {
32 for (int i = 0; i < mesh->dimension() + 1; i++)
33 {
34 const int vid = mesh->element_vertex(e, i);
35 if (!mesh->is_boundary_vertex(vid))
36 node_ids.insert(vid);
37 }
38 }
39 }
40
41 set_output_indexing(std::vector(node_ids.begin(), node_ids.end()));
42 }
43
44 VariableToBoundaryNodes::VariableToBoundaryNodes(const State &state, const std::vector<int> &surface_selection) : VariableToNodes(state)
45 {
46 const auto &mesh = state.mesh;
47 const auto &bases = state.bases;
48 const auto &gbases = state.geom_bases();
49
50 std::set<int> node_ids;
51 for (const auto &lb : state.total_local_boundary)
52 {
53 const int e = lb.element_id();
54 for (int i = 0; i < lb.size(); ++i)
55 {
56 const int primitive_global_id = lb.global_primitive_id(i);
57 const int boundary_id = mesh->get_boundary_id(primitive_global_id);
58
59 if (surface_selection.size() == 0 || std::find(surface_selection.begin(), surface_selection.end(), boundary_id) != surface_selection.end())
60 for (long n = 0; n < mesh->dimension(); ++n)
61 node_ids.insert(mesh->boundary_element_vertex(primitive_global_id, n));
62 }
63 }
64
65 set_output_indexing(std::vector(node_ids.begin(), node_ids.end()));
66 }
67
68 VariableToBoundaryNodesExclusive::VariableToBoundaryNodesExclusive(const State &state, const std::vector<int> &exclude_surface_selections) : VariableToNodes(state)
69 {
70 const auto &mesh = state.mesh;
71 const auto &bases = state.bases;
72 const auto &gbases = state.geom_bases();
73
74 if (!mesh->is_simplicial())
75 log_and_throw_adjoint_error("VariableToBoundaryNodesExclusive only supports simplices!");
76
77 std::set<int> excluded_node_ids;
78 std::set<int> all_node_ids;
79 for (const auto &lb : state.total_local_boundary)
80 {
81 const int e = lb.element_id();
82 for (int i = 0; i < lb.size(); ++i)
83 {
84 const int primitive_global_id = lb.global_primitive_id(i);
85 const int boundary_id = mesh->get_boundary_id(primitive_global_id);
86
87 if (std::count(exclude_surface_selections.begin(), exclude_surface_selections.end(), boundary_id))
88 for (long n = 0; n < mesh->dimension(); ++n)
89 excluded_node_ids.insert(mesh->boundary_element_vertex(primitive_global_id, n));
90 for (long n = 0; n < mesh->dimension(); ++n)
91 all_node_ids.insert(mesh->boundary_element_vertex(primitive_global_id, n));
92 }
93 }
94
95 std::vector<int> node_ids;
96 std::set_difference(all_node_ids.begin(), all_node_ids.end(), excluded_node_ids.begin(), excluded_node_ids.end(), std::back_inserter(node_ids));
97
98 set_output_indexing(node_ids);
99 }
100}
main class that contains the polyfem solver and all its state
Definition State.hpp:79
const std::vector< basis::ElementBases > & geom_bases() const
Get a constant reference to the geometry mapping bases.
Definition State.hpp:223
std::unique_ptr< mesh::Mesh > mesh
current mesh, it can be a Mesh2D or Mesh3D
Definition State.hpp:466
std::vector< basis::ElementBases > bases
FE bases, the size is #elements.
Definition State.hpp:171
std::vector< mesh::LocalBoundary > total_local_boundary
mapping from elements to nodes for all mesh
Definition State.hpp:431
VariableToBoundaryNodesExclusive(const State &state, const std::vector< int > &exclude_surface_selections)
VariableToBoundaryNodes(const State &state, const std::vector< int > &surface_selection)
VariableToInteriorNodes(const State &state, const std::vector< int > &volume_selection)
virtual void set_output_indexing(const std::vector< int > &node_ids) final
void log_and_throw_adjoint_error(const std::string &msg)
Definition Logger.cpp:77