-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstep-74-variant_01a.cc
291 lines (247 loc) · 11.2 KB
/
step-74-variant_01a.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// ---------------------------------------------------------------------
//
// Copyright (C) 2020 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The 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 2.1 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 deal.II distribution.
//
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// 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.
//
// ---------------------------------------------------------------------
// This test replicates step-74.
// It is used as a baseline for the weak form tests.
#include "../weak_forms_tests.h"
#include "wf_common_tests/step-74.h"
namespace Step74
{
template <int dim>
class Step74 : public SIPGLaplace<dim>
{
using ScratchData = typename SIPGLaplace<dim>::ScratchData;
public:
Step74(const TestCase &test_case)
: SIPGLaplace<dim>(test_case)
{}
protected:
void
assemble_system() override;
};
template <int dim>
void
Step74<dim>::assemble_system()
{
const auto cell_worker =
[this](const auto &cell, auto &scratch_data, auto ©_data)
{
const FEValues<dim> &fe_v = scratch_data.reinit(cell);
const unsigned int dofs_per_cell = fe_v.dofs_per_cell;
copy_data.reinit(cell, dofs_per_cell);
const auto & q_points = scratch_data.get_quadrature_points();
const unsigned int n_q_points = q_points.size();
const std::vector<double> &JxW = scratch_data.get_JxW_values();
std::vector<double> rhs(n_q_points);
this->rhs_function->value_list(q_points, rhs);
for (unsigned int point = 0; point < n_q_points; ++point)
for (unsigned int i = 0; i < fe_v.dofs_per_cell; ++i)
{
for (unsigned int j = 0; j < fe_v.dofs_per_cell; ++j)
copy_data.cell_matrix(i, j) +=
this->diffusion_coefficient * // nu
fe_v.shape_grad(i, point) * // grad v_h
fe_v.shape_grad(j, point) * // grad u_h
JxW[point]; // dx
copy_data.cell_rhs(i) += fe_v.shape_value(i, point) * // v_h
rhs[point] * // f
JxW[point]; // dx
}
};
const auto boundary_worker = [this](const auto & cell,
const unsigned int &face_no,
auto & scratch_data,
auto & copy_data)
{
const FEFaceValuesBase<dim> &fe_fv = scratch_data.reinit(cell, face_no);
const auto & q_points = scratch_data.get_quadrature_points();
const unsigned int n_q_points = q_points.size();
const unsigned int dofs_per_cell = fe_fv.dofs_per_cell;
const std::vector<double> & JxW = scratch_data.get_JxW_values();
const std::vector<Tensor<1, dim>> &normals =
scratch_data.get_normal_vectors();
std::vector<double> g(n_q_points);
this->exact_solution->value_list(q_points, g);
const double extent1 = cell->measure() / cell->face(face_no)->measure();
const double penalty = get_penalty_factor(this->degree, extent1, extent1);
for (unsigned int point = 0; point < n_q_points; ++point)
{
for (unsigned int i = 0; i < dofs_per_cell; ++i)
for (unsigned int j = 0; j < dofs_per_cell; ++j)
copy_data.cell_matrix(i, j) +=
(-this->diffusion_coefficient * // - nu
fe_fv.shape_value(i, point) * // v_h
(fe_fv.shape_grad(j, point) * // (grad u_h .
normals[point]) // n)
- this->diffusion_coefficient * // - nu
(fe_fv.shape_grad(i, point) * // (grad v_h .
normals[point]) * // n)
fe_fv.shape_value(j, point) // u_h
+ this->diffusion_coefficient * penalty * // + nu sigma
fe_fv.shape_value(i, point) * // v_h
fe_fv.shape_value(j, point) // u_h
) *
JxW[point]; // dx
for (unsigned int i = 0; i < dofs_per_cell; ++i)
copy_data.cell_rhs(i) +=
(-this->diffusion_coefficient * // - nu
(fe_fv.shape_grad(i, point) * // (grad v_h .
normals[point]) * // n)
g[point] // g
+ this->diffusion_coefficient * penalty * // + nu sigma
fe_fv.shape_value(i, point) * g[point] // v_h g
) *
JxW[point]; // dx
}
};
const auto face_worker = [this](const auto & cell,
const unsigned int &f,
const unsigned int &sf,
const auto & ncell,
const unsigned int &nf,
const unsigned int &nsf,
auto & scratch_data,
auto & copy_data)
{
const FEInterfaceValues<dim> &fe_iv =
scratch_data.reinit(cell, f, sf, ncell, nf, nsf);
copy_data.face_data.emplace_back();
CopyDataFace & copy_data_face = copy_data.face_data.back();
const unsigned int n_dofs_face = fe_iv.n_current_interface_dofs();
copy_data_face.joint_dof_indices = fe_iv.get_interface_dof_indices();
copy_data_face.cell_matrix.reinit(n_dofs_face, n_dofs_face);
const std::vector<double> & JxW = fe_iv.get_JxW_values();
const std::vector<Tensor<1, dim>> &normals = fe_iv.get_normal_vectors();
const double extent1 = cell->measure() / cell->face(f)->measure();
const double extent2 = ncell->measure() / ncell->face(nf)->measure();
const double penalty = get_penalty_factor(this->degree, extent1, extent2);
for (const unsigned int point : fe_iv.quadrature_point_indices())
{
for (const unsigned int i : fe_iv.dof_indices())
for (const unsigned int j : fe_iv.dof_indices())
copy_data_face.cell_matrix(i, j) +=
(-this->diffusion_coefficient * // - nu
fe_iv.jump_in_shape_values(i, point) * // [v_h]
(fe_iv.average_of_shape_gradients(j, //
point) * // ({grad u_h} .
normals[point]) // n)
-
this->diffusion_coefficient * // - nu
(fe_iv.average_of_shape_gradients(i, point) * // (grad v_h .
normals[point]) * // n)
fe_iv.jump_in_shape_values(j, point) // [u_h]
+ this->diffusion_coefficient * penalty * // + nu sigma
fe_iv.jump_in_shape_values(i, point) * // [v_h]
fe_iv.jump_in_shape_values(j, point) // [u_h]
) *
JxW[point]; // dx
}
};
AffineConstraints<double> constraints;
constraints.close();
const auto copier = [this, &constraints](const auto &c)
{
constraints.distribute_local_to_global(c.cell_matrix,
c.cell_rhs,
c.local_dof_indices,
this->system_matrix,
this->system_rhs);
for (auto &cdf : c.face_data)
{
constraints.distribute_local_to_global(cdf.cell_matrix,
cdf.joint_dof_indices,
this->system_matrix);
}
};
const UpdateFlags cell_flags = update_values | update_gradients |
update_quadrature_points | update_JxW_values;
const UpdateFlags face_flags = update_values | update_gradients |
update_quadrature_points |
update_normal_vectors | update_JxW_values;
ScratchData scratch_data(this->mapping,
this->fe,
this->quadrature,
cell_flags,
this->face_quadrature,
face_flags);
CopyData copy_data;
MeshWorker::mesh_loop(this->dof_handler.begin_active(),
this->dof_handler.end(),
cell_worker,
copier,
scratch_data,
copy_data,
MeshWorker::assemble_own_cells |
MeshWorker::assemble_boundary_faces |
MeshWorker::assemble_own_interior_faces_once,
boundary_worker,
face_worker);
}
} // namespace Step74
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 Step74::TestCase test_case = Step74::TestCase::l_singularity;
const int dim = 2;
Step74::Step74<dim> problem(test_case);
problem.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;
}