13
13
//
14
14
// ---------------------------------------------------------------------
15
15
16
- #include < deal.II/base/function.h>
17
-
18
16
#include < CGAL/Constrained_Delaunay_triangulation_2.h>
19
17
#include < CGAL/Delaunay_mesh_face_base_2.h>
20
18
#include < CGAL/Delaunay_mesh_size_criteria_2.h>
21
19
#include < CGAL/Delaunay_mesher_2.h>
22
20
#include < deal.II/base/convergence_table.h>
21
+ #include < deal.II/base/function.h>
22
+ #include < deal.II/base/function_signed_distance.h>
23
23
#include < deal.II/base/mpi.h>
24
24
#include < deal.II/base/point.h>
25
25
#include < deal.II/base/quadrature.h>
28
28
#include < deal.II/base/utilities.h>
29
29
#include < deal.II/cgal/triangulation.h>
30
30
#include < deal.II/distributed/shared_tria.h>
31
- #include < deal.II/grid/grid_out.h>
32
- #include < deal.II/lac/generic_linear_algebra.h>
33
-
34
31
#include < deal.II/dofs/dof_tools.h>
35
-
36
32
#include < deal.II/fe/fe_interface_values.h>
37
33
#include < deal.II/fe/fe_nothing.h>
38
34
#include < deal.II/fe/fe_q.h>
39
35
#include < deal.II/fe/fe_system.h>
40
36
#include < deal.II/fe/fe_update_flags.h>
41
37
#include < deal.II/fe/fe_values.h>
42
- #include < deal.II/hp/q_collection.h>
43
-
44
38
#include < deal.II/grid/filtered_iterator.h>
45
39
#include < deal.II/grid/grid_generator.h>
40
+ #include < deal.II/grid/grid_out.h>
46
41
#include < deal.II/grid/grid_tools_cache.h>
47
42
#include < deal.II/grid/tria.h>
48
-
49
43
#include < deal.II/hp/fe_collection.h>
50
44
#include < deal.II/hp/q_collection.h>
51
-
52
45
#include < deal.II/lac/affine_constraints.h>
53
46
#include < deal.II/lac/dynamic_sparsity_pattern.h>
54
47
#include < deal.II/lac/full_matrix.h>
48
+ #include < deal.II/lac/generic_linear_algebra.h>
55
49
#include < deal.II/lac/precondition.h>
56
50
#include < deal.II/lac/solver_cg.h>
57
51
#include < deal.II/lac/solver_control.h>
58
52
#include < deal.II/lac/sparse_matrix.h>
59
53
#include < deal.II/lac/sparsity_pattern.h>
60
54
#include < deal.II/lac/vector.h>
61
-
55
+ #include < deal.II/non_matching/fe_immersed_values.h>
56
+ #include < deal.II/non_matching/fe_values.h>
57
+ #include < deal.II/non_matching/mesh_classifier.h>
62
58
#include < deal.II/numerics/data_out.h>
63
59
#include < deal.II/numerics/vector_tools.h>
64
60
65
61
#include < fstream>
66
62
#include < vector>
67
63
68
- #include < deal.II/base/function_signed_distance.h>
69
-
70
64
#include " coupling_utilities.h"
71
- #include < deal.II/non_matching/fe_immersed_values.h>
72
- #include < deal.II/non_matching/fe_values.h>
73
- #include < deal.II/non_matching/mesh_classifier.h>
74
65
75
66
static constexpr double Cx = .5 ;
76
67
static constexpr double Cy = .5 ;
@@ -79,7 +70,7 @@ static constexpr double R = .3;
79
70
namespace Step85 {
80
71
using namespace dealii ;
81
72
class ImplicitFunction : public Function <2 > {
82
- public:
73
+ public:
83
74
virtual double value (const Point<2 > &p,
84
75
const unsigned int component = 0 ) const override {
85
76
(void )component;
@@ -89,13 +80,14 @@ class ImplicitFunction : public Function<2> {
89
80
}
90
81
};
91
82
92
- template <int dim> class LaplaceSolver {
93
- public:
83
+ template <int dim>
84
+ class LaplaceSolver {
85
+ public:
94
86
LaplaceSolver ();
95
87
96
88
void run ();
97
89
98
- private:
90
+ private:
99
91
void make_grid ();
100
92
101
93
void setup_discrete_level_set (const unsigned int cycle);
@@ -165,8 +157,11 @@ template <int dim> class LaplaceSolver {
165
157
166
158
template <int dim>
167
159
LaplaceSolver<dim>::LaplaceSolver()
168
- : fe_degree(1 ), triangulation(MPI_COMM_WORLD), fe_level_set(fe_degree),
169
- level_set_dof_handler (triangulation), dof_handler(triangulation),
160
+ : fe_degree(1 ),
161
+ triangulation (MPI_COMM_WORLD),
162
+ fe_level_set(fe_degree),
163
+ level_set_dof_handler(triangulation),
164
+ dof_handler(triangulation),
170
165
fe_in(FE_Q<dim>(fe_degree), 1, FE_Nothing<dim>(), 1),
171
166
fe_surf(FE_Q<dim>(fe_degree), 1, FE_Q<dim>(fe_degree), 1),
172
167
fe_out(FE_Nothing<dim>(), 1, FE_Q<dim>(fe_degree), 1),
@@ -179,7 +174,8 @@ LaplaceSolver<dim>::LaplaceSolver()
179
174
fe_collection.push_back (fe_out);
180
175
}
181
176
182
- template <int dim> void LaplaceSolver<dim>::make_grid() {
177
+ template <int dim>
178
+ void LaplaceSolver<dim>::make_grid() {
183
179
std::cout << " Creating background mesh" << std::endl;
184
180
185
181
GridGenerator::hyper_cube (triangulation, -1 ., 1 .);
@@ -231,8 +227,9 @@ void LaplaceSolver<dim>::setup_discrete_level_set(const unsigned int cycle) {
231
227
level_set);
232
228
}
233
229
234
- template <int dim> class AnalyticalSolution : public Function <dim> {
235
- public:
230
+ template <int dim>
231
+ class AnalyticalSolution : public Function <dim> {
232
+ public:
236
233
double value (const Point<dim> &point,
237
234
const unsigned int component = 0 ) const override ;
238
235
@@ -251,9 +248,8 @@ double AnalyticalSolution<dim>::value(const Point<dim> &point,
251
248
}
252
249
253
250
template <int dim>
254
- Tensor<1 , dim>
255
- AnalyticalSolution<dim>::gradient(const Point<dim> &point,
256
- const unsigned int component) const {
251
+ Tensor<1 , dim> AnalyticalSolution<dim>::gradient(
252
+ const Point<dim> &point, const unsigned int component) const {
257
253
AssertIndexRange (component, this ->n_components );
258
254
(void )component;
259
255
Assert (dim == 2 , ExcMessage (" Tested so far for 1d2d" ));
@@ -267,8 +263,9 @@ AnalyticalSolution<dim>::gradient(const Point<dim> &point,
267
263
return gradient;
268
264
}
269
265
270
- template <int dim> class BoundaryValues : public Function <dim> {
271
- public:
266
+ template <int dim>
267
+ class BoundaryValues : public Function <dim> {
268
+ public:
272
269
BoundaryValues () : Function<dim>(dim) {}
273
270
274
271
virtual double value (const Point<dim> &p,
@@ -284,13 +281,12 @@ double BoundaryValues<dim>::value(const Point<dim> &p,
284
281
Assert (component < this ->n_components ,
285
282
ExcIndexRange (component, 0 , this ->n_components ));
286
283
287
- if (component == dim - 1 )
288
- switch (dim) {
289
- case 2 :
290
- return AnalyticalSolution<dim>().value (p);
291
- break ;
292
- default :
293
- Assert (false , ExcNotImplemented ());
284
+ if (component == dim - 1 ) switch (dim) {
285
+ case 2 :
286
+ return AnalyticalSolution<dim>().value (p);
287
+ break ;
288
+ default :
289
+ Assert (false , ExcNotImplemented ());
294
290
}
295
291
296
292
return 0 ;
@@ -303,8 +299,9 @@ void BoundaryValues<dim>::vector_value(const Point<dim> &p,
303
299
values (c) = BoundaryValues<dim>::value (p, c);
304
300
}
305
301
306
- template <int dim> class RhsFunction : public Function <dim> {
307
- public:
302
+ template <int dim>
303
+ class RhsFunction : public Function <dim> {
304
+ public:
308
305
RhsFunction () : Function<dim>() {}
309
306
virtual double value (const Point<dim> &p,
310
307
const unsigned int component = 0 ) const override ;
@@ -319,12 +316,13 @@ double RhsFunction<dim>::value(const Point<dim> &p,
319
316
}
320
317
321
318
enum ActiveFEIndex {
322
- sol_in = 0 , // inside
323
- sol_intersection = 1 , // intersection
324
- sol_out = 2 // outside
319
+ sol_in = 0 , // inside
320
+ sol_intersection = 1 , // intersection
321
+ sol_out = 2 // outside
325
322
};
326
323
327
- template <int dim> void LaplaceSolver<dim>::distribute_dofs() {
324
+ template <int dim>
325
+ void LaplaceSolver<dim>::distribute_dofs() {
328
326
std::cout << " Distributing degrees of freedom" << std::endl;
329
327
330
328
for (const auto &cell : dof_handler.active_cell_iterators ()) {
@@ -357,7 +355,8 @@ template <int dim> void LaplaceSolver<dim>::distribute_dofs() {
357
355
constraints.close ();
358
356
}
359
357
360
- template <int dim> void LaplaceSolver<dim>::initialize_matrices() {
358
+ template <int dim>
359
+ void LaplaceSolver<dim>::initialize_matrices() {
361
360
std::cout << " Initializing matrices" << std::endl;
362
361
363
362
const auto face_has_flux_coupling = [&](const auto &cell,
@@ -421,12 +420,12 @@ void LaplaceSolver<dim>::distribute_penalty_terms(
421
420
const double cell_side_length, const unsigned int reminder) {
422
421
const QGauss<dim - 1 > face_quadrature (2 * fe_degree + 1 );
423
422
hp::QCollection<dim - 1 > q_collection (face_quadrature);
424
- hp::FEFaceValues<dim> hp_fe_face0 (fe_collection, q_collection,
425
- update_gradients | update_JxW_values |
426
- update_normal_vectors);
427
- hp::FEFaceValues<dim> hp_fe_face1 (fe_collection, q_collection,
428
- update_gradients | update_JxW_values |
429
- update_normal_vectors);
423
+ hp::FEFaceValues<dim> hp_fe_face0 (
424
+ fe_collection, q_collection,
425
+ update_gradients | update_JxW_values | update_normal_vectors);
426
+ hp::FEFaceValues<dim> hp_fe_face1 (
427
+ fe_collection, q_collection,
428
+ update_gradients | update_JxW_values | update_normal_vectors);
430
429
hp_fe_face0.reinit (cell, f);
431
430
// initialize for neighboring cell and the same face f, seen by
432
431
// the neighboring cell
@@ -452,7 +451,7 @@ void LaplaceSolver<dim>::distribute_penalty_terms(
452
451
for (unsigned int q = 0 ; q < fe_face0.n_quadrature_points ; ++q) {
453
452
const Tensor<1 , dim> normal = fe_face0.normal_vector (q);
454
453
Assert (std::abs (fe_face0.JxW (q) - fe_face1.JxW (q)) < 1e-15 ,
455
- ExcMessage (" Not consistent JxW" )); // sanity check.
454
+ ExcMessage (" Not consistent JxW" )); // sanity check.
456
455
const double interface_JxW = fe_face0.JxW (q);
457
456
{
458
457
for (unsigned int i = 0 ; i < fe_face0.dofs_per_cell ; ++i) {
@@ -569,8 +568,7 @@ template <int dim>
569
568
bool LaplaceSolver<dim>::face_has_ghost_penalty(
570
569
const typename Triangulation<dim>::active_cell_iterator &cell,
571
570
const unsigned int face_index) const {
572
- if (cell->at_boundary (face_index))
573
- return false ;
571
+ if (cell->at_boundary (face_index)) return false ;
574
572
575
573
const NonMatching::LocationToLevelSet cell_location =
576
574
mesh_classifier.location_to_level_set (cell);
@@ -593,8 +591,7 @@ template <int dim>
593
591
bool LaplaceSolver<dim>::face_has_ghost_penalty_outside(
594
592
const typename Triangulation<dim>::active_cell_iterator &cell,
595
593
const unsigned int face_index) const {
596
- if (cell->at_boundary (face_index))
597
- return false ;
594
+ if (cell->at_boundary (face_index)) return false ;
598
595
599
596
const NonMatching::LocationToLevelSet cell_location =
600
597
mesh_classifier.location_to_level_set (cell);
@@ -613,7 +610,8 @@ bool LaplaceSolver<dim>::face_has_ghost_penalty_outside(
613
610
return false ;
614
611
}
615
612
616
- template <int dim> void LaplaceSolver<dim>::assemble_system() {
613
+ template <int dim>
614
+ void LaplaceSolver<dim>::assemble_system() {
617
615
std::cout << " Assembling" << std::endl;
618
616
619
617
const unsigned int n_dofs_per_cell = fe_collection[0 ].dofs_per_cell ;
@@ -688,7 +686,7 @@ template <int dim> void LaplaceSolver<dim>::assemble_system() {
688
686
for (unsigned int f : cell->face_indices ()) {
689
687
if (face_has_ghost_penalty (cell, f)) {
690
688
distribute_penalty_terms (cell, f, ghost_parameter, cell_side_length,
691
- 0 ); // reminder == 0
689
+ 0 ); // reminder == 0
692
690
}
693
691
}
694
692
}
@@ -732,7 +730,7 @@ template <int dim> void LaplaceSolver<dim>::assemble_system() {
732
730
for (unsigned int f : cell->face_indices ()) {
733
731
if (face_has_ghost_penalty_outside (cell, f)) {
734
732
distribute_penalty_terms (cell, f, ghost_parameter, cell_side_length,
735
- 1 ); // reminder == 1
733
+ 1 ); // reminder == 1
736
734
}
737
735
}
738
736
}
@@ -778,11 +776,11 @@ template <int dim> void LaplaceSolver<dim>::assemble_system() {
778
776
for (unsigned int f : cell->face_indices ()) {
779
777
if (face_has_ghost_penalty (cell, f)) {
780
778
distribute_penalty_terms (cell, f, ghost_parameter, cell_side_length,
781
- 0 ); // reminder == 0
779
+ 0 ); // reminder == 0
782
780
}
783
781
if (face_has_ghost_penalty_outside (cell, f)) {
784
782
distribute_penalty_terms (cell, f, ghost_parameter, cell_side_length,
785
- 1 ); // reminder == 1
783
+ 1 ); // reminder == 1
786
784
}
787
785
}
788
786
@@ -854,7 +852,6 @@ template <int dim> void LaplaceSolver<dim>::assemble_system() {
854
852
}
855
853
856
854
if (i % 2 == 0 ) {
857
-
858
855
local_rhs_surf (i) +=
859
856
AnalyticalSolution<dim>().value (point) *
860
857
(nitsche_parameter / cell_side_length *
@@ -884,7 +881,8 @@ template <int dim> void LaplaceSolver<dim>::assemble_system() {
884
881
rhs.compress (VectorOperation::add);
885
882
}
886
883
887
- template <int dim> void LaplaceSolver<dim>::solve() {
884
+ template <int dim>
885
+ void LaplaceSolver<dim>::solve() {
888
886
std::cout << " Solving system" << std::endl;
889
887
890
888
LinearAlgebraTrilinos::MPI::PreconditionAMG preconditioner;
@@ -897,7 +895,8 @@ template <int dim> void LaplaceSolver<dim>::solve() {
897
895
constraints.distribute (solution);
898
896
}
899
897
900
- template <int dim> void LaplaceSolver<dim>::output_results() const {
898
+ template <int dim>
899
+ void LaplaceSolver<dim>::output_results() const {
901
900
std::cout << " Writing vtu file" << std::endl;
902
901
903
902
DataOut<dim> data_out;
@@ -1231,7 +1230,8 @@ double LaplaceSolver<dim>::compute_H1_error_from_inside() const {
1231
1230
return std::sqrt (error_H1_squared + sqrtL2error);
1232
1231
}
1233
1232
1234
- template <int dim> void LaplaceSolver<dim>::run() {
1233
+ template <int dim>
1234
+ void LaplaceSolver<dim>::run() {
1235
1235
ConvergenceTable convergence_table;
1236
1236
const unsigned int n_refinements = 6 ;
1237
1237
@@ -1274,13 +1274,13 @@ template <int dim> void LaplaceSolver<dim>::run() {
1274
1274
convergence_table.evaluate_convergence_rates (
1275
1275
" H1-Error" , ConvergenceTable::reduction_rate_log2);
1276
1276
}
1277
-
1277
+
1278
1278
std::string conv_filename = " table_09.txt" ;
1279
1279
std::ofstream table_file (conv_filename);
1280
- convergence_table.write_text (conv_filename );
1280
+ convergence_table.write_text (table_file );
1281
1281
}
1282
1282
1283
- } // namespace Step85
1283
+ } // namespace Step85
1284
1284
1285
1285
int main (int argc, char *argv[]) {
1286
1286
const int dim = 2 ;
0 commit comments