Skip to content

Commit 93bf342

Browse files
committed
Propagation of master branch changes
2 parents 8912ba1 + f7f36f7 commit 93bf342

File tree

9 files changed

+173
-123
lines changed

9 files changed

+173
-123
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ p
2323
/*.txt
2424
.idea/*
2525
*.ipynb_checkpoint*
26+
test-*/
2627
tools/.format/*

example/python/karman_vtk.xml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0"?>
2+
<CLBConfig version="2.0" output="output/" permissive="true">
3+
<Geometry nx="1024" ny="100">
4+
<MRT>
5+
<Box/>
6+
</MRT>
7+
<WVelocity name="Inlet">
8+
<Inlet/>
9+
</WVelocity>
10+
<EPressure name="Outlet">
11+
<Outlet/>
12+
</EPressure>
13+
<Inlet nx="1" dx="5">
14+
<Box/>
15+
</Inlet>
16+
<Outlet nx="1" dx="-5">
17+
<Box/>
18+
</Outlet>
19+
<Wall mask="ALL">
20+
<Channel/>
21+
<Wedge dx="120" nx="20" dy="50" ny="20" direction="LowerRight"/>
22+
<Wedge dx="120" nx="20" dy="30" ny="20" direction="UpperRight"/>
23+
<Wedge dx="140" nx="20" dy="50" ny="20" direction="LowerLeft"/>
24+
<Wedge dx="140" nx="20" dy="30" ny="20" direction="UpperLeft"/>
25+
</Wall>
26+
</Geometry>
27+
<Model>
28+
<Param name="VelocityX" value="0.01"/>
29+
<Param name="Viscosity" value="0.02"/>
30+
<Param name="Smag" value="0.16"/>
31+
<Param name="PressDiffInObj" value="1"/>
32+
<Param name="EOSScale" value="0.05"/>
33+
<Param name="Tension" value="0.01"/>
34+
<Param name="Coriolis" value="0.001"/>
35+
<Param name="SolidAlfa" value="0.166"/>
36+
<Param name="FluidAlfa" value="0.01"/>
37+
<Param name="InitTemperature" value="0"/>
38+
<Param name="InletTemperature" value="1"/>
39+
</Model>
40+
<RunPython>
41+
import vtk;
42+
from vtk.util import numpy_support
43+
</RunPython>
44+
<RunPython Iterations="1000">
45+
img = vtk.vtkImageData()
46+
tab = Solver.Geometry.X
47+
img.SetDimensions(tab.shape[0]+1, tab.shape[1]+1, tab.shape[2]+1)
48+
49+
for n,tab in Solver.Quantities:
50+
vtk_data = numpy_support.numpy_to_vtk(num_array=tab.reshape(-1,order='F'))
51+
vtk_data.SetName(n)
52+
if len(tab.shape) == 4:
53+
vtk_data.SetNumberOfComponents(tab.shape[0])
54+
img.GetCellData().AddArray(vtk_data)
55+
56+
writer = vtk.vtkXMLImageDataWriter()
57+
writer.SetFileName("test.vti")
58+
writer.SetInputData(img)
59+
writer.Update()
60+
</RunPython>
61+
<Solve Iterations="10000"/>
62+
</CLBConfig>

example/python/pythonGeom.xml

-53
This file was deleted.

example/python/runexternal.py

-10
This file was deleted.

example/python/runexternal.xml

-34
This file was deleted.

src/Handlers/cbRunR.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class rQuantities : public rWrapper {
207207
SEXP Dollar(std::string name) {
208208
bool si = false;
209209
std::string quant = name;
210-
size_t last_index = name.find_last_not_of(".");
210+
size_t last_index = name.find_last_of(".");
211211
if (last_index != std::string::npos) {
212212
std::string result = name.substr(last_index + 1);
213213
if (result == "si") {
@@ -460,6 +460,7 @@ class rSolver : public rWrapper {
460460
ret.push_back("Globals");
461461
ret.push_back("Actions");
462462
ret.push_back("Geometry");
463+
ret.push_back("Info");
463464
return ret;
464465
}
465466
};
@@ -642,13 +643,21 @@ namespace RunPython {
642643
}
643644

644645
void initializePy() {
646+
if (py_initialised) return;
645647
RInside& R = RunR::GetR();
646648
has_reticulate = R.parseEval("require(reticulate, quietly=TRUE)");
647649
if (!has_reticulate) throw std::string("Tried to call Python, but no reticulate installed");
648650
py_initialised = true;
649651
R.parseEval(
650652
"py_names = function(obj) names(obj) \n"
651-
"py_element = function(obj, name) `[[`(obj,name) \n"
653+
"py_element = function(obj, name) { \n"
654+
" ret = `[[`(obj,name) \n"
655+
" if (is.factor(ret)) { \n"
656+
" as.integer(ret) - 1L \n"
657+
" } else { \n"
658+
" ret \n"
659+
" } \n"
660+
"} \n"
652661
"py_element_assign = function(obj, name, value) `[[<-`(obj,name,value) \n"
653662
"r_to_py.CLB = function(x, convert=FALSE) py$S3(reticulate:::py_capsule(x))\n"
654663
);
@@ -660,6 +669,9 @@ namespace RunPython {
660669
" return r.print(self.obj) \n"
661670
" def __dir__(self): \n"
662671
" return r.py_names(self.obj) \n"
672+
" def __iter__(self): \n"
673+
" for n in r.py_names(self.obj): \n"
674+
" yield n, r.py_element(self.obj, n) \n"
663675
" def __getattr__(self, index): \n"
664676
" if index.startswith('_'): \n"
665677
" return None \n"

tools/csvconcatenate

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env Rscript
2+
3+
library(optparse)
4+
options <- list(
5+
make_option(c("-o","--output"), "store", default="", help="Output file", type="character"),
6+
make_option(c("-c","--continue"), "store", default="Iteration,Time_si,Walltime", help="regexp for columns to continue by addition (default: Iteration,Time_si,Walltime)", type="character"),
7+
make_option(c("-d","--discard"), "store", default="", help="regexp for columns to discard (separate by '|')", type="character")
8+
)
9+
10+
opt <- parse_args(OptionParser(usage="Usage: csvconcatenate -o file file1 file2 file3", options), positional_arguments=TRUE)
11+
12+
read = function(f) {
13+
if (! file.exists(f)) stop(paste("File not found:",f))
14+
tab = try(read.csv(f),silent=TRUE)
15+
if (inherits(tab, "try-error")) stop(paste(f,"is not a valid CSV file"))
16+
tab
17+
}
18+
19+
args = opt$args
20+
opt = opt$options
21+
22+
opt$discard = strsplit(opt$discard,",")[[1]]
23+
if (! is.character(opt$discard)) stop("Discard list is not text")
24+
25+
opt$continue = strsplit(opt$continue,",")[[1]]
26+
if (! is.character(opt$continue)) stop("Continue list is not text")
27+
28+
grepl_any = function(pattern, x, ...) {
29+
sel = rep(FALSE,length(x))
30+
for (p in pattern) sel = sel | grepl(p, x, ...)
31+
sel
32+
}
33+
34+
if (length(args) < 1) stop("No csv files provided")
35+
tab = NULL
36+
for (fn in args) {
37+
tab1 = read(fn)
38+
sel = grepl_any(opt$discard, names(tab1))
39+
if (any(sel)) tab1=tab1[,!sel]
40+
if (is.null(tab)) {
41+
tab = tab1
42+
} else {
43+
if ( ! identical(sort(names(tab)), sort(names(tab1))) ) {
44+
cat("names (header) not identical:\n")
45+
print(sort(names(tab)))
46+
print(sort(names(tab1)))
47+
q(status=-2)
48+
}
49+
sel = grepl_any(opt$continue, names(tab1))
50+
if (any(sel)) {
51+
for (cn in names(tab1)[sel]) {
52+
if (! cn %in% names(tab)) stop(cn,"not in previous csv files")
53+
tab1[[cn]] = tab1[[cn]] + max(tab[[cn]])
54+
}
55+
}
56+
tab = rbind(tab,tab1)
57+
}
58+
}
59+
60+
if (opt$output != "") {
61+
write.csv(tab, opt$output, row.names=FALSE)
62+
} else {
63+
write.csv(tab, row.names=FALSE)
64+
}
65+
66+
q(status=0);
67+

tools/tests.sh

+28-23
Original file line numberDiff line numberDiff line change
@@ -172,31 +172,35 @@ export PYTHONPATH="$PYTHONPATH:$PWD/tools/python"
172172
function runline {
173173
CMD=$1
174174
shift
175+
case $CMD in
176+
run) try "running solver" "$@"; return $?;;
177+
fail) try "running solver (should fail)" '!' "$@"; return $? ;;
178+
csvconcatenate) try "concatenating csv files" $TCLB/tools/csvconcatenate "$@"; return $? ;;
179+
esac
175180
R=$1
176-
G=$TEST_DIR/$R
181+
shift
177182
case $CMD in
178-
need)
179-
comment_wait "copy $@"
180-
for i in "$@"
181-
do
182-
SRC=$TEST_DIR/$i
183-
if test -f "$SRC"
184-
then
185-
cp $SRC $i
186-
else
187-
comment_fail "copy $@"
188-
echo " $i not found"
189-
return -1;
190-
fi
191-
done
192-
comment_ok "copy $@"
193-
;;
194-
run) try "running solver" "$@" ;;
195-
fail) try "running solver" '!' "$@" ;;
196-
csvdiff) try "checking $R (csvdiff)" $TCLB/tools/csvdiff -a "$R" -b "$G" -x "${2:-1e-10}" -d ${3:-$CSV_DISCARD} ;;
197-
diff) try "checking $R" diff "$R" "$G" ;;
198-
sha1) try "checking $R (sha1)" sha1sum -c "$G.sha1" ;;
199-
pvtidiff) try "checking $R (pvtidiff)" $TCLB/CLB/$MODEL/compare "$R" "$G" "${2:-8}" ${3:-} ${4:-} ${5:-} ;; # ${2:-8} is { if $2 == "" then "8" else $2 }
183+
exists) try "checking $R (exists)" test -f "$R"; return $? ;;
184+
sha1) G="$R.sha1" ;;
185+
*) G="$R" ;;
186+
esac
187+
if test -f "$TEST_DIR/$1"
188+
then
189+
G="$1"
190+
shift
191+
fi
192+
G="$TEST_DIR/$G"
193+
if ! test -f "$G"
194+
then
195+
comment_fail "Requested file not found: $G"
196+
return -1
197+
fi
198+
case $CMD in
199+
need) try "copy needed file" cp "$G" "$R"; return $? ;;
200+
csvdiff) try "checking $R (csvdiff)" $TCLB/tools/csvdiff -a "$R" -b "$G" -x "${1:-1e-10}" -d ${2:-$CSV_DISCARD}; return $? ;;
201+
diff) try "checking $R" diff "$R" "$G"; return $? ;;
202+
sha1) try "checking $R (sha1)" sha1sum -c "$G.sha1"; return $? ;;
203+
pvtidiff) try "checking $R (pvtidiff)" $TCLB/CLB/$MODEL/compare "$R" "$G" "${1:-8}" ${2:-} ${3:-} ${4:-}; return $? ;; # ${2:-8} is { if $2 == "" then "8" else $2 }
200204
*) echo "unknown: $CMD"; return -1;;
201205
esac
202206
return 0;
@@ -214,6 +218,7 @@ function testModel {
214218
TCLB=".."
215219
SOLVER="$TCLB/CLB/$MODEL/main"
216220
MODELBIN="$TCLB/CLB/$MODEL"
221+
TOOLS="$TCLB/tools"
217222
TEST_DIR="../tests/external/$MODEL"
218223
CAN_FAIL=false
219224
CSV_DISCARD=Walltime

0 commit comments

Comments
 (0)