Commit 1484db71 authored by Aron Helser's avatar Aron Helser

Particles fixed after moving to master.

parent 4a3897ec
......@@ -45,7 +45,7 @@ inline bool IsVertexInsideBounds(const Vertex& v, const Bounds& b)
struct Block
{
Block(int gid_, const Bounds& bounds_, const Bounds& domain_, const Oscillators* oscillators_):
Block(int gid_, const Bounds& bounds_, const Bounds& domain_, const Oscillators& oscillators_):
gid(gid_),
bounds(bounds_),
domain(domain_),
......@@ -69,12 +69,9 @@ struct Block
for (auto& particle : particles)
{
particle.velocity = { 0, 0, 0 };
if (oscillators)
for (auto& o : oscillators)
{
for (auto& o : *oscillators)
{
particle.velocity += o.evaluateGradient(particle.position, t);
}
particle.velocity += o.evaluateGradient(particle.position, t);
}
// normalize
particle.velocity /= std::sqrt(particle.velocity.norm());
......@@ -165,7 +162,7 @@ struct Block
Bounds domain;
Grid grid;
Particles particles;
const Oscillators* oscillators;
Oscillators oscillators;
private:
Block() {} // for create; to let Master manage the blocks
......@@ -295,7 +292,7 @@ int main(int argc, char** argv)
diy::decompose(3, world.rank(), domain, assigner,
[&](int gid, const Bounds&, const Bounds& bounds, const Bounds& domain, const Link& link)
{
auto b = new Block(gid, bounds, domain, &oscillators);
auto b = new Block(gid, bounds, domain, oscillators);
// generate particles
int start = particlesPerBlock * gid;
......
......@@ -10,7 +10,7 @@
struct Oscillator
{
using Vertex = grid::Point<int,3>;
using Vertex = grid::Point<float,3>;
static constexpr float pi = 3.14159265358979323846;
......@@ -41,6 +41,15 @@ struct Oscillator
return 0; // impossible
}
inline Vertex evaluateGradient(const Vertex& x, float t) const {
// let f(x, t) = this->evaluate(x,t) = o(t) * g(x)
// where o = oscillator, g = gaussian
// therefore, df/dx = o * dg/dx
// given g = e^u(t), so dg/dx = e^u * du/dx
// therefore, df/dx = o * e^u * du/dx = f * du/dx
return evaluate(x, t) * ((center - x)/(radius * radius));
}
Vertex center;
float radius;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment