Unverified Commit 3db944de authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

apply clang-format settings to the c++ sources in the unittest tree

parent 4d62ea98
Loading
Loading
Loading
Loading
+200 −234
Original line number Diff line number Diff line
@@ -13,32 +13,32 @@

// unit tests for angle styles intended for molecular systems

#include "yaml_reader.h"
#include "yaml_writer.h"
#include "error_stats.h"
#include "test_config.h"
#include "test_config_reader.h"
#include "test_main.h"
#include "yaml_reader.h"
#include "yaml_writer.h"

#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

#include "lammps.h"
#include "angle.h"
#include "atom.h"
#include "modify.h"
#include "compute.h"
#include "force.h"
#include "angle.h"
#include "info.h"
#include "input.h"
#include "lammps.h"
#include "modify.h"
#include "universe.h"

#include <mpi.h>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>
#include <mpi.h>

#include <iostream>
#include <map>
@@ -46,12 +46,13 @@
#include <utility>
#include <vector>

using ::testing::StartsWith;
using ::testing::HasSubstr;
using ::testing::StartsWith;

using namespace LAMMPS_NS;

static void delete_file(const std::string & filename) {
static void delete_file(const std::string &filename)
{
    remove(filename.c_str());
};

@@ -63,9 +64,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
    delete lmp;
}

LAMMPS *init_lammps(int argc, char **argv,
                               const TestConfig &cfg,
                               const bool newton=true)
LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true)
{
    LAMMPS *lmp;

@@ -164,8 +163,7 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg)
        command("angle_style " + cfg.angle_style);
    }

    if ((cfg.angle_style.substr(0,6) == "hybrid")
        || !lmp->force->angle->writedata) {
    if ((cfg.angle_style.substr(0, 6) == "hybrid") || !lmp->force->angle->writedata) {
        for (auto &angle_coeff : cfg.angle_coeff) {
            command("angle_coeff " + angle_coeff);
        }
@@ -226,8 +224,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
        std::cerr << "One or more prerequisite styles are not available "
                     "in this LAMMPS configuration:\n";
        for (auto &prerequisite : config.prerequisites) {
            std::cerr << prerequisite.first << "_style "
                      << prerequisite.second << "\n";
            std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
        }
        return;
    }
@@ -309,8 +306,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)

    // init_stress
    double *stress = lmp->force->angle->virial;
    snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e",
             stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]);
    snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0],
             stress[1], stress[2], stress[3], stress[4], stress[5]);
    writer.emit_block("init_stress", buf);

    // init_forces
@@ -318,8 +315,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
    double **f = lmp->atom->f;
    tagint *tag = lmp->atom->tag;
    for (int i = 0; i < natoms; ++i) {
        snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n",
                 (int)tag[i], f[i][0], f[i][1], f[i][2]);
        snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1],
                 f[i][2]);
        block += buf;
    }
    writer.emit_block("init_forces", block);
@@ -332,16 +329,16 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)

    // run_stress
    stress = lmp->force->angle->virial;
    snprintf(buf,bufsize,"% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e",
             stress[0],stress[1],stress[2],stress[3],stress[4],stress[5]);
    snprintf(buf, bufsize, "% 23.16e % 23.16e % 23.16e % 23.16e % 23.16e % 23.16e", stress[0],
             stress[1], stress[2], stress[3], stress[4], stress[5]);
    writer.emit_block("run_stress", buf);

    block.clear();
    f = lmp->atom->f;
    tag = lmp->atom->tag;
    for (int i = 0; i < natoms; ++i) {
        snprintf(buf,bufsize,"% 3d % 23.16e % 23.16e % 23.16e\n",
                 (int)tag[i], f[i][0], f[i][1], f[i][2]);
        snprintf(buf, bufsize, "% 3d % 23.16e % 23.16e % 23.16e\n", (int)tag[i], f[i][0], f[i][1],
                 f[i][2]);
        block += buf;
    }
    writer.emit_block("run_forces", block);
@@ -350,7 +347,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
    return;
}

TEST(AngleStyle, plain) {
TEST(AngleStyle, plain)
{
    const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"};
    char **argv = (char **)args;
    int argc = sizeof(args) / sizeof(char *);
@@ -364,8 +362,7 @@ TEST(AngleStyle, plain) {
        std::cerr << "One or more prerequisite styles are not available "
                     "in this LAMMPS configuration:\n";
        for (auto &prerequisite : test_config.prerequisites) {
            std::cerr << prerequisite.first << "_style "
                      << prerequisite.second << "\n";
            std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
        }
        GTEST_SKIP();
    }
@@ -389,8 +386,7 @@ TEST(AngleStyle, plain) {
        EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon);
        EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
    }
    if (print_stats)
        std::cerr << "init_forces stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl;

    Angle *angle = lmp->force->angle;
    double *stress = angle->virial;
@@ -401,13 +397,11 @@ TEST(AngleStyle, plain) {
    EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
    if (print_stats)
        std::cerr << "init_stress stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl;

    stats.reset();
    EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
    if (print_stats)
        std::cerr << "init_energy stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl;

    if (!verbose) ::testing::internal::CaptureStdout();
    run_lammps(lmp);
@@ -423,8 +417,7 @@ TEST(AngleStyle, plain) {
        EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon);
        EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
    }
    if (print_stats)
        std::cerr << "run_forces  stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "run_forces  stats, newton on: " << stats << std::endl;

    stress = angle->virial;
    stats.reset();
@@ -434,16 +427,14 @@ TEST(AngleStyle, plain) {
    EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
    if (print_stats)
        std::cerr << "run_stress  stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "run_stress  stats, newton on: " << stats << std::endl;

    stats.reset();
    int id = lmp->modify->find_compute("sum");
    double energy = lmp->modify->compute[id]->compute_scalar();
    EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.run_energy, epsilon);
    EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon);
    if (print_stats)
        std::cerr << "run_energy  stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "run_energy  stats, newton on: " << stats << std::endl;

    if (!verbose) ::testing::internal::CaptureStdout();
    cleanup_lammps(lmp, test_config);
@@ -461,8 +452,7 @@ TEST(AngleStyle, plain) {
            EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon);
            EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
        }
        if (print_stats)
            std::cerr << "init_forces stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl;

        angle = lmp->force->angle;
        stress = angle->virial;
@@ -473,13 +463,11 @@ TEST(AngleStyle, plain) {
        EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 2 * epsilon);
        EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 2 * epsilon);
        EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 2 * epsilon);
        if (print_stats)
            std::cerr << "init_stress stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl;

        stats.reset();
        EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
        if (print_stats)
            std::cerr << "init_energy stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl;

        if (!verbose) ::testing::internal::CaptureStdout();
        run_lammps(lmp);
@@ -493,8 +481,7 @@ TEST(AngleStyle, plain) {
            EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon);
            EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
        }
        if (print_stats)
            std::cerr << "run_forces  stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "run_forces  stats, newton off:" << stats << std::endl;

        stress = angle->virial;
        stats.reset();
@@ -504,16 +491,14 @@ TEST(AngleStyle, plain) {
        EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, epsilon);
        EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, epsilon);
        EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, epsilon);
        if (print_stats)
            std::cerr << "run_stress  stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "run_stress  stats, newton off:" << stats << std::endl;

        stats.reset();
        id = lmp->modify->find_compute("sum");
        energy = lmp->modify->compute[id]->compute_scalar();
        EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.run_energy, epsilon);
        EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon);
        if (print_stats)
            std::cerr << "run_energy  stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "run_energy  stats, newton off:" << stats << std::endl;
    }

    if (!verbose) ::testing::internal::CaptureStdout();
@@ -529,8 +514,7 @@ TEST(AngleStyle, plain) {
        EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon);
        EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
    }
    if (print_stats)
        std::cerr << "restart_forces stats:" << stats << std::endl;
    if (print_stats) std::cerr << "restart_forces stats:" << stats << std::endl;

    angle = lmp->force->angle;
    stress = angle->virial;
@@ -541,13 +525,11 @@ TEST(AngleStyle, plain) {
    EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
    if (print_stats)
        std::cerr << "restart_stress stats:" << stats << std::endl;
    if (print_stats) std::cerr << "restart_stress stats:" << stats << std::endl;

    stats.reset();
    EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
    if (print_stats)
        std::cerr << "restart_energy stats:" << stats << std::endl;
    if (print_stats) std::cerr << "restart_energy stats:" << stats << std::endl;

    if (!verbose) ::testing::internal::CaptureStdout();
    data_lammps(lmp, test_config);
@@ -562,8 +544,7 @@ TEST(AngleStyle, plain) {
        EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon);
        EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
    }
    if (print_stats)
        std::cerr << "data_forces stats:" << stats << std::endl;
    if (print_stats) std::cerr << "data_forces stats:" << stats << std::endl;

    angle = lmp->force->angle;
    stress = angle->virial;
@@ -574,23 +555,22 @@ TEST(AngleStyle, plain) {
    EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon);
    if (print_stats)
        std::cerr << "data_stress stats:" << stats << std::endl;
    if (print_stats) std::cerr << "data_stress stats:" << stats << std::endl;

    stats.reset();
    EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
    if (print_stats)
        std::cerr << "data_energy stats:" << stats << std::endl;
    if (print_stats) std::cerr << "data_energy stats:" << stats << std::endl;

    if (!verbose) ::testing::internal::CaptureStdout();
    cleanup_lammps(lmp, test_config);
    if (!verbose) ::testing::internal::GetCapturedStdout();
};

TEST(AngleStyle, omp) {
TEST(AngleStyle, omp)
{
    if (!LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP();
    const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen",
                          "-nocite", "-pk", "omp", "4", "-sf", "omp"};
    const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite",
                          "-pk",        "omp",  "4",    "-sf",   "omp"};
    char **argv = (char **)args;
    int argc = sizeof(args) / sizeof(char *);

@@ -603,8 +583,7 @@ TEST(AngleStyle, omp) {
        std::cerr << "One or more prerequisite styles with /omp suffix\n"
                     "are not available in this LAMMPS configuration:\n";
        for (auto &prerequisite : test_config.prerequisites) {
            std::cerr << prerequisite.first << "_style "
                      << prerequisite.second << "\n";
            std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
        }
        GTEST_SKIP();
    }
@@ -628,8 +607,7 @@ TEST(AngleStyle, omp) {
        EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon);
        EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
    }
    if (print_stats)
        std::cerr << "init_forces stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "init_forces stats, newton on: " << stats << std::endl;

    Angle *angle = lmp->force->angle;
    double *stress = angle->virial;
@@ -641,13 +619,11 @@ TEST(AngleStyle, omp) {
    EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon);
    if (print_stats)
        std::cerr << "init_stress stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "init_stress stats, newton on: " << stats << std::endl;

    stats.reset();
    EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
    if (print_stats)
        std::cerr << "init_energy stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "init_energy stats, newton on: " << stats << std::endl;

    if (!verbose) ::testing::internal::CaptureStdout();
    run_lammps(lmp);
@@ -663,8 +639,7 @@ TEST(AngleStyle, omp) {
        EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon);
        EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
    }
    if (print_stats)
        std::cerr << "run_forces  stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "run_forces  stats, newton on: " << stats << std::endl;

    stress = angle->virial;
    stats.reset();
@@ -674,8 +649,7 @@ TEST(AngleStyle, omp) {
    EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon);
    EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon);
    if (print_stats)
        std::cerr << "run_stress  stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "run_stress  stats, newton on: " << stats << std::endl;

    stats.reset();
    int id = lmp->modify->find_compute("sum");
@@ -685,8 +659,7 @@ TEST(AngleStyle, omp) {
    // needs to be fixed in the main code somewhere. Not sure where, though.
    if (test_config.angle_style.substr(0, 6) != "hybrid")
        EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon);
    if (print_stats)
        std::cerr << "run_energy  stats, newton on: " << stats << std::endl;
    if (print_stats) std::cerr << "run_energy  stats, newton on: " << stats << std::endl;

    if (!verbose) ::testing::internal::CaptureStdout();
    cleanup_lammps(lmp, test_config);
@@ -704,8 +677,7 @@ TEST(AngleStyle, omp) {
            EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon);
            EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon);
        }
        if (print_stats)
            std::cerr << "init_forces stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "init_forces stats, newton off:" << stats << std::endl;

        angle = lmp->force->angle;
        stress = angle->virial;
@@ -716,13 +688,11 @@ TEST(AngleStyle, omp) {
        EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, 10 * epsilon);
        EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, 10 * epsilon);
        EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, 10 * epsilon);
        if (print_stats)
            std::cerr << "init_stress stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "init_stress stats, newton off:" << stats << std::endl;

        stats.reset();
        EXPECT_FP_LE_WITH_EPS(angle->energy, test_config.init_energy, epsilon);
        if (print_stats)
            std::cerr << "init_energy stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "init_energy stats, newton off:" << stats << std::endl;

        if (!verbose) ::testing::internal::CaptureStdout();
        run_lammps(lmp);
@@ -735,8 +705,7 @@ TEST(AngleStyle, omp) {
            EXPECT_FP_LE_WITH_EPS(f[i][1], f_run[tag[i]].y, 10 * epsilon);
            EXPECT_FP_LE_WITH_EPS(f[i][2], f_run[tag[i]].z, 10 * epsilon);
        }
        if (print_stats)
            std::cerr << "run_forces  stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "run_forces  stats, newton off:" << stats << std::endl;

        stress = angle->virial;
        stats.reset();
@@ -746,8 +715,7 @@ TEST(AngleStyle, omp) {
        EXPECT_FP_LE_WITH_EPS(stress[3], test_config.run_stress.xy, 10 * epsilon);
        EXPECT_FP_LE_WITH_EPS(stress[4], test_config.run_stress.xz, 10 * epsilon);
        EXPECT_FP_LE_WITH_EPS(stress[5], test_config.run_stress.yz, 10 * epsilon);
        if (print_stats)
            std::cerr << "run_stress  stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "run_stress  stats, newton off:" << stats << std::endl;

        stats.reset();
        id = lmp->modify->find_compute("sum");
@@ -757,8 +725,7 @@ TEST(AngleStyle, omp) {
        // needs to be fixed in the main code somewhere. Not sure where, though.
        if (test_config.angle_style.substr(0, 6) != "hybrid")
            EXPECT_FP_LE_WITH_EPS(angle->energy, energy, epsilon);
        if (print_stats)
            std::cerr << "run_energy  stats, newton off:" << stats << std::endl;
        if (print_stats) std::cerr << "run_energy  stats, newton off:" << stats << std::endl;
    }

    if (!verbose) ::testing::internal::CaptureStdout();
@@ -766,7 +733,8 @@ TEST(AngleStyle, omp) {
    if (!verbose) ::testing::internal::GetCapturedStdout();
};

TEST(AngleStyle, single) {
TEST(AngleStyle, single)
{
    const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"};
    char **argv = (char **)args;
    int argc = sizeof(args) / sizeof(char *);
@@ -780,8 +748,7 @@ TEST(AngleStyle, single) {
        std::cerr << "One or more prerequisite styles are not available "
                     "in this LAMMPS configuration:\n";
        for (auto &prerequisite : test_config.prerequisites) {
            std::cerr << prerequisite.first << "_style "
                      << prerequisite.second << "\n";
            std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n";
        }
        GTEST_SKIP();
    }
@@ -904,8 +871,7 @@ TEST(AngleStyle, single) {
    EXPECT_FP_LE_WITH_EPS(eangle[1], esingle[1], epsilon);
    EXPECT_FP_LE_WITH_EPS(eangle[2], esingle[2], epsilon);
    EXPECT_FP_LE_WITH_EPS(eangle[3], esingle[3], epsilon);
    if (print_stats)
        std::cerr << "single_energy  stats:" << stats << std::endl;
    if (print_stats) std::cerr << "single_energy  stats:" << stats << std::endl;

    int i = 0;
    for (auto &dist : test_config.equilibrium)
+270 −305

File changed.

Preview size limit exceeded, changes collapsed.

+14 −13
Original line number Diff line number Diff line
@@ -12,17 +12,19 @@
------------------------------------------------------------------------- */

#include "error_stats.h"
#include <cmath>
#include <iostream>
#include <string>
#include <cmath>

void ErrorStats::reset() {
void ErrorStats::reset()
{
    num = 0;
    maxidx = -1;
    sum = sumsq = maxerr = 0.0;
}

void ErrorStats::add(const double &val) {
void ErrorStats::add(const double &val)
{
    ++num;
    if (val > maxerr) {
        maxidx = num;
@@ -32,11 +34,13 @@ void ErrorStats::add(const double &val) {
    sumsq += val * val;
}

double ErrorStats::avg() const {
double ErrorStats::avg() const
{
    return (num > 0) ? sum / num : 0.0;
}

double ErrorStats::dev() const {
double ErrorStats::dev() const
{
    return (num > 0) ? sqrt(sumsq / num - sum / num * sum / num) : 0.0;
}

@@ -46,9 +50,7 @@ std::ostream &operator<<(std::ostream &out, const ErrorStats &stats)
    const std::streamsize width = out.width(10);
    const std::streamsize prec = out.precision(3);

    out << std::scientific
        << "Average: " << stats.avg()
        << " StdDev: " << stats.dev()
    out << std::scientific << "Average: " << stats.avg() << " StdDev: " << stats.dev()
        << " MaxErr: " << stats.max();

    out.precision(prec);
@@ -57,4 +59,3 @@ std::ostream &operator<<(std::ostream &out, const ErrorStats &stats)

    return out << " @ item: " << stats.idx();
}
+3 −5
Original line number Diff line number Diff line
@@ -20,9 +20,7 @@ class ErrorStats {
public:
    friend std::ostream &operator<<(std::ostream &out, const ErrorStats &stats);

    ErrorStats() {
            reset();
    }
    ErrorStats() { reset(); }
    virtual ~ErrorStats() {}

    void reset();
+344 −397

File changed.

Preview size limit exceeded, changes collapsed.

Loading