1
// Copyright (C) 2004-2005 Anders Logg.
2
// Licensed under the GNU GPL Version 2.
4
// First added: 2004-01-19
7
#ifndef __PARTICLE_SYSTEM
8
#define __PARTICLE_SYSTEM
10
#include <dolfin/constants.h>
11
#include <dolfin/ODE.h>
16
/// A ParticleSystem represents a system of particles in three
17
/// dimensions, consisting of a given number of particles and
18
/// obeying Newton's second law:
22
/// where F is the force, m is the mass, and a is the acceleration.
24
/// Positions and velocities are stored in the following order in
25
/// the solution vector u(t):
27
/// u = (x_0, y_0, z_0, ... , x_n-1, y_n-1, z_n-1,
28
/// x_0', y_0', z_0', ... , x_n-1', y_n-1', z_n-1').
30
/// FIXME: Need to implement ODE::feval()
32
class ParticleSystem : public ODE
37
ParticleSystem(unsigned int n, real T, unsigned int dim = 3);
42
/// Return x-component of initial position for particle i
43
virtual real x0(unsigned int i);
45
/// Return y-component of initial position for particle i
46
virtual real y0(unsigned int i);
48
/// Return z-component of initial position for particle i
49
virtual real z0(unsigned int i);
51
/// Return x-component of initial velocity for particle i
52
virtual real vx0(unsigned int i);
54
/// Return x-component of initial velocity for particle i
55
virtual real vy0(unsigned int i);
57
/// Return x-component of initial velocity for particle i
58
virtual real vz0(unsigned int i);
60
/// Return x-component of the force on particle i at time t
61
virtual real Fx(unsigned int i, real t);
63
/// Return y-component of the force on particle i at time t
64
virtual real Fy(unsigned int i, real t);
66
/// Return z-component of the force on particle i at time t
67
virtual real Fz(unsigned int i, real t);
69
/// Return mass of particle i at time t
70
virtual real mass(unsigned int i, real t);
72
/// Return time step for particle i
73
virtual real k(unsigned int i);
75
/// Return initial value for ODE
76
real u0(unsigned int i);
78
/// Return right-hand side for ODE
79
real f(const real u[], real t, unsigned int i);
81
/// Return time step for ODE
82
real timestep(unsigned int i);
86
// Return x-component of current position (inline optimized)
87
real x(unsigned int i) const { return u[dim*i]; }
88
// Return y-component of current position (inline optimized)
89
real y(unsigned int i) const { return u[dim*i + 1]; }
90
// Return z-component of current position (inline optimized)
91
real z(unsigned int i) const { return u[dim*i + 2]; }
92
// Return x-component of current velocity (inline optimized)
93
real vx(unsigned int i) const { return u[offset + dim*i]; }
94
// Return y-component of current velocity (inline optimized)
95
real vy(unsigned int i) const { return u[offset + dim*i + 1]; }
96
// Return z-component of current velocity (inline optimized)
97
real vz(unsigned int i) const { return u[offset + dim*i + 2]; }
99
// Return distance between to particles
100
real dist(unsigned int i, unsigned int j) const;
102
// Number of particles
105
// Number of dimensions
108
// Half the number of components in the ODE system