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
24template<DOF... D> bool check_dof_definition(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
25
26template<DOF... D> vec get_current_position(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
27
28template<DOF... D> vec get_trial_position(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
29
30template<DOF... D> vec get_current_displacement(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
31
32template<DOF... D> vec get_current_velocity(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
33
34template<DOF... D> vec get_current_acceleration(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
35
36template<DOF... D> vec get_trial_displacement(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
37
38template<DOF... D> vec get_trial_velocity(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
39
40template<DOF... D> vec get_trial_acceleration(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
41
42template<DOF... D> vec get_incre_displacement(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
43
44template<DOF... D> vec get_incre_velocity(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
45
46template<DOF... D> vec get_incre_acceleration(const shared_ptr<Node>&) { throw std::logic_error("not implemented"); }
47
48template<> 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
53template<> 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
58template<> 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
63template<> 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
69template<> 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
75template<> inline vec get_current_displacement<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_current_displacement().head(1); }
76
77template<> inline vec get_current_velocity<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_current_velocity().head(1); }
78
79template<> inline vec get_current_acceleration<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_current_acceleration().head(1); }
80
81template<> inline vec get_trial_displacement<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_trial_displacement().head(1); }
82
83template<> inline vec get_trial_velocity<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_trial_velocity().head(1); }
84
85template<> inline vec get_trial_acceleration<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_trial_acceleration().head(1); }
86
87template<> inline vec get_incre_displacement<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_incre_displacement().head(1); }
88
89template<> inline vec get_incre_velocity<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_incre_velocity().head(1); }
90
91template<> inline vec get_incre_acceleration<DOF::U1>(const shared_ptr<Node>& t_node) { return t_node->get_incre_acceleration().head(1); }
92
93template<> 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
100template<> 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
107template<> inline vec get_current_displacement<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_current_displacement().head(2); }
108
109template<> inline vec get_current_velocity<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_current_velocity().head(2); }
110
111template<> inline vec get_current_acceleration<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_current_acceleration().head(2); }
112
113template<> inline vec get_trial_displacement<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_trial_displacement().head(2); }
114
115template<> inline vec get_trial_velocity<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_trial_velocity().head(2); }
116
117template<> inline vec get_trial_acceleration<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_trial_acceleration().head(2); }
118
119template<> inline vec get_incre_displacement<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_incre_displacement().head(2); }
120
121template<> inline vec get_incre_velocity<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_incre_velocity().head(2); }
122
123template<> inline vec get_incre_acceleration<DOF::U1, DOF::U2>(const shared_ptr<Node>& t_node) { return t_node->get_incre_acceleration().head(2); }
124
125template<> 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
132template<> 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
139template<> 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
141template<> 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
143template<> 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
145template<> 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
147template<> 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
149template<> 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
151template<> 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
153template<> 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
155template<> 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