-
Notifications
You must be signed in to change notification settings - Fork 23
/
compliance_output.cpp
332 lines (231 loc) · 9.92 KB
/
compliance_output.cpp
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
* MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
* Copyright (C) 2013-2020 Manav Bhatia and MAST authors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
// MAST includes
#include "elasticity/compliance_output.h"
#include "elasticity/structural_element_base.h"
#include "base/assembly_base.h"
#include "base/system_initialization.h"
#include "base/nonlinear_system.h"
#include "base/physics_discipline_base.h"
#include "base/boundary_condition_base.h"
#include "property_cards/element_property_card_1D.h"
#include "level_set/level_set_intersection.h"
#include "level_set/level_set_intersected_elem.h"
#include "mesh/geom_elem.h"
// libMesh includes
#include "libmesh/parallel.h"
MAST::ComplianceOutput::ComplianceOutput():
MAST::OutputAssemblyElemOperations(),
_compliance (0.),
_dcompliance_dp (0.) {
}
MAST::ComplianceOutput::~ComplianceOutput() {
}
void
MAST::ComplianceOutput::zero_for_analysis() {
_compliance = 0.;
_dcompliance_dp = 0.;
}
void
MAST::ComplianceOutput::zero_for_sensitivity() {
_compliance = 0.;
_dcompliance_dp = 0.;
}
void
MAST::ComplianceOutput::evaluate() {
// make sure that this has not been initialized ana calculated for all elems
libmesh_assert(_physics_elem);
if (this->if_evaluate_for_element(_physics_elem->elem())) {
MAST::StructuralElementBase& e =
dynamic_cast<MAST::StructuralElementBase&>(*_physics_elem);
RealVectorX
vec = RealVectorX::Zero(e.sol().size());
RealMatrixX
dummy = RealMatrixX::Zero(vec.size(), vec.size());
e.side_external_residual(false,
vec,
dummy,
dummy,
_discipline->side_loads());
e.volume_external_residual(false,
vec,
dummy,
dummy,
_discipline->volume_loads());
// compute the contribution of this element to compliance
_compliance -= vec.dot(e.sol());
}
}
void
MAST::ComplianceOutput::evaluate_sensitivity(const MAST::FunctionBase &f) {
// make sure that this has not been initialized ana calculated for all elems
libmesh_assert(_physics_elem);
if (this->if_evaluate_for_element(_physics_elem->elem())) {
MAST::StructuralElementBase& e =
dynamic_cast<MAST::StructuralElementBase&>(*_physics_elem);
RealVectorX
vec = RealVectorX::Zero(e.sol().size());
RealMatrixX
dummy = RealMatrixX::Zero(vec.size(), vec.size());
e.side_external_residual_sensitivity(f, false,
vec,
dummy,
dummy,
_discipline->side_loads());
e.volume_external_residual_sensitivity(f, false,
vec,
dummy,
dummy,
_discipline->volume_loads());
// ask for the values
_dcompliance_dp -= vec.dot(e.sol());
vec.setZero();
e.side_external_residual(false,
vec,
dummy,
dummy,
_discipline->side_loads());
e.volume_external_residual(false,
vec,
dummy,
dummy,
_discipline->volume_loads());
// ask for the values
_dcompliance_dp -= vec.dot(e.sol(true));
}
}
void
MAST::ComplianceOutput::
evaluate_topology_sensitivity(const MAST::FunctionBase &f) {
// the primal data should have been calculated
libmesh_assert(_physics_elem);
libmesh_assert(f.is_topology_parameter());
if (this->if_evaluate_for_element(_physics_elem->elem())) {
std::pair<const MAST::FieldFunction<RealVectorX>*, unsigned int>
val = this->get_elem_boundary_velocity_data();
if (val.first) {
MAST::StructuralElementBase& e =
dynamic_cast<MAST::StructuralElementBase&>(*_physics_elem);
RealVectorX
vec = RealVectorX::Zero(e.sol().size());
RealMatrixX
dummy = RealMatrixX::Zero(vec.size(), vec.size());
e.volume_external_residual_boundary_velocity(f,
val.second,
*val.first,
_discipline->volume_loads(),
false,
vec,
dummy);
// compute the contribution of this element to compliance
_dcompliance_dp -= vec.dot(e.sol());
}
}
}
void
MAST::ComplianceOutput::
evaluate_topology_sensitivity(const MAST::FunctionBase &f,
const MAST::FieldFunction<RealVectorX> &vel) {
// the primal data should have been calculated
libmesh_assert(_physics_elem);
libmesh_assert(f.is_topology_parameter());
const MAST::LevelSetIntersectedElem
&elem = dynamic_cast<const MAST::LevelSetIntersectedElem&>(_physics_elem->elem());
// sensitivity only exists at the boundary. So, we proceed with calculation
// only if this element has an intersection in the interior, or with a side.
if (this->if_evaluate_for_element(elem) &&
elem.if_elem_has_level_set_boundary() &&
elem.if_subelem_has_side_on_level_set_boundary()) {
MAST::StructuralElementBase& e =
dynamic_cast<MAST::StructuralElementBase&>(*_physics_elem);
RealVectorX
vec = RealVectorX::Zero(e.sol().size());
RealMatrixX
dummy = RealMatrixX::Zero(vec.size(), vec.size());
e.volume_external_residual_boundary_velocity(f,
elem.get_subelem_side_on_level_set_boundary(),
vel,
_discipline->volume_loads(),
false,
vec,
dummy);
// compute the contribution of this element to compliance
_dcompliance_dp -= vec.dot(e.sol());
}
}
Real
MAST::ComplianceOutput::output_total() {
Real val = _compliance;
if (!_skip_comm_sum)
_system->system().comm().sum(val);
return val;
}
Real
MAST::ComplianceOutput::output_sensitivity_total(const MAST::FunctionBase& p) {
Real val = _dcompliance_dp;
if (!_skip_comm_sum)
_system->system().comm().sum(val);
return val;
}
void
MAST::ComplianceOutput::output_derivative_for_elem(RealVectorX& dq_dX) {
// make sure that this has not been initialized ana calculated for all elems
libmesh_assert(_physics_elem);
// since compliance = -X^T F, derivative wrt X = -F.
if (this->if_evaluate_for_element(_physics_elem->elem())) {
MAST::StructuralElementBase& e =
dynamic_cast<MAST::StructuralElementBase&>(*_physics_elem);
dq_dX.setZero();
RealMatrixX
dummy = RealMatrixX::Zero(dq_dX.size(), dq_dX.size());
e.side_external_residual(false,
dq_dX,
dummy,
dummy,
_discipline->side_loads());
e.volume_external_residual(false,
dq_dX,
dummy,
dummy,
_discipline->volume_loads());
dq_dX *= -1.;
}
}
void
MAST::ComplianceOutput::
set_elem_data(unsigned int dim,
const libMesh::Elem& ref_elem,
MAST::GeomElem& elem) const {
libmesh_assert(!_physics_elem);
if (dim == 1) {
const MAST::ElementPropertyCard1D& p =
dynamic_cast<const MAST::ElementPropertyCard1D&>(_discipline->get_property_card(ref_elem));
elem.set_local_y_vector(p.y_vector());
}
}
void
MAST::ComplianceOutput::init(const MAST::GeomElem& elem) {
libmesh_assert(!_physics_elem);
libmesh_assert(_assembly);
libmesh_assert(_system);
const MAST::ElementPropertyCardBase& p =
dynamic_cast<const MAST::ElementPropertyCardBase&>(_discipline->get_property_card(elem));
_physics_elem =
MAST::build_structural_element(*_system, elem, p).release();
}