Skip to content

Commit

Permalink
resolve dsval#2
Browse files Browse the repository at this point in the history
  • Loading branch information
jaideep777 committed Jun 8, 2024
1 parent 34f188b commit 1e521f7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions R/splash.point.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ splash.point<-function(sw_in, tc, pn, lat,elev,slop=0,asp=0,soil_data,Au=0,resol
#if there is no information on how many cell drain to this point, assume 3 sides of the octogonal cell
ncellin<-3
ncellout<-3
soil_info<-c(SAT,WP,FC,soil_info$Ksat,lambda,depth,bub_press,RES,Au[1],resolution^2,ncellin,ncellout)
soil_info<-c(SAT,WP,FC,soil_info$Ksat,lambda,depth,bub_press,RES,Au[1],resolution^2,ncellin,ncellout,0)
# ^ Jaideep FIXME: Note that this does not set soil_info[13] to AI. This means that when this is dereferenced in quick-run, there's a risk of segfault or garbage value
}else{
ncellin<-Au[2]
Expand Down Expand Up @@ -149,7 +149,7 @@ splash.point<-function(sw_in, tc, pn, lat,elev,slop=0,asp=0,soil_data,Au=0,resol
initial_AI<-my_splash$spin_up(as.integer(365), as.integer(y[1]), as.numeric(sw_av[1:365]), as.numeric(tc_av[1:365]),as.numeric(pn_av[1:365]),slop,asp,as.numeric(snowf_av[1:365]),soil_info)
# ^ Jaideep FIXME: This sees a size-12 soil_info when length(Au)=1, so might get segfault, or worse, AI will get garbage value
#update aridity
soil_info[12]<-sum(initial_AI$pet,na.rm=T)/sum(Pinit[1:365],na.rm = T)
soil_info[13]<-sum(initial_AI$pet,na.rm=T)/sum(Pinit[1:365],na.rm = T)
# ^ Jaideep FIXME: This is assigning AI to soil_info[12] (R indexing) which is ncellout. It should instead go into soil_info[13] (R indexing), i.e. soil_info[12] (C++ indexing)
# run spin up
initial<-my_splash$spin_up(as.integer(365), as.integer(y[1]), as.numeric(sw_av[1:365]), as.numeric(tc_av[1:365]),as.numeric(pn_av[1:365]),slop,asp,as.numeric(snowf_av[1:365]),soil_info)
Expand Down
2 changes: 1 addition & 1 deletion src/EVAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void EVAP::calculate_daily_fluxes(double sw, int n, int y, double sw_in,
rnn_d = d_sr.rnn_d;
double ts = d_sr.ts;

printf("Rnl in EVAP function: %0.6f W/m^2\n", rnl);
// printf("Rnl in EVAP function: %0.6f W/m^2\n", rnl);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 1.1. Assume water temperature 0.0 if air temperature < 0.0
Expand Down
4 changes: 2 additions & 2 deletions src/SOLAR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void SOLAR::calculate_daily_fluxes(int n, int y, double sw_in, double tc, double
Output:
Features: Calculates the daily solar radiation fluxes
*********************************************************************** */
cout << "SOLAR calc inputs: " << n << " " << y << " " << sw_in << " " << tc << " " << slop << " " << asp << " " << snow << " " << nd << " " << sw << '\n';
// cout << "SOLAR calc inputs: " << n << " " << y << " " << sw_in << " " << tc << " " << slop << " " << asp << " " << snow << " " << nd << " " << sw << '\n';

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 0. Save day of year
Expand Down Expand Up @@ -266,7 +266,7 @@ void SOLAR::calculate_daily_fluxes(int n, int y, double sw_in, double tc, double
//max air temeperature
//ts = tc/dcos(hs/2);

cout << "End of SOLAR calc: rnl = " << rnl << endl;
// cout << "End of SOLAR calc: rnl = " << rnl << endl;

}

Expand Down
2 changes: 1 addition & 1 deletion src/SPLASH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,7 @@ etr SPLASH::run_one_day(int n, int y, double wn, double sw_in, double tc,
dsoil.nd = nd;

dsoil.stress_factor = (sm-RES)/(Wmax-RES);
cout << "sw_end(calc at start) / stress_end (calc at end) = " << sw << " / " << dsoil.stress_factor << '\n';
// cout << "sw_end(calc at start) / stress_end (calc at end) = " << sw << " / " << dsoil.stress_factor << '\n';

theta_i = (sm)/(depth*1000.0);
// correct theta_i for NA error reaching boundary conditions
Expand Down

0 comments on commit 1e521f7

Please sign in to comment.