-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathGlobalRecorder.cpp
More file actions
112 lines (90 loc) · 4.56 KB
/
Copy pathGlobalRecorder.cpp
File metadata and controls
112 lines (90 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*******************************************************************************
* Copyright (C) 2017-2026 Theodore Chang
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include "GlobalRecorder.h"
#include <Domain/DomainBase.h>
#include <Domain/Factory.hpp>
#include <Element/Element.h>
void GlobalRecorder::assemble_matrix(const mat& local, const uvec& encoding, mat& global) {
if(local.is_empty()) return;
for(unsigned I{0}; I < encoding.n_elem; ++I)
for(unsigned J{0}; J < encoding.n_elem; ++J) global(encoding(J), encoding(I)) += local(J, I);
}
void GlobalRecorder::record_impl(const shared_ptr<DomainBase>& D) {
if(OutputType::KE == variable_type) {
auto kinetic_energy = 0.;
for(auto& I : D->get_pool<Element>()) kinetic_energy += I->get_kinetic_energy();
insert({{kinetic_energy, D->get_factory()->get_kinetic_energy()}}, 0);
}
else if(OutputType::VE == variable_type) {
auto viscous_energy = 0.;
for(auto& I : D->get_pool<Element>()) viscous_energy += I->get_viscous_energy();
insert({{viscous_energy, D->get_factory()->get_viscous_energy()}}, 0);
}
else if(OutputType::NVE == variable_type) {
auto nonviscous_energy = 0.;
for(auto& I : D->get_pool<Element>()) nonviscous_energy += I->get_nonviscous_energy();
insert({{nonviscous_energy, D->get_factory()->get_nonviscous_energy()}}, 0);
}
else if(OutputType::SE == variable_type) {
auto strain_energy = 0.;
for(auto& I : D->get_pool<Element>()) strain_energy += I->get_strain_energy();
insert({{strain_energy, D->get_factory()->get_strain_energy()}}, 0);
}
else return;
insert(D->get_factory()->get_current_time());
}
GlobalRecorder::GlobalRecorder(const unsigned T, const OutputType L, const unsigned I, const bool H)
: Recorder(T, {0}, L, I, H) {}
void GlobalRecorder::print() { suanpan_info("A global recorder.\n"); }
void GlobalStiffnessRecorder::record_impl(const shared_ptr<DomainBase>& D) {
const uword S = D->get_factory()->get_size();
vec stiffness(S * S, fill::zeros);
auto& C = D->get_color_map();
if(mat g_stiffness(stiffness.memptr(), S, S, false, true); C.empty())
for(const auto& I : D->get_element_pool()) assemble_matrix(I->get_current_stiffness(), I->get_dof_encoding(), g_stiffness);
else
std::ranges::for_each(C, [&](const std::vector<unsigned>& color) {
suanpan::for_all(color, [&](const unsigned tag) {
const auto& I = D->get<Element>(tag);
assemble_matrix(I->get_current_stiffness(), I->get_dof_encoding(), g_stiffness);
});
});
insert({stiffness}, 0);
insert(D->get_factory()->get_current_time());
}
GlobalStiffnessRecorder::GlobalStiffnessRecorder(const unsigned T, const unsigned I, const bool H)
: GlobalRecorder(T, OutputType::K, I, H) {}
void GlobalStiffnessRecorder::print() { suanpan_info("A global stiffness recorder.\n"); }
void GlobalMassRecorder::record_impl(const shared_ptr<DomainBase>& D) {
const uword S = D->get_factory()->get_size();
vec mass(S * S, fill::zeros);
auto& C = D->get_color_map();
if(mat g_mass(mass.memptr(), S, S, false, true); C.empty())
for(const auto& I : D->get_element_pool()) assemble_matrix(I->get_current_mass(), I->get_dof_encoding(), g_mass);
else
std::ranges::for_each(C, [&](const std::vector<unsigned>& color) {
suanpan::for_all(color, [&](const unsigned tag) {
const auto& I = D->get<Element>(tag);
assemble_matrix(I->get_current_mass(), I->get_dof_encoding(), g_mass);
});
});
insert({mass}, 0);
insert(D->get_factory()->get_current_time());
}
GlobalMassRecorder::GlobalMassRecorder(const unsigned T, const unsigned I, const bool H)
: GlobalRecorder(T, OutputType::M, I, H) {}
void GlobalMassRecorder::print() { suanpan_info("A global mass recorder.\n"); }