aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2018-04-12 16:17:42 +0200
committerAnton Khirnov <anton@khirnov.net>2018-04-12 16:17:42 +0200
commit5cfa9f81db7e1326062f9a4e29b4e4cfd17662e1 (patch)
tree6f0f70a477afb52a09bd21758784586ab14ee246
Initial commit.
-rw-r--r--configuration.ccl0
-rw-r--r--interface.ccl3
-rw-r--r--param.ccl37
-rw-r--r--schedule.ccl6
-rw-r--r--src/make.code.defn5
-rw-r--r--src/revive.c82
6 files changed, 133 insertions, 0 deletions
diff --git a/configuration.ccl b/configuration.ccl
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/configuration.ccl
diff --git a/interface.ccl b/interface.ccl
new file mode 100644
index 0000000..dd03a85
--- /dev/null
+++ b/interface.ccl
@@ -0,0 +1,3 @@
+implements: ReviveData
+
+INHERITS: ADMBase grid CoordBase
diff --git a/param.ccl b/param.ccl
new file mode 100644
index 0000000..3c65ef4
--- /dev/null
+++ b/param.ccl
@@ -0,0 +1,37 @@
+SHARES: ADMBase
+
+EXTENDS KEYWORD initial_data
+{
+ "revivedata" :: "Load existing simulation output and interpolate it onto a new grid"
+}
+
+EXTENDS KEYWORD initial_lapse
+{
+ "revivedata" :: "Load existing simulation output and interpolate it onto a new grid"
+}
+
+EXTENDS KEYWORD initial_shift
+{
+ "revivedata" :: "Load existing simulation output and interpolate it onto a new grid"
+}
+
+RESTRICTED:
+STRING load_data_exe ""
+{
+ "" :: ""
+} ""
+
+STRING simdata_path ""
+{
+ "" :: ""
+} ""
+
+REAL load_time ""
+{
+ : :: ""
+} 0.0
+
+INT load_iteration ""
+{
+ : :: ""
+} -1
diff --git a/schedule.ccl b/schedule.ccl
new file mode 100644
index 0000000..1ccef5b
--- /dev/null
+++ b/schedule.ccl
@@ -0,0 +1,6 @@
+if (CCTK_Equals(initial_data, "revivedata")) {
+
+ SCHEDULE revive_data IN ADMBase_InitialData {
+ LANG: C
+ } "Load existing simulation data"
+}
diff --git a/src/make.code.defn b/src/make.code.defn
new file mode 100644
index 0000000..04c8acf
--- /dev/null
+++ b/src/make.code.defn
@@ -0,0 +1,5 @@
+# Source files in this directory
+SRCS = revive.c
+
+# Subdirectories containing source files
+SUBDIRS =
diff --git a/src/revive.c b/src/revive.c
new file mode 100644
index 0000000..75793ce
--- /dev/null
+++ b/src/revive.c
@@ -0,0 +1,82 @@
+#include <errno.h>
+#include <limits.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "cctk.h"
+#include "cctk_Arguments.h"
+#include "cctk_Parameters.h"
+
+#define ARRAY_ELEMS(x) (sizeof(x) / sizeof(*x))
+
+static const char *vars[] = {
+ "ADMBASE::gxx",
+ "ADMBASE::gyy",
+ "ADMBASE::gzz",
+ "ADMBASE::gxy",
+ "ADMBASE::gxz",
+ "ADMBASE::gyz",
+ "ADMBASE::kxx",
+ "ADMBASE::kyy",
+ "ADMBASE::kzz",
+ "ADMBASE::kxy",
+ "ADMBASE::kxz",
+ "ADMBASE::kyz",
+ "ADMBASE::alp",
+ "ADMBASE::betax",
+ "ADMBASE::betay",
+ "ADMBASE::betaz",
+};
+
+void revive_data(CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ double x0, z0, dx, dz;
+ int dummy;
+ size_t grid_size = cctk_lsh[2] * cctk_lsh[0];
+
+ x0 = x[CCTK_GFINDEX3D(cctkGH, 0, 0, 0)];
+ z0 = z[CCTK_GFINDEX3D(cctkGH, 0, 0, 0)];
+ dx = x[CCTK_GFINDEX3D(cctkGH, 1, 0, 0)] - x0;
+ dz = z[CCTK_GFINDEX3D(cctkGH, 0, 0, 1)] - z0;
+
+ for (int i = 0; i < ARRAY_ELEMS(vars); i++) {
+ double *dst = CCTK_VarDataPtr(cctkGH, 0, vars[i]);
+ char popen_cmd_buf[1024];
+ int ret;
+ FILE *child_stream;
+
+ snprintf(popen_cmd_buf, sizeof(popen_cmd_buf),
+ "%s %s %16.16g %d "
+ "%s %16.16g %16.16g %16.16g %16.16g %d %d",
+ load_data_exe, simdata_path, load_time, load_iteration,
+ vars[i], x0, z0, dx, dz, cctk_lsh[0], cctk_lsh[2]);
+ fprintf(stderr, "%s\n", popen_cmd_buf);
+
+ child_stream = popen(popen_cmd_buf, "r");
+ if (!child_stream) {
+ fprintf(stderr, "Error starting child process '%s': %s\n",
+ popen_cmd_buf, strerror(errno));
+ abort();
+ }
+
+ ret = fread(dst, sizeof(*dst), grid_size, child_stream);
+ if (ret < grid_size) {
+ fprintf(stderr, "Not enough items read for var %s: %d\n",
+ vars[i], ret);
+ abort();
+ }
+
+ /* check that there is nothing more to read */
+ ret = fread(&dummy, sizeof(dummy), 1, child_stream);
+ if (ret > 0 || !feof(child_stream)) {
+ fprintf(stderr, "Extra data in input for var %s\n", vars[i]);
+ abort();
+ }
+ pclose(child_stream);
+ }
+}