#### Previous topic

Programming examples II

<no title>

# Testing Procedures¶

The procedure used in the tests is based on a comparison between a numerical solution and an analytical solution.

Considering that the three bodies problem does not have a known analytical solution, the problems used in the tests generally will be based on systems of two particles, except in special cases.

Tests currently implemented:

1. Free fall in a drag fluid.
2. Harmonic motion
3. Damped harmonic motion

For executiong the tests via pyparticles_add we must use the option -d

pyparticles_add -d <test_name>

Commands for executing available tests:

pyparticles_app -t fall
pyparticles_app -t harmonic
pyparticles_app -t dharmonic

## Test problems definitions¶

### Free fall in a drag fluid¶

The free fall test is based on a single particle that falls in a constant force field with a drag fluid (or air).

The equation of motion is defined as follow:

Where:

And as initial condition I’ve used:

The analytical solution is given by the following expression:

In pyparticles the problem is desribed as follow:

constf = cf.ConstForce( self.pset.size , u_force=[ 0 , 0 , -10.0 ] , dim=self.pset.dim )
drag = dr.Drag( self.pset.size , Consts=1.0 )

multi = mf.MultipleForce( self.pset.size )

multi.append_force( constf )
multi.append_force( drag )

multi.set_masses( self.pset.M )


### Harmonic motion¶

The first particle is fixed to a point while the second free to move.

The equation of motion is defined as follow:

Where:

And as initial condition I’ve used:

The analytical solution is given by the following expression:

In pyparticles the problem is desribed as follow:

self.pset.X[0,:] = 0.0
self.pset.X[1,:] = 1.0 / np.sqrt(3)

ci = np.array( [ 0 ] )
cx = np.array( [ 0.0 , 0.0 , 0.0 ] )

costrs = csx.ConstrainedX( self.pset )

self.t = np.zeros(( self.steps ))
self.x = np.zeros(( self.steps , self.pset.dim ))

self.xn = np.zeros(( self.steps , self.pset.dim ))

spring = ls.LinearSpring( self.pset.size , self.pset.dim , Consts=1.0 )


### Damped Harmonic motion¶

The first particle is fixed to a point while the second free to move. The damping force has a magnitude proportional to the velocity.

The equation of motion is defined as follow:

Where:

And as initial condition I’ve used:

The analytical solution is given by the following expressions:

The magnitude of is:

The vectorized and effective solution of the initial value problem, is:

In pyparticles the problem is desribed as follow:

self.pset.X[0,:] = 0.0
self.pset.X[1,:] = 1.0 / np.sqrt(3)

ci = np.array( [ 0 ] )
cx = np.array( [ 0.0 , 0.0 , 0.0 ] )

costrs = csx.ConstrainedX( self.pset )

spring = ls.LinearSpring( self.pset.size , self.pset.dim , Consts=1.0 )
damp = da.Damping( self.pset.size , self.pset.dim , Consts=0.5 )

multi = mf.MultipleForce( self.pset.size )

multi.append_force( spring )
multi.append_force( damp )

multi.set_masses( self.pset.M )


## Tests results¶

Below are shown evolution of the absolute error in the problems described above, we can see that the error is always low and reasonably acceptable.

(To see the image at full size, it must be opened in another tab)