From 32d35190cbd7a966d98d41bbb9bea0bd69878dd7 Mon Sep 17 00:00:00 2001 From: Max Luebke Date: Tue, 14 Feb 2023 16:37:56 +0100 Subject: [PATCH] fix: write fields using R after chem simulation --- app/poet.cpp | 1 + include/poet/DiffusionModule.hpp | 2 +- include/poet/Grid.hpp | 3 +++ src/Grid.cpp | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/poet.cpp b/app/poet.cpp index 69999a82d..097c9ff33 100644 --- a/app/poet.cpp +++ b/app/poet.cpp @@ -164,6 +164,7 @@ inline double RunMasterLoop(SimParams ¶ms, RInside &R, Grid &grid, chem.RunCells(); chem_state->mem = chem.GetField(); + grid.WriteFieldsToR(R); grid.PreModuleFieldCopy(tick++); R["req_dt"] = dt; diff --git a/include/poet/DiffusionModule.hpp b/include/poet/DiffusionModule.hpp index ce486b9e2..52d0199d0 100644 --- a/include/poet/DiffusionModule.hpp +++ b/include/poet/DiffusionModule.hpp @@ -39,7 +39,7 @@ namespace poet { * */ -constexpr const char *DIFFUSION_MODULE_NAME = "state_t"; +constexpr const char *DIFFUSION_MODULE_NAME = "state_T"; class DiffusionModule { public: diff --git a/include/poet/Grid.hpp b/include/poet/Grid.hpp index 852220919..2ea2068b9 100644 --- a/include/poet/Grid.hpp +++ b/include/poet/Grid.hpp @@ -22,6 +22,7 @@ #define GRID_H #include "poet/SimParams.hpp" +#include #include #include #include @@ -97,6 +98,8 @@ public: std::string module_name = poet::GRID_MODULE_NAME) const -> std::vector; + void WriteFieldsToR(RInside &R); + private: std::vector flow_vec; diff --git a/src/Grid.cpp b/src/Grid.cpp index 2fe125d32..ba70e16ee 100644 --- a/src/Grid.cpp +++ b/src/Grid.cpp @@ -19,7 +19,9 @@ */ #include "poet/SimParams.hpp" +#include #include +#include #include #include #include @@ -253,3 +255,20 @@ auto poet::Grid::GetSpeciesByName(std::string name, return std::vector(module_memory->mem.begin() + begin_vec, module_memory->mem.begin() + end_vec); } + +// HACK: Helper function +void poet::Grid::WriteFieldsToR(RInside &R) { + + for (auto const &elem : this->state_register) { + std::string field_name = elem.first; + StateMemory *field = elem.second; + + const uint32_t n_cells_per_prop = field->mem.size() / field->props.size(); + + R["TMP"] = Rcpp::wrap(field->mem); + R["TMP_PROPS"] = Rcpp::wrap(field->props); + R.parseEval(std::string( + "mysetup$" + field_name + " <- setNames(data.frame(matrix(TMP, nrow=" + + std::to_string(n_cells_per_prop) + ")), TMP_PROPS)")); + } +}