Skip to content

Commit 12ed756

Browse files
authored
Merge pull request #3096 from E3SM-Project/jgfouca/bfb_unit_no_f90
Big rework of P3 around new BFB baseline unit tests
2 parents aca29bc + e779856 commit 12ed756

File tree

59 files changed

+1972
-2990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1972
-2990
lines changed

components/eamxx/src/physics/p3/CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
set(P3_SRCS
2-
p3_f90.cpp
3-
p3_ic_cases.cpp
42
p3_iso_c.f90
53
${SCREAM_BASE_DIR}/../eam/src/physics/p3/scream/micro_p3.F90
64
eamxx_p3_process_interface.cpp
75
eamxx_p3_run.cpp
86
)
97

10-
if (NOT SCREAM_LIB_ONLY)
11-
list(APPEND P3_SRCS
12-
p3_functions_f90.cpp
13-
p3_main_wrap.cpp
14-
) # Add f90 bridges needed for testing
15-
endif()
16-
178
# Add ETI source files if not on CUDA/HIP
189
if (NOT EAMXX_ENABLE_GPU OR Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE OR Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE)
1910
list(APPEND P3_SRCS
@@ -27,6 +18,7 @@ if (NOT EAMXX_ENABLE_GPU OR Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE OR Kokkos
2718
eti/p3_table_ice.cpp
2819
eti/p3_dsd2.cpp
2920
eti/p3_find.cpp
21+
eti/p3_init.cpp
3022
eti/p3_update_prognostics.cpp
3123
eti/p3_get_time_space_phys_variables.cpp
3224
eti/p3_autoconversion.cpp
@@ -123,11 +115,6 @@ endforeach()
123115
add_executable(p3_tables_setup EXCLUDE_FROM_ALL p3_tables_setup.cpp)
124116
target_link_libraries(p3_tables_setup p3)
125117

126-
#crusher change
127-
if (Kokkos_ENABLE_HIP)
128-
set_source_files_properties(p3_functions_f90.cpp PROPERTIES COMPILE_FLAGS -O0)
129-
endif()
130-
131118
if (NOT SCREAM_LIB_ONLY)
132119
add_subdirectory(tests)
133120
endif()

components/eamxx/src/physics/p3/eamxx_p3_process_interface.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#include "physics/p3/eamxx_p3_process_interface.hpp"
21
#include "share/property_checks/field_within_interval_check.hpp"
32
#include "share/property_checks/field_lower_bound_check.hpp"
4-
// Needed for p3_init, the only F90 code still used.
5-
#include "physics/p3/p3_functions.hpp"
6-
#include "physics/p3/p3_f90.hpp"
3+
#include "p3_functions.hpp"
4+
#include "eamxx_p3_process_interface.hpp"
75

86
#include "ekat/ekat_assert.hpp"
97
#include "ekat/util/ekat_units.hpp"
@@ -243,8 +241,8 @@ void P3Microphysics::initialize_impl (const RunType /* run_type */)
243241
add_postcondition_check<FieldWithinIntervalCheck>(get_field_out("eff_radius_qr"),m_grid,0.0,5.0e3,false);
244242

245243
// Initialize p3
246-
p3::p3_init(/* write_tables = */ false,
247-
this->get_comm().am_i_root());
244+
P3F::p3_init(/* write_tables = */ false,
245+
this->get_comm().am_i_root());
248246

249247
// Initialize all of the structures that are passed to p3_main in run_impl.
250248
// Note: Some variables in the structures are not stored in the field manager. For these
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "p3_init_impl.hpp"
2+
3+
namespace scream {
4+
namespace p3 {
5+
6+
/*
7+
* Explicit instantiation for doing find functions on Reals using the
8+
* default device.
9+
*/
10+
11+
template struct Functions<Real,DefaultDevice>;
12+
13+
} // namespace p3
14+
} // namespace scream
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef P3_INIT_IMPL_HPP
2+
#define P3_INIT_IMPL_HPP
3+
4+
#include "p3_functions.hpp" // for ETI only but harmless for GPU
5+
6+
extern "C" {
7+
void micro_p3_utils_init_c(scream::Real Cpair, scream::Real Rair, scream::Real RH2O, scream::Real RHO_H2O,
8+
scream::Real MWH2O, scream::Real MWdry, scream::Real gravit, scream::Real LatVap, scream::Real LatIce,
9+
scream::Real CpLiq, scream::Real Tmelt, scream::Real Pi, bool masterproc);
10+
void p3_init_c(const char** lookup_file_dir, int* info, const bool& write_tables);
11+
}
12+
13+
namespace scream {
14+
namespace p3 {
15+
16+
/*
17+
* Implementation of p3 init. Clients should NOT #include
18+
* this file, #include p3_functions.hpp instead.
19+
*/
20+
template <typename S, typename D>
21+
void Functions<S,D>
22+
::p3_init (const bool write_tables, const bool masterproc) {
23+
static bool is_init = false;
24+
if (!is_init) {
25+
using c = scream::physics::Constants<Real>;
26+
micro_p3_utils_init_c(c::Cpair, c::Rair, c::RH2O, c::RHO_H2O,
27+
c::MWH2O, c::MWdry, c::gravit, c::LatVap, c::LatIce,
28+
c::CpLiq, c::Tmelt, c::Pi, masterproc);
29+
static const char* dir = SCREAM_DATA_DIR "/tables";
30+
Int info;
31+
p3_init_c(&dir, &info, write_tables);
32+
EKAT_REQUIRE_MSG(info == 0, "p3_init_c returned info " << info);
33+
is_init = true;
34+
}
35+
}
36+
37+
} // namespace p3
38+
} // namespace scream
39+
40+
#endif

components/eamxx/src/physics/p3/p3_functions.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ struct Functions
357357
static void init_kokkos_ice_lookup_tables(
358358
view_ice_table& ice_table_vals, view_collect_table& collect_table_vals);
359359

360+
static void p3_init(const bool write_tables = false,
361+
const bool masterproc = false);
362+
360363
// Map (mu_r, lamr) to Table3 data.
361364
KOKKOS_FUNCTION
362365
static void lookup(const Spack& mu_r, const Spack& lamr,
@@ -1468,5 +1471,6 @@ void init_tables_from_f90_c(Real* vn_table_vals_data, Real* vm_table_vals_data,
14681471
# include "p3_nr_conservation_impl.hpp"
14691472
# include "p3_ni_conservation_impl.hpp"
14701473
# include "p3_prevent_liq_supersaturation_impl.hpp"
1474+
# include "p3_init_impl.hpp"
14711475
#endif // GPU && !KOKKOS_ENABLE_*_RELOCATABLE_DEVICE_CODE
14721476
#endif // P3_FUNCTIONS_HPP

0 commit comments

Comments
 (0)