Skip to content

Commit

Permalink
Merge pull request #3096 from E3SM-Project/jgfouca/bfb_unit_no_f90
Browse files Browse the repository at this point in the history
Big rework of P3 around new BFB baseline unit tests
  • Loading branch information
jgfouca authored Nov 12, 2024
2 parents aca29bc + e779856 commit 12ed756
Show file tree
Hide file tree
Showing 59 changed files with 1,972 additions and 2,990 deletions.
15 changes: 1 addition & 14 deletions components/eamxx/src/physics/p3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
set(P3_SRCS
p3_f90.cpp
p3_ic_cases.cpp
p3_iso_c.f90
${SCREAM_BASE_DIR}/../eam/src/physics/p3/scream/micro_p3.F90
eamxx_p3_process_interface.cpp
eamxx_p3_run.cpp
)

if (NOT SCREAM_LIB_ONLY)
list(APPEND P3_SRCS
p3_functions_f90.cpp
p3_main_wrap.cpp
) # Add f90 bridges needed for testing
endif()

# Add ETI source files if not on CUDA/HIP
if (NOT EAMXX_ENABLE_GPU OR Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE OR Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE)
list(APPEND P3_SRCS
Expand All @@ -27,6 +18,7 @@ if (NOT EAMXX_ENABLE_GPU OR Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE OR Kokkos
eti/p3_table_ice.cpp
eti/p3_dsd2.cpp
eti/p3_find.cpp
eti/p3_init.cpp
eti/p3_update_prognostics.cpp
eti/p3_get_time_space_phys_variables.cpp
eti/p3_autoconversion.cpp
Expand Down Expand Up @@ -123,11 +115,6 @@ endforeach()
add_executable(p3_tables_setup EXCLUDE_FROM_ALL p3_tables_setup.cpp)
target_link_libraries(p3_tables_setup p3)

#crusher change
if (Kokkos_ENABLE_HIP)
set_source_files_properties(p3_functions_f90.cpp PROPERTIES COMPILE_FLAGS -O0)
endif()

if (NOT SCREAM_LIB_ONLY)
add_subdirectory(tests)
endif()
Expand Down
10 changes: 4 additions & 6 deletions components/eamxx/src/physics/p3/eamxx_p3_process_interface.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "physics/p3/eamxx_p3_process_interface.hpp"
#include "share/property_checks/field_within_interval_check.hpp"
#include "share/property_checks/field_lower_bound_check.hpp"
// Needed for p3_init, the only F90 code still used.
#include "physics/p3/p3_functions.hpp"
#include "physics/p3/p3_f90.hpp"
#include "p3_functions.hpp"
#include "eamxx_p3_process_interface.hpp"

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

// Initialize p3
p3::p3_init(/* write_tables = */ false,
this->get_comm().am_i_root());
P3F::p3_init(/* write_tables = */ false,
this->get_comm().am_i_root());

// Initialize all of the structures that are passed to p3_main in run_impl.
// Note: Some variables in the structures are not stored in the field manager. For these
Expand Down
14 changes: 14 additions & 0 deletions components/eamxx/src/physics/p3/eti/p3_init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "p3_init_impl.hpp"

namespace scream {
namespace p3 {

/*
* Explicit instantiation for doing find functions on Reals using the
* default device.
*/

template struct Functions<Real,DefaultDevice>;

} // namespace p3
} // namespace scream
40 changes: 40 additions & 0 deletions components/eamxx/src/physics/p3/impl/p3_init_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef P3_INIT_IMPL_HPP
#define P3_INIT_IMPL_HPP

#include "p3_functions.hpp" // for ETI only but harmless for GPU

extern "C" {
void micro_p3_utils_init_c(scream::Real Cpair, scream::Real Rair, scream::Real RH2O, scream::Real RHO_H2O,
scream::Real MWH2O, scream::Real MWdry, scream::Real gravit, scream::Real LatVap, scream::Real LatIce,
scream::Real CpLiq, scream::Real Tmelt, scream::Real Pi, bool masterproc);
void p3_init_c(const char** lookup_file_dir, int* info, const bool& write_tables);
}

namespace scream {
namespace p3 {

/*
* Implementation of p3 init. Clients should NOT #include
* this file, #include p3_functions.hpp instead.
*/
template <typename S, typename D>
void Functions<S,D>
::p3_init (const bool write_tables, const bool masterproc) {
static bool is_init = false;
if (!is_init) {
using c = scream::physics::Constants<Real>;
micro_p3_utils_init_c(c::Cpair, c::Rair, c::RH2O, c::RHO_H2O,
c::MWH2O, c::MWdry, c::gravit, c::LatVap, c::LatIce,
c::CpLiq, c::Tmelt, c::Pi, masterproc);
static const char* dir = SCREAM_DATA_DIR "/tables";
Int info;
p3_init_c(&dir, &info, write_tables);
EKAT_REQUIRE_MSG(info == 0, "p3_init_c returned info " << info);
is_init = true;
}
}

} // namespace p3
} // namespace scream

#endif
4 changes: 4 additions & 0 deletions components/eamxx/src/physics/p3/p3_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ struct Functions
static void init_kokkos_ice_lookup_tables(
view_ice_table& ice_table_vals, view_collect_table& collect_table_vals);

static void p3_init(const bool write_tables = false,
const bool masterproc = false);

// Map (mu_r, lamr) to Table3 data.
KOKKOS_FUNCTION
static void lookup(const Spack& mu_r, const Spack& lamr,
Expand Down Expand Up @@ -1468,5 +1471,6 @@ void init_tables_from_f90_c(Real* vn_table_vals_data, Real* vm_table_vals_data,
# include "p3_nr_conservation_impl.hpp"
# include "p3_ni_conservation_impl.hpp"
# include "p3_prevent_liq_supersaturation_impl.hpp"
# include "p3_init_impl.hpp"
#endif // GPU && !KOKKOS_ENABLE_*_RELOCATABLE_DEVICE_CODE
#endif // P3_FUNCTIONS_HPP
Loading

0 comments on commit 12ed756

Please sign in to comment.