From b6a6ccfca8fc54ec4c7b4bd2122bb6d128f92c67 Mon Sep 17 00:00:00 2001
From: Cristian C Lalescu <Cristian.Lalescu@ds.mpg.de>
Date: Thu, 4 Jul 2019 14:31:49 +0200
Subject: [PATCH] adds method to copy PP parameters into vorticity_equation
 object

also corrects `joint_acc_vel_stats`, in the sense that forcing
parameters should be read beforehand if the acceleration statistics are
to make sense.
---
 cpp/full_code/joint_acc_vel_stats.cpp |  1 +
 cpp/full_code/postprocess.cpp         | 24 ++++++++++++++++++++++++
 cpp/full_code/postprocess.hpp         | 16 +++++++++++++++-
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/cpp/full_code/joint_acc_vel_stats.cpp b/cpp/full_code/joint_acc_vel_stats.cpp
index 23804755..6c670819 100644
--- a/cpp/full_code/joint_acc_vel_stats.cpp
+++ b/cpp/full_code/joint_acc_vel_stats.cpp
@@ -45,6 +45,7 @@ int joint_acc_vel_stats<rnumber>::initialize(void)
             this->dky,
             this->dkz,
             this->vorticity->fftw_plan_rigor);
+    this->template copy_parameters_into<rnumber, FFTW>(this->ve);
     hid_t parameter_file = H5Fopen(
             (this->simname + std::string(".h5")).c_str(),
             H5F_ACC_RDONLY,
diff --git a/cpp/full_code/postprocess.cpp b/cpp/full_code/postprocess.cpp
index e8c7fb27..a6bbe18b 100644
--- a/cpp/full_code/postprocess.cpp
+++ b/cpp/full_code/postprocess.cpp
@@ -70,9 +70,33 @@ int postprocess::read_parameters()
     this->fk0 = hdf5_tools::read_value<double>(parameter_file, "parameters/fk0");
     this->fk1 = hdf5_tools::read_value<double>(parameter_file, "parameters/fk1");
     this->energy = hdf5_tools::read_value<double>(parameter_file, "parameters/energy");
+    this->injection_rate = hdf5_tools::read_value<double>(parameter_file, "parameters/injection_rate");
     std::string tmp = hdf5_tools::read_string(parameter_file, "parameters/forcing_type");
     snprintf(this->forcing_type, 511, "%s", tmp.c_str());
     H5Fclose(parameter_file);
     return EXIT_SUCCESS;
 }
 
+template <typename rnumber,
+          field_backend be>
+int postprocess::copy_parameters_into(
+        vorticity_equation<rnumber, be> *dst)
+{
+    dst->nu = this->nu;
+    dst->fmode = this->fmode;
+    dst->famplitude = this->famplitude;
+    dst->fk0 = this->fk0;
+    dst->fk1 = this->fk1;
+    dst->injection_rate = this->injection_rate;
+    dst->energy = this->energy;
+    dst->friction_coefficient = this->friction_coefficient;
+    strncpy(this->forcing_type, dst->forcing_type, 128);
+    return EXIT_SUCCESS;
+}
+
+template int postprocess::copy_parameters_into<float, FFTW>(
+        vorticity_equation<float, FFTW> *dst);
+
+template int postprocess::copy_parameters_into<double, FFTW>(
+        vorticity_equation<double, FFTW> *dst);
+
diff --git a/cpp/full_code/postprocess.hpp b/cpp/full_code/postprocess.hpp
index 65e6eadd..25e023b8 100644
--- a/cpp/full_code/postprocess.hpp
+++ b/cpp/full_code/postprocess.hpp
@@ -32,6 +32,7 @@
 #include <sys/stat.h>
 #include <vector>
 #include "base.hpp"
+#include "vorticity_equation.hpp"
 #include "full_code/code_base.hpp"
 
 class postprocess: public code_base
@@ -40,13 +41,18 @@ class postprocess: public code_base
         std::vector<int> iteration_list;
         hid_t stat_file;
 
-        /* parameters that are read in read_parameters */
+        /* parameters that are read in read_parameters.
+         * This includes physical parameters, such that children of `postprocess`
+         * do not need to read them (but they do need to be copied with
+         * the `copy_parameters_into` method or similar.
+         * */
         double dt;
         double famplitude;
         double friction_coefficient;
         double fk0;
         double fk1;
         double energy;
+        double injection_rate;
         int fmode;
         char forcing_type[512];
         double nu;
@@ -65,6 +71,14 @@ class postprocess: public code_base
 
         int main_loop(void);
         virtual int read_parameters(void);
+
+        /* Method to copy physical simulation parameters into arbitrary
+         * `vorticity_equation` object (defined by children classes).
+         * */
+        template <typename rnumber,
+                  field_backend be>
+        int copy_parameters_into(
+                vorticity_equation<rnumber, be> *dst);
 };
 
 #endif//POSTPROCESS_HPP
-- 
GitLab