Fix force tests
This commit is contained in:
parent
ac44ceaab1
commit
fe6d88306f
2 changed files with 62 additions and 69 deletions
|
@ -21,13 +21,7 @@ __global__ void calc_forces_and_energies(real *xs, real *forces, real *energies,
|
||||||
PotentialType potential) {
|
PotentialType potential) {
|
||||||
int i = blockIdx.x * blockDim.x + threadIdx.x;
|
int i = blockIdx.x * blockDim.x + threadIdx.x;
|
||||||
|
|
||||||
if (i == 0) {
|
|
||||||
printf("n_particles: %d\n", n_particles);
|
|
||||||
printf("box_len: %f %f %f\n", box_len[0], box_len[1], box_len[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i < n_particles) {
|
if (i < n_particles) {
|
||||||
printf("Thread %d, Block %d\n", threadIdx.x, blockIdx.x);
|
|
||||||
real xi = xs[3 * i];
|
real xi = xs[3 * i];
|
||||||
real yi = xs[3 * i + 1];
|
real yi = xs[3 * i + 1];
|
||||||
real zi = xs[3 * i + 2];
|
real zi = xs[3 * i + 2];
|
||||||
|
|
|
@ -92,7 +92,7 @@ TEST_F(CudaForceKernelTest, BasicFunctionalityTest) {
|
||||||
// Set up test data - simple 2x2 grid of particles
|
// Set up test data - simple 2x2 grid of particles
|
||||||
std::vector<real> positions = {
|
std::vector<real> positions = {
|
||||||
0.0, 0.0, 0.0, // particle 0
|
0.0, 0.0, 0.0, // particle 0
|
||||||
1.0, 0.0, 0.0, // particle 1
|
0.5, 0.0, 0.0, // particle 1
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<real> box_dimensions = {10.0, 10.0, 10.0};
|
std::vector<real> box_dimensions = {10.0, 10.0, 10.0};
|
||||||
|
@ -124,67 +124,66 @@ TEST_F(CudaForceKernelTest, BasicFunctionalityTest) {
|
||||||
EXPECT_TRUE(has_nonzero_energy)
|
EXPECT_TRUE(has_nonzero_energy)
|
||||||
<< "Expected non-zero energies for particles ";
|
<< "Expected non-zero energies for particles ";
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// TEST_F(CudaKernelTest, PeriodicBoundaryConditionsTest) {
|
|
||||||
// const int n_particles = 2;
|
|
||||||
// const real tolerance = 1e-5;
|
|
||||||
//
|
|
||||||
// // Place particles near opposite edges of a small box
|
|
||||||
// std::vector<real> positions = {
|
|
||||||
// 0.1, 0.0, 0.0, // particle 0 near left edge
|
|
||||||
// 4.9, 0.0, 0.0 // particle 1 near right edge
|
|
||||||
// };
|
|
||||||
// std::vector<real> box_dimensions = {5.0, 5.0, 5.0}; // Small box to test
|
|
||||||
// PBC
|
|
||||||
//
|
|
||||||
// auto [result_forces, result_energies] =
|
|
||||||
// run_force_calculation(n_particles, &positions, &box_dimensions);
|
|
||||||
//
|
|
||||||
// // With PBC, particles should interact as if they're close (distance ~0.2)
|
|
||||||
// // rather than far apart (distance ~4.8)
|
|
||||||
// EXPECT_GT(std::abs(result_forces[0]), tolerance)
|
|
||||||
// << "Expected significant force due to PBC";
|
|
||||||
// EXPECT_GT(std::abs(result_energies[0]), tolerance)
|
|
||||||
// << "Expected significant energy due to PBC";
|
|
||||||
// }
|
|
||||||
|
|
||||||
// TEST_F(CudaForceKernelTest, SingleParticleTest) {
|
TEST_F(CudaForceKernelTest, PeriodicBoundaryConditionsTest) {
|
||||||
// const int n_particles = 1;
|
const int n_particles = 2;
|
||||||
//
|
const real tolerance = 1e-5;
|
||||||
// std::vector<real> positions = {0.0, 0.0, 0.0};
|
|
||||||
// std::vector<real> box_dimensions = {10.0, 10.0, 10.0};
|
|
||||||
//
|
|
||||||
// auto [result_forces, result_energies] =
|
|
||||||
// run_force_calculation(n_particles, positions, box_dimensions);
|
|
||||||
// // Single particle should have zero force and energy
|
|
||||||
// EXPECT_NEAR(result_forces[0], 0.0, 1e-10);
|
|
||||||
// EXPECT_NEAR(result_forces[1], 0.0, 1e-10);
|
|
||||||
// EXPECT_NEAR(result_forces[2], 0.0, 1e-10);
|
|
||||||
// EXPECT_NEAR(result_energies[0], 0.0, 1e-10);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// TEST_F(CudaKernelTest, ForceSymmetryTest) {
|
// Place particles near opposite edges of a small box
|
||||||
// const int n_particles = 2;
|
std::vector<real> positions = {
|
||||||
// const real tolerance = 1e-5;
|
0.1, 0.0, 0.0, // particle 0 near left edge
|
||||||
//
|
4.9, 0.0, 0.0 // particle 1 near right edge
|
||||||
// std::vector<real> positions = {
|
};
|
||||||
// 0.0, 0.0, 0.0, // particle 0
|
std::vector<real> box_dimensions = {5.0, 5.0, 5.0}; // Small box to test PBC
|
||||||
// 1.5, 0.0, 0.0 // particle 1
|
|
||||||
// };
|
auto [result_forces, result_energies] =
|
||||||
// std::vector<real> box_dimensions = {10.0, 10.0, 10.0};
|
run_force_calculation(n_particles, positions, box_dimensions);
|
||||||
//
|
|
||||||
// auto [result_forces, result_energies] =
|
// With PBC, particles should interact as if they're close (distance ~0.2)
|
||||||
// run_force_calculation(n_particles, &positions, &box_dimensions);
|
// rather than far apart (distance ~4.8)
|
||||||
//
|
EXPECT_GT(std::abs(result_forces[0]), tolerance)
|
||||||
// // Newton's third law: forces should be equal and opposite
|
<< "Expected significant force due to PBC";
|
||||||
// EXPECT_NEAR(result_forces[0], -result_forces[3], tolerance)
|
EXPECT_GT(std::abs(result_energies[0]), tolerance)
|
||||||
// << "Force x-components should be opposite";
|
<< "Expected significant energy due to PBC";
|
||||||
// EXPECT_NEAR(result_forces[1], -result_forces[4], tolerance)
|
}
|
||||||
// << "Force y-components should be opposite";
|
|
||||||
// EXPECT_NEAR(result_forces[2], -result_forces[5], tolerance)
|
TEST_F(CudaForceKernelTest, SingleParticleTest) {
|
||||||
// << "Force z-components should be opposite";
|
const int n_particles = 1;
|
||||||
//
|
|
||||||
// // Energies should be equal for symmetric particles
|
std::vector<real> positions = {0.0, 0.0, 0.0};
|
||||||
// EXPECT_NEAR(result_energies[0], result_energies[1], tolerance)
|
std::vector<real> box_dimensions = {10.0, 10.0, 10.0};
|
||||||
// << "Energies should be equal";
|
|
||||||
// }
|
auto [result_forces, result_energies] =
|
||||||
|
run_force_calculation(n_particles, positions, box_dimensions);
|
||||||
|
// Single particle should have zero force and energy
|
||||||
|
EXPECT_NEAR(result_forces[0], 0.0, 1e-10);
|
||||||
|
EXPECT_NEAR(result_forces[1], 0.0, 1e-10);
|
||||||
|
EXPECT_NEAR(result_forces[2], 0.0, 1e-10);
|
||||||
|
EXPECT_NEAR(result_energies[0], 0.0, 1e-10);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CudaForceKernelTest, ForceSymmetryTest) {
|
||||||
|
const int n_particles = 2;
|
||||||
|
const real tolerance = 1e-5;
|
||||||
|
|
||||||
|
std::vector<real> positions = {
|
||||||
|
0.0, 0.0, 0.0, // particle 0
|
||||||
|
1.5, 0.0, 0.0 // particle 1
|
||||||
|
};
|
||||||
|
std::vector<real> box_dimensions = {10.0, 10.0, 10.0};
|
||||||
|
|
||||||
|
auto [result_forces, result_energies] =
|
||||||
|
run_force_calculation(n_particles, positions, box_dimensions);
|
||||||
|
|
||||||
|
// Newton's third law: forces should be equal and opposite
|
||||||
|
EXPECT_NEAR(result_forces[0], -result_forces[3], tolerance)
|
||||||
|
<< "Force x-components should be opposite";
|
||||||
|
EXPECT_NEAR(result_forces[1], -result_forces[4], tolerance)
|
||||||
|
<< "Force y-components should be opposite";
|
||||||
|
EXPECT_NEAR(result_forces[2], -result_forces[5], tolerance)
|
||||||
|
<< "Force z-components should be opposite";
|
||||||
|
|
||||||
|
// Energies should be equal for symmetric particles
|
||||||
|
EXPECT_NEAR(result_energies[0], result_energies[1], tolerance)
|
||||||
|
<< "Energies should be equal";
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue