diff --git a/example/python/karman_vtk.xml b/example/python/karman_vtk.xml
new file mode 100644
index 000000000..142e37f10
--- /dev/null
+++ b/example/python/karman_vtk.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+import vtk;
+from vtk.util import numpy_support
+
+
+img = vtk.vtkImageData()
+tab = Solver.Geometry.X
+img.SetDimensions(tab.shape[0]+1, tab.shape[1]+1, tab.shape[2]+1)
+
+for n,tab in Solver.Quantities:
+ vtk_data = numpy_support.numpy_to_vtk(num_array=tab.reshape(-1,order='F'))
+ vtk_data.SetName(n)
+ if len(tab.shape) == 4:
+ vtk_data.SetNumberOfComponents(tab.shape[0])
+ img.GetCellData().AddArray(vtk_data)
+
+writer = vtk.vtkXMLImageDataWriter()
+writer.SetFileName("test.vti")
+writer.SetInputData(img)
+writer.Update()
+
+
+
diff --git a/example/python/pythonGeom.xml b/example/python/pythonGeom.xml
deleted file mode 100644
index cd3de5699..000000000
--- a/example/python/pythonGeom.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/example/python/runexternal.py b/example/python/runexternal.py
deleted file mode 100644
index 7d8bb61c3..000000000
--- a/example/python/runexternal.py
+++ /dev/null
@@ -1,10 +0,0 @@
-from mpi4py import MPI
-import numpy as np
-def test(*args):
- comm = MPI.COMM_WORLD
- rank = comm.Get_rank()
- print(rank)
- print(args[0])
- for i in range(3):
- print(np.asarray(args[i]).shape)
-
diff --git a/example/python/runexternal.xml b/example/python/runexternal.xml
deleted file mode 100644
index d6143d6c7..000000000
--- a/example/python/runexternal.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Handlers/cbRunR.cpp b/src/Handlers/cbRunR.cpp
index 2032e477d..f09b7277e 100644
--- a/src/Handlers/cbRunR.cpp
+++ b/src/Handlers/cbRunR.cpp
@@ -210,7 +210,7 @@ class rQuantities : public rWrapper {
Rcpp::NumericVector ret;
bool si = false;
std::string quant = name;
- size_t last_index = name.find_last_not_of(".");
+ size_t last_index = name.find_last_of(".");
if (last_index != std::string::npos) {
std::string result = name.substr(last_index + 1);
if (result == "si") {
@@ -514,6 +514,7 @@ class rSolver : public rWrapper {
ret.push_back("Globals");
ret.push_back("Actions");
ret.push_back("Geometry");
+ ret.push_back("Info");
return ret;
}
};
@@ -696,13 +697,21 @@ namespace RunPython {
}
void initializePy() {
+ if (py_initialised) return;
RInside& R = RunR::GetR();
has_reticulate = R.parseEval("require(reticulate, quietly=TRUE)");
if (!has_reticulate) throw std::string("Tried to call Python, but no reticulate installed");
py_initialised = true;
R.parseEval(
"py_names = function(obj) names(obj) \n"
- "py_element = function(obj, name) `[[`(obj,name) \n"
+ "py_element = function(obj, name) { \n"
+ " ret = `[[`(obj,name) \n"
+ " if (is.factor(ret)) { \n"
+ " as.integer(ret) - 1L \n"
+ " } else { \n"
+ " ret \n"
+ " } \n"
+ "} \n"
"py_element_assign = function(obj, name, value) `[[<-`(obj,name,value) \n"
"r_to_py.CLB = function(x, convert=FALSE) py$S3(reticulate:::py_capsule(x))\n"
);
@@ -714,6 +723,9 @@ namespace RunPython {
" return r.print(self.obj) \n"
" def __dir__(self): \n"
" return r.py_names(self.obj) \n"
+ " def __iter__(self): \n"
+ " for n in r.py_names(self.obj): \n"
+ " yield n, r.py_element(self.obj, n) \n"
" def __getattr__(self, index): \n"
" if index.startswith('_'): \n"
" return None \n"