~hrg/hrg-packaging/zm

« back to all changes in this revision

Viewing changes to example/ode/ode2_leapfrog_test.c

  • Committer: Yosuke Matsusaka
  • Date: 2016-01-12 04:52:39 UTC
  • Revision ID: yosuke.matsusaka@gmail.com-20160112045239-cy93cfjhdtpjf17w
initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <zm/zm_ode.h>
 
2
 
 
3
/* sample: unit circle function */
 
4
zVec ddp(double t, zVec x, zVec v, void *dummy, zVec a)
 
5
{
 
6
  zVecSetElem( a, 0,-zVecElem(x,0) );
 
7
  return a;
 
8
}
 
9
 
 
10
#define DT 0.1
 
11
#define T  1000.0
 
12
 
 
13
void output2(zVec x, zVec v)
 
14
{
 
15
  printf( "%f %f\n", zVecElem(x,0), zVecElem(v,0) );
 
16
}
 
17
 
 
18
int main(void)
 
19
{
 
20
  zODE2 ode;
 
21
  zVec x, v;
 
22
  double t;
 
23
 
 
24
  zODE2Assign( &ode, Leapfrog, NULL, NULL, NULL, NULL );
 
25
  zODE2Init( &ode, 1, 0, ddp );
 
26
  x = zVecCreateList( 1, 1.0 );
 
27
  v = zVecAlloc( 1 );
 
28
  zODE2InitHistLeapfrog( &ode, x, v, DT );
 
29
  output2( x, v );
 
30
  for( t=0; t<T; t+=DT ){
 
31
    zODE2Update( &ode, t, x, v, DT, NULL );
 
32
    output2( x, v );
 
33
  }
 
34
  zVecFree( x );
 
35
  zVecFree( v );
 
36
  zODE2Destroy( &ode );
 
37
  return 0;
 
38
}