Fixed C interface and updated example

This commit is contained in:
Yohai Meiron 2026-03-13 10:56:47 -04:00
parent 69e1a7ad9d
commit 25a54291d0
2 changed files with 15 additions and 10 deletions

View file

@ -6,10 +6,11 @@ static grapite::Active_particles* particles_i;
static grapite::Etics_interface* etics_interface;
extern "C"
void etics_external_init(const int n_total)
void etics_external_init(const int n_total, const double length_scale)
{
particles_i = new grapite::Active_particles{n_total};
etics_interface = new grapite::Etics_interface{n_total};
etics::scf::SetLengthScale(length_scale);
}
extern "C"
@ -18,13 +19,17 @@ void etics_external_grav(const double* const A, const int n_act, double x_act[][
// Load coefficients
std::span A_complex{reinterpret_cast<const Complex*>(A), 1024};
std::copy(begin(A_complex), end(A_complex), etics_interface->A_h);
etics_interface->GetGpuLock();
etics_interface->SendCoeffsToGPU();
etics_interface->ReleaseGpuLock();
// Calculate potentials and forces
particles_i->ni_core = 0;
particles_i->ni_total = n_act;
for (int i = 0; i < n_act; i++) {
grapite::Particle_ext p{};
p.m = 1;
p.t = 0;
p.pos = vec3(x_act[i][0], x_act[i][1], x_act[i][2]);
particles_i->add_particle(i, &p);
}
particles_i->flush_memory();
etics_interface->calculate_gravity(particles_i, grapite::Selector::halo, 0, pot_act, reinterpret_cast<vec3*>(a_act));
}