Skip to content

Commit

Permalink
Merge pull request #109 from mmbell/control_flow_sandbox
Browse files Browse the repository at this point in the history
Control flow sandbox
  • Loading branch information
cenamiller authored Sep 19, 2024
2 parents 7b6252b + 076b229 commit 2d99a40
Show file tree
Hide file tree
Showing 25 changed files with 1,232 additions and 563 deletions.
95 changes: 77 additions & 18 deletions ncar_scripts/TDRP/beltramiTR.tdrp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ debug_kd = 0;

debug_kd_step = 0;

///////////// wind_file //////////////////////////
//
// Needed by Samurai THERMO mode
//
// Type: string

wind_file = "../ncar_scripts/input/beltrami_test_v2.nc";

//======================================================================
//
// BACKGROUND SECTION.
Expand Down Expand Up @@ -981,6 +989,36 @@ mesonet_rhow_error = 1;

mesonet_tempk_error = 1;

///////////// thermo_A_error /////////////////////
//
// Type: float

thermo_A_error = 0.01;

///////////// thermo_B_error /////////////////////
//
// Type: float

thermo_B_error = 0.01;

///////////// thermo_C_error /////////////////////
//
// Type: float

thermo_C_error = 0.01;

///////////// thermo_D_error /////////////////////
//
// Type: float

thermo_D_error = 0.01;

///////////// thermo_E_error /////////////////////
//
// Type: float

thermo_E_error = 0.01;

//======================================================================
//
// XYP SPECIFIC SECTION.
Expand Down Expand Up @@ -1172,6 +1210,27 @@ bg_rhow_error = { 20, 2 };

bg_tempk_error = { 20, 2 };

///////////// bg_pip_error //////////////////////////
//
// Type: float
// 1D array - variable length.

bg_pip_error = { 10, 10 };

///////////// bg_thetarhop_error //////////////////////////
//
// Type: float
// 1D array - variable length.

bg_thetarhop_error = { 10, 10 };

///////////// bg_ftheta_error //////////////////////////
//
// Type: float
// 1D array - variable length.

bg_ftheta_error = { 10, 10 };

///////////// i_filter_length /////////////////////////
//
// Type: float
Expand Down Expand Up @@ -1245,106 +1304,106 @@ k_max_wavenumber = { -1, -1 };
//
// Type: int

i_pip_bcL = -1;
i_pip_bcL = "R0";

///////////// i_pip_bcR ///////////////////////////////
//
// Type: int

i_pip_bcR = -1;
i_pip_bcR = "R0";

///////////// i_thetarhop_bcL ///////////////////////////////
//
// Type: int

i_thetarhop_bcL = -1;
i_thetarhop_bcL = "R0";

///////////// i_thetarhop_bcR ///////////////////////////////
//
// Type: int

i_thetarhop_bcR = -1;
i_thetarhop_bcR = "R0";

///////////// i_ftheta_bcL ///////////////////////////////
//
// Type: int

i_ftheta_bcL = -1;
i_ftheta_bcL = "R0";

///////////// i_ftheta_bcR ///////////////////////////////
//
// Type: int

i_ftheta_bcR = -1;
i_ftheta_bcR = "R0";

///////////// j_pip_bcL ///////////////////////////////
//
// Type: int

j_pip_bcL = -1;
j_pip_bcL = "R0";

///////////// j_pip_bcR ///////////////////////////////
//
// Type: int

j_pip_bcR = -1;
j_pip_bcR = "R0";

///////////// j_thetarhop_bcL ///////////////////////////////
//
// Type: int

j_thetarhop_bcL = -1;
j_thetarhop_bcL = "R0";

///////////// j_thetarhop_bcR ///////////////////////////////
//
// Type: int

j_thetarhop_bcR = -1;
j_thetarhop_bcR = "R0";

///////////// j_ftheta_bcL ///////////////////////////////
//
// Type: int

j_ftheta_bcL = -1;
j_ftheta_bcL = "R0";

///////////// j_ftheta_bcR ///////////////////////////////
//
// Type: int

j_ftheta_bcR = -1;
j_ftheta_bcR = "R0";

///////////// k_pip_bcL ///////////////////////////////
//
// Type: int

k_pip_bcL = -1;
k_pip_bcL = "R0";

///////////// k_pip_bcR ///////////////////////////////
//
// Type: int

k_pip_bcR = -1;
k_pip_bcR = "R0";

///////////// k_thetarhop_bcL ///////////////////////////////
//
// Type: int

k_thetarhop_bcL = -1;
k_thetarhop_bcL = "R0";

///////////// k_thetarhop_bcR ///////////////////////////////
//
// Type: int

k_thetarhop_bcR = -1;
k_thetarhop_bcR = "R0";

///////////// k_ftheta_bcL ///////////////////////////////
//
// Type: int

k_ftheta_bcL = -1;
k_ftheta_bcL = "R0";

///////////// k_ftheta_bcR ///////////////////////////////
//
// Type: int

k_ftheta_bcR = -1;
k_ftheta_bcR = "R0";
Binary file added ncar_scripts/input/beltrami_test_v2.nc
Binary file not shown.
53 changes: 33 additions & 20 deletions src/Args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ bool Args::paramsToHash(HashMap *configHash) {
CONFIG_INSERT_STR(debug_bgu_nc);
CONFIG_INSERT_STR(debug_bgu_overwrite);
CONFIG_INSERT_STR(fractl_nc_file);
CONFIG_INSERT_STR(wind_file);
CONFIG_INSERT_BOOL(horizontal_radar_appx);
CONFIG_INSERT_BOOL(load_background);
CONFIG_INSERT_BOOL(load_bg_coefficients);
Expand Down Expand Up @@ -280,13 +281,20 @@ bool Args::paramsToHash(HashMap *configHash) {
CONFIG_INSERT_FLOAT(output_pressure_increment);
CONFIG_INSERT_FLOAT(qscat_rhou_error);
CONFIG_INSERT_FLOAT(qscat_rhov_error);
CONFIG_INSERT_FLOAT(thermo_A_error);
CONFIG_INSERT_FLOAT(thermo_B_error);
CONFIG_INSERT_FLOAT(thermo_C_error);
CONFIG_INSERT_FLOAT(thermo_D_error);
CONFIG_INSERT_FLOAT(thermo_E_error);
CONFIG_INSERT_FLOAT(radar_fallspeed_error);
CONFIG_INSERT_FLOAT(radar_min_error);
CONFIG_INSERT_FLOAT(radar_sw_error);
CONFIG_INSERT_FLOAT(rain_dbz);
CONFIG_INSERT_FLOAT(sfmr_windspeed_error);


for (int iter = 1; iter <= params.num_iterations; iter++) {
// for WIND analysis
CONFIG_INSERT_FLOAT_ARRAY(bg_qr_error, iter);
CONFIG_INSERT_FLOAT_ARRAY(bg_rhoa_error, iter);
CONFIG_INSERT_FLOAT_ARRAY(bg_rhou_error, iter);
Expand All @@ -295,6 +303,11 @@ bool Args::paramsToHash(HashMap *configHash) {
CONFIG_INSERT_FLOAT_ARRAY(bg_tempk_error, iter);
CONFIG_INSERT_FLOAT_ARRAY(bg_qv_error, iter);

// for THERMO analysis
CONFIG_INSERT_FLOAT_ARRAY(bg_pip_error, iter);
CONFIG_INSERT_FLOAT_ARRAY(bg_thetarhop_error, iter);
CONFIG_INSERT_FLOAT_ARRAY(bg_ftheta_error, iter);

CONFIG_INSERT_FLOAT_ARRAY(i_filter_length, iter);
CONFIG_INSERT_FLOAT_ARRAY(j_filter_length, iter);
CONFIG_INSERT_FLOAT_ARRAY(k_filter_length, iter);
Expand All @@ -309,26 +322,26 @@ bool Args::paramsToHash(HashMap *configHash) {
CONFIG_INSERT_FLOAT_ARRAY(dirichlet_w_weight, iter);
}
// arguments required by THERMO
CONFIG_INSERT_INT(i_pip_bcL);
CONFIG_INSERT_INT(i_pip_bcR);
CONFIG_INSERT_INT(i_thetarhop_bcL);
CONFIG_INSERT_INT(i_thetarhop_bcR);
CONFIG_INSERT_INT(i_ftheta_bcL);
CONFIG_INSERT_INT(i_ftheta_bcR);

CONFIG_INSERT_INT(j_pip_bcL);
CONFIG_INSERT_INT(j_pip_bcR);
CONFIG_INSERT_INT(j_thetarhop_bcL);
CONFIG_INSERT_INT(j_thetarhop_bcR);
CONFIG_INSERT_INT(j_ftheta_bcL);
CONFIG_INSERT_INT(j_ftheta_bcR);

CONFIG_INSERT_INT(k_pip_bcL);
CONFIG_INSERT_INT(k_pip_bcR);
CONFIG_INSERT_INT(k_thetarhop_bcL);
CONFIG_INSERT_INT(k_thetarhop_bcR);
CONFIG_INSERT_INT(k_ftheta_bcL);
CONFIG_INSERT_INT(k_ftheta_bcR);
CONFIG_INSERT_STR(i_pip_bcL);
CONFIG_INSERT_STR(i_pip_bcR);
CONFIG_INSERT_STR(i_thetarhop_bcL);
CONFIG_INSERT_STR(i_thetarhop_bcR);
CONFIG_INSERT_STR(i_ftheta_bcL);
CONFIG_INSERT_STR(i_ftheta_bcR);

CONFIG_INSERT_STR(j_pip_bcL);
CONFIG_INSERT_STR(j_pip_bcR);
CONFIG_INSERT_STR(j_thetarhop_bcL);
CONFIG_INSERT_STR(j_thetarhop_bcR);
CONFIG_INSERT_STR(j_ftheta_bcL);
CONFIG_INSERT_STR(j_ftheta_bcR);

CONFIG_INSERT_STR(k_pip_bcL);
CONFIG_INSERT_STR(k_pip_bcR);
CONFIG_INSERT_STR(k_thetarhop_bcL);
CONFIG_INSERT_STR(k_thetarhop_bcR);
CONFIG_INSERT_STR(k_ftheta_bcL);
CONFIG_INSERT_STR(k_ftheta_bcR);

return true;
}
8 changes: 6 additions & 2 deletions src/CostFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void CostFunction::truncatedNewton(real* qstate, real* g, const real ftol)
real n_init_grad, n_grad, grad_dot;
real gg;
real rr, pAp, rr_m1, r_norm, r0_norm, rel_resid;
real r0_init_norm;
real beta, alpha;
real initstep;

Expand Down Expand Up @@ -150,6 +151,7 @@ void CostFunction::truncatedNewton(real* qstate, real* g, const real ftol)
if (its == 0) {
f_init = f_val;
n_init_grad = n_grad;
r0_init_norm = n_init_grad;
//cout << "Newton: Initial Norm of the Gradient = " << n_init_grad << endl;
}

Expand Down Expand Up @@ -189,12 +191,14 @@ void CostFunction::truncatedNewton(real* qstate, real* g, const real ftol)
r[j] = -g[j]; //initial residual r0 = b -Ax = -g
p[j] = r[j]; //inital direction po = r0
}
//JMD: I am wondering if r0_norm should be the initial residual n_init_grad
// r0_norm = n_grad;
r0_norm = n_grad;

neg_curve = 0; //negative curvature check

if (verbose) {
std::cout << "\t\tCG iteration " << std::setw(7) << std::right << "0" << ": r_norm = " << std::fixed << std::setw(20) << std::setprecision(8) << std::right << r0_norm << " rel_resid = " << std::setw(14) << std::setprecision(10) << std::right << 1.0 << endl;
std::cout << "\t\tCG iteration " << std::setw(7) << std::right << "0" << ": r_norm = " << std::fixed << std::setw(20) << std::setprecision(8) << std::right << r0_norm << " rel_resid = " << std::setw(14) << std::setprecision(10) << std::right << r0_norm/r0_init_norm << endl;
}

}
Expand Down Expand Up @@ -252,7 +256,7 @@ void CostFunction::truncatedNewton(real* qstate, real* g, const real ftol)

//CG cconvergence check
r_norm = sqrt(rr);
rel_resid = r_norm/r0_norm;
rel_resid = r_norm/r0_init_norm;

std::cout << std::right;
if (verbose) cout << "\t\tCG iteration " << std::setw(7) << std::right << cg_its + 1 << ": r_norm = " << std::setw(20) << std::fixed << std::setprecision(8) << std::right << r_norm << " rel_resid = " << std::setw(14) << std::setprecision(10) << std::right << rel_resid << endl;
Expand Down
Loading

0 comments on commit 2d99a40

Please sign in to comment.