Skip to content

Commit

Permalink
Rename FortranData
Browse files Browse the repository at this point in the history
  • Loading branch information
jgfouca committed Nov 4, 2024
1 parent 58b70ac commit 576d7b4
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 46 deletions.
14 changes: 7 additions & 7 deletions components/eamxx/src/physics/p3/p3_f90.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {
namespace scream {
namespace p3 {

FortranData::FortranData (Int ncol_, Int nlev_)
P3Data::P3Data (Int ncol_, Int nlev_)
: ncol(ncol_), nlev(nlev_)
{
do_predict_nc = true;
Expand Down Expand Up @@ -62,11 +62,11 @@ FortranData::FortranData (Int ncol_, Int nlev_)
vap_ice_exchange = Array2("sum of vap-ice phase change tendenices", ncol, nlev);
}

FortranDataIterator::FortranDataIterator (const FortranData::Ptr& d) {
P3DataIterator::P3DataIterator (const P3Data::Ptr& d) {
init(d);
}

void FortranDataIterator::init (const FortranData::Ptr& dp) {
void P3DataIterator::init (const P3Data::Ptr& dp) {
d_ = dp;
#define fdipb(name) \
fields_.push_back({#name, \
Expand All @@ -87,8 +87,8 @@ void FortranDataIterator::init (const FortranData::Ptr& dp) {
#undef fdipb
}

const FortranDataIterator::RawArray&
FortranDataIterator::getfield (Int i) const {
const P3DataIterator::RawArray&
P3DataIterator::getfield (Int i) const {
EKAT_ASSERT(i >= 0 || i < nfield());
return fields_[i];
}
Expand All @@ -112,8 +112,8 @@ void p3_init (const bool write_tables, const bool masterproc) {
}
}

int test_FortranData () {
FortranData d(11, 72);
int test_P3Data () {
P3Data d(11, 72);
return 0;
}

Expand Down
24 changes: 12 additions & 12 deletions components/eamxx/src/physics/p3/p3_f90.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace scream {
namespace p3 {

// Data format we can use to communicate with Fortran version.
struct FortranData {
typedef std::shared_ptr<FortranData> Ptr;
struct P3Data {
typedef std::shared_ptr<P3Data> Ptr;

using KT = KokkosTypes<HostDevice>;
using Scalar = Real;
Expand All @@ -36,29 +36,29 @@ struct FortranData {
Array3 p3_tend_out;
Array2 liq_ice_exchange,vap_liq_exchange,vap_ice_exchange;

FortranData(Int ncol, Int nlev);
P3Data(Int ncol, Int nlev);
};

// Iterate over a FortranData's arrays. For examples, see Baseline::write, read.
struct FortranDataIterator {
// Iterate over a P3Data's arrays. For examples, see Baseline::write, read.
struct P3DataIterator {
struct RawArray {
std::string name;
Int dim;
Int extent[3];
FortranData::Scalar* data;
FortranData::Array1::size_type size;
P3Data::Scalar* data;
P3Data::Array1::size_type size;
};

explicit FortranDataIterator(const FortranData::Ptr& d);
explicit P3DataIterator(const P3Data::Ptr& d);

Int nfield () const { return fields_.size(); }
const RawArray& getfield(Int i) const;

private:
FortranData::Ptr d_;
P3Data::Ptr d_;
std::vector<RawArray> fields_;

void init(const FortranData::Ptr& d);
void init(const P3Data::Ptr& d);
};

void p3_init(const bool write_tables = false,
Expand All @@ -68,9 +68,9 @@ void p3_init(const bool write_tables = false,
// to the exact implementation or arithmetic in P3. For now, these checks are
// here to establish that the initial regression-testing code gives results that
// match the python f2py tester, without needing a data file.
Int check_against_python(const FortranData& d);
Int check_against_python(const P3Data& d);

int test_FortranData();
int test_P3Data();

} // namespace p3
} // namespace scream
Expand Down
2 changes: 1 addition & 1 deletion components/eamxx/src/physics/p3/p3_functions_f90.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void p3_init_a_c(Real* ice_table_vals, Real* collect_table_vals);
namespace scream {
namespace p3 {

void p3_init_a(P3InitAFortranData& d)
void p3_init_a(P3InitAP3Data& d)
{
p3_init(); // need to initialize p3 first so that tables are loaded
p3_init_a_c(d.ice_table_vals.data(), d.collect_table_vals.data());
Expand Down
10 changes: 5 additions & 5 deletions components/eamxx/src/physics/p3/p3_functions_f90.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace p3 {

///////////////////////////////////////////////////////////////////////////////

struct P3InitAFortranData
struct P3InitAP3Data
{
// Must use Host as device, f90 code might not be able to use Device memory
using P3F = Functions<Real, HostDevice>;
Expand All @@ -28,9 +28,9 @@ struct P3InitAFortranData
view_ice_table ice_table_vals;
view_collect_table collect_table_vals;

P3InitAFortranData() :
ice_table_vals("P3InitAFortranData::ice_table_vals"),
collect_table_vals("P3InitAFortranData::collect_table_vals")
P3InitAP3Data() :
ice_table_vals("P3InitAP3Data::ice_table_vals"),
collect_table_vals("P3InitAP3Data::collect_table_vals")
{}
};

Expand Down Expand Up @@ -882,7 +882,7 @@ struct PreventLiqSupersaturationData {
PTD_RW_SCALARS_ONLY(2, qi2qv_sublim_tend, qr2qv_evap_tend);
};

void p3_init_a(P3InitAFortranData& d);
void p3_init_a(P3InitAP3Data& d);

/**
* Convenience functions for calling p3 routines from the host with scalar data.
Expand Down
8 changes: 4 additions & 4 deletions components/eamxx/src/physics/p3/p3_ic_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace p3 {
namespace ic {

// From mixed_case_data.py in scream-docs at commit 4bbea4.
FortranData::Ptr make_mixed (const Int ncol, const Int nlev) {
P3Data::Ptr make_mixed (const Int ncol, const Int nlev) {
using consts = scream::physics::Constants<Real>;

const Int nk = nlev;
Int k;
const auto dp = std::make_shared<FortranData>(ncol, nk);
const auto dp = std::make_shared<P3Data>(ncol, nk);
auto& d = *dp;

for (Int i = 0; i < ncol; ++i) {
Expand Down Expand Up @@ -66,7 +66,7 @@ FortranData::Ptr make_mixed (const Int ncol, const Int nlev) {
// To get potential temperature, start by making absolute temperature vary
// between 150K at top of atmos and 300k at surface, then convert to potential
// temp.
FortranData::Array1 T_atm("T", nk);
P3Data::Array1 T_atm("T", nk);
for (k = 0; k < nk; ++k) {
T_atm(k) = 150 + 150/double(nk)*k;
if (i > 0) T_atm(k) += ((i % 3) - 0.5)/double(nk)*k;
Expand Down Expand Up @@ -119,7 +119,7 @@ FortranData::Ptr make_mixed (const Int ncol, const Int nlev) {
return dp;
}

FortranData::Ptr Factory::create (IC ic, Int ncol, Int nlev) {
P3Data::Ptr Factory::create (IC ic, Int ncol, Int nlev) {
switch (ic) {
case mixed: return make_mixed(ncol, nlev);
default:
Expand Down
4 changes: 2 additions & 2 deletions components/eamxx/src/physics/p3/p3_ic_cases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace scream {
namespace p3 {
namespace ic {

FortranData::Ptr make_mixed(Int ncol);
P3Data::Ptr make_mixed(Int ncol);

struct Factory {
enum IC { mixed };

static FortranData::Ptr create(IC ic, Int ncol = 1, Int nlev = 72);
static P3Data::Ptr create(IC ic, Int ncol = 1, Int nlev = 72);
};

} // namespace ic
Expand Down
2 changes: 1 addition & 1 deletion components/eamxx/src/physics/p3/p3_main_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using scream::Int;
namespace scream {
namespace p3 {

Int p3_main_wrap(const FortranData& d) {
Int p3_main_wrap(const P3Data& d) {
EKAT_REQUIRE_MSG(d.dt > 0, "invalid dt");
return p3_main_host(d.qc.data(), d.nc.data(), d.qr.data(), d.nr.data(), d.th_atm.data(),
d.qv.data(), d.dt, d.qi.data(), d.qm.data(), d.ni.data(),
Expand Down
4 changes: 2 additions & 2 deletions components/eamxx/src/physics/p3/p3_main_wrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace scream {
namespace p3 {

struct FortranData;
struct P3Data;

// Returns number of microseconds of p3_main execution
Int p3_main_wrap(const FortranData& d);
Int p3_main_wrap(const P3Data& d);

int test_p3_init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct UnitWrap::UnitTest<D>::TestTableIce : public UnitWrap::UnitTest<D>::Base
Functions::init_kokkos_ice_lookup_tables(ice_table_vals, collect_table_vals);

// Get data from fortran
P3InitAFortranData d;
P3InitAP3Data d;
p3_init_a(d);

// Copy device data to host
Expand Down
14 changes: 7 additions & 7 deletions components/eamxx/src/physics/p3/tests/p3_run_and_cmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ using namespace scream::p3;
* large discrepancies.
*/
Int compare (const double& tol,
const FortranData::Ptr& ref, const FortranData::Ptr& d) {
const P3Data::Ptr& ref, const P3Data::Ptr& d) {

Int nerr = 0;
FortranDataIterator refi(ref), di(d);
P3DataIterator refi(ref), di(d);
EKAT_ASSERT(refi.nfield() == di.nfield());
for (Int i = 0, n = refi.nfield(); i < n; ++i) {
const auto& fr = refi.getfield(i);
Expand Down Expand Up @@ -170,7 +170,7 @@ struct Baseline {
bool do_predict_nc, do_prescribed_CCN;
};

static void set_params (const ParamSet& ps, FortranData& d) {
static void set_params (const ParamSet& ps, P3Data& d) {
// Items not set by factory
d.dt = ps.dt;
d.it = ps.nsteps;
Expand All @@ -180,8 +180,8 @@ struct Baseline {

std::vector<ParamSet> params_;

static void write (const ekat::FILEPtr& fid, const FortranData::Ptr& d) {
FortranDataIterator fdi(d);
static void write (const ekat::FILEPtr& fid, const P3Data::Ptr& d) {
P3DataIterator fdi(d);
for (Int i = 0, n = fdi.nfield(); i < n; ++i) {
const auto& f = fdi.getfield(i);
ekat::write(&f.dim, 1, fid);
Expand All @@ -190,8 +190,8 @@ struct Baseline {
}
}

static void read (const ekat::FILEPtr& fid, const FortranData::Ptr& d) {
FortranDataIterator fdi(d);
static void read (const ekat::FILEPtr& fid, const P3Data::Ptr& d) {
P3DataIterator fdi(d);
for (Int i = 0, n = fdi.nfield(); i < n; ++i) {
const auto& f = fdi.getfield(i);
int dim, ds[3];
Expand Down
8 changes: 4 additions & 4 deletions components/eamxx/src/physics/p3/tests/p3_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

namespace {

TEST_CASE("FortranData", "p3") {
int val = scream::p3::test_FortranData();
TEST_CASE("P3Data", "p3") {
int val = scream::p3::test_P3Data();
REQUIRE(val == 0);
}

TEST_CASE("FortranDataIterator", "p3") {
TEST_CASE("P3DataIterator", "p3") {
using scream::p3::ic::Factory;
const auto d = Factory::create(Factory::mixed);
scream::p3::FortranDataIterator fdi(d);
scream::p3::P3DataIterator fdi(d);
REQUIRE(fdi.nfield() == 35);
const auto& f = fdi.getfield(0);
REQUIRE(f.dim == 2);
Expand Down

0 comments on commit 576d7b4

Please sign in to comment.