File: AdBaseFunctions.h

package info (click to toggle)
adun.app 0.81-15
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,384 kB
  • sloc: objc: 70,952; ansic: 6,668; yacc: 394; python: 75; cpp: 36; makefile: 33; xml: 15; awk: 3
file content (43 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef _ADBASEFUNCTIONS_
#define _ADBASEFUNCTIONS_

#include <Base/AdMatrix.h>

#ifdef __GNUC__

/**
Calculates the kinetic energy of a set of particles.
\param velocities A DoubleMatrix with one row for each particle. Each row has three elements
which are the particles velocity.
\param masses An array of doubles. The length is assumed to be the same as the number of rows in \e velocities.
Each element of \e masses must be the mass of the particle in the corresponding row in velcocities.
*/
extern inline double AdCalculateKineticEnergy(DoubleMatrix* velocities, double* masses)
{
	register int j;
	register uintptr_t i;
	double *vhold;
	double **matrix;
	double en, enhold;
	
	matrix = velocities->matrix;
	for(en =0, i=0; i<velocities->no_rows; i++)
	{	
		vhold = matrix[i];
		for(enhold = 0,j=0; j< 3; j++)
			enhold += *(vhold + j)* *(vhold + j);
		
		en += enhold*masses[i];
	}
	en = en*0.5;
	
	return en;
}

#else

double AdCalculateKineticEnergy(DoubleMatrix* velocities, double* masses);

#endif

#endif