mirror of
https://git.gfz-potsdam.de/naaice/poet.git
synced 2025-12-16 04:48:23 +01:00
fix: write fields using R after chem simulation
This commit is contained in:
parent
e6819b59bc
commit
32d35190cb
@ -164,6 +164,7 @@ inline double RunMasterLoop(SimParams ¶ms, RInside &R, Grid &grid,
|
|||||||
chem.RunCells();
|
chem.RunCells();
|
||||||
chem_state->mem = chem.GetField();
|
chem_state->mem = chem.GetField();
|
||||||
|
|
||||||
|
grid.WriteFieldsToR(R);
|
||||||
grid.PreModuleFieldCopy(tick++);
|
grid.PreModuleFieldCopy(tick++);
|
||||||
|
|
||||||
R["req_dt"] = dt;
|
R["req_dt"] = dt;
|
||||||
|
|||||||
@ -39,7 +39,7 @@ namespace poet {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
constexpr const char *DIFFUSION_MODULE_NAME = "state_t";
|
constexpr const char *DIFFUSION_MODULE_NAME = "state_T";
|
||||||
|
|
||||||
class DiffusionModule {
|
class DiffusionModule {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
#define GRID_H
|
#define GRID_H
|
||||||
|
|
||||||
#include "poet/SimParams.hpp"
|
#include "poet/SimParams.hpp"
|
||||||
|
#include <RInside.h>
|
||||||
#include <Rcpp.h>
|
#include <Rcpp.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@ -97,6 +98,8 @@ public:
|
|||||||
std::string module_name = poet::GRID_MODULE_NAME) const
|
std::string module_name = poet::GRID_MODULE_NAME) const
|
||||||
-> std::vector<double>;
|
-> std::vector<double>;
|
||||||
|
|
||||||
|
void WriteFieldsToR(RInside &R);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<FlowInputOutputInfo> flow_vec;
|
std::vector<FlowInputOutputInfo> flow_vec;
|
||||||
|
|
||||||
|
|||||||
19
src/Grid.cpp
19
src/Grid.cpp
@ -19,7 +19,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "poet/SimParams.hpp"
|
#include "poet/SimParams.hpp"
|
||||||
|
#include <RInside.h>
|
||||||
#include <Rcpp.h>
|
#include <Rcpp.h>
|
||||||
|
#include <Rcpp/internal/wrap.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@ -253,3 +255,20 @@ auto poet::Grid::GetSpeciesByName(std::string name,
|
|||||||
return std::vector<double>(module_memory->mem.begin() + begin_vec,
|
return std::vector<double>(module_memory->mem.begin() + begin_vec,
|
||||||
module_memory->mem.begin() + end_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)"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user