Unverified Commit 2edad432 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

add support for storing a global scalar and global vector

parent 4b5bc8f6
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ public:
    double run_coul;
    stress_t init_stress;
    stress_t run_stress;
    double global_scalar;
    std::vector<double> global_vector;
    std::vector<coord_t> init_forces;
    std::vector<coord_t> run_forces;
    std::vector<coord_t> run_pos;
@@ -70,7 +72,7 @@ public:
        pair_style("zero"), bond_style("zero"), angle_style("zero"), dihedral_style("zero"),
        improper_style("zero"), kspace_style("none"), natoms(0), init_energy(0), run_energy(0),
        init_vdwl(0), run_vdwl(0), init_coul(0), run_coul(0), init_stress({0, 0, 0, 0, 0, 0}),
        run_stress({0, 0, 0, 0, 0, 0})
        run_stress({0, 0, 0, 0, 0, 0}), global_scalar(0)
    {
        prerequisites.clear();
        pre_commands.clear();
@@ -87,6 +89,7 @@ public:
        restart_pos.clear();
        run_vel.clear();
        restart_vel.clear();
        global_vector.clear();
    }
    virtual ~TestConfig(){};

+23 −0
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ TestConfigReader::TestConfigReader(TestConfig &config) : YamlReader(), config(co
    consumers["run_vdwl"]   = &TestConfigReader::run_vdwl;
    consumers["run_coul"]   = &TestConfigReader::run_coul;

    consumers["global_scalar"] = &TestConfigReader::global_scalar;
    consumers["global_vector"] = &TestConfigReader::global_vector;

    consumers["bond_style"]  = &TestConfigReader::bond_style;
    consumers["bond_coeff"]  = &TestConfigReader::bond_coeff;
    consumers["angle_style"] = &TestConfigReader::angle_style;
@@ -299,3 +302,23 @@ void TestConfigReader::run_energy(const yaml_event_t &event)
{
    config.run_energy = atof((char *)event.data.scalar.value);
}

void TestConfigReader::global_scalar(const yaml_event_t &event)
{
    config.global_scalar = atof((char *)event.data.scalar.value);
}

void TestConfigReader::global_vector(const yaml_event_t &event)
{
    std::stringstream data((char *)event.data.scalar.value);
    config.global_vector.clear();
    double value;
    std::size_t num;
    data >> num;
    for (std::size_t i = 0; i < num; ++i) {
        data >> value;
        if (data.eof()) break;
        config.global_vector.push_back(value);
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ public:
    void run_forces(const yaml_event_t &event);
    void run_pos(const yaml_event_t &event);
    void run_vel(const yaml_event_t &event);
    void fix_style(const yaml_event_t &event);
    void pair_style(const yaml_event_t &event);
    void pair_coeff(const yaml_event_t &event);
    void bond_style(const yaml_event_t &event);
@@ -52,6 +51,8 @@ public:
    void run_coul(const yaml_event_t &event);
    void init_energy(const yaml_event_t &event);
    void run_energy(const yaml_event_t &event);
    void global_scalar(const yaml_event_t &event);
    void global_vector(const yaml_event_t &event);
};

#endif
+24 −2
Original line number Diff line number Diff line
@@ -231,6 +231,28 @@ void generate_yaml_file(const char *outfile, const TestConfig &config)
    // natoms
    writer.emit("natoms", natoms);

    int ifix = lmp->modify->find_fix("test");
    if (ifix < 0) {
        std::cerr << "WARNING: no fix defined with fix ID 'test'\n";
    } else {
        Fix *fix = lmp->modify->fix[ifix];

        // global scalar
        if (fix->scalar_flag) {
            double value = fix->compute_scalar();
            writer.emit("global_scalar", value);
        }

        // global vector
        if (fix->vector_flag) {
            int num = fix->size_vector;
            block   = std::to_string(num);
            for (int i = 0; i < num; ++i)
                block += fmt::format(" {}", fix->compute_vector(i));
            writer.emit_block("global_vector", block);
        }
    }

    // run_pos
    block.clear();
    auto x   = lmp->atom->x;