Skip to content

Commit cf7df53

Browse files
committed
fix write_text()
1 parent cb18707 commit cf7df53

13 files changed

+473
-474
lines changed

examples/cut_fem/1d2d/non_smooth_disk.cc

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
//
1414
// ---------------------------------------------------------------------
1515

16-
#include <deal.II/base/function.h>
17-
1816
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
1917
#include <CGAL/Delaunay_mesh_face_base_2.h>
2018
#include <CGAL/Delaunay_mesh_size_criteria_2.h>
2119
#include <CGAL/Delaunay_mesher_2.h>
2220
#include <deal.II/base/convergence_table.h>
21+
#include <deal.II/base/function.h>
22+
#include <deal.II/base/function_signed_distance.h>
2323
#include <deal.II/base/mpi.h>
2424
#include <deal.II/base/point.h>
2525
#include <deal.II/base/quadrature.h>
@@ -28,49 +28,40 @@
2828
#include <deal.II/base/utilities.h>
2929
#include <deal.II/cgal/triangulation.h>
3030
#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-
3431
#include <deal.II/dofs/dof_tools.h>
35-
3632
#include <deal.II/fe/fe_interface_values.h>
3733
#include <deal.II/fe/fe_nothing.h>
3834
#include <deal.II/fe/fe_q.h>
3935
#include <deal.II/fe/fe_system.h>
4036
#include <deal.II/fe/fe_update_flags.h>
4137
#include <deal.II/fe/fe_values.h>
42-
#include <deal.II/hp/q_collection.h>
43-
4438
#include <deal.II/grid/filtered_iterator.h>
4539
#include <deal.II/grid/grid_generator.h>
40+
#include <deal.II/grid/grid_out.h>
4641
#include <deal.II/grid/grid_tools_cache.h>
4742
#include <deal.II/grid/tria.h>
48-
4943
#include <deal.II/hp/fe_collection.h>
5044
#include <deal.II/hp/q_collection.h>
51-
5245
#include <deal.II/lac/affine_constraints.h>
5346
#include <deal.II/lac/dynamic_sparsity_pattern.h>
5447
#include <deal.II/lac/full_matrix.h>
48+
#include <deal.II/lac/generic_linear_algebra.h>
5549
#include <deal.II/lac/precondition.h>
5650
#include <deal.II/lac/solver_cg.h>
5751
#include <deal.II/lac/solver_control.h>
5852
#include <deal.II/lac/sparse_matrix.h>
5953
#include <deal.II/lac/sparsity_pattern.h>
6054
#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>
6258
#include <deal.II/numerics/data_out.h>
6359
#include <deal.II/numerics/vector_tools.h>
6460

6561
#include <fstream>
6662
#include <vector>
6763

68-
#include <deal.II/base/function_signed_distance.h>
69-
7064
#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>
7465

7566
static constexpr double Cx = .5;
7667
static constexpr double Cy = .5;
@@ -79,7 +70,7 @@ static constexpr double R = .3;
7970
namespace Step85 {
8071
using namespace dealii;
8172
class ImplicitFunction : public Function<2> {
82-
public:
73+
public:
8374
virtual double value(const Point<2> &p,
8475
const unsigned int component = 0) const override {
8576
(void)component;
@@ -89,13 +80,14 @@ class ImplicitFunction : public Function<2> {
8980
}
9081
};
9182

92-
template <int dim> class LaplaceSolver {
93-
public:
83+
template <int dim>
84+
class LaplaceSolver {
85+
public:
9486
LaplaceSolver();
9587

9688
void run();
9789

98-
private:
90+
private:
9991
void make_grid();
10092

10193
void setup_discrete_level_set(const unsigned int cycle);
@@ -165,8 +157,11 @@ template <int dim> class LaplaceSolver {
165157

166158
template <int dim>
167159
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),
170165
fe_in(FE_Q<dim>(fe_degree), 1, FE_Nothing<dim>(), 1),
171166
fe_surf(FE_Q<dim>(fe_degree), 1, FE_Q<dim>(fe_degree), 1),
172167
fe_out(FE_Nothing<dim>(), 1, FE_Q<dim>(fe_degree), 1),
@@ -179,7 +174,8 @@ LaplaceSolver<dim>::LaplaceSolver()
179174
fe_collection.push_back(fe_out);
180175
}
181176

182-
template <int dim> void LaplaceSolver<dim>::make_grid() {
177+
template <int dim>
178+
void LaplaceSolver<dim>::make_grid() {
183179
std::cout << "Creating background mesh" << std::endl;
184180

185181
GridGenerator::hyper_cube(triangulation, -1., 1.);
@@ -231,8 +227,9 @@ void LaplaceSolver<dim>::setup_discrete_level_set(const unsigned int cycle) {
231227
level_set);
232228
}
233229

234-
template <int dim> class AnalyticalSolution : public Function<dim> {
235-
public:
230+
template <int dim>
231+
class AnalyticalSolution : public Function<dim> {
232+
public:
236233
double value(const Point<dim> &point,
237234
const unsigned int component = 0) const override;
238235

@@ -251,9 +248,8 @@ double AnalyticalSolution<dim>::value(const Point<dim> &point,
251248
}
252249

253250
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 {
257253
AssertIndexRange(component, this->n_components);
258254
(void)component;
259255
Assert(dim == 2, ExcMessage("Tested so far for 1d2d"));
@@ -267,8 +263,9 @@ AnalyticalSolution<dim>::gradient(const Point<dim> &point,
267263
return gradient;
268264
}
269265

270-
template <int dim> class BoundaryValues : public Function<dim> {
271-
public:
266+
template <int dim>
267+
class BoundaryValues : public Function<dim> {
268+
public:
272269
BoundaryValues() : Function<dim>(dim) {}
273270

274271
virtual double value(const Point<dim> &p,
@@ -284,13 +281,12 @@ double BoundaryValues<dim>::value(const Point<dim> &p,
284281
Assert(component < this->n_components,
285282
ExcIndexRange(component, 0, this->n_components));
286283

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());
294290
}
295291

296292
return 0;
@@ -303,8 +299,9 @@ void BoundaryValues<dim>::vector_value(const Point<dim> &p,
303299
values(c) = BoundaryValues<dim>::value(p, c);
304300
}
305301

306-
template <int dim> class RhsFunction : public Function<dim> {
307-
public:
302+
template <int dim>
303+
class RhsFunction : public Function<dim> {
304+
public:
308305
RhsFunction() : Function<dim>() {}
309306
virtual double value(const Point<dim> &p,
310307
const unsigned int component = 0) const override;
@@ -319,12 +316,13 @@ double RhsFunction<dim>::value(const Point<dim> &p,
319316
}
320317

321318
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
325322
};
326323

327-
template <int dim> void LaplaceSolver<dim>::distribute_dofs() {
324+
template <int dim>
325+
void LaplaceSolver<dim>::distribute_dofs() {
328326
std::cout << "Distributing degrees of freedom" << std::endl;
329327

330328
for (const auto &cell : dof_handler.active_cell_iterators()) {
@@ -357,7 +355,8 @@ template <int dim> void LaplaceSolver<dim>::distribute_dofs() {
357355
constraints.close();
358356
}
359357

360-
template <int dim> void LaplaceSolver<dim>::initialize_matrices() {
358+
template <int dim>
359+
void LaplaceSolver<dim>::initialize_matrices() {
361360
std::cout << "Initializing matrices" << std::endl;
362361

363362
const auto face_has_flux_coupling = [&](const auto &cell,
@@ -421,12 +420,12 @@ void LaplaceSolver<dim>::distribute_penalty_terms(
421420
const double cell_side_length, const unsigned int reminder) {
422421
const QGauss<dim - 1> face_quadrature(2 * fe_degree + 1);
423422
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);
430429
hp_fe_face0.reinit(cell, f);
431430
// initialize for neighboring cell and the same face f, seen by
432431
// the neighboring cell
@@ -452,7 +451,7 @@ void LaplaceSolver<dim>::distribute_penalty_terms(
452451
for (unsigned int q = 0; q < fe_face0.n_quadrature_points; ++q) {
453452
const Tensor<1, dim> normal = fe_face0.normal_vector(q);
454453
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.
456455
const double interface_JxW = fe_face0.JxW(q);
457456
{
458457
for (unsigned int i = 0; i < fe_face0.dofs_per_cell; ++i) {
@@ -569,8 +568,7 @@ template <int dim>
569568
bool LaplaceSolver<dim>::face_has_ghost_penalty(
570569
const typename Triangulation<dim>::active_cell_iterator &cell,
571570
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;
574572

575573
const NonMatching::LocationToLevelSet cell_location =
576574
mesh_classifier.location_to_level_set(cell);
@@ -593,8 +591,7 @@ template <int dim>
593591
bool LaplaceSolver<dim>::face_has_ghost_penalty_outside(
594592
const typename Triangulation<dim>::active_cell_iterator &cell,
595593
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;
598595

599596
const NonMatching::LocationToLevelSet cell_location =
600597
mesh_classifier.location_to_level_set(cell);
@@ -613,7 +610,8 @@ bool LaplaceSolver<dim>::face_has_ghost_penalty_outside(
613610
return false;
614611
}
615612

616-
template <int dim> void LaplaceSolver<dim>::assemble_system() {
613+
template <int dim>
614+
void LaplaceSolver<dim>::assemble_system() {
617615
std::cout << "Assembling" << std::endl;
618616

619617
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() {
688686
for (unsigned int f : cell->face_indices()) {
689687
if (face_has_ghost_penalty(cell, f)) {
690688
distribute_penalty_terms(cell, f, ghost_parameter, cell_side_length,
691-
0); // reminder == 0
689+
0); // reminder == 0
692690
}
693691
}
694692
}
@@ -732,7 +730,7 @@ template <int dim> void LaplaceSolver<dim>::assemble_system() {
732730
for (unsigned int f : cell->face_indices()) {
733731
if (face_has_ghost_penalty_outside(cell, f)) {
734732
distribute_penalty_terms(cell, f, ghost_parameter, cell_side_length,
735-
1); // reminder == 1
733+
1); // reminder == 1
736734
}
737735
}
738736
}
@@ -778,11 +776,11 @@ template <int dim> void LaplaceSolver<dim>::assemble_system() {
778776
for (unsigned int f : cell->face_indices()) {
779777
if (face_has_ghost_penalty(cell, f)) {
780778
distribute_penalty_terms(cell, f, ghost_parameter, cell_side_length,
781-
0); // reminder == 0
779+
0); // reminder == 0
782780
}
783781
if (face_has_ghost_penalty_outside(cell, f)) {
784782
distribute_penalty_terms(cell, f, ghost_parameter, cell_side_length,
785-
1); // reminder == 1
783+
1); // reminder == 1
786784
}
787785
}
788786

@@ -854,7 +852,6 @@ template <int dim> void LaplaceSolver<dim>::assemble_system() {
854852
}
855853

856854
if (i % 2 == 0) {
857-
858855
local_rhs_surf(i) +=
859856
AnalyticalSolution<dim>().value(point) *
860857
(nitsche_parameter / cell_side_length *
@@ -884,7 +881,8 @@ template <int dim> void LaplaceSolver<dim>::assemble_system() {
884881
rhs.compress(VectorOperation::add);
885882
}
886883

887-
template <int dim> void LaplaceSolver<dim>::solve() {
884+
template <int dim>
885+
void LaplaceSolver<dim>::solve() {
888886
std::cout << "Solving system" << std::endl;
889887

890888
LinearAlgebraTrilinos::MPI::PreconditionAMG preconditioner;
@@ -897,7 +895,8 @@ template <int dim> void LaplaceSolver<dim>::solve() {
897895
constraints.distribute(solution);
898896
}
899897

900-
template <int dim> void LaplaceSolver<dim>::output_results() const {
898+
template <int dim>
899+
void LaplaceSolver<dim>::output_results() const {
901900
std::cout << "Writing vtu file" << std::endl;
902901

903902
DataOut<dim> data_out;
@@ -1231,7 +1230,8 @@ double LaplaceSolver<dim>::compute_H1_error_from_inside() const {
12311230
return std::sqrt(error_H1_squared + sqrtL2error);
12321231
}
12331232

1234-
template <int dim> void LaplaceSolver<dim>::run() {
1233+
template <int dim>
1234+
void LaplaceSolver<dim>::run() {
12351235
ConvergenceTable convergence_table;
12361236
const unsigned int n_refinements = 6;
12371237

@@ -1274,13 +1274,13 @@ template <int dim> void LaplaceSolver<dim>::run() {
12741274
convergence_table.evaluate_convergence_rates(
12751275
"H1-Error", ConvergenceTable::reduction_rate_log2);
12761276
}
1277-
1277+
12781278
std::string conv_filename = "table_09.txt";
12791279
std::ofstream table_file(conv_filename);
1280-
convergence_table.write_text(conv_filename);
1280+
convergence_table.write_text(table_file);
12811281
}
12821282

1283-
} // namespace Step85
1283+
} // namespace Step85
12841284

12851285
int main(int argc, char *argv[]) {
12861286
const int dim = 2;

0 commit comments

Comments
 (0)