mirror of
https://git.gfz-potsdam.de/naaice/poet.git
synced 2025-12-16 12:54:50 +01:00
Update RAW Keywords to always refer to ID 1
This commit is contained in:
parent
9b144f8ec5
commit
d012936c6d
@ -3,12 +3,12 @@
|
|||||||
#include <IPhreeqcPOET.hpp>
|
#include <IPhreeqcPOET.hpp>
|
||||||
#include <Rcpp/Function.h>
|
#include <Rcpp/Function.h>
|
||||||
#include <Rcpp/vector/instantiation.h>
|
#include <Rcpp/vector/instantiation.h>
|
||||||
|
#include <map>
|
||||||
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace poet {
|
namespace poet {
|
||||||
static Rcpp::NumericMatrix
|
static Rcpp::NumericMatrix pqcScriptToGrid(IPhreeqcPOET &phreeqc, RInside &R) {
|
||||||
pqcScriptToGrid(RInside &R, const std::string &script, const std::string &db,
|
|
||||||
std::map<int, std::string> &raw_dumps) {
|
|
||||||
IPhreeqcPOET phreeqc(db, script);
|
|
||||||
|
|
||||||
const auto solution_ids = phreeqc.getSolutionIds();
|
const auto solution_ids = phreeqc.getSolutionIds();
|
||||||
auto col_names = phreeqc.getInitNames();
|
auto col_names = phreeqc.getInitNames();
|
||||||
@ -32,24 +32,29 @@ pqcScriptToGrid(RInside &R, const std::string &script, const std::string &db,
|
|||||||
|
|
||||||
Rcpp::colnames(mat) = Rcpp::wrap(col_names);
|
Rcpp::colnames(mat) = Rcpp::wrap(col_names);
|
||||||
|
|
||||||
raw_dumps = phreeqc.raw_dumps();
|
|
||||||
|
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Rcpp::List matToGrid(RInside &R, const Rcpp::NumericMatrix &mat,
|
static inline Rcpp::List matToGrid(RInside &R, const Rcpp::NumericMatrix &mat,
|
||||||
const Rcpp::NumericMatrix &grid) {
|
const Rcpp::NumericMatrix &grid) {
|
||||||
// Rcpp::List res;
|
|
||||||
// res["init_mat"] = mat;
|
|
||||||
// res["grid_mat"] = grid;
|
|
||||||
|
|
||||||
Rcpp::Function pqc_to_grid("pqc_to_grid");
|
Rcpp::Function pqc_to_grid("pqc_to_grid");
|
||||||
|
|
||||||
// R.parseEvalQ("res_df <- pqc_to_grid(init_mat, grid_mat)");
|
|
||||||
|
|
||||||
return pqc_to_grid(mat, grid);
|
return pqc_to_grid(mat, grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline std::map<int, std::string>
|
||||||
|
replaceRawSolutionsIDs(std::map<int, std::string> raws) {
|
||||||
|
for (auto &raw : raws) {
|
||||||
|
std::string &s = raw.second;
|
||||||
|
// find at beginning of line '*_RAW' followed by a number and change this
|
||||||
|
// number to 1
|
||||||
|
std::regex re(R"((RAW\s+)(\d+))");
|
||||||
|
s = std::regex_replace(s, re, "RAW 1");
|
||||||
|
}
|
||||||
|
|
||||||
|
return raws;
|
||||||
|
}
|
||||||
|
|
||||||
void InitialList::initGrid(const Rcpp::List &grid_input) {
|
void InitialList::initGrid(const Rcpp::List &grid_input) {
|
||||||
// parse input values
|
// parse input values
|
||||||
const std::string script = Rcpp::as<std::string>(grid_input["pqc_in"]);
|
const std::string script = Rcpp::as<std::string>(grid_input["pqc_in"]);
|
||||||
@ -95,10 +100,13 @@ void InitialList::initGrid(const Rcpp::List &grid_input) {
|
|||||||
throw std::runtime_error("Grid size must be positive.");
|
throw std::runtime_error("Grid size must be positive.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this->phreeqc_mat =
|
IPhreeqcPOET phreeqc(database_rp, script_rp);
|
||||||
pqcScriptToGrid(R, script_rp, database_rp, this->pqc_raw_dumps);
|
|
||||||
|
this->phreeqc_mat = pqcScriptToGrid(phreeqc, R);
|
||||||
this->initial_grid = matToGrid(R, this->phreeqc_mat, grid_def);
|
this->initial_grid = matToGrid(R, this->phreeqc_mat, grid_def);
|
||||||
|
|
||||||
|
this->pqc_raw_dumps = replaceRawSolutionsIDs(phreeqc.raw_dumps());
|
||||||
|
|
||||||
R["pqc_mat"] = this->phreeqc_mat;
|
R["pqc_mat"] = this->phreeqc_mat;
|
||||||
R["grid_def"] = initial_grid;
|
R["grid_def"] = initial_grid;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user