suanPan
🧮 An Open Source, Parallel and Heterogeneous Finite Element Analysis Framework
Loading...
Searching...
No Matches
Embed.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 ******************************************************************************/
29#ifndef EMBED_H
30#define EMBED_H
31
32#include "Constraint.h"
33
34#include <Domain/Factory.hpp>
35#include <Element/Element.h>
36
37template<unsigned DIM> class Embed final : public Constraint {
38 static constexpr unsigned max_iteration = 20u;
39 static constexpr double tolerance = 1E-14;
40
41public:
42 Embed(const unsigned T, const unsigned ET, const unsigned NT)
43 : Constraint(T, 0, suanpan::translational(DIM), {}, DIM) {
44 target_node = NT;
45 target_element = ET;
46 }
47
48 int initialize(const shared_ptr<DomainBase>& D) override {
50
51 if(!validate_node(D)) return SUANPAN_FAIL;
52 if(!validate_element(D)) return SUANPAN_FAIL;
53
54 auto& t_node = D->get<Node>(target_node(0));
55 auto& t_element = D->get<Element>(target_element(0));
56
57 vec normalised_coor(DIM, fill::zeros);
58
59 if(t_element->compute_shape_function(normalised_coor, 0).is_empty()) return SUANPAN_FAIL;
60
61 const auto element_coor = t_element->get_coordinate(DIM);
62 const auto node_coor = t_node->initial_position(DIM);
63
64 rowvec shape;
65
66 // solve local system to obtain the shape function at the position of node
67 auto counter = 0u;
68 while(true) {
69 if(max_iteration == ++counter) return SUANPAN_FAIL;
70 const vec incre = solve((t_element->compute_shape_function(normalised_coor, 1) * element_coor).t(), node_coor - ((shape = t_element->compute_shape_function(normalised_coor, 0)) * element_coor).t());
71 if(suanpan::inf_norm(incre) < tolerance) break;
72 normalised_coor += incre;
73 }
74
75 auxiliary_stiffness.zeros(D->get_factory()->get_size(), DIM);
76
77 auto& node_dof = t_node->get_reordered_dof();
78 auto& element_dof = t_element->get_dof_encoding();
79 for(auto K = 0u; K < DIM; ++K) {
80 auxiliary_stiffness(node_dof(K), K) = -1.;
81 for(uword I = 0, J = K; I < shape.n_elem; ++I, J += t_element->get_dof_number()) auxiliary_stiffness(element_dof(J), K) = shape(I);
82 }
83
84 return SUANPAN_SUCCESS;
85 }
86
87 int process(const shared_ptr<DomainBase>& D) override {
88 auxiliary_resistance = auxiliary_stiffness.t() * D->get_factory()->get_trial_displacement();
89
90 return SUANPAN_SUCCESS;
91 }
92};
93
94#endif
95
virtual int initialize(const shared_ptr< DomainBase > &)
Definition ConditionalModifier.cpp:85
uvec target_element
Definition ConditionalModifier.h:123
bool validate_element(const shared_ptr< DomainBase > &) const
Definition ConditionalModifier.cpp:40
uvec target_node
Definition ConditionalModifier.h:123
bool validate_node(const shared_ptr< DomainBase > &) const
Definition ConditionalModifier.cpp:25
A Constraint class.
Definition Constraint.h:36
sp_mat auxiliary_stiffness
Definition Constraint.h:48
vec auxiliary_resistance
Definition Constraint.h:46
A Element class.
Definition Element.h:118
A Embed class.
Definition Embed.h:37
int process(const shared_ptr< DomainBase > &D) override
Process and update both stiffness and resistance.
Definition Embed.h:87
Embed(const unsigned T, const unsigned ET, const unsigned NT)
Definition Embed.h:42
int initialize(const shared_ptr< DomainBase > &D) override
Definition Embed.h:48
The Node class holds the number of DoFs, coordinate, displacement, velocity and acceleration.
Definition Node.h:79
const vec & get_coordinate() const
Definition Node.cpp:103
Definition shape.h:56
Definition SparseMatMAGMA.hpp:43
enable_if2< is_arma_type< T1 >::value, typenameT1::pod_type >::result inf_norm(const T1 &X)
Definition suanPan.h:373
constexpr auto SUANPAN_SUCCESS
Definition suanPan.h:166
constexpr auto SUANPAN_FAIL
Definition suanPan.h:167