-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstep-47-variant_01b.cc
245 lines (214 loc) · 8.65 KB
/
step-47-variant_01b.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
// ---------------------------------------------------------------------
//
// 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.
//
// ---------------------------------------------------------------------
// Biharmonic problem: Assembly using composite weak forms.
// This test replicates step-47 exactly.
#include <weak_forms/weak_forms.h>
#include "../weak_forms_tests.h"
#include "wf_common_tests/step-47.h"
namespace Step47
{
template <int dim>
class Step47 : public BiharmonicProblem<dim>
{
public:
Step47(const unsigned int degree)
: BiharmonicProblem<dim>(degree)
{}
protected:
void
assemble_system() override;
};
template <int dim>
void
Step47<dim>::assemble_system()
{
using namespace WeakForms;
constexpr int spacedim = dim;
// Symbolic types for test function, trial solution and a coefficient.
const TestFunction<dim, spacedim> test;
const TrialSolution<dim, spacedim> trial;
// Test function
const auto test_value = test.value();
const auto test_gradient = test.gradient();
const auto test_hessian = test.hessian();
const auto test_ave_hessian = test.average_of_hessians();
const auto test_jump_gradient = test.jump_in_gradients();
// Trial solution
const auto trial_gradient = trial.gradient();
const auto trial_hessian = trial.hessian();
const auto trial_ave_hessian = trial.average_of_hessians();
const auto trial_jump_gradient = trial.jump_in_gradients();
// Boundaries and interfaces
const Normal<spacedim> normal{};
const auto N = normal.value();
// Functions
const ExactSolution::RightHandSide<dim> right_hand_side;
const ScalarFunctionFunctor<spacedim> rhs_function(
"f(x)", "f\\left(\\mathbf{X}\\right)");
const ExactSolution::Solution<dim> exact_solution;
const ScalarFunctionFunctor<spacedim> exact_solution_function(
"u(x)", "u\\left(\\mathbf{X}\\right)");
const ScalarFunctor gamma_over_h_functor("gamma/h", "\\frac{\\gamma}{h}");
const auto gamma_over_h =
gamma_over_h_functor.template value<double, dim, spacedim>(
[](const FEValuesBase<dim, spacedim> &fe_values,
const unsigned int q_point)
{
Assert((dynamic_cast<const FEFaceValuesBase<dim, spacedim> *const>(
&fe_values)),
ExcMessage("Cannot cast to FEFaceValues."));
const auto &fe_face_values =
static_cast<const FEFaceValuesBase<dim, spacedim> &>(fe_values);
const auto &cell = fe_face_values.get_cell();
const auto f = fe_face_values.get_face_number();
const unsigned int p = fe_face_values.get_fe().degree;
const double gamma_over_h =
(1.0 * p * (p + 1) /
cell->extent_in_direction(
GeometryInfo<dim>::unit_normal_direction[f]));
return gamma_over_h;
},
[](const FEInterfaceValues<dim, spacedim> &fe_interface_values,
const unsigned int q_point)
{
Assert(fe_interface_values.at_boundary() == false,
ExcInternalError());
const auto cell =
fe_interface_values.get_fe_face_values(0).get_cell();
const auto ncell =
fe_interface_values.get_fe_face_values(1).get_cell();
const auto f =
fe_interface_values.get_fe_face_values(0).get_face_number();
const auto nf =
fe_interface_values.get_fe_face_values(1).get_face_number();
const unsigned int p = fe_interface_values.get_fe().degree;
const double gamma_over_h =
std::max((1.0 * p * (p + 1) /
cell->extent_in_direction(
GeometryInfo<dim>::unit_normal_direction[f])),
(1.0 * p * (p + 1) /
ncell->extent_in_direction(
GeometryInfo<dim>::unit_normal_direction[nf])));
return gamma_over_h;
});
// Assembly
MatrixBasedAssembler<dim> assembler;
// Cell LHS to assemble:
// (nabla^2 phi_i(x) * nabla^2 phi_j(x)).dV
// - ({grad^2 v n n} * [grad u n]).dI
// - ({grad^2 u n n} * [grad v n]).dI
// + (gamma/h [grad v n] * [grad u n]).dI
// - ({grad^2 v n n} * [grad u n]).dA
// - ({grad^2 u n n} * [grad v n]).dA
// + (gamma/h [grad v n] * [grad u n]).dA
assembler +=
bilinear_form(test_hessian, 1.0, trial_hessian).dV() -
bilinear_form(N * test_ave_hessian * N, 1.0, trial_jump_gradient * N)
.dI() -
bilinear_form(test_jump_gradient * N, 1.0, N * trial_ave_hessian * N)
.dI() +
bilinear_form(test_jump_gradient * N,
gamma_over_h,
trial_jump_gradient * N)
.dI() -
bilinear_form(N * test_hessian * N, 1.0, trial_gradient * N).dA() -
bilinear_form(test_gradient * N, 1.0, N * trial_hessian * N).dA() +
bilinear_form(test_gradient * N, gamma_over_h, trial_gradient * N).dA();
// Cell RHS to assemble:
// (phi_i(x) * f(x)).dV
// - ({grad^2 v n n} * (grad u_exact . n)).dA
// + (gamma/h [grad v n] * (grad u_exact . n)).dA
assembler -=
linear_form(test_value, rhs_function.value(right_hand_side)).dV() -
linear_form(N * test_hessian * N,
exact_solution_function.gradient(exact_solution) * N)
.dA() +
linear_form(gamma_over_h * test_gradient * N,
exact_solution_function.gradient(exact_solution) * N)
.dA();
// Look at what we're going to compute
const SymbolicDecorations decorator;
static bool output = true;
if (output)
{
deallog << "\n" << std::endl;
deallog << "Weak form (ascii):\n"
<< assembler.as_ascii(decorator) << std::endl;
deallog << "Weak form (LaTeX):\n"
<< assembler.as_latex(decorator) << std::endl;
deallog << "\n" << std::endl;
output = false;
}
// Now we pass in concrete objects to get data from
// and assemble into.
const unsigned int quadrature_degree =
this->dof_handler.get_fe().degree + 1;
const QGauss<dim> cell_quadrature(quadrature_degree);
const QGauss<dim - 1> face_quadrature(quadrature_degree);
assembler.assemble_system(this->system_matrix,
this->system_rhs,
this->constraints,
this->dof_handler,
cell_quadrature,
face_quadrature);
}
} // namespace Step47
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 = 2;
const unsigned int fe_degree = 2;
const unsigned int n_local_refinement_levels = 4;
Assert(fe_degree >= 2,
ExcMessage("The C0IP formulation for the biharmonic problem "
"only works if one uses elements of polynomial "
"degree at least 2."));
Step47::Step47<dim> biharmonic_problem(fe_degree);
biharmonic_problem.run(n_local_refinement_levels);
}
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;
}