MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / initial_conditions_galaxy

Function initial_conditions_galaxy

examples/graphics/gravity_sim.cpp:40–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40void initial_conditions_galaxy(af::array &mass, vector<af::array> &pos,
41 vector<af::array> &vels,
42 vector<af::array> &forces) {
43 af::array initial_cond_consts(af::dim4(7, total_particles), hbd);
44 initial_cond_consts = initial_cond_consts.T();
45
46 for (int i = 0; i < (int)pos.size(); ++i) {
47 pos[i] = af::randn(total_particles) * width + width;
48 vels[i] = 0 * (af::randu(total_particles) - 0.5);
49 forces[i] = af::constant(0, total_particles);
50 }
51
52 mass = initial_cond_consts(span, 0);
53 pos[0] = (initial_cond_consts(span, 1) / 32 + 0.6) * width;
54 pos[1] = (initial_cond_consts(span, 2) / 32 + 0.3) * height;
55 pos[2] = (initial_cond_consts(span, 3) / 32 + 0.5) * depth;
56 vels[0] = (initial_cond_consts(span, 4) / 32) * width;
57 vels[1] = (initial_cond_consts(span, 5) / 32) * height;
58 vels[2] = (initial_cond_consts(span, 6) / 32) * depth;
59
60 pos[0](seq(0, pos[0].dims(0) - 1, 2)) -= 0.4 * width;
61 pos[1](seq(0, pos[0].dims(0) - 1, 2)) += 0.4 * height;
62 vels[0](seq(0, pos[0].dims(0) - 1, 2)) += 4;
63
64 min_mass = min<float>(mass);
65 mass_range = max<float>(mass) - min<float>(mass);
66}
67
68af::array ids_from_pos(vector<af::array> &pos) {
69 return (pos[0].as(u32) * height) + pos[1].as(u32);

Callers 1

mainFunction · 0.85

Calls 7

randnFunction · 0.85
randuFunction · 0.85
constantFunction · 0.85
seqClass · 0.85
TMethod · 0.80
dim4Class · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected