You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge Pull Request #2348 from E3SM-Project/scream/aarondonahue/force_sfc_export_from_file_v2
Automatically Merged using E3SM Pull Request AutoTester
PR Title: Add capability to set surface export values via data from file(s)
PR Author: AaronDonahue
Kokkos::deep_copy(m_export_source_h,FROM_MODEL); // The default is that all export variables will be derived from the EAMxx state.
211
212
m_num_from_model_exports = m_num_scream_exports;
212
-
213
+
214
+
// Parse all fields that will be set by interpolating data from file(s):
215
+
if (m_params.isSublist("prescribed_from_file")) {
216
+
// Retrieve the parameters for prescribed from file
217
+
auto export_from_file_params = m_params.sublist("prescribed_from_file");
218
+
EKAT_REQUIRE_MSG(export_from_file_params.isParameter("fields"),"Error! surface_coupling_exporter::init - prescribed_from_file does not have 'fields' parameter.");
219
+
auto export_from_file_fields = export_from_file_params.get<vos_type>("fields");
220
+
221
+
EKAT_REQUIRE_MSG(export_from_file_params.isParameter("files"),"Error! surface_coupling_exporter::init - prescribed_from_file does not have 'files' parameter.");
222
+
auto export_from_file_names = export_from_file_params.get<vos_type>("files");
223
+
224
+
bool are_fields_present = (std::find(export_from_file_fields.begin(),export_from_file_fields.end(),"NONE") == export_from_file_fields.end()) and (export_from_file_fields.size() > 0);
225
+
bool are_files_present = (std::find(export_from_file_names.begin(),export_from_file_names.end(),"NONE") == export_from_file_names.end()) and (export_from_file_names.size() > 0);
226
+
if (are_fields_present) {
227
+
EKAT_REQUIRE_MSG(are_files_present,"ERROR!! surface_coupling_exporter::init - prescribed_from_file has fields but no files.");
228
+
}
229
+
if (are_files_present) {
230
+
EKAT_REQUIRE_MSG(are_fields_present,"ERROR!! surface_coupling_exporter::init - prescribed_from_file has files but no fields.");
231
+
}
232
+
bool do_export_from_file = are_fields_present and are_files_present;
233
+
if (do_export_from_file) {
234
+
// Construct a time interpolation object
235
+
auto time_interp = util::TimeInterpolation(m_grid,export_from_file_names);
236
+
for (auto fname : export_from_file_fields) {
237
+
// Find the index for this field in the list of export fields.
238
+
auto v_loc = std::find(m_export_field_names_vector.begin(),m_export_field_names_vector.end(),fname);
239
+
EKAT_REQUIRE_MSG(v_loc != m_export_field_names_vector.end(), "ERROR!! surface_coupling_exporter::init - prescribed_from_file has field with name " << fname << " which can't be found in set of exported fields\n.");
240
+
auto idx = v_loc - m_export_field_names_vector.begin();
241
+
EKAT_REQUIRE_MSG(m_export_source_h(idx)==FROM_MODEL,"Error! surface_coupling_exporter::init - attempting to set field " << fname << " export type, which has already been set. Please check namelist options");
242
+
m_export_source_h(idx) = FROM_FILE;
243
+
++m_num_from_file_exports;
244
+
--m_num_from_model_exports;
245
+
auto& f_helper = m_helper_fields.at(fname);
246
+
// We want to add the field as a deep copy so that the helper_fields are automatically updated.
247
+
time_interp.add_field(f_helper, true);
248
+
m_export_from_file_field_names.push_back(fname);
249
+
}
250
+
m_time_interp = time_interp;
251
+
m_time_interp.initialize_data_from_files();
252
+
}
253
+
}
254
+
255
+
// Parse all fields that will be set to a constant value:
213
256
if (m_params.isSublist("prescribed_constants")) {
214
257
auto export_constant_params = m_params.sublist("prescribed_constants");
215
258
EKAT_REQUIRE_MSG(export_constant_params.isParameter("fields"),"Error! surface_coupling_exporter::init - prescribed_constants does not have 'fields' parameter.");
216
259
EKAT_REQUIRE_MSG(export_constant_params.isParameter("values"),"Error! surface_coupling_exporter::init - prescribed_constants does not have 'values' parameter.");
217
260
auto export_constant_fields = export_constant_params.get<vos_type>("fields");
218
261
auto export_constant_values = export_constant_params.get<vor_type>("values");
219
262
EKAT_REQUIRE_MSG(export_constant_fields.size()==export_constant_values.size(),"Error! surface_coupling_exporter::init - prescribed_constants 'fields' and 'values' are not the same size");
220
-
if (export_constant_fields.size()>0) {
263
+
bool are_fields_present = (std::find(export_constant_fields.begin(),export_constant_fields.end(),"NONE") == export_constant_fields.end()) and (export_constant_fields.size() > 0);
264
+
if (are_fields_present) {
221
265
// Determine which fields need constants
222
-
for (int i=0; i<m_num_scream_exports; ++i) { // TODO: This loop would probably be simpler if we just checked which "i" corresponded to each name in the fields list.
223
-
std::string fname = m_export_field_names[i];
224
-
auto loc = std::find(export_constant_fields.begin(),export_constant_fields.end(),fname);
for (int ii=0; ii<export_constant_fields.size(); ii++) {
267
+
auto fname = export_constant_fields[ii];
268
+
// Find the index for this field in the list of export fields.
269
+
auto v_loc = std::find(m_export_field_names_vector.begin(),m_export_field_names_vector.end(),fname);
270
+
EKAT_REQUIRE_MSG(v_loc != m_export_field_names_vector.end(), "ERROR!! surface_coupling_exporter::init - prescribed_constants has field with name " << fname << " which can't be found in set of exported fields\n.");
271
+
auto idx = v_loc - m_export_field_names_vector.begin();
272
+
// This field should not have been set to anything else yet (recall FROM_MODEL is the default)
273
+
EKAT_REQUIRE_MSG(m_export_source_h(idx)==FROM_MODEL,"Error! surface_coupling_exporter::init - attempting to set field " + fname + " export type, which has already been set. Please check namelist options");
EKAT_REQUIRE_MSG(m_num_scream_exports = m_num_const_exports+m_num_from_model_exports,"Error! surface_coupling_exporter - Something went wrong set the type of export for all variables.");
284
+
EKAT_REQUIRE_MSG(m_num_scream_exports = m_num_from_file_exports+m_num_const_exports+m_num_from_model_exports,"Error! surface_coupling_exporter - Something went wrong set the type of export for all variables.");
239
285
EKAT_REQUIRE_MSG(m_num_from_model_exports>=0,"Error! surface_coupling_exporter - The number of exports derived from EAMxx < 0, something must have gone wrong in assigning the types of exports for all variables.");
240
286
241
287
// Perform initial export (if any are marked for export during initialization)
EKAT_REQUIRE_MSG(num_set==m_num_const_exports,"ERROR! SurfaceCouplingExporter::set_constant_exports() - Number of fields set to a constant (" + std::to_string(num_set) +") doesn't match the number recorded at initialization (" + std::to_string(m_num_const_exports) +"). Something went wrong.");
// Sanity check that we don't have multiples of the same timesnap
272
+
EKAT_REQUIRE_MSG(map_of_times_to_vector_idx.count(time)==0,"Error! TimeInterpolation::set_file_data_triplets - The same time step has been encountered more than once in the data files, please check\n"
0 commit comments