-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstep-44-variant_01d.cc
274 lines (251 loc) · 10.8 KB
/
step-44-variant_01d.cc
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
// ---------------------------------------------------------------------
//
// Copyright (C) 2021 - 2022 by Jean-Paul Pelteret
//
// This file is part of the Weak forms for deal.II library.
//
// The Weak forms for deal.II library is free software; you can use it,
// 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 3.0 of the License, or (at your option) any later
// version. The full text of the license can be found in the file LICENSE
// at the top level of the Weak forms for deal.II distribution.
//
// ---------------------------------------------------------------------
// Finite strain elasticity problem: Assembly using composite weak forms
// This test replicates step-44 exactly.
//
// In this variant:
// - the Piola stress is used for the problem parameterisation
// (i.e. this is an application of the two-point formulation).
#include <weak_forms/weak_forms.h>
#include "../weak_forms_tests.h"
#include "wf_common_tests/step-44.h"
namespace Step44
{
template <int dim>
class Step44 : public Step44_Base<dim>
{
public:
Step44(const std::string &input_file)
: Step44_Base<dim>(input_file)
{}
protected:
void
assemble_system(const BlockVector<double> &solution_delta) override;
};
template <int dim>
void
Step44<dim>::assemble_system(const BlockVector<double> &solution_delta)
{
using namespace WeakForms;
constexpr int spacedim = dim;
this->timer.enter_subsection("Assemble system");
std::cout << " ASM_SYS " << std::flush;
this->tangent_matrix = 0.0;
this->system_rhs = 0.0;
const BlockVector<double> solution_total(
this->get_total_solution(solution_delta));
// Symbolic types for test function, trial solution and a coefficient.
const TestFunction<dim, spacedim> test;
const TrialSolution<dim, spacedim> trial;
const FieldSolution<dim, spacedim> field_solution;
const SubSpaceExtractors::Vector subspace_extractor_u(0,
"u",
"\\mathbf{u}");
const SubSpaceExtractors::Scalar subspace_extractor_p(spacedim,
"p_tilde",
"\\tilde{p}");
const SubSpaceExtractors::Scalar subspace_extractor_J(spacedim + 1,
"J_tilde",
"\\tilde{J}");
// Test function (subspaced)
const auto test_ss_u = test[subspace_extractor_u];
const auto test_ss_p = test[subspace_extractor_p];
const auto test_ss_J = test[subspace_extractor_J];
const auto test_u = test_ss_u.value();
const auto test_p = test_ss_p.value();
const auto test_J = test_ss_J.value();
const auto Grad_test_u = test_ss_u.gradient();
// Trial solution (subspaces)
const auto trial_ss_u = trial[subspace_extractor_u];
const auto trial_ss_p = trial[subspace_extractor_p];
const auto trial_ss_J = trial[subspace_extractor_J];
const auto Grad_trial_u = trial_ss_u.gradient();
const auto trial_p = trial_ss_p.value();
const auto trial_J = trial_ss_J.value();
// Field solution
const auto p_tilde = field_solution[subspace_extractor_p].value();
const auto J_tilde = field_solution[subspace_extractor_J].value();
// Field variables
const ScalarFunctor one_symb("1", "1");
const ScalarFunctor det_F_symb("det_F", "det(\\mathbf{F})");
const ScalarFunctor dPsi_vol_dJ_symb("dPsi_vol_dJ",
"\\frac{d \\Psi^{vol}(J)}{dJ}");
const ScalarFunctor d2Psi_vol_dJ2_symb(
"d2Psi_vol_dJ2", "\\frac{d^{2} \\Psi^{vol}(J)}{dJ^{2}}");
const TensorFunctor<2, spacedim> F_inv_T_symb("F_inv_T",
"\\mathbf{F}^{-T}");
const TensorFunctor<2, spacedim> P_symb("P", "\\mathbf{P}"); // Piola stress
const TensorFunctor<4, spacedim> HH_symb(
"HH", "\\mathcal{H}"); // Linearisation of Piola stress
const auto unity = one_symb.template value<double, dim, spacedim>(
[](const FEValuesBase<dim, spacedim> &, const unsigned int)
{ return 1.0; });
const auto det_F = det_F_symb.template value<double, dim, spacedim>(
[this](const FEValuesBase<dim, spacedim> &fe_values,
const unsigned int q_point)
{
const auto &cell = fe_values.get_cell();
const auto &qph = this->quadrature_point_history;
const std::vector<std::shared_ptr<const PointHistory<dim>>> lqph =
qph.get_data(cell);
return lqph[q_point]->get_det_F();
});
const auto dPsi_vol_dJ =
dPsi_vol_dJ_symb.template value<double, dim, spacedim>(
[this](const FEValuesBase<dim, spacedim> &fe_values,
const unsigned int q_point)
{
const auto &cell = fe_values.get_cell();
const auto &qph = this->quadrature_point_history;
const std::vector<std::shared_ptr<const PointHistory<dim>>> lqph =
qph.get_data(cell);
return lqph[q_point]->get_dPsi_vol_dJ();
});
const auto d2Psi_vol_dJ2 =
d2Psi_vol_dJ2_symb.template value<double, dim, spacedim>(
[this](const FEValuesBase<dim, spacedim> &fe_values,
const unsigned int q_point)
{
const auto &cell = fe_values.get_cell();
const auto &qph = this->quadrature_point_history;
const std::vector<std::shared_ptr<const PointHistory<dim>>> lqph =
qph.get_data(cell);
return lqph[q_point]->get_d2Psi_vol_dJ2();
});
const auto F_inv_T = F_inv_T_symb.template value<double, dim>(
[this](const FEValuesBase<dim, spacedim> &fe_values,
const unsigned int q_point)
{
const auto &cell = fe_values.get_cell();
const auto &qph = this->quadrature_point_history;
const std::vector<std::shared_ptr<const PointHistory<dim>>> lqph =
qph.get_data(cell);
return lqph[q_point]->get_F_inv_T();
});
const auto P = P_symb.template value<double, dim>(
[this](const FEValuesBase<dim, spacedim> &fe_values,
const unsigned int q_point)
{
const auto &cell = fe_values.get_cell();
const auto &qph = this->quadrature_point_history;
const std::vector<std::shared_ptr<const PointHistory<dim>>> lqph =
qph.get_data(cell);
return lqph[q_point]->get_P();
});
const auto HH = HH_symb.template value<double, dim>(
[this](const FEValuesBase<dim, spacedim> &fe_values,
const unsigned int q_point)
{
const auto &cell = fe_values.get_cell();
const auto &qph = this->quadrature_point_history;
const std::vector<std::shared_ptr<const PointHistory<dim>>> lqph =
qph.get_data(cell);
return lqph[q_point]->get_HH();
});
// Boundary conditions
const dealii::types::boundary_id traction_boundary_id = 6;
const ScalarFunctor p_symb("p", "p"); // Applied pressure
const Normal<spacedim> normal{};
const auto p = p_symb.template value<double, dim, spacedim>(
[this](const FEValuesBase<dim, spacedim> &, const unsigned int)
{
static const double p0 =
-4.0 / (this->parameters.scale * this->parameters.scale);
const double time_ramp = (this->time.current() / this->time.end());
const double pressure = p0 * this->parameters.p_p0 * time_ramp;
return pressure;
});
const auto N = normal.value();
// Assembly
MatrixBasedAssembler<dim> assembler;
assembler +=
bilinear_form(Grad_test_u, HH, Grad_trial_u).dV() // K_uu
+ bilinear_form(Grad_test_u, det_F * F_inv_T, trial_p).dV() // K_up
+ bilinear_form(test_p, det_F * F_inv_T, Grad_trial_u).dV() // K_pu
- bilinear_form(test_p, unity, trial_J).dV() // K_pJ
- bilinear_form(test_J, unity, trial_p).dV() // K_Jp
+ bilinear_form(test_J, d2Psi_vol_dJ2, trial_J).dV(); // K_JJ
assembler += linear_form(Grad_test_u, P).dV() // r_u
+ linear_form(test_p, det_F - J_tilde).dV() // r_p
+ linear_form(test_J, dPsi_vol_dJ - p_tilde).dV(); // r_J
assembler -= linear_form(test_u, N * p).dA(traction_boundary_id); // f_u
// Look at what we're going to compute
const SymbolicDecorations decorator;
static bool output = true;
if (output)
{
std::cout << "\n\n" << std::endl;
std::cout << "Weak form (ascii):\n"
<< assembler.as_ascii(decorator) << std::endl;
std::cout << "Weak form (LaTeX):\n"
<< assembler.as_latex(decorator) << std::endl;
std::cout << "\n\n" << std::endl;
output = false;
}
// Now we pass in concrete objects to get data from
// and assemble into.
const QGauss<dim> qf_cell(this->fe.degree + 1);
const QGauss<dim - 1> qf_face(this->fe.degree + 1);
assembler.assemble_system(this->tangent_matrix,
this->system_rhs,
solution_total,
this->constraints,
this->dof_handler_ref,
qf_cell,
qf_face);
this->timer.leave_subsection();
}
} // namespace Step44
int
main(int argc, char **argv)
{
initlog();
deallog << std::setprecision(9);
Utilities::MPI::MPI_InitFinalize mpi_initialization(
argc, argv, testing_max_num_threads());
using namespace dealii;
try
{
const unsigned int dim = 3;
Step44::Step44<dim> solid(SOURCE_DIR "/prm/parameters-step-44.prm");
solid.run();
}
catch (std::exception &exc)
{
std::cerr << std::endl
<< std::endl
<< "----------------------------------------------------"
<< std::endl;
std::cerr << "Exception on processing: " << std::endl
<< exc.what() << std::endl
<< "Aborting!" << std::endl
<< "----------------------------------------------------"
<< std::endl;
return 1;
}
catch (...)
{
std::cerr << std::endl
<< std::endl
<< "----------------------------------------------------"
<< std::endl;
std::cerr << "Unknown exception!" << std::endl
<< "Aborting!" << std::endl
<< "----------------------------------------------------"
<< std::endl;
return 1;
}
return 0;
}