File: compressed_dump_test.h

package info (click to toggle)
lammps 20250204%2Bdfsg.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 474,368 kB
  • sloc: cpp: 1,060,070; python: 27,785; ansic: 8,956; f90: 7,254; sh: 6,044; perl: 4,171; fortran: 2,442; xml: 1,714; makefile: 1,352; objc: 238; lisp: 188; yacc: 58; csh: 16; awk: 14; tcl: 6; javascript: 2
file content (112 lines) | stat: -rw-r--r-- 4,200 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* ----------------------------------------------------------------------
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
   https://www.lammps.org/ Sandia National Laboratories
   LAMMPS Development team: developers@lammps.org

   Copyright (2003) Sandia Corporation.  Under the terms of Contract
   DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
   certain rights in this software.  This software is distributed under
   the GNU General Public License.

   See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifndef TESTCASE_COMPRESSED_DUMP__H
#define TESTCASE_COMPRESSED_DUMP__H

#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include <string>

extern const char *COMPRESS_SUFFIX;
extern const char *COMPRESS_EXTENSION;
extern char *COMPRESS_EXECUTABLE;

class CompressedDumpTest : public MeltTest {
protected:
    std::string dump_style;
    std::string compression_style;

public:
    CompressedDumpTest(const std::string &dump_style) : MeltTest(), dump_style(dump_style)
    {
        compression_style = fmt::format("{}/{}", dump_style, COMPRESS_SUFFIX);
    }

    std::string text_dump_filename(std::string ident)
    {
        return fmt::format("dump_{}_text_{}", COMPRESS_SUFFIX, ident);
    }

    std::string compressed_dump_filename(std::string ident)
    {
        return fmt::format("dump_{}_compressed_{}.{}", COMPRESS_SUFFIX, ident, COMPRESS_EXTENSION);
    }

    std::string converted_dump_filename(std::string ident)
    {
        return fmt::format("dump_{}_compressed_{}", COMPRESS_SUFFIX, ident);
    }

    void enable_triclinic()
    {
        BEGIN_HIDE_OUTPUT();
        command("change_box all triclinic");
        END_HIDE_OUTPUT();
    }

    void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps)
    {
        BEGIN_HIDE_OUTPUT();
        command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));

        if (!dump_modify_options.empty()) {
            command(fmt::format("dump_modify id {}", dump_modify_options));
        }

        command(fmt::format("run {}", ntimesteps));
        END_HIDE_OUTPUT();
    }

    void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
                                           std::string dump_options,
                                           std::string dump_modify_options, int ntimesteps)
    {
        generate_text_and_compressed_dump(text_file, compressed_file, dump_options, dump_options,
                                          dump_modify_options, dump_modify_options, ntimesteps);
    }

    void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
                                           std::string text_options, std::string compressed_options,
                                           std::string text_modify_options,
                                           std::string compressed_modify_options, int ntimesteps)
    {
        BEGIN_HIDE_OUTPUT();
        command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, text_options));
        command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file,
                            compressed_options));

        if (!text_modify_options.empty()) {
            command(fmt::format("dump_modify id0 {}", text_modify_options));
        }

        if (!compressed_modify_options.empty()) {
            command(fmt::format("dump_modify id1 {}", compressed_modify_options));
        }

        command(fmt::format("run {}", ntimesteps));
        END_HIDE_OUTPUT();
    }

    std::string convert_compressed_to_text(std::string compressed_file)
    {
        BEGIN_HIDE_OUTPUT();
        std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
        std::string cmdline        = fmt::format("\"{}\" -d -c {} > {}", COMPRESS_EXECUTABLE,
                                                 compressed_file, converted_file);
        system(cmdline.c_str());
        END_HIDE_OUTPUT();
        return converted_file;
    }
};

#endif