Skip to content
Snippets Groups Projects
Commit 07c42e54 authored by Kyle Klenk's avatar Kyle Klenk
Browse files

added structure for variables and can pass arrays to fortran

parent 6fb12d50
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "caf/all.hpp" #include "caf/all.hpp"
#include "fortran_data_types.hpp" #include "fortran_data_types.hpp"
#include "timing_info.hpp" #include "timing_info.hpp"
#include "global.hpp"
#include <vector> #include <vector>
#include <array> #include <array>
#include <chrono> #include <chrono>
...@@ -19,11 +20,18 @@ struct gru_state { ...@@ -19,11 +20,18 @@ struct gru_state {
int ref_gru; // The actual ID of the GRU we are int ref_gru; // The actual ID of the GRU we are
int num_hrus; int num_hrus;
int num_bpar_vars; // number of variables in the fortran structure for bpar_struct
int num_bvar_vars; // number of variables in the fortran structure for bvar_struct
int n_time_delay = 2000; // number of timesteps in the time delay historgram. int num_bpar_vars; // number of variables in the fortran structure for bpar_struct
std::vector<double> bpar_struct; std::vector<double> bpar_struct;
std::vector<std::vector<double>> bvar_struct; std::vector<int> bpar_struct_var_type_list; // The types to the variable at each element in bpar_struct
int num_bvar_vars; // number of variables in the fortran structure for bvar_struct
std::vector<std::vector<double>> bvar_struct;
std::vector<int> bvar_struct_var_type_list;
int num_var_types;
std::vector<int> i_look_var_type_list; // The types to the variable at each element in bvar_struct
}; };
behavior gru_actor(stateful_actor<gru_state>* self, int refGRU, int indxGRU, behavior gru_actor(stateful_actor<gru_state>* self, int refGRU, int indxGRU,
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
extern "C" { extern "C" {
void getVarSizes(int* num_bpar_vars, int* num_bvar_vars); void getVarSizes(int* num_var_types, int* num_bpar_vars, int* num_bvar_vars);
void fillVarTypeLists(int* num_var_types, int* num_bpar_vars, int* num_bvar_vars, void* i_look_var_type_list,
void* bpar_struct_var_type_list, void* bvar_struct_var_type_list);
} }
\ No newline at end of file
...@@ -14,16 +14,16 @@ ACTORS_LIBRARIES = -L/usr/lib -L/usr/local/lib -L/Summa-Actors/bin -lcaf_core -l ...@@ -14,16 +14,16 @@ ACTORS_LIBRARIES = -L/usr/lib -L/usr/local/lib -L/Summa-Actors/bin -lcaf_core -l
# Production runs # Production runs
FLAGS_NOAH = -O3 -ffree-form -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors # FLAGS_NOAH = -O3 -ffree-form -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors
FLAGS_COMM = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors # FLAGS_COMM = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors
FLAGS_SUMMA = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors # FLAGS_SUMMA = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors
FLAGS_ACTORS = -O3 -Wfatal-errors -std=c++17 # FLAGS_ACTORS = -O3 -Wfatal-errors -std=c++17
# Debug runs # Debug runs
# FLAGS_NOAH = -g -O0 -ffree-form -ffree-line-length-none -fmax-errors=0 -fbacktrace -Wno-unused -Wno-unused-dummy-argument -fPIC FLAGS_NOAH = -g -O0 -ffree-form -ffree-line-length-none -fmax-errors=0 -fbacktrace -Wno-unused -Wno-unused-dummy-argument -fPIC
# FLAGS_COMM = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC FLAGS_COMM = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC
# FLAGS_SUMMA = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC FLAGS_SUMMA = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC
# FLAGS_ACTORS = -g -O0 -Wall -std=c++17 FLAGS_ACTORS = -g -O0 -Wall -std=c++17
......
#include "global.hpp" #include "global.hpp"
#include <chrono> #include <chrono>
struct iLookVarType {
// These values should be one index less than the Fortran structure
// This is so they align with C++ vectors that start at 0
int scalarv = -9999;
int wLength = -9999;
int midSnow = -9999;
int midSoil = -9999;
int midToto = -9999;
int ifcSnow = -9999;
int ifcSoil = -9999;
int ifcToto = -9999;
int parSoil = -9999;
int routing = -9999;
int outstat = -9999;
int unknown = -9999;
};
double calculateTime(std::chrono::time_point<std::chrono::system_clock> start, double calculateTime(std::chrono::time_point<std::chrono::system_clock> start,
std::chrono::time_point<std::chrono::system_clock> end) { std::chrono::time_point<std::chrono::system_clock> end) {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "gru_actor.hpp" #include "gru_actor.hpp"
#include "global.hpp" #include "global.hpp"
#include "message_atoms.hpp" #include "message_atoms.hpp"
#include <vector>
#include "gru_actor_subroutine_wrappers.hpp" #include "gru_actor_subroutine_wrappers.hpp"
namespace caf { namespace caf {
...@@ -18,14 +19,38 @@ behavior gru_actor(stateful_actor<gru_state>* self, int refGRU, int indxGRU, ...@@ -18,14 +19,38 @@ behavior gru_actor(stateful_actor<gru_state>* self, int refGRU, int indxGRU,
// //
[=](init_gru) { [=](init_gru) {
// Get the variable data length, we also need the type information // Get the variable data length, we also need the type information
aout(self) << "init GRU"; aout(self) << "init GRU \n";
int integer_missing_value = -9999;
getVarSizes(&self->state.num_bpar_vars, // Get the sizes we need for the lists from Fortran
getVarSizes(&self->state.num_var_types,
&self->state.num_bpar_vars,
&self->state.num_bvar_vars); &self->state.num_bvar_vars);
aout(self) << "GRU: GOT VAR SIZES\n";
aout(self) << "NUM VAR Type = " << self->state.num_var_types << "\n";
aout(self) << "NUM BPAR = " << self->state.num_bpar_vars << "\n"; aout(self) << "NUM BPAR = " << self->state.num_bpar_vars << "\n";
aout(self) << "NUM BVAR = " << self->state.num_bvar_vars << "\n"; aout(self) << "NUM BVAR = " << self->state.num_bvar_vars << "\n";
for (int i = 0; i < self->state.num_var_types; i++) {
self->state.i_look_var_type_list.push_back(integer_missing_value);
}
for (int i = 0; i < self->state.num_bpar_vars; i++) {
self->state.bpar_struct_var_type_list.push_back(integer_missing_value);
}
for (int i = 0; i < self->state.num_bvar_vars; i++) {
self->state.bvar_struct_var_type_list.push_back(integer_missing_value);
}
// Fill The lists with the values from the fortran lists
fillVarTypeLists(&self->state.num_var_types,
&self->state.num_bpar_vars,
&self->state.num_bvar_vars,
&self->state.i_look_var_type_list[0],
&self->state.bpar_struct_var_type_list[0],
&self->state.bvar_struct_var_type_list[0]);
} }
......
...@@ -2,29 +2,104 @@ ...@@ -2,29 +2,104 @@
!!! If lateral flows exits use the code !!! If lateral flows exits use the code
module gru_actor module gru_actor
USE,intrinsic :: iso_c_binding USE,intrinsic :: iso_c_binding
USE nrtype
implicit none implicit none
! public::run_gru ! public::run_gru
public::getVarSizes public::getVarSizes
! public::run_gru_for_timestep() public::fillvarTypeLists
contains contains
subroutine getVarSizes(num_bpar_vars, & subroutine getVarSizes(num_var_types, &
num_bpar_vars, &
num_bvar_vars) bind(C,name="getVarSizes") num_bvar_vars) bind(C,name="getVarSizes")
USE var_lookup,only:maxvarBpar, maxvarBvar USE var_lookup,only:maxvarBpar, maxvarBvar, maxvarVarType
implicit none implicit none
integer(c_int), intent(out) :: num_var_types
integer(c_int), intent(out) :: num_bpar_vars
integer(c_int), intent(out) :: num_bvar_vars
integer(c_int), intent(out) :: num_bpar_vars num_var_types = maxvarVarType
integer(c_int), intent(out) :: num_bvar_vars
num_bpar_vars = maxvarBpar num_bpar_vars = maxvarBpar
num_bvar_vars = maxvarBvar num_bvar_vars = maxvarBvar
end subroutine getVarSizes end subroutine getVarSizes
subroutine initVarType(num_var_types, &
i_look_var_type_list) bind(C, name="initVarType")
USE var_lookup,only:iLookVarType
implicit none
integer(c_int), intent(in) :: num_var_types
integer(c_int), intent(out), dimension(num_var_types) :: i_look_var_type_list
i_look_var_type_list(1) = iLookVarType%scalarv
i_look_var_type_list(2) = iLookVarType%wLength
i_look_var_type_list(3) = iLookVarType%midSnow
i_look_var_type_list(4) = iLookVarType%midSoil
i_look_var_type_list(5) = iLookVarType%midToto
i_look_var_type_list(6) = iLookVarType%ifcSnow
i_look_var_type_list(7) = iLookVarType%ifcSoil
i_look_var_type_list(8) = iLookVarType%ifcToto
i_look_var_type_list(9) = iLookVarType%parSoil
i_look_var_type_list(10) = iLookVarType%routing
i_look_var_type_list(11) = iLookVarType%outstat
i_look_var_type_list(12) = iLookVarType%unknown
end subroutine
subroutine fillVarTypeLists(num_var_types, &
num_bpar_vars, &
num_bvar_vars, &
i_look_var_type_list, &
bpar_struct_var_type_list, &
bvar_struct_var_type_list) bind(C, name="fillVarTypeLists")
USE globalData,only:type_meta,bpar_meta,bvar_meta
USE var_lookup,only:iLookBVAR,iLookBPAR,iLookVarType
implicit none
integer(c_int), intent(in) :: num_var_types
integer(c_int), intent(in) :: num_bpar_vars
integer(c_int), intent(in) :: num_bvar_vars
integer(c_int), intent(out), dimension(num_var_types) :: i_look_var_type_list
integer(c_int), intent(out), dimension(num_bpar_vars) :: bpar_struct_var_type_list
integer(c_int), intent(out), dimension(num_bvar_vars) :: bvar_struct_var_type_list
integer(i4b) :: i
i_look_var_type_list(1) = iLookVarType%scalarv
i_look_var_type_list(2) = iLookVarType%wLength
i_look_var_type_list(3) = iLookVarType%midSnow
i_look_var_type_list(4) = iLookVarType%midSoil
i_look_var_type_list(5) = iLookVarType%midToto
i_look_var_type_list(6) = iLookVarType%ifcSnow
i_look_var_type_list(7) = iLookVarType%ifcSoil
i_look_var_type_list(8) = iLookVarType%ifcToto
i_look_var_type_list(9) = iLookVarType%parSoil
i_look_var_type_list(10) = iLookVarType%routing
i_look_var_type_list(11) = iLookVarType%outstat
i_look_var_type_list(12) = iLookVarType%unknown
do i = 1, num_var_types
print*, "iLookVarType = ", i_look_var_type_list(i)
end do
do i = 1, num_bpar_vars
bpar_struct_var_type_list(i) = bpar_meta(i)%varType
end do
do i = 1, num_bvar_vars
bvar_struct_var_type_list(i) = bvar_meta(i)%varType
end do
end subroutine fillVarTypeLists
! subroutine run_gru_for_timestep() ! subroutine run_gru_for_timestep()
......
...@@ -49,8 +49,8 @@ behavior job_actor(stateful_actor<job_state>* self, int startGRU, int numGRU, ...@@ -49,8 +49,8 @@ behavior job_actor(stateful_actor<job_state>* self, int startGRU, int numGRU,
// Print Settings // Print Settings
aout(self) << "\nSETTINGS FOR JOB_ACTOR\n" << aout(self) << "\nSETTINGS FOR JOB_ACTOR\n" <<
"File Manager Path = " << self->state.fileManager << "\n" << "File Manager Path = " << self->state.fileManager << "\n" <<
"outputCSV = " << self->state.outputCSV << "\n"; "outputCSV = " << self->state.outputCSV << "\n";
if (self->state.outputCSV) { if (self->state.outputCSV) {
aout(self) << "csvPath = " << self->state.csvPath << "\n"; aout(self) << "csvPath = " << self->state.csvPath << "\n";
} }
......
module job_actor module job_actor
implicit none implicit none
public::init_veg_
\ No newline at end of file
end module
\ No newline at end of file
File added
Run start time on system: ccyy=2022 - mm=08 - dd=17 - hh=22 - mi=54 - ss=02.427 Run start time on system: ccyy=2022 - mm=08 - dd=18 - hh=16 - mi=51 - ss=11.619
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment