Fixed C interface and updated example
This commit is contained in:
parent
69e1a7ad9d
commit
25a54291d0
2 changed files with 15 additions and 10 deletions
12
example.c
12
example.c
|
|
@ -1,25 +1,25 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void etics_external_init(const int n_total);
|
void etics_external_init(const int n_total, const double length_scale);
|
||||||
void etics_external_grav(const double* const A, const int n_act, double x_act[][3], double pot_act[], double a_act[][3]);
|
void etics_external_grav(const double* const A, const int n_act, double x_act[][3], double pot_act[], double a_act[][3]);
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
const int n_total = 1024;
|
const int n_total = 1024;
|
||||||
etics_external_init(n_total);
|
etics_external_init(n_total, 1.);
|
||||||
|
|
||||||
srand(19640916);
|
srand(19640916);
|
||||||
|
|
||||||
double x_act[n_total][3], pot_act[n_total], a_act[n_total][3];
|
double x_act[n_total][3], pot_act[n_total], a_act[n_total][3];
|
||||||
for (int i = 0; i < n_total; i++) {
|
for (int i = 0; i < n_total; i++) {
|
||||||
x_act[i][0] = rand();
|
x_act[i][0] = rand()/(double)RAND_MAX;
|
||||||
x_act[i][1] = rand();
|
x_act[i][1] = rand()/(double)RAND_MAX;
|
||||||
x_act[i][2] = rand();
|
x_act[i][2] = rand()/(double)RAND_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
double A[2048];
|
double A[2048];
|
||||||
for (int i = 0; i < 2048; i++) {
|
for (int i = 0; i < 2048; i++) {
|
||||||
A[i] = rand();
|
A[i] = rand()/(double)RAND_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
etics_external_grav(A, n_total, x_act, pot_act, a_act);
|
etics_external_grav(A, n_total, x_act, pot_act, a_act);
|
||||||
|
|
|
||||||
13
gravity.cpp
13
gravity.cpp
|
|
@ -6,10 +6,11 @@ static grapite::Active_particles* particles_i;
|
||||||
static grapite::Etics_interface* etics_interface;
|
static grapite::Etics_interface* etics_interface;
|
||||||
|
|
||||||
extern "C"
|
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};
|
particles_i = new grapite::Active_particles{n_total};
|
||||||
etics_interface = new grapite::Etics_interface{n_total};
|
etics_interface = new grapite::Etics_interface{n_total};
|
||||||
|
etics::scf::SetLengthScale(length_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
|
|
@ -18,13 +19,17 @@ void etics_external_grav(const double* const A, const int n_act, double x_act[][
|
||||||
// Load coefficients
|
// Load coefficients
|
||||||
std::span A_complex{reinterpret_cast<const Complex*>(A), 1024};
|
std::span A_complex{reinterpret_cast<const Complex*>(A), 1024};
|
||||||
std::copy(begin(A_complex), end(A_complex), etics_interface->A_h);
|
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
|
// Calculate potentials and forces
|
||||||
particles_i->ni_core = 0;
|
particles_i->ni_core = 0;
|
||||||
particles_i->ni_total = n_act;
|
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();
|
particles_i->flush_memory();
|
||||||
etics_interface->calculate_gravity(particles_i, grapite::Selector::halo, 0, pot_act, reinterpret_cast<vec3*>(a_act));
|
etics_interface->calculate_gravity(particles_i, grapite::Selector::halo, 0, pot_act, reinterpret_cast<vec3*>(a_act));
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue