Refactor chemistry module and RHookFunction

This commit is contained in:
Max Luebke 2024-04-02 20:23:42 +00:00
parent c7b9ab0b53
commit ca1f8a19bb
4 changed files with 26 additions and 15 deletions

View File

@ -58,6 +58,13 @@ public:
}
}
RHookFunction &operator=(const RHookFunction &rhs) {
this->func = rhs.func;
return *this;
}
RHookFunction(const RHookFunction &rhs) { this->func = rhs.func; }
bool isValid() const { return this->func.has_value(); }
SEXP asSEXP() const { return Rcpp::as<SEXP>(this->func.value()); }

View File

@ -155,11 +155,9 @@ inverseDistanceWeighting(const std::vector<std::int32_t> &to_calc,
}
poet::ChemistryModule::ChemistryModule(
uint32_t wp_size_, const InitialList::ChemistryInit &chem_params,
uint32_t wp_size_, const InitialList::ChemistryInit chem_params,
MPI_Comm communicator)
: params(chem_params), wp_size(wp_size_), group_comm(communicator),
dht_species(chem_params.dht_species),
interp_species(chem_params.interp_species) {
: params(chem_params), wp_size(wp_size_), group_comm(communicator) {
MPI_Comm_rank(communicator, &comm_rank);
MPI_Comm_size(communicator, &comm_size);

View File

@ -43,7 +43,7 @@ public:
* \param communicator MPI communicator to distribute work in.
*/
ChemistryModule(uint32_t wp_size,
const InitialList::ChemistryInit &chem_params,
const InitialList::ChemistryInit chem_params,
MPI_Comm communicator);
/**
@ -97,12 +97,13 @@ public:
this->interp_enabled = setup.interp_enabled;
if (this->dht_enabled || this->interp_enabled) {
this->initializeDHT(setup.dht_size_mb, this->dht_species);
this->initializeDHT(setup.dht_size_mb, this->params.dht_species);
}
if (this->interp_enabled) {
this->initializeInterp(setup.interp_bucket_size, setup.interp_size_mb,
setup.interp_min_entries, this->interp_species);
setup.interp_min_entries,
this->params.interp_species);
}
}
@ -376,12 +377,9 @@ protected:
uint32_t prop_count = 0;
std::vector<std::string> prop_names;
NamedVector<std::uint32_t> dht_species;
NamedVector<std::uint32_t> interp_species;
Field chem_field;
const InitialList::ChemistryInit &params;
const InitialList::ChemistryInit params;
std::map<int, std::unique_ptr<IPhreeqcPOET>> phreeqc_instances;
};

View File

@ -42,10 +42,18 @@ InitialList::ChemistryInit InitialList::getChemistryInit() const {
chem_init.interp_species = interp_species;
if (this->chem_hooks.size() > 0) {
chem_init.hooks.dht_fill = this->chem_hooks["dht_fill"];
chem_init.hooks.dht_fuzz = this->chem_hooks["dht_fuzz"];
chem_init.hooks.interp_pre = this->chem_hooks["interp_pre"];
chem_init.hooks.interp_post = this->chem_hooks["interp_post"];
if (this->chem_hooks.containsElementNamed("dht_fill")) {
chem_init.hooks.dht_fill = this->chem_hooks["dht_fill"];
}
if (this->chem_hooks.containsElementNamed("dht_fuzz")) {
chem_init.hooks.dht_fuzz = this->chem_hooks["dht_fuzz"];
}
if (this->chem_hooks.containsElementNamed("interp_pre")) {
chem_init.hooks.interp_pre = this->chem_hooks["interp_pre"];
}
if (this->chem_hooks.containsElementNamed("interp_post")) {
chem_init.hooks.interp_post = this->chem_hooks["interp_post"];
}
}
return chem_init;