suanPan
🧮 An Open Source, Parallel and Heterogeneous Finite Element Analysis Framework
Loading...
Searching...
No Matches
FixedLength.h
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright (C) 2017-2026 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 ******************************************************************************/
26#ifndef FIXEDLENGTH_H
27#define FIXEDLENGTH_H
28
29#include "Constraint.h"
30
31#include <Domain/Factory.hpp>
32
40template<unsigned DIM> class FixedLength : public Constraint {
41 vec initial_chord;
42
43protected:
44 bool min_bound = false, max_bound = false;
45 double min_gap = 0., max_gap = 0.;
46
47public:
48 FixedLength(const unsigned T, uvec&& N)
49 : Constraint(T, 0, suanpan::translational(DIM), {}, 1) { target_node = std::move(N); }
50
51 int initialize(const shared_ptr<DomainBase>& D) override {
53
54 if(!validate_node(D)) return SUANPAN_FAIL;
55
57
58 initial_chord = D->get<Node>(target_node(1))->initial_position(DIM) - D->get<Node>(target_node(0))->initial_position(DIM);
59
61
62 return SUANPAN_SUCCESS;
63 }
64
65 int process(const shared_ptr<DomainBase>& D) override {
66 auto& W = D->get_factory();
67
68 const uvec dof_i = target_dof.head(DIM), dof_j = target_dof.tail(DIM);
69
70 const vec t_disp = W->get_trial_displacement()(dof_j) - W->get_trial_displacement()(dof_i);
71 const vec t_chord = initial_chord + t_disp;
72
73 if(const auto t_gap = dot(t_chord, t_chord); min_bound && max_bound) {
74 if(0u == lagrangian_size && t_gap > min_gap && t_gap < max_gap) return SUANPAN_SUCCESS;
75
76 auxiliary_load = (2. * std::sqrt(t_gap) < std::sqrt(min_gap) + std::sqrt(max_gap) ? min_gap : max_gap) - dot(initial_chord, initial_chord);
77 }
78 else if(min_bound) {
79 if(0u == lagrangian_size && t_gap > min_gap) return SUANPAN_SUCCESS;
80
81 auxiliary_load = min_gap - dot(initial_chord, initial_chord);
82 }
83 else if(max_bound) {
84 if(0u == lagrangian_size && t_gap < max_gap) return SUANPAN_SUCCESS;
85
86 auxiliary_load = max_gap - dot(initial_chord, initial_chord);
87 }
88 // no need as empty quantities are skipped
89 // else auxiliary_load = 0.;
90
92
93 auxiliary_stiffness.zeros(W->get_size(), lagrangian_size);
95 for(auto I = 0u; I < DIM; ++I) {
96 auxiliary_stiffness(dof_i(I)) = -(auxiliary_stiffness(dof_j(I)) = 2. * t_chord(I));
97 auxiliary_resistance += t_disp(I) * (2. * initial_chord(I) + t_disp(I));
98 }
99
100 stiffness.zeros(target_dof.n_elem, target_dof.n_elem);
101 const auto t_factor = 2. * trial_lambda(0);
102 for(auto I = 0u; I < DIM; ++I) stiffness(I + DIM, I) = stiffness(I, I + DIM) = -(stiffness(I, I) = stiffness(I + DIM, I + DIM) = t_factor);
103
105
106 return SUANPAN_SUCCESS;
107 }
108
109 [[nodiscard]] bool is_connected() const override { return true; }
110
111 void update_status(const vec& incre_lambda) override { trial_lambda += incre_lambda; }
112
113 void commit_status() override {
116 }
117
118 void clear_status() override {
121 }
122
123 void reset_status() override {
126 }
127};
128
133template<unsigned DIM> class MinimumGap final : public FixedLength<DIM> {
134public:
135 MinimumGap(const unsigned T, const double M, uvec&& N)
136 : FixedLength<DIM>(T, std::move(N)) {
139 }
140};
141
146template<unsigned DIM> class MaximumGap final : public FixedLength<DIM> {
147public:
148 MaximumGap(const unsigned T, const double M, uvec&& N)
149 : FixedLength<DIM>(T, std::move(N)) {
152 }
153};
154
159template<unsigned DIM> class Sleeve final : public FixedLength<DIM> {
160public:
161 Sleeve(const unsigned T, const double M1, const double M2, uvec&& N)
162 : FixedLength<DIM>(T, std::move(N)) {
165 FixedLength<DIM>::min_gap = std::pow(std::min(M1, M2), 2.);
166 FixedLength<DIM>::max_gap = std::pow(std::max(M1, M2), 2.);
167 }
168};
169
174template<unsigned DIM> class MaxForce final : public FixedLength<DIM> {
175 const double max_force;
176
177 bool trial_flag = false, current_flag = false;
178
179public:
180 MaxForce(const unsigned T, const double MF, uvec&& N)
181 : FixedLength<DIM>(T, std::move(N))
182 , max_force(MF) {}
183
184 int process(const shared_ptr<DomainBase>& D) override {
185 if(current_flag) {
186 // if already exceeded, the constraint is not triggered
188 return SUANPAN_SUCCESS;
189 }
190
192
194
195 vec nodal_resistance(DIM);
196 for(auto I = 0u; I < DIM; ++I) nodal_resistance(I) = FixedLength<DIM>::resistance(FixedLength<DIM>::target_dof(I));
197
198 if(norm(nodal_resistance) > max_force) {
199 trial_flag = true;
201 }
202
203 return SUANPAN_SUCCESS;
204 }
205
206 void commit_status() override {
207 current_flag = trial_flag;
209 }
210
211 void clear_status() override {
212 current_flag = trial_flag = false;
214 }
215
216 void reset_status() override {
217 trial_flag = current_flag;
219 }
220};
221
222#endif
223
virtual int initialize(const shared_ptr< DomainBase > &)
Definition ConditionalModifier.cpp:85
uvec target_node
Definition ConditionalModifier.h:123
uvec collect_node_dof(const shared_ptr< DomainBase > &) const
Definition ConditionalModifier.cpp:55
uvec target_dof
Definition ConditionalModifier.h:123
bool validate_node(const shared_ptr< DomainBase > &) const
Definition ConditionalModifier.cpp:25
A Constraint class.
Definition Constraint.h:36
unsigned lagrangian_size
Definition Constraint.h:38
sp_mat stiffness
Definition Constraint.h:44
sp_vec resistance
Definition Constraint.h:43
vec current_lambda
Definition Constraint.h:41
vec trial_lambda
Definition Constraint.h:40
sp_mat auxiliary_stiffness
Definition Constraint.h:48
vec auxiliary_load
Definition Constraint.h:47
void set_multiplier_size(unsigned)
Definition Constraint.cpp:34
vec auxiliary_resistance
Definition Constraint.h:46
A FixedLength class.
Definition FixedLength.h:40
int process(const shared_ptr< DomainBase > &D) override
Process and update both stiffness and resistance.
Definition FixedLength.h:65
bool max_bound
Definition FixedLength.h:44
double max_gap
Definition FixedLength.h:45
int initialize(const shared_ptr< DomainBase > &D) override
Definition FixedLength.h:51
bool min_bound
Definition FixedLength.h:44
double min_gap
Definition FixedLength.h:45
void commit_status() override
Definition FixedLength.h:113
void update_status(const vec &incre_lambda) override
Definition FixedLength.h:111
FixedLength(const unsigned T, uvec &&N)
Definition FixedLength.h:48
void clear_status() override
Definition FixedLength.h:118
bool is_connected() const override
Indicate if this modifier can be deemed as an element that needs to account for connectivity.
Definition FixedLength.h:109
void reset_status() override
Definition FixedLength.h:123
A MaxForce class.
Definition FixedLength.h:174
void commit_status() override
Definition FixedLength.h:206
int process(const shared_ptr< DomainBase > &D) override
Process and update both stiffness and resistance.
Definition FixedLength.h:184
MaxForce(const unsigned T, const double MF, uvec &&N)
Definition FixedLength.h:180
void clear_status() override
Definition FixedLength.h:211
void reset_status() override
Definition FixedLength.h:216
A MaximumGap class.
Definition FixedLength.h:146
MaximumGap(const unsigned T, const double M, uvec &&N)
Definition FixedLength.h:148
A MinimumGap class.
Definition FixedLength.h:133
MinimumGap(const unsigned T, const double M, uvec &&N)
Definition FixedLength.h:135
The Node class holds the number of DoFs, coordinate, displacement, velocity and acceleration.
Definition Node.h:79
A Sleeve class.
Definition FixedLength.h:159
Sleeve(const unsigned T, const double M1, const double M2, uvec &&N)
Definition FixedLength.h:161
Definition SparseMatMAGMA.hpp:43
constexpr auto SUANPAN_SUCCESS
Definition suanPan.h:166
constexpr auto SUANPAN_FAIL
Definition suanPan.h:167