Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,17 @@ void core::config_output(pt::ptree &value)
OGRCoordinateTransformation::DestroyCT(coordTrans);
}

if(!_mesh->is_geographic())
out.face = _mesh->locate_face(out.x, out.y);
else
out.face = _mesh->locate_face(out.longitude, out.latitude);


// if(!_mesh->is_geographic())
// {
// out.face = _mesh->locate_face(out.x, out.y);
// }
// else
// {
// out.face = _mesh->locate_face(out.longitude, out.latitude);
// }
out.face = _mesh->face(0);

if(out.face != nullptr)
{
Expand Down
120 changes: 106 additions & 14 deletions src/modules/point_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,68 @@ point_mode::point_mode(config_file cfg)
: module_base("point_mode", parallel::data, cfg)
{

t = cfg.get("provide.t",true);
rh = cfg.get("provide.rh",true);
U_R = cfg.get("provide.U_R",true);
U_2m_above_srf = cfg.get("provide.U_2m_above_srf",true);
p = cfg.get("provide.p",true);
ilwr = cfg.get("provide.ilwr",true);
iswr = cfg.get("provide.iswr",true);
vw_dir = cfg.get("provide.vw_dir",true);
iswr_diffuse = cfg.get("provide.iswr_diffuse",false);
iswr_direct = cfg.get("provide.iswr_direct",false);
T_g = cfg.get("provide.T_g",false);
t = cfg.get("provide.t",false);
rh = cfg.get("provide.rh",false);
U_R = cfg.get("provide.U_R",false);
U_2m_above_srf = cfg.get("provide.U_2m_above_srf",false);
p = cfg.get("provide.p",false);
ilwr = cfg.get("provide.ilwr",false);
iswr = cfg.get("provide.iswr",false);
vw_dir = cfg.get("provide.vw_dir",false);
iswr_diffuse = cfg.get("provide.iswr_diffuse",false);
iswr_direct = cfg.get("provide.iswr_direct",false);
T_g = cfg.get("provide.T_g",false);
svf = cfg.get("provide.svf",false);

unit_test_new_modules = cfg.get("provide.unit_test_Donovan",false);



if(unit_test_new_modules)
{
// Infil_All
depends_from_met("SWE");
provides("swe");

depends_from_met("snowmeltD");
provides("snowmelt_int");

depends_from_met("net_rain");
provides("rainfall_int");

depends_from_met("fallstat_V");
provides("soil_storage_at_freeze");

// t is included in another section

// Evapotranspiration_All
depends_from_met("Rn");
provides("netall");

depends_from_met("Pa");
provides("P_atm");

depends_from_met("hru_ea");
provides("ea");

// rh, t, U_2m_above_srf included already here
// soil_storage comes from the soil module

// soil_module
depends_from_met("rho");
provides("snow_density");
// All depends/provides come from other modules
// swe, ET, inf, runoff
//
depends_from_met("hru_t");
provides("t");

depends_from_met("hru_u");
provides("U_2m_above_srf");

depends_from_met("hru_tsf");
provides("surface_temperature");
}
if(t)
{
depends_from_met("t");
Expand Down Expand Up @@ -110,11 +160,52 @@ point_mode::~point_mode()

}

void point_mode::init(mesh &domain)
{
size_t i=0;
auto face = domain->face(i);
elevation = face->parameter("elevation"_s);
};
void point_mode::run(mesh_elem &face)
{
// at this point, if the user has provided more than 1 station, they've been stripped out.
// we can safetly take the 1st (and only) station.

if(unit_test_new_modules)
{
double swe = (*face->nearest_station())["SWE"_s];
(*face)["swe"_s] = swe;

double snowmelt_int = (*face->nearest_station())["snowmeltD"_s];
(*face)["snowmelt_int"_s] = snowmelt_int/24;

double rainfall_int = (*face->nearest_station())["net_rain"_s];
(*face)["rainfall_int"_s] = rainfall_int;

double soil_storage_at_freeze = (*face->nearest_station())["fallstat_V"_s];
(*face)["soil_storage_at_freeze"_s] = soil_storage_at_freeze;

double netall = (*face->nearest_station())["Rn"_s];
(*face)["netall"_s] = netall;

double P_atm = 101.3*pow( (293.0 - 0.0065*elevation)/293.0,5.26);
(*face)["P_atm"_s] = P_atm;

double ea = (*face->nearest_station())["hru_ea"_s];
(*face)["ea"_s] = ea;

double rho = (*face->nearest_station())["rho"_s];
(*face)["snow_density"_s] = rho;

double t = (*face->nearest_station())["hru_t"_s];
(*face)["t"_s] = t;

double u = (*face->nearest_station())["hru_u"_s];
(*face)["U_2m_above_srf"_s] = u;

double temp = (*face->nearest_station())["hru_tsf"_s];
(*face)["surface_temperature"_s] = temp;
}
if(t)
{
double st =(*face->nearest_station())["t"_s];
Expand Down Expand Up @@ -180,7 +271,8 @@ void point_mode::run(mesh_elem &face)
double T_g =(*face->nearest_station())["T_g"_s];
(*face)["T_g"_s]= T_g;
}

face->parameter("svf") = cfg.get("override.svf", face->parameter("svf"_s));

if(svf)
{
face->parameter("svf") = cfg.get("override.svf", face->parameter("svf"_s));
}
}
8 changes: 5 additions & 3 deletions src/modules/point_mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ REGISTER_MODULE_HPP(point_mode);
~point_mode();

virtual void run(mesh_elem &face);

virtual void init(mesh &domain);

bool t ;
bool rh ;
Expand All @@ -126,6 +126,8 @@ REGISTER_MODULE_HPP(point_mode);
bool iswr_direct ;
bool U_2m_above_srf ;
bool T_g;


bool svf;
bool unit_test_new_modules;
double elevation = 0.0;
double soil_storage_at_freeze = 0.0;
};
212 changes: 212 additions & 0 deletions test_data/unit-test-example-data/unit-test_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
{
"option": {
"per_triangle_timeseries": "true",
"ui": "false",
"debug_level": "debug",
"point_mode": {
},
"prj_name": "UNITTEST"
},
"modules": [
"Infil_All",
"soil_module",
"Evapotranspiration_All",
"point_mode"
],
"remove_depency": {
"Simple_Canopy": "snobal",
"Richard_albedo": "snobal",
"scale_wind_vert": "snobal",

"Simple_Canopy": "Lehning_snowpack",
"Richard_albedo": "Lehning_snowpack",
"scale_wind_vert": "Lehning_snowpack",

"scale_wind_vert": "FSM",
"snow_slide": "snobal",
"PBSM3D": "snobal",
"WindNinja": "snobal",
"WindNinja": "FSM",
"WindNinja": "Lehning_snowpack",

"Simple_Canopy": "FSM",
"scale_wind_vert": "FSM",
"snow_slide": "FSM",
"PBSM3D": "FSM",
"WindNinja": "FSM",

"Evapotranspiration_All" : "soil_module",
"Infil_All" : "soil_module"
},
"config": {
"point_mode": {
"provide": {
"t": "false",
"U_2m_above_srf": "false",
"iswr": "true",
"unit_test_Donovan": "true"
}
},
"Evapotranspiration_All": {
"alpha": "1.26",
"stomatal_resistance_min": "25",
"Frac_to_ground": 0.1,
"wind_measurement_height": "10"
},

"Infil_All": {
"infDays": "6",
"min_swe_to_freeze": "25.0",
"major": "5",
"AllowPrior_inf": "true",
"thaw_type": "0",
"lens_temp": "-10.0"
},

"soil_module": {
"Ksaturated_rechr": "0.00176",
"Ksaturated_lower": "6.9E-6",
"Ksaturated_groundwater": "6.9E-6",
"Ksaturated_organic": "6.9E-6",
"Trigthrhld": "100.0",
"depth_per_layer": "0.5",
"theta_default": "0.5",
"uniform_conductivities": "true",
"dry_soil_k": "2.5",
"sat_soil_frozen_k": "1.98",
"sat_soil_thaw_k": "1.67",
"number_XG_layers": "10",
"moisture_content_min_per_layer": "0.0001",
"update_k_behind_front_freeze": "true",
"update_k_behind_front_thaw": "true",
"k_update": "1",
"Johansen_conductivity": "false"
},

"Richard_albedo": {
"min_swe_refresh": "10",
"init_albedo_snow": "0.8",
"a2": "3.6e5"
},
"snobal": {
"param_snow_compaction": "1"
},
"Thornton_p": {
"apply_cosine_correction": "true"
},
"p_no_lapse": {
"apply_cosine_correction": "true"
},
"snow_slide": {
"use_vertical_snow": "true"
},
"PBSM3D": {
"nLayer": "10",
"smooth_coeff": "6500",
"rouault_diffusion_coef": "false",
"min_sd_trans": "0.1",
"enable_veg": "true",
"snow_diffusion_const": "0.3",
"settling_velocity": "0.5",
"do_fixed_settling": "true",
"do_sublimation": "true",
"use_tanh_fetch": "true",
"use_R94_lambda": "false",
"use_PomLi_probability": "false",
"use_subgrid_topo": "false",
"use_subgrid_topo_V2": "false",
"z0_ustar_coupling": "false",
"debug_output": "false"
},
"fetchr": {
"incl_veg": "false",
"I": "0.06"
},
"WindNinja": {
"Max_spdup": "3.5",
"ninja_recirc": "true",
"compute_Sx": "false",
"Sx_crit": "20.0",
"L_avg": "1000"
},
"iswr": {
"already_cosine_corrected": "true"
}
},
"meshes": {

"mesh": "unit-test_example.mesh",
"parameters": {
"file": "unit-test_example.param"
}


},
"parameter_mapping": {
"landcover": {
"1": {
"is_water": "false"
},
"0": {
"is_water": "true"
}
},
"soils": {
"soil_type": {
"0": "sand",
"1": "loam",
"2": "clay",
"3": "loamsand",
"4": "sandloam",
"5": "siltloam",
"6": "saclloam",
"7": "clayloam",
"8": "siclloam",
"9": "sandclay",
"10": "siltclay",
"99": "pavement"
},
"soil_texture": {
"0": "coarse_over_coarse",
"1": "medium_over_medium",
"2": "medium_over_fine",
"3": "fine_over_fine",
"4": "soil_over_bedrock"
},
"soil_groundcover": {
"0" : "bare_soil",
"1" : "row_crop",
"2" : "poor_pasture",
"3" : "small_grains",
"4" : "good_pasture",
"5" : "forested"
}

}
},
"output": {
"UpperClearing" : {
"longitude": -115.175362,
"latitude": 50.956547,
"file": "output_test.txt",
"type": "timeseries"
}

},
"forcing":
{
"UTC_offset":11,
"num_stations_to_use": "1",
"interpolant": "nearest",

"UpperClearing":
{
"file": "combined.csv",
"longitude": -115.175362,
"latitude": 50.95654,
"elevation": 1845
}


}
}
Loading