Skip to content

Commit

Permalink
Use initlog() in more tests.
Browse files Browse the repository at this point in the history
Here's the script:

#!/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 1b9331f commit bd201b1
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 138 deletions.
6 changes: 2 additions & 4 deletions tests/bits/step-12.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@


#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 @@ -877,12 +875,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
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
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
6 changes: 2 additions & 4 deletions tests/fe/bdm_8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
#define PRECISION 5


std::ofstream logfile("output");

template <int dim>
void
test(const unsigned int degree)
Expand Down Expand Up @@ -76,7 +74,7 @@ test(const unsigned int degree)
(fe.shape_value_component(i, q_point, d) *
fe.shape_value_component(j, q_point, d) * fe.JxW(q_point));

mass_matrix.print_formatted(logfile, 3, false, 0, "0", 1);
mass_matrix.print_formatted(deallog.get_file_stream(), 3, false, 0, "0", 1);

SolverControl solver_control(2 * dofs_per_cell, 1e-8);
PrimitiveVectorMemory<> vector_memory;
Expand All @@ -98,9 +96,9 @@ test(const unsigned int degree)
int
main()
{
initlog();
deallog << std::setprecision(PRECISION);
deallog << std::fixed;
deallog.attach(logfile);

for (unsigned int i = 1; i < 4; ++i)
{
Expand Down
6 changes: 2 additions & 4 deletions tests/fe/bdm_9.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#define PRECISION 2


std::ofstream logfile("output");

template <int dim>
void
test(const unsigned int degree)
Expand All @@ -72,7 +70,7 @@ test(const unsigned int degree)

MatrixTools::create_mass_matrix(dof, q, mass_matrix);

mass_matrix.print_formatted(logfile, 3, false, 0, "0", 1);
mass_matrix.print_formatted(deallog.get_file_stream(), 3, false, 0, "0", 1);

SolverControl solver_control(3 * dofs_per_cell, 1e-8);
PrimitiveVectorMemory<> vector_memory;
Expand All @@ -94,9 +92,9 @@ test(const unsigned int degree)
int
main()
{
initlog();
deallog << std::setprecision(PRECISION);
deallog << std::fixed;
deallog.attach(logfile);

for (unsigned int i = 1; i < 4; ++i)
{
Expand Down
9 changes: 3 additions & 6 deletions tests/fe/br_approximation_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#define PRECISION 8


std::ofstream logfile("output");


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

Expand Down Expand Up @@ -413,11 +410,11 @@ TestProjection(Mapping<2> &mapping, DoFHandler<2> *dof_handler)
int
main()
{
initlog();
deallog << std::setprecision(PRECISION);
deallog << std::fixed;
logfile << std::setprecision(PRECISION);
logfile << std::fixed;
deallog.attach(logfile);
deallog.get_file_stream() << std::setprecision(PRECISION);
deallog.get_file_stream() << std::fixed;

Triangulation<2> tria_test;
DoFHandler<2> * dof_handler, *dof_handler_def;
Expand Down
7 changes: 2 additions & 5 deletions tests/fe/numbering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include "../tests.h"


std::ofstream logfile("output");


template <int dim>
void
check(const FE_Q<dim> &fe)
Expand Down Expand Up @@ -240,7 +237,7 @@ check(const FE_Q<dim> &fe)
{
Assert(l2h[hierarchic_to_lexicographic_numbering[i]] == i,
ExcInternalError());
logfile << dim << "d, degree=" << degree << ": " << l2h[i] << ' '
deallog.get_file_stream() << dim << "d, degree=" << degree << ": " << l2h[i] << ' '
<< hierarchic_to_lexicographic_numbering[i] << std::endl;
};

Expand Down Expand Up @@ -269,9 +266,9 @@ check_dim()
int
main()
{
initlog();
deallog << std::setprecision(2);
deallog << std::fixed;
deallog.attach(logfile);

check_dim<1>();
check_dim<2>();
Expand Down
6 changes: 2 additions & 4 deletions tests/fe/rt_8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
#define PRECISION 8


std::ofstream logfile("output");

template <int dim>
void
test(const unsigned int degree)
Expand Down Expand Up @@ -79,7 +77,7 @@ test(const unsigned int degree)
for (unsigned int j = 0; j < dofs_per_cell; ++j)
if (std::fabs(mass_matrix(i, j)) < 1e-14)
mass_matrix(i, j) = 0;
mass_matrix.print_formatted(logfile, 3, false, 0, " ", 1);
mass_matrix.print_formatted(deallog.get_file_stream(), 3, false, 0, " ", 1);

SolverControl solver_control(dofs_per_cell, 1e-8);
PrimitiveVectorMemory<> vector_memory;
Expand All @@ -98,9 +96,9 @@ test(const unsigned int degree)
int
main()
{
initlog();
deallog << std::setprecision(PRECISION);
deallog << std::fixed;
deallog.attach(logfile);

for (unsigned int i = 0; i < 4; ++i)
test<2>(i);
Expand Down
6 changes: 2 additions & 4 deletions tests/fe/rt_9.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#define PRECISION 8


std::ofstream logfile("output");

template <int dim>
void
test(const unsigned int degree)
Expand All @@ -72,7 +70,7 @@ test(const unsigned int degree)

MatrixTools::create_mass_matrix(dof, q, mass_matrix);

mass_matrix.print_formatted(logfile, 3, false, 0, " ", 1);
mass_matrix.print_formatted(deallog.get_file_stream(), 3, false, 0, " ", 1);

SolverControl solver_control(dofs_per_cell, 1e-8);
PrimitiveVectorMemory<> vector_memory;
Expand All @@ -91,9 +89,9 @@ test(const unsigned int degree)
int
main()
{
initlog();
deallog << std::setprecision(PRECISION);
deallog << std::fixed;
deallog.attach(logfile);

for (unsigned int i = 0; i < 4; ++i)
test<2>(i);
Expand Down
9 changes: 3 additions & 6 deletions tests/fe/rt_approximation_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
#define PRECISION 8


std::ofstream logfile("output");


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

Expand Down Expand Up @@ -425,11 +422,11 @@ TestProjection(Mapping<2> &mapping, DoFHandler<2> *dof_handler)
int
main()
{
initlog();
deallog << std::setprecision(PRECISION);
deallog << std::fixed;
logfile << std::setprecision(PRECISION);
logfile << std::fixed;
deallog.attach(logfile);
deallog.get_file_stream() << std::setprecision(PRECISION);
deallog.get_file_stream() << std::fixed;

Triangulation<2> tria_test;
DoFHandler<2> * dof_handler, *dof_handler_def;
Expand Down
6 changes: 2 additions & 4 deletions tests/fe/rt_bubbles_8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
#define PRECISION 5


std::ofstream logfile("output");

template <int dim>
void
test(const unsigned int degree)
Expand Down Expand Up @@ -75,7 +73,7 @@ test(const unsigned int degree)
(fe.shape_value_component(i, q_point, d) *
fe.shape_value_component(j, q_point, d) * fe.JxW(q_point));

mass_matrix.print_formatted(logfile, 3, false, 0, "0", 1);
mass_matrix.print_formatted(deallog.get_file_stream(), 3, false, 0, "0", 1);

SolverControl solver_control(2 * dofs_per_cell, 1e-8);
PrimitiveVectorMemory<> vector_memory;
Expand All @@ -98,9 +96,9 @@ test(const unsigned int degree)
int
main()
{
initlog();
deallog << std::setprecision(PRECISION);
deallog << std::fixed;
deallog.attach(logfile);

for (unsigned int i = 1; i < 4; ++i)
{
Expand Down
6 changes: 2 additions & 4 deletions tests/fe/rt_bubbles_9.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
#define PRECISION 5


std::ofstream logfile("output");

template <int dim>
void
test(const unsigned int degree)
Expand All @@ -73,7 +71,7 @@ test(const unsigned int degree)

MatrixTools::create_mass_matrix(dof, q, mass_matrix);

mass_matrix.print_formatted(logfile, 3, false, 0, "0", 1);
mass_matrix.print_formatted(deallog.get_file_stream(), 3, false, 0, "0", 1);

SolverControl solver_control(3 * dofs_per_cell, 1e-8);
PrimitiveVectorMemory<> vector_memory;
Expand All @@ -96,9 +94,9 @@ test(const unsigned int degree)
int
main()
{
initlog();
deallog << std::setprecision(PRECISION);
deallog << std::fixed;
deallog.attach(logfile);

for (unsigned int i = 1; i < 4; ++i)
{
Expand Down
9 changes: 3 additions & 6 deletions tests/lac/constraints_merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@



std::ofstream logfile("output");


void
merge_check()
{
Expand Down Expand Up @@ -72,17 +69,17 @@ merge_check()
// now merge the two and print the
// results
c1.merge(c2);
c1.print(logfile);
c1.print(deallog.get_file_stream());
};
}


int
main()
{
initlog();
deallog << std::setprecision(2);
logfile << std::setprecision(2);
deallog.attach(logfile);
deallog.get_file_stream() << std::setprecision(2);

merge_check();
}

0 comments on commit bd201b1

Please sign in to comment.