suanPan
NodeHelper.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (C) 2017-2024 Theodore Chang
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  ******************************************************************************/
17 
18 #ifndef NODE_HELPER_HPP
19 #define NODE_HELPER_HPP
20 
21 #include "DOF.h"
22 #include "Node.h"
23 
24 template<DOF... D> bool check_dof_definition(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
25 
26 template<DOF... D> vec get_current_position(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
27 
28 template<DOF... D> vec get_trial_position(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
29 
30 template<DOF... D> vec get_current_displacement(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
31 
32 template<DOF... D> vec get_current_velocity(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
33 
34 template<DOF... D> vec get_current_acceleration(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
35 
36 template<DOF... D> vec get_trial_displacement(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
37 
38 template<DOF... D> vec get_trial_velocity(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
39 
40 template<DOF... D> vec get_trial_acceleration(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
41 
42 template<DOF... D> vec get_incre_displacement(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
43 
44 template<DOF... D> vec get_incre_velocity(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
45 
46 template<DOF... D> vec get_incre_acceleration(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
47 
48 template<> inline bool check_dof_definition<DOF::U1>(const shared_ptr<Node>& t_node) {
49  auto& t_dof = t_node->get_dof_identifier();
50  return !t_dof.empty() && t_dof.at(0) == DOF::U1;
51 }
52 
53 template<> inline bool check_dof_definition<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) {
54  auto& t_dof = t_node->get_dof_identifier();
55  return t_dof.size() > 1 && t_dof.at(0) == DOF::U1 && t_dof.at(1) == DOF::U2;
56 }
57 
58 template<> inline bool check_dof_definition<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) {
59  auto& t_dof = t_node->get_dof_identifier();
60  return t_dof.size() > 2 && t_dof.at(0) == DOF::U1 && t_dof.at(1) == DOF::U2 && t_dof.at(2) == DOF::U3;
61 }
62 
63 template<> inline vec get_current_position<DOF::U1>(const shared_ptr<Node>& t_node) {
64  vec t_vec = t_node->get_current_displacement().head(1);
65  if(auto& t_coor = t_node->get_coordinate(); !t_coor.empty()) t_vec(0) += t_coor(0);
66  return t_vec;
67 }
68 
69 template<> inline vec get_trial_position<DOF::U1>(const shared_ptr<Node>& t_node) {
70  vec t_vec = t_node->get_trial_displacement().head(1);
71  if(auto& t_coor = t_node->get_coordinate(); !t_coor.empty()) t_vec(0) += t_coor(0);
72  return t_vec;
73 }
74 
75 template<> inline vec get_current_displacement<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_current_displacement().head(1); }
76 
77 template<> inline vec get_current_velocity<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_current_velocity().head(1); }
78 
79 template<> inline vec get_current_acceleration<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_current_acceleration().head(1); }
80 
81 template<> inline vec get_trial_displacement<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_trial_displacement().head(1); }
82 
83 template<> inline vec get_trial_velocity<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_trial_velocity().head(1); }
84 
85 template<> inline vec get_trial_acceleration<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_trial_acceleration().head(1); }
86 
87 template<> inline vec get_incre_displacement<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_incre_displacement().head(1); }
88 
89 template<> inline vec get_incre_velocity<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_incre_velocity().head(1); }
90 
91 template<> inline vec get_incre_acceleration<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_incre_acceleration().head(1); }
92 
93 template<> inline vec get_current_position<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) {
94  const auto& t_coor = t_node->get_coordinate();
95  vec t_vec = t_node->get_current_displacement().head(2);
96  for(auto I = 0llu; I < std::min(2llu, t_coor.n_elem); ++I) t_vec(I) += t_coor(I);
97  return t_vec;
98 }
99 
100 template<> inline vec get_trial_position<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) {
101  const auto& t_coor = t_node->get_coordinate();
102  vec t_vec = t_node->get_trial_displacement().head(2);
103  for(auto I = 0llu; I < std::min(2llu, t_coor.n_elem); ++I) t_vec(I) += t_coor(I);
104  return t_vec;
105 }
106 
107 template<> inline vec get_current_displacement<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_current_displacement().head(2); }
108 
109 template<> inline vec get_current_velocity<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_current_velocity().head(2); }
110 
111 template<> inline vec get_current_acceleration<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_current_acceleration().head(2); }
112 
113 template<> inline vec get_trial_displacement<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_trial_displacement().head(2); }
114 
115 template<> inline vec get_trial_velocity<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_trial_velocity().head(2); }
116 
117 template<> inline vec get_trial_acceleration<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_trial_acceleration().head(2); }
118 
119 template<> inline vec get_incre_displacement<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_incre_displacement().head(2); }
120 
121 template<> inline vec get_incre_velocity<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_incre_velocity().head(2); }
122 
123 template<> inline vec get_incre_acceleration<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_incre_acceleration().head(2); }
124 
125 template<> inline vec get_current_position<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) {
126  const auto& t_coor = t_node->get_coordinate();
127  vec t_vec = t_node->get_current_displacement().head(3);
128  for(auto I = 0llu; I < std::min(3llu, t_coor.n_elem); ++I) t_vec(I) += t_coor(I);
129  return t_vec;
130 }
131 
132 template<> inline vec get_trial_position<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) {
133  const auto& t_coor = t_node->get_coordinate();
134  vec t_vec = t_node->get_trial_displacement().head(3);
135  for(auto I = 0llu; I < std::min(3llu, t_coor.n_elem); ++I) t_vec(I) += t_coor(I);
136  return t_vec;
137 }
138 
139 template<> inline vec get_current_displacement<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) { return t_node->get_current_displacement().head(3); }
140 
141 template<> inline vec get_current_velocity<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) { return t_node->get_current_velocity().head(3); }
142 
143 template<> inline vec get_current_acceleration<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) { return t_node->get_current_acceleration().head(3); }
144 
145 template<> inline vec get_trial_displacement<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) { return t_node->get_trial_displacement().head(3); }
146 
147 template<> inline vec get_trial_velocity<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) { return t_node->get_trial_velocity().head(3); }
148 
149 template<> inline vec get_trial_acceleration<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) { return t_node->get_trial_acceleration().head(3); }
150 
151 template<> inline vec get_incre_displacement<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) { return t_node->get_incre_displacement().head(3); }
152 
153 template<> inline vec get_incre_velocity<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) { return t_node->get_incre_velocity().head(3); }
154 
155 template<> inline vec get_incre_acceleration<DOF::U1, DOF::U2, DOF::U3>(const shared_ptr<Node>& t_node) { return t_node->get_incre_acceleration().head(3); }
156 
157 #endif
vec get_current_displacement(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:30
vec get_current_acceleration(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:34
vec get_current_velocity(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:32
vec get_incre_velocity(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:44
vec get_incre_displacement(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:42
bool check_dof_definition(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:24
vec get_current_position(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:26
vec get_incre_acceleration(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:46
vec get_trial_acceleration(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:40
vec get_trial_position(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:28
vec get_trial_velocity(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:38
vec get_trial_displacement(const shared_ptr< Node > &)
Definition: NodeHelper.hpp:36
DOF
Definition: DOF.h:29