Skip to content

Commit a555140

Browse files
committed
Ecotypes unit test: Don't read parameter file.
1 parent a88bfb0 commit a555140

File tree

5 files changed

+71
-43
lines changed

5 files changed

+71
-43
lines changed

main/EDParamsMod.F90

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ module EDParamsMod
268268
character(len=param_string_length),parameter,public :: eca_name_plant_escalar = "fates_cnp_eca_plant_escalar"
269269

270270
public :: FatesParamsInit
271+
public :: FatesParamsInitForFactory
271272
public :: FatesRegisterParams
272273
public :: FatesReceiveParams
273274
public :: FatesReportParams
@@ -353,6 +354,21 @@ subroutine FatesParamsInit()
353354

354355
end subroutine FatesParamsInit
355356

357+
!-----------------------------------------------------------------------
358+
359+
subroutine FatesParamsInitForFactory()
360+
! Initialize some parameters that are needed for unit-testing factories
361+
362+
allocate(ED_val_history_ageclass_bin_edges(7))
363+
ED_val_history_ageclass_bin_edges = [0, 1, 2, 5, 10, 20, 50]
364+
365+
allocate(ED_val_history_sizeclass_bin_edges(13))
366+
ED_val_history_sizeclass_bin_edges = [0, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100]
367+
368+
allocate(ED_val_history_coageclass_bin_edges(13))
369+
ED_val_history_coageclass_bin_edges = [0, 5]
370+
end subroutine FatesParamsInitForFactory
371+
356372
!-----------------------------------------------------------------------
357373
subroutine FatesRegisterParams(fates_params)
358374
! Register the parameters we want the host to provide, and

testing/run_unit_tests.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from build_fortran_tests import build_tests
2525
from path_utils import add_cime_lib_to_path
2626
from utils import config_to_dict, parse_test_list
27-
from utils import check_param_file, create_param_file, _DEFAULT_CDL_PATH
2827

2928
add_cime_lib_to_path()
3029

@@ -100,26 +99,12 @@ def commandline_args():
10099
"for all tests. If not supplied, will run all tests.",
101100
)
102101

103-
parser.add_argument(
104-
"-f",
105-
"--parameter-file",
106-
type=str,
107-
default=_DEFAULT_CDL_PATH,
108-
help="Parameter file to run the FATES tests with.\n"
109-
"Can be a netcdf (.nc) or cdl (.cdl) file.\n"
110-
"If no file is specified the script will use the default .cdl file in the\n"
111-
"parameter_files directory.\n",
112-
)
113-
114102
args = parser.parse_args()
115103

116-
# check to make sure parameter file exists and is one of the correct forms
117-
check_param_file(args.parameter_file)
118-
119104
return args
120105

121106

122-
def run_unit_tests(clean, verbose_make, build_dir, make_j, test_dict, param_file):
107+
def run_unit_tests(clean, verbose_make, build_dir, make_j, test_dict):
123108
"""Builds and runs the fates unit tests
124109
125110
Args:
@@ -133,12 +118,6 @@ def run_unit_tests(clean, verbose_make, build_dir, make_j, test_dict, param_file
133118
# absolute path to desired build directory
134119
build_dir_path = os.path.abspath(build_dir)
135120

136-
# create parameter file, if needed
137-
for _, attributes in test_dict.items():
138-
if attributes["use_param_file"]:
139-
param_file = create_param_file(param_file, build_dir_path)
140-
break
141-
142121
# compile code
143122
build_tests(
144123
build_dir_path, _CMAKE_BASE_DIR, make_j, clean=clean, verbose=verbose_make
@@ -151,11 +130,6 @@ def run_unit_tests(clean, verbose_make, build_dir, make_j, test_dict, param_file
151130
test_dir = os.path.join(build_dir_path, _TEST_SUB_DIR, attributes["test_dir"])
152131
ctest_command = ["ctest", "--output-on-failure"]
153132

154-
# Copy parameter file to test directory, if needed
155-
if attributes["use_param_file"]:
156-
test_param_file = os.path.join(test_dir, "params.nc")
157-
copyfile(param_file, test_param_file)
158-
159133
output = run_cmd_no_fail(
160134
" ".join(ctest_command), from_dir=test_dir, combine_output=True
161135
)
@@ -177,7 +151,6 @@ def main():
177151
args.build_dir,
178152
args.make_j,
179153
test_dict,
180-
args.parameter_file,
181154
)
182155

183156

testing/testing_shr/FatesFactoryMod.F90

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ module FatesFactoryMod
2323
use EDParamsMod, only : nclmax
2424
use EDParamsMod, only : photo_temp_acclim_timescale
2525
use EDParamsMod, only : photo_temp_acclim_thome_time
26+
use EDParamsMod, only : FatesParamsInitForFactory
2627
use FatesRunningMeanMod, only : ema_24hr, fixed_24hr, ema_lpa, ema_longterm
2728
use FatesRunningMeanMod, only : moving_ema_window, fixed_window
2829
use EDCohortDynamicsMod, only : InitPRTObject
2930
use PRTParametersMod, only : prt_params
31+
use EDPftvarcon, only : EDPftvarcon_inst
32+
use FatesParameterDerivedMod, only : param_derived
3033
use PRTGenericMod, only : element_pos
3134
use PRTGenericMod, only : num_elements
3235
use PRTGenericMod, only : element_list
@@ -80,6 +83,57 @@ subroutine InitializeGlobals(step_size)
8083

8184
! LOCALS:
8285
integer :: i ! looping index
86+
integer, parameter :: n_pfts = 14
87+
integer, parameter :: n_leafage_class = 1
88+
89+
! Things from parameter file for prt_params
90+
call FatesParamsInitForFactory()
91+
allocate(prt_params%allom_amode(n_pfts)); prt_params%allom_amode = [3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 5, 5, 5]
92+
allocate(prt_params%allom_agb1(n_pfts)); prt_params%allom_agb1 = [0.0673, 0.1364012, 0.0393057, 0.2653695, 0.0673, 0.0728698, 0.06896, 0.06896, 0.06896, 0.06896, 0.06896, 0.001, 0.001, 0.003]
93+
allocate(prt_params%allom_agb2(n_pfts)); prt_params%allom_agb2 = [0.976, 0.9449041, 1.087335, 0.8321321, 0.976, 1.0373211, 0.572, 0.572, 0.572, 0.5289883, 0.6853945, 1.6592, 1.6592, 1.3456]
94+
allocate(prt_params%allom_agb3(n_pfts)); prt_params%allom_agb3 = [1.94, 1.94, 1.94, 1.94, 1.94, 1.94, 1.94, 1.94, 1.94, 2.1010352, 1.7628613, 1.248, 1.248, 1.869]
95+
allocate(prt_params%allom_agb4(n_pfts)); prt_params%allom_agb4 = [0.931, 0.931, 0.931, 0.931, 0.931, 0.931, 0.931, 0.931, 0.931, 0.931, 0.931, -999.9, -999.9, -999.9]
96+
allocate(prt_params%allom_agb_frac(n_pfts)); prt_params%allom_agb_frac = [0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 1., 1., 1.]
97+
allocate(prt_params%allom_blca_expnt_diff(n_pfts)); prt_params%allom_blca_expnt_diff = [-0.12, -0.34, -0.32, -0.22, -0.12, -0.35, 0., 0., 0., 0., 0., -0.487, -0.487, -0.259]
98+
allocate(prt_params%allom_d2bl1(n_pfts)); prt_params%allom_d2bl1 = [0.04, 0.07, 0.07, 0.01, 0.04, 0.07, 0.07, 0.07, 0.07, 0.0481934, 0.0481934, 0.0004, 0.0004, 0.0012]
99+
allocate(prt_params%allom_d2bl2(n_pfts)); prt_params%allom_d2bl2 = [1.6019679, 1.5234373, 1.3051237, 1.9621397, 1.6019679, 1.3998939, 1.3, 1.3, 1.3, 1.0600586, 1.7176758, 1.7092, 1.7092, 1.5879]
100+
allocate(prt_params%allom_d2bl3(n_pfts)); prt_params%allom_d2bl3 = [0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.3417, 0.3417, 0.9948]
101+
allocate(prt_params%allom_d2ca_coefficient_max(n_pfts)); prt_params%allom_d2ca_coefficient_max = [0.2715891, 0.3693718, 1.0787259, 0.0579297, 0.2715891, 1.1553612, 0.6568464, 0.6568464, 0.6568464, 0.4363427, 0.3166497, 0.0408, 0.0408, 0.0862]
102+
allocate(prt_params%allom_d2ca_coefficient_min(n_pfts)); prt_params%allom_d2ca_coefficient_min = prt_params%allom_d2ca_coefficient_max
103+
allocate(prt_params%allom_d2h1(n_pfts)); prt_params%allom_d2h1 = [78.4087704, 306.842667, 106.8745821, 104.3586841, 78.4087704, 31.4557047, 0.64, 0.64, 0.64, 0.8165625, 0.778125, 0.1812, 0.1812, 0.3353]
104+
allocate(prt_params%allom_d2h2(n_pfts)); prt_params%allom_d2h2 = [0.8124383, 0.752377, 0.9471302, 1.1146973, 0.8124383, 0.9734088, 0.37, 0.37, 0.37, 0.2316113, 0.4027002, 0.6384, 0.6384, 0.4235]
105+
allocate(prt_params%allom_d2h3(n_pfts)); prt_params%allom_d2h3 = [47.6666164, 196.6865691, 93.9790461, 160.6835089, 47.6666164, 16.5928174, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9, -999.9]
106+
allocate(prt_params%allom_dbh_maxheight(n_pfts)); prt_params%allom_dbh_maxheight = [1000., 1000., 1000., 1000., 1000., 1000., 3., 3., 2., 2.4, 1.9, 20., 20., 30.]
107+
allocate(prt_params%allom_hmode(n_pfts)); prt_params%allom_hmode = [5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 3, 3, 3]
108+
allocate(prt_params%allom_lmode(n_pfts)); prt_params%allom_lmode = [2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 5, 5, 5]
109+
allocate(prt_params%c2b(n_pfts)); prt_params%c2b(:) = 2
110+
allocate(prt_params%phen_leaf_habit(n_pfts)); prt_params%phen_leaf_habit = [1, 1, 2, 1, 3, 2, 1, 3, 2, 1, 2, 2, 3, 3]
111+
allocate(prt_params%wood_density(n_pfts)); prt_params%wood_density = [0.548327, 0.44235, 0.454845, 0.754336, 0.548327, 0.566452, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7]
112+
allocate(prt_params%allom_cmode(n_pfts)); prt_params%allom_cmode(:) = 1
113+
allocate(prt_params%allom_l2fr(n_pfts)); prt_params%allom_l2fr = [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0.67, 0.67, 1.41]
114+
allocate(prt_params%allom_fmode(n_pfts)); prt_params%allom_fmode(:) = 1
115+
allocate(prt_params%allom_smode(n_pfts)); prt_params%allom_smode = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2]
116+
allocate(prt_params%slatop(n_pfts)); prt_params%slatop = [0.012, 0.005, 0.024, 0.009, 0.03, 0.03, 0.012, 0.03, 0.03, 0.01, 0.032, 0.027, 0.05, 0.05]
117+
allocate(prt_params%allom_la_per_sa_int(n_pfts)); prt_params%allom_la_per_sa_int(:) = 0.8
118+
allocate(prt_params%allom_la_per_sa_slp(n_pfts)); prt_params%allom_la_per_sa_slp(:) = 0.
119+
allocate(prt_params%allom_stmode(n_pfts)); prt_params%allom_stmode(:) = 1
120+
allocate(prt_params%cushion(n_pfts)); prt_params%cushion = [1.2, 1.2, 1.2, 1.2, 2.4, 1.2, 1.2, 2.4, 1.2, 1.5, 1.4, 1.2, 1.2, 1.2]
121+
allocate(prt_params%leafn_vert_scaler_coeff1(n_pfts)); prt_params%leafn_vert_scaler_coeff1(:) = 0.00963
122+
allocate(prt_params%leafn_vert_scaler_coeff2(n_pfts)); prt_params%leafn_vert_scaler_coeff2(:) = 2.43
123+
allocate(prt_params%slamax(n_pfts)); prt_params%slamax = [0.0954, 0.0954, 0.0954, 0.0954, 0.0954, 0.0954, 0.012, 0.03, 0.03, 0.012, 0.032, 0.05, 0.05, 0.05]
124+
allocate(prt_params%allom_sai_scaler(n_pfts)); prt_params%allom_sai_scaler(:) = 0.1
125+
allocate(prt_params%phen_fnrt_drop_fraction(n_pfts)); prt_params%phen_fnrt_drop_fraction(:) = 0.
126+
allocate(prt_params%phen_stem_drop_fraction(n_pfts)); prt_params%phen_stem_drop_fraction(:) = 0.
127+
allocate(prt_params%leaf_long(n_pfts,n_leafage_class)); prt_params%leaf_long = reshape([1.5, 4., 1., 1.5, 1., 1., 1.5, 1., 1., 1.5, 1., 1., 1., 1.], shape(prt_params%leaf_long))
128+
129+
! Things from parameter file for EDPftvarcon_inst
130+
allocate(EDPftvarcon_inst%damage_frac(n_pfts))
131+
EDPftvarcon_inst%damage_frac = [0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, &
132+
0.01, 0.01, 0.01, 0.01]
133+
134+
! Derived parameters
135+
! call EDPftvarcon_inst%EDpftconInit()
136+
call param_derived%Init(n_pfts)
83137

84138
! initialize some values
85139
hlm_parteh_mode = prt_carbon_allom_hyp

testing/unit_testing/ecotypes_test/test_Ecotypes.pf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ module test_Ecotypes
1212
use SyntheticPatchTypes, only : synthetic_patch_array_type
1313
use SyntheticPatchTypes, only : forest_tree_fraction_threshold
1414
use SyntheticPatchTypes, only : grass_biomass_threshold
15-
use FatesUnitTestParamReaderMod, only : fates_unit_test_param_reader
1615
use FatesArgumentUtils, only : command_line_arg
1716
use funit
1817

1918
implicit none
2019

2120
! LOCALS:
22-
type(fates_unit_test_param_reader) :: param_reader ! param reader instance
2321
integer :: i
2422
logical :: already_initialized = .false.
2523

@@ -52,10 +50,6 @@ module test_Ecotypes
5250
! Only need to do this for the first test
5351
if (.not. already_initialized) then
5452

55-
! read in parameter file
56-
call param_reader%Init('params.nc')
57-
call param_reader%RetrieveParameters()
58-
5953
! initialize some global data we need
6054
call InitializeGlobals(step_size)
6155

testing/unit_tests.cfg

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
[fire_weather]
22
test_dir = fates_fire_weather_utest
3-
use_param_file = False
43

54
[ecotypes]
65
test_dir = fates_ecotypes_utest
7-
use_param_file = True
86

97
[edge_forest]
108
test_dir = fates_edge_forest_utest
11-
use_param_file = False
129

1310
[fire_fuel]
1411
test_dir = fates_fire_fuel_utest
15-
use_param_file = False
1612

1713
[sort_cohorts]
1814
test_dir = fates_sort_cohorts_utest
19-
use_param_file = False
2015

2116
[insert_cohort]
2217
test_dir = fates_insert_cohort_utest
23-
use_param_file = False
2418

2519
[validate_cohorts]
2620
test_dir = fates_validate_cohorts_utest
27-
use_param_file = False
2821

2922
[count_cohorts]
3023
test_dir = fates_count_cohorts_utest
31-
use_param_file = False
3224

3325
[fire_equations]
3426
test_dir = fates_fire_equations_utest
35-
use_param_file = False

0 commit comments

Comments
 (0)