OGS
ChemistryLib::PhreeqcIOData::Dump Struct Reference

Detailed Description

Definition at line 20 of file Dump.h.

#include <Dump.h>

Public Member Functions

 Dump (std::string const &project_file_name)
void print (std::ostream &os, std::size_t const num_chemical_systems) const
void readDumpFile (std::istream &in, std::size_t const num_chemical_systems)
void readDumpFromString (std::string_view dump_content, std::size_t const num_chemical_systems)

Public Attributes

std::string const dump_file
std::vector< std::string > aqueous_solutions_prev
std::string dump_content_stream

Constructor & Destructor Documentation

◆ Dump()

ChemistryLib::PhreeqcIOData::Dump::Dump ( std::string const & project_file_name)
inlineexplicit

Definition at line 22 of file Dump.h.

23 : dump_file(specifyFileName(project_file_name, ".dmp"))
24 {
25 try
26 {
27 if (std::filesystem::remove(dump_file))
28 {
29 INFO("Deleted the redundant phreeqc dump file {:s}\n",
30 dump_file);
31 }
32 }
33 catch (std::filesystem::filesystem_error const& e)
34 {
35 ERR("filesystem error: {:s}\n", e.what());
36 }
37 }
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::string specifyFileName(std::string const &project_file_name, std::string const &file_extension)
std::string const dump_file
Definition Dump.h:46

References dump_file, ERR(), INFO(), and ChemistryLib::PhreeqcIOData::specifyFileName().

Member Function Documentation

◆ print()

void ChemistryLib::PhreeqcIOData::Dump::print ( std::ostream & os,
std::size_t const num_chemical_systems ) const

Definition at line 12 of file Dump.cpp.

13{
14 os << "DUMP"
15 << "\n";
16 os << "-file " << dump_file << "\n";
17 os << "-append false"
18 << "\n";
19 os << "-solution 1-" << num_chemical_systems << "\n";
20 os << "END"
21 << "\n";
22}

References dump_file.

◆ readDumpFile()

void ChemistryLib::PhreeqcIOData::Dump::readDumpFile ( std::istream & in,
std::size_t const num_chemical_systems )

Definition at line 24 of file Dump.cpp.

26{
28 aqueous_solutions_prev.reserve(num_chemical_systems);
29
30 std::string line;
31 std::string aqueous_solution_prev;
32 std::size_t chemical_system_id = 0;
33 while (std::getline(in, line))
34 {
35 if (line.find("USE reaction_pressure none") != std::string::npos)
36 {
37 break;
38 }
39
40 if (line.find("SOLUTION_RAW") != std::string::npos)
41 {
42 aqueous_solution_prev =
43 "SOLUTION_RAW " +
44 std::to_string(num_chemical_systems + chemical_system_id + 1) +
45 "\n";
46 continue;
47 }
48
49 aqueous_solution_prev += line + "\n";
50
51 if (line.find("-gammas") != std::string::npos)
52 {
53 aqueous_solutions_prev.push_back(aqueous_solution_prev);
54 aqueous_solution_prev.clear();
55 ++chemical_system_id;
56 }
57 }
58}
std::vector< std::string > aqueous_solutions_prev
Definition Dump.h:47

References aqueous_solutions_prev.

◆ readDumpFromString()

void ChemistryLib::PhreeqcIOData::Dump::readDumpFromString ( std::string_view dump_content,
std::size_t const num_chemical_systems )

Definition at line 60 of file Dump.cpp.

62{
64 aqueous_solutions_prev.reserve(num_chemical_systems);
65
66 std::string_view line;
67 std::string aqueous_solution_prev;
68 std::size_t chemical_system_id = 0;
69 std::size_t pos = 0;
70
71 while (pos < dump_content.size())
72 {
73 // Extract next line
74 if (const auto newline_pos = dump_content.find('\n', pos);
75 newline_pos == std::string_view::npos)
76 {
77 line = dump_content.substr(pos);
78 pos = dump_content.size();
79 }
80 else
81 {
82 line = dump_content.substr(pos, newline_pos - pos);
83 pos = newline_pos + 1;
84 }
85
86 // Remove trailing \r if present (Windows line endings)
87 if (!line.empty() && line.back() == '\r')
88 {
89 line.remove_suffix(1);
90 }
91
92 if (line.find("USE reaction_pressure none") != std::string::npos)
93 {
94 break;
95 }
96
97 if (line.find("SOLUTION_RAW") != std::string::npos)
98 {
99 aqueous_solution_prev =
100 "SOLUTION_RAW " +
101 std::to_string(num_chemical_systems + chemical_system_id + 1) +
102 "\n";
103 continue;
104 }
105
106 aqueous_solution_prev += line;
107 aqueous_solution_prev += "\n";
108
109 if (line.find("-gammas") != std::string::npos)
110 {
111 aqueous_solutions_prev.push_back(aqueous_solution_prev);
112 aqueous_solution_prev.clear();
113 ++chemical_system_id;
114 }
115 }
116}

References aqueous_solutions_prev.

Member Data Documentation

◆ aqueous_solutions_prev

std::vector<std::string> ChemistryLib::PhreeqcIOData::Dump::aqueous_solutions_prev

Definition at line 47 of file Dump.h.

Referenced by readDumpFile(), and readDumpFromString().

◆ dump_content_stream

std::string ChemistryLib::PhreeqcIOData::Dump::dump_content_stream

Definition at line 48 of file Dump.h.

◆ dump_file

std::string const ChemistryLib::PhreeqcIOData::Dump::dump_file

Definition at line 46 of file Dump.h.

Referenced by Dump(), and print().


The documentation for this struct was generated from the following files: