suanPan
🧮 An Open Source, Parallel and Heterogeneous Finite Element Analysis Framework
Loading...
Searching...
No Matches
Embedded.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 ******************************************************************************/
31#ifndef EMBEDDED_H
32#define EMBEDDED_H
33
34#include <Domain/DomainBase.h>
35#include <Element/Element.h>
36
37template<unsigned DIM> class Embedded final : public Element {
38 static constexpr unsigned max_iteration = 20u;
39
40 const unsigned host_tag;
41 const double multiplier;
42
43 rowvec shape;
44 vec weight;
45
46 std::vector<uvec> idx;
47
48 shared_ptr<Element> host_element;
49
50public:
51 Embedded(const unsigned T, const unsigned ET, const unsigned NT, const double P)
52 : Element(T, DIM, ET, NT, suanpan::translational(DIM))
53 , host_tag(ET)
54 , multiplier(P) {}
55
56 int initialize(const shared_ptr<DomainBase>& D) override {
57 host_element = D->get<Element>(host_tag);
58
59 vec normalised_coor(DIM, fill::zeros);
60
61 if(!host_element->is_active() || host_element->compute_shape_function(normalised_coor, 0).empty()) return SUANPAN_FAIL;
62
63 const auto host_size = host_element->get_node_number();
64
65 idx.clear();
66 idx.reserve(DIM);
67 idx.emplace_back(linspace<uvec>(DIM, DIM * host_size, host_size));
68 for(auto I = 1u; I < DIM; ++I) idx.emplace_back(idx.back() + 1);
69
70 const auto temp_coor = get_coordinate(DIM);
71 const mat element_coor = temp_coor.tail_rows(host_size);
72 const vec node_coor = temp_coor.row(0).t();
73
74 auto counter = 0u;
75 while(++counter <= max_iteration) {
76 const vec incre = solve((host_element->compute_shape_function(normalised_coor, 1) * element_coor).t(), node_coor - ((shape = host_element->compute_shape_function(normalised_coor, 0)) * element_coor).t());
77 if(suanpan::inf_norm(incre) < 1E-14) {
78 weight.ones(get_node_number());
79 weight.tail(host_size) = -shape.t();
80
81 const vec shape_a = multiplier * shape.t();
82 const mat shape_b = -shape_a * shape;
83
85 for(auto I = 0u; I < DIM; ++I) {
86 initial_stiffness(I, I) = -multiplier;
87 initial_stiffness(uvec{I}, idx[I]) = shape_a.t();
88 initial_stiffness(idx[I], uvec{I}) = shape_a;
89 initial_stiffness(idx[I], idx[I]) = shape_b;
90 }
92
93 return SUANPAN_SUCCESS;
94 }
95 normalised_coor += incre;
96 }
97
98 return SUANPAN_FAIL;
99 }
100
101 int update_status() override {
103
104 const vec reaction = multiplier * reshape(get_trial_displacement(), DIM, get_node_number()) * weight;
105
106 trial_resistance.head(DIM) = -reaction;
107
108 for(auto I = 0u; I < DIM; ++I) trial_resistance(idx[I]) = shape.t() * reaction(I);
109
110 return SUANPAN_SUCCESS;
111 }
112
113 int clear_status() override { return SUANPAN_SUCCESS; }
114 int commit_status() override { return SUANPAN_SUCCESS; }
115 int reset_status() override { return SUANPAN_SUCCESS; }
116};
117
118#endif
119
A Element class.
Definition Element.h:118
unsigned get_node_number() const override
Definition Element.cpp:351
unsigned get_total_number() const override
Definition Element.cpp:353
vec get_trial_displacement() const override
Definition Element.cpp:416
friend void ConstantStiffness(DataElement *)
Definition Element.cpp:38
mat get_coordinate() const override
Definition Element.cpp:359
A Embedded class.
Definition Embedded.h:37
int clear_status() override
Definition Embedded.h:113
int initialize(const shared_ptr< DomainBase > &D) override
Definition Embedded.h:56
int update_status() override
Definition Embedded.h:101
int reset_status() override
Definition Embedded.h:115
Embedded(const unsigned T, const unsigned ET, const unsigned NT, const double P)
Definition Embedded.h:51
int commit_status() override
Definition Embedded.h:114
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
mat initial_stiffness
Definition Element.h:73
vec trial_resistance
Definition Element.h:88
constexpr auto SUANPAN_SUCCESS
Definition suanPan.h:166
constexpr auto SUANPAN_FAIL
Definition suanPan.h:167