Skip to content

Commit

Permalink
Use initlog() in more tests.
Browse files Browse the repository at this point in the history
These required a small amount of manual tidying-up but the script I used to
generate most of the changes is

#!/usr/bin/env python3

import sys

lines = list()
skip_next_if_blank = False
with open(sys.argv[1], 'r') as handle:
    for line in handle:
        if line != 'std::ofstream logfile("output");\n':
            if "deallog.attach" not in line:
                if skip_next_if_blank and line == "\n":
                    pass
                else:
                    lines.append(line.replace("logfile",
                                              "deallog.get_file_stream()"))
                    skip_next_if_blank = False
        else:
            skip_next_if_blank = True

found_main = False
line_after_main = -1
with open(sys.argv[1], 'w') as handle:
    for line in lines:
        handle.write(line)
        if line.startswith("main("):
            found_main = True
        if found_main:
            line_after_main = line_after_main + 1
        if line_after_main == 1:
            handle.write("  initlog();\n")
  • Loading branch information
drwells committed Jan 24, 2023
1 parent 069d370 commit d59afbd
Show file tree
Hide file tree
Showing 80 changed files with 185 additions and 411 deletions.
10 changes: 4 additions & 6 deletions tests/bits/step-10-high-order.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
// that things still work for very high order


#include "../tests.h"
std::ofstream logfile("output");


#include <deal.II/base/convergence_table.h>
#include <deal.II/base/quadrature_lib.h>

Expand All @@ -42,6 +38,8 @@ std::ofstream logfile("output");

#include <deal.II/hp/fe_values.h>

#include "../tests.h"


const long double pi = 3.141592653589793238462643;

Expand Down Expand Up @@ -180,10 +178,10 @@ compute_pi_by_perimeter()
int
main()
{
initlog();
deallog << std::setprecision(16);
logfile << std::setprecision(16);
deallog.get_file_stream() << std::setprecision(16);

deallog.attach(logfile);

compute_pi_by_area<2>();
compute_pi_by_perimeter<2>();
Expand Down
10 changes: 4 additions & 6 deletions tests/bits/step-10.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
// a un-hp-ified version of hp/step-10


#include "../tests.h"
std::ofstream logfile("output");


#include <deal.II/base/convergence_table.h>
#include <deal.II/base/quadrature_lib.h>

Expand All @@ -40,6 +36,8 @@ std::ofstream logfile("output");

#include <deal.II/hp/fe_values.h>

#include "../tests.h"


const long double pi = 3.141592653589793238462643;

Expand Down Expand Up @@ -223,10 +221,10 @@ compute_pi_by_perimeter()
int
main()
{
initlog();
deallog << std::setprecision(6);
logfile << std::setprecision(6);
deallog.get_file_stream() << std::setprecision(6);

deallog.attach(logfile);

gnuplot_output<2>();

Expand Down
9 changes: 4 additions & 5 deletions tests/bits/step-12.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
// a un-hp-ified version of hp/step-12


#include "../tests.h"
std::ofstream logfile("output");

#include <deal.II/base/function.h>
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/timer.h>
Expand Down Expand Up @@ -48,6 +45,8 @@ std::ofstream logfile("output");
#include <deal.II/numerics/data_out.h>
#include <deal.II/numerics/derivative_approximation.h>

#include "../tests.h"



template <int dim>
Expand Down Expand Up @@ -877,12 +876,12 @@ DGMethod<dim>::run()
int
main()
{
initlog();
try
{
deallog << std::setprecision(2);
logfile << std::setprecision(2);
deallog.get_file_stream() << std::setprecision(2);

deallog.attach(logfile);

DGMethod<2> dgmethod;
dgmethod.run();
Expand Down
5 changes: 1 addition & 4 deletions tests/bits/step-2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@



std::ofstream logfile("output");


void
make_grid(Triangulation<2> &triangulation)
{
Expand Down Expand Up @@ -111,9 +108,9 @@ renumber_dofs(DoFHandler<2> &dof_handler)
int
main()
{
initlog();
deallog << std::setprecision(2);

deallog.attach(logfile);

Triangulation<2> triangulation;
make_grid(triangulation);
Expand Down
8 changes: 2 additions & 6 deletions tests/bits/step-3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@

#include "../tests.h"

std::ofstream logfile("output");



class LaplaceProblem
{
public:
Expand Down Expand Up @@ -217,10 +213,10 @@ LaplaceProblem::run()
int
main()
{
initlog();
deallog << std::setprecision(2);
logfile << std::setprecision(2);
deallog.get_file_stream() << std::setprecision(2);

deallog.attach(logfile);

LaplaceProblem laplace_problem;
laplace_problem.run();
Expand Down
5 changes: 1 addition & 4 deletions tests/bits/subdomain_ids_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#include "../tests.h"


std::ofstream logfile("output");


template <int dim>
void
test()
Expand Down Expand Up @@ -89,8 +86,8 @@ test()
int
main()
{
initlog();
deallog << std::setprecision(4);
deallog.attach(logfile);

test<1>();
test<2>();
Expand Down
5 changes: 1 addition & 4 deletions tests/bits/subdomain_ids_02.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#include "../tests.h"


std::ofstream logfile("output");


template <int dim>
void
test()
Expand Down Expand Up @@ -99,8 +96,8 @@ test()
int
main()
{
initlog();
deallog << std::setprecision(4);
deallog.attach(logfile);

test<1>();
test<2>();
Expand Down
5 changes: 1 addition & 4 deletions tests/bits/subdomain_ids_03.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#include "../tests.h"


std::ofstream logfile("output");


template <int dim>
void
test()
Expand Down Expand Up @@ -83,8 +80,8 @@ test()
int
main()
{
initlog();
deallog << std::setprecision(4);
deallog.attach(logfile);

test<1>();
test<2>();
Expand Down
5 changes: 1 addition & 4 deletions tests/bits/subdomain_ids_04.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#include "../tests.h"


std::ofstream logfile("output");


template <int dim>
void
test()
Expand Down Expand Up @@ -104,8 +101,8 @@ test()
int
main()
{
initlog();
deallog << std::setprecision(4);
deallog.attach(logfile);

test<1>();
test<2>();
Expand Down
5 changes: 1 addition & 4 deletions tests/bits/subdomain_ids_05.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#include "../tests.h"


std::ofstream logfile("output");


template <int dim>
void
test()
Expand Down Expand Up @@ -91,8 +88,8 @@ test()
int
main()
{
initlog();
deallog << std::setprecision(4);
deallog.attach(logfile);

test<1>();
test<2>();
Expand Down
5 changes: 1 addition & 4 deletions tests/bits/subdomain_ids_06.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#include "../tests.h"


std::ofstream logfile("output");


template <int dim>
void
test()
Expand Down Expand Up @@ -93,8 +90,8 @@ test()
int
main()
{
initlog();
deallog << std::setprecision(4);
deallog.attach(logfile);

test<1>();
test<2>();
Expand Down
5 changes: 1 addition & 4 deletions tests/bits/subdomain_ids_07.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#include "../tests.h"


std::ofstream logfile("output");


template <int dim>
void
test()
Expand Down Expand Up @@ -94,8 +91,8 @@ test()
int
main()
{
initlog();
deallog << std::setprecision(4);
deallog.attach(logfile);

test<1>();
test<2>();
Expand Down
9 changes: 3 additions & 6 deletions tests/dofs/dof_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
// 2: refinement of the circle at the boundary
// 2: refinement of a wiggled area at the boundary

std::ofstream logfile("output");


template <int dim>
class Ball : public FlatManifold<dim>
{
Expand Down Expand Up @@ -325,7 +322,7 @@ TestCases<dim>::run(const unsigned int test_case)
int unconstrained_bandwidth = sparsity.bandwidth();

deallog << " Writing sparsity pattern..." << std::endl;
sparsity.print_gnuplot(logfile);
sparsity.print_gnuplot(deallog.get_file_stream());


// computing constraints
Expand All @@ -336,7 +333,7 @@ TestCases<dim>::run(const unsigned int test_case)
constraints.condense(sparsity);

deallog << " Writing condensed sparsity pattern..." << std::endl;
sparsity.print_gnuplot(logfile);
sparsity.print_gnuplot(deallog.get_file_stream());


deallog << std::endl
Expand Down Expand Up @@ -364,7 +361,7 @@ TestCases<dim>::run(const unsigned int test_case)
int
main()
{
deallog.attach(logfile);
initlog();

for (unsigned int test_case = 1; test_case <= 2; ++test_case)
{
Expand Down
7 changes: 2 additions & 5 deletions tests/dofs/dof_tools_21_b.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@

#include "../tests.h"

std::ofstream logfile("output");


//
// Test
// DoFTools::
Expand Down Expand Up @@ -361,9 +358,9 @@ print_matching(DoFHandler<dim, spacedim> &dof_handler,
int
main()
{
initlog();
deallog << std::setprecision(4);
logfile << std::setprecision(4);
deallog.attach(logfile);
deallog.get_file_stream() << std::setprecision(4);

deallog << "Test for 2D, Q1:" << std::endl << std::endl;

Expand Down
8 changes: 2 additions & 6 deletions tests/dofs/dof_tools_21_b_x.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@

#include "../tests.h"

std::ofstream logfile("output");



/*
* Generate a grid consisting of two disjoint cells, colorize the two
* outermost faces. They will be matched via collect_periodic_faces
Expand Down Expand Up @@ -223,9 +219,9 @@ print_matching(DoFHandler<dim, spacedim> &dof_handler)
int
main()
{
initlog();
deallog << std::setprecision(4);
logfile << std::setprecision(4);
deallog.attach(logfile);
deallog.get_file_stream() << std::setprecision(4);

{
// Generate a triangulation and match:
Expand Down
8 changes: 2 additions & 6 deletions tests/dofs/dof_tools_21_b_x_q3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@

#include "../tests.h"

std::ofstream logfile("output");



/*
* Generate a grid consisting of two disjoint cells, colorize the two
* outermost faces. They will be matched via collect_periodic_faces
Expand Down Expand Up @@ -257,9 +253,9 @@ print_matching(DoFHandler<dim, spacedim> &dof_handler)
int
main()
{
initlog();
deallog << std::setprecision(4);
logfile << std::setprecision(4);
deallog.attach(logfile);
deallog.get_file_stream() << std::setprecision(4);

{
// Generate a triangulation and match:
Expand Down

0 comments on commit d59afbd

Please sign in to comment.