Skip to content

Commit

Permalink
Moved parameter values to parameter file
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-menke committed Jun 30, 2021
1 parent 2cdf2d5 commit ed0b693
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
19 changes: 10 additions & 9 deletions SPH-CUDA/helper_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ struct Parameters {
int thread_groups_cell;

/* Particle spawn parameters */
float spawn_dist; // unit: coordinates
int edge_length; // unit: particles
float3 spawn_offset; // unit: coordinates
float spawn_dist; // unit: coordinates
int edge_length; // unit: particles
float3 spawn_offset; // unit: coordinates

/* Visualization parameters */
float particle_radius;
Expand All @@ -81,12 +81,13 @@ struct Parameters {
const_visc(15 / (2 * float(M_PI) * powf(h, 3))),
const_surf(3 / (2 * float(M_PI) * powf(h, 3))),

h(1.), h_inv(1 / h), h2(h* h), h3(h* h* h),
k(.01), p0(1.), e(.02), s(0.1), mass(1.), g(make_float3(0, -9.81, 0)),
h(std::stof(params["h"])), h_inv(1 / h), h2(h* h), h3(h* h* h),
k(std::stof(params["k"])), p0(std::stof(params["p0"])), e(std::stof(params["e"])), s(std::stof(params["s"])),
mass(std::stof(params["mass"])), g(make_float3(0, std::stof(params["g"]), 0)),

damping(std::stof(params["boundary_damping"])),
min_box_bound(make_float3(-10., 0., -10.)),
max_box_bound(make_float3(10., 20., 10.)),
min_box_bound(make_float3(std::stof(params["min_box_x"]), std::stof(params["min_box_y"]), std::stof(params["min_box_z"]))),
max_box_bound(make_float3(std::stof(params["max_box_x"]), std::stof(params["max_box_y"]), std::stof(params["max_box_z"]))),
cell_dims((max_box_bound - min_box_bound) / h),
cell_size((max_box_bound - min_box_bound) / cell_dims),
cell_num(int(cell_dims.x* cell_dims.y* cell_dims.z)),
Expand All @@ -95,9 +96,9 @@ struct Parameters {
thread_groups_part(int((particle_num + threads_per_group - 1) / threads_per_group)),
thread_groups_cell(int((cell_num + threads_per_group - 1) / threads_per_group)),

spawn_dist(2.),
spawn_dist(std::stof(params["spawn_dist"])),
edge_length(powf(particle_num, 1./3.)),
spawn_offset(make_float3(0., 10., 0.)),
spawn_offset(make_float3(std::stof(params["spawn_off_x"]), std::stof(params["spawn_off_y"]), std::stof(params["spawn_off_z"]))),

particle_radius(std::stof(params["particle_radius"]))
{}
Expand Down
9 changes: 5 additions & 4 deletions SPH-CUDA/main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,18 @@ int main() {

/* Spawns particles in a cubic shape */
void initializeParticles(std::vector<Particle>& particles, Parameters& p) {
// calculate shift in order to spawn the cubic shape in the center of the box
// shift equals half of the length of the cubic shape
// Calculate shift in order to spawn the cubic shape in the center of the box
// Shift equals half of the length of the cubic shape
float shift = (p.edge_length * p.spawn_dist) / 2;

for (int i = 0; i < p.particle_num; i++) {
// calculate cubic shape

// Calculate cubic shape
float x = (i % p.edge_length) * p.spawn_dist;
float y = ((i / p.edge_length) % p.edge_length) * p.spawn_dist;
float z = (i / (p.edge_length * p.edge_length)) * p.spawn_dist;

// add offsets
// Add offsets
x += p.spawn_offset.x - shift;
y += p.spawn_offset.y - shift;
z += p.spawn_offset.z - shift;
Expand Down
36 changes: 30 additions & 6 deletions SPH-CUDA/parameter_files/params_0.par
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
particle_num 512
timestep 0.001
threads_per_group 64
integrator euler
boundary_damping 0.8
particle_radius 1.0
particle_num 512
timestep 0.001

integrator euler

h 3.0

k 0.01
p0 1.0
e 0.02
s 0.1
mass 1.0
g -9.81

boundary_damping 0.8
min_box_x -10.0
min_box_y -0.0
min_box_z -10.0
max_box_x 10.0
max_box_y 20.0
max_box_z 10.0

threads_per_group 128

spawn_dist 2.0
spawn_off_x 0.0
spawn_off_y 10.0
spawn_off_z 0.0

particle_radius 1.0

0 comments on commit ed0b693

Please sign in to comment.