Skip to content

Commit

Permalink
simplify code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahm-LANL committed Oct 10, 2023
1 parent 9d19dd4 commit bc25dae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
5 changes: 1 addition & 4 deletions doc/sphinx/src/using-eos.rst
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,13 @@ is summed using the ``Kokkos::parallel_reduce`` functionality in the
// PORTABLE_INLINE_FUNCTION
// decorator here.
void operator()(const T &eos) const {
Real *P = P_; // gets around warnings regarding capture of "this" pointer
Real *rho = rho_;
Real *sie = sie_;
// reduction target
Real tot_diff;
// reduction op
Kokkos::parallel_reduce(
"MyCheckPofRE", N_,
KOKKOS_LAMBDA(const int i, Real &diff) {
diff += std::abs(P[i] - eos.PressureFromDensityInternalEnergy(rho[i], sie[i]));
diff += std::abs(P_[i] - eos.PressureFromDensityInternalEnergy(rho_[i], sie_[i]));
},
tot_diff);
std::cout << "Total difference = " << tot_diff << std::endl;
Expand Down
20 changes: 9 additions & 11 deletions test/test_eos_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,23 +514,20 @@ class CheckPofRE {
public:
CheckPofRE(Real *P, Real *rho, Real *sie, int N) : P_(P), rho_(rho), sie_(sie), N_(N) {}
template <typename T>
void operator()(const T &eos) const {
Real *P = P_; // gets around capture of this pointer
Real *rho = rho_;
Real *sie = sie_;
// must be initialized to zero because portableReduce is a simple for loop on host
int nwrong = 0;
void operator()(const T &eos) {
portableReduce(
"MyCheckPofRE", 0, N_,
PORTABLE_LAMBDA(const int i, int &nw) {
nw += !(isClose(P[i],
eos.PressureFromDensityInternalEnergy(rho[i], sie[i], nullptr),
nw += !(isClose(P_[i],
eos.PressureFromDensityInternalEnergy(rho_[i], sie_[i], nullptr),
1e-15));
},
nwrong);
REQUIRE(nwrong == 0);
}

// must be initialized to zero because portableReduce is a simple for loop on host
int nwrong = 0;

private:
int N_;
Real *P_;
Expand Down Expand Up @@ -564,8 +561,9 @@ SCENARIO("Ideal gas vector Evaluate call", "[IdealGas][Evaluate]") {
P[i] = eos_device.PressureFromDensityInternalEnergy(rho[i], sie[i]);
});
THEN("The vector Evaluate API can be used to compare") {
CheckPofRE myOp(P, rho, sie, N);
eos_device.Evaluate(myOp);
CheckPofRE my_op(P, rho, sie, N);
eos_device.Evaluate(my_op);
REQUIRE(my_op.nwrong == 0);
}
}

Expand Down

0 comments on commit bc25dae

Please sign in to comment.