Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion test/test_mean_opacities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,27 +446,42 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") {

constexpr Real kappa = 1.e-20;

// Load analytic Opacity Eos
photons::Gray opac_host(kappa);
// Put it on the GPU
photons::Opacity opac = opac_host.GetOnDevice();

// Load a table Opacity
photons::MeanOpacity mean_opac_host = photons::MeanOpacityBase(
opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT);
// Put it on the GPU
auto mean_opac = mean_opac_host.GetOnDevice();

// This is a part of the catch2 control flow for unit testing.
THEN("The emissivity per nu omega is consistent with the emissity per nu") {
int n_wrong_h = 0;
#ifdef PORTABILITY_STRATEGY_KOKKOS
// Creates a device-side view with the atomic trait when using Kokkos!
// This allocates data on device.
Kokkos::View<int, atomic_view> n_wrong_d("wrong");
#else
// Create something that works like a View but is fine on CPU
PortableMDArray<int> n_wrong_d(&n_wrong_h, 1);
Comment thread
Yurlungur marked this conversation as resolved.
#endif

// This is a for loop that can be device side (default) or host side
portableFor(
"calc mean opacities", 0, 100, PORTABLE_LAMBDA(const int &i) {
// The for loop is called "calc mean opacities"
// It loops over an index from 0 to 100
"calc mean opacities", 0, 100,
// Define a Lambda that takes an argument (we'll cal it i)
PORTABLE_LAMBDA(const int &i) {
// Inside of this lambda, we are calculating these opacities
Real alphaPlanck =
mean_opac.PlanckMeanAbsorptionCoefficient(rho, temp);
Real alphaRosseland =
mean_opac.RosselandMeanAbsorptionCoefficient(rho, temp);
// Check if they're wrong and if they are increase the wrong counter
if (FractionalDifference(kappa * rho, alphaPlanck) > 1.e-12) {
n_wrong_d() += 1;
}
Expand All @@ -476,6 +491,7 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") {
});

#ifdef PORTABILITY_STRATEGY_KOKKOS
// Copies counter from device to host
Kokkos::deep_copy(n_wrong_h, n_wrong_d);
#endif
REQUIRE(n_wrong_h == 0);
Expand Down
Loading