Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uninitialised counter variable #1095

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 52 additions & 51 deletions src/amuse/community/huayno/src/evolve_sf.c
LourensVeen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@
static void drift_naive(int clevel,struct sys s, DOUBLE etime); /* drift/extrap sys to itime*/
static void split(FLOAT dt, struct sys s, struct sys *slow, struct sys *fast);

void evolve_split_pass(int clevel,struct sys sys1,struct sys sys2,
void evolve_split_pass(int clevel,struct sys sys1,struct sys sys2,
DOUBLE stime, DOUBLE etime, DOUBLE dt, int calc_timestep)
{
struct sys slow=zerosys,fast=zerosys;
CHECK_TIMESTEP(etime,stime,dt,clevel);
if(calc_timestep) timestep(clevel,sys1, join(sys1,sys2), SIGN(dt));
// if(calc_timestep) timestep(clevel,sys1, sys1, SIGN(dt));
split((FLOAT) dt, sys1, &slow, &fast);
if(fast.n==0)
if(fast.n==0)
{
diag->deepsteps++;
diag->simtime+=dt;
}
}
if(fast.n>0) evolve_split_pass(clevel+1,fast, join(slow,sys2), stime, stime+dt/2, dt/2,0);
if(slow.n>0) kdk(clevel,slow,sys2, stime, etime, dt);
if(fast.n>0) evolve_split_pass(clevel+1,fast, join(slow,sys2), stime+dt/2, etime, dt/2,1);
}

void evolve_split_naive(int clevel,struct sys sys1,struct sys sys2,
void evolve_split_naive(int clevel,struct sys sys1,struct sys sys2,
DOUBLE stime, DOUBLE etime, DOUBLE dt, int calc_timestep)
{
struct sys slow=zerosys,fast=zerosys;
CHECK_TIMESTEP(etime,stime,dt,clevel);
if(calc_timestep) timestep(clevel,sys1, join(sys1,sys2), SIGN(dt));
// if(calc_timestep) timestep(clevel,sys1, sys1, SIGN(dt));
split((FLOAT) dt, sys1, &slow, &fast);
if(fast.n==0)
if(fast.n==0)
{
diag->deepsteps++;
diag->simtime+=dt;
}
}
if(slow.n>0) kick(clevel,slow, join(sys1,sys2), dt/2);
if(fast.n>0) evolve_split_naive(clevel+1,fast, join(slow,sys2), stime, stime+dt/2, dt/2,0);
if(slow.n>0) drift_naive(clevel,join(slow,sys2),stime+dt/2);
Expand All @@ -51,11 +51,11 @@ void evolve_split_bridge(int clevel,struct sys s, DOUBLE stime, DOUBLE etime, DO
CHECK_TIMESTEP(etime,stime,dt,clevel);
if(calc_timestep) timestep(clevel,s,s, SIGN(dt));
split((FLOAT) dt, s, &slow, &fast);
if(fast.n==0)
if(fast.n==0)
{
diag->deepsteps++;
diag->simtime+=dt;
}
}
if(slow.n>0 && fast.n>0) kick(clevel,slow, fast, dt/2);
if(slow.n>0 && fast.n>0) kick(clevel,fast, slow, dt/2);
if(fast.n>0) evolve_split_bridge(clevel+1,fast, stime, stime+dt/2, dt/2,0); /* note calc_timestep? */
Expand All @@ -71,11 +71,11 @@ void evolve_split_bridge_dkd(int clevel,struct sys s, DOUBLE stime, DOUBLE etime
CHECK_TIMESTEP(etime,stime,dt,clevel);
if(calc_timestep) timestep(clevel,s,s, SIGN(dt));
split((FLOAT) dt, s, &slow, &fast);
if(fast.n==0)
if(fast.n==0)
{
diag->deepsteps++;
diag->simtime+=dt;
}
}
if(slow.n>0 && fast.n>0) kick(clevel,slow, fast, dt/2);
if(slow.n>0 && fast.n>0) kick(clevel,fast, slow, dt/2);
if(fast.n>0) evolve_split_bridge_dkd(clevel+1,fast, stime, stime+dt/2, dt/2,0); /* note calc_timestep? */
Expand All @@ -91,11 +91,11 @@ void evolve_split_hold(int clevel,struct sys s, DOUBLE stime, DOUBLE etime, DOUB
CHECK_TIMESTEP(etime,stime,dt,clevel);
if(calc_timestep) timestep(clevel,s,s, SIGN(dt));
split((FLOAT) dt, s, &slow, &fast);
if(fast.n==0)
if(fast.n==0)
{
diag->deepsteps++;
diag->simtime+=dt;
}
}
if(fast.n>0) evolve_split_hold(clevel+1,fast, stime, stime+dt/2, dt/2,0);
if(slow.n>0) kdk(clevel,slow,fast,stime,etime,dt);
if(fast.n>0) evolve_split_hold(clevel+1,fast, stime+dt/2, etime, dt/2,1);
Expand All @@ -107,56 +107,56 @@ void evolve_split_hold_dkd(int clevel,struct sys s, DOUBLE stime, DOUBLE etime,
CHECK_TIMESTEP(etime,stime,dt,clevel);
if(calc_timestep) timestep(clevel,s,s, SIGN(dt));
split((FLOAT) dt, s, &slow, &fast);
if(fast.n==0)
if(fast.n==0)
{
diag->deepsteps++;
diag->simtime+=dt;
}
}
if(fast.n>0) evolve_split_hold_dkd(clevel+1,fast, stime, stime+dt/2, dt/2,0);
if(slow.n>0) dkd(clevel,slow,fast,stime,etime,dt);
if(fast.n>0) evolve_split_hold_dkd(clevel+1,fast, stime+dt/2, etime, dt/2,1);
}

void evolve_split_pass_dkd(int clevel,struct sys sys1,struct sys sys2,
void evolve_split_pass_dkd(int clevel,struct sys sys1,struct sys sys2,
DOUBLE stime, DOUBLE etime, DOUBLE dt, int calc_timestep)
{
struct sys slow=zerosys,fast=zerosys;
CHECK_TIMESTEP(etime,stime,dt,clevel);
if(calc_timestep) timestep(clevel,sys1, join(sys1,sys2), SIGN(dt));
// if(calc_timestep) timestep(clevel,sys1, sys1, SIGN(dt));
split((FLOAT) dt, sys1, &slow, &fast);
if(fast.n==0)
if(fast.n==0)
{
diag->deepsteps++;
diag->simtime+=dt;
}
}
if(fast.n>0) evolve_split_pass_dkd(clevel+1,fast, join(slow,sys2), stime, stime+dt/2, dt/2,0);
if(slow.n>0) dkd(clevel,slow,sys2, stime, etime, dt);
if(fast.n>0) evolve_split_pass_dkd(clevel+1,fast, join(slow,sys2), stime+dt/2, etime, dt/2,1);
}

void evolve_split_ppass_dkd(int clevel,struct sys sys1,struct sys sys2,
void evolve_split_ppass_dkd(int clevel,struct sys sys1,struct sys sys2,
DOUBLE stime, DOUBLE etime, DOUBLE dt, int calc_timestep)
{
struct sys slow=zerosys,fast=zerosys;
CHECK_TIMESTEP(etime,stime,dt,clevel);
if(calc_timestep) timestep(clevel,sys1, join(sys1,sys2), SIGN(dt));
// if(calc_timestep) timestep(clevel,sys1, sys1, SIGN(dt));
split((FLOAT) dt, sys1, &slow, &fast);
if(fast.n==0)
if(fast.n==0)
{
diag->deepsteps++;
diag->simtime+=dt;
}
if(fast.n>0)
}
if(fast.n>0)
evolve_split_ppass_dkd(clevel+1,fast, join(slow,sys2), stime, stime+dt/2, dt/2,0);
else
else
drift(clevel,join(slow,sys2),etime,dt/2);
if(slow.n>0) kick(clevel,slow,join(slow,sys2), dt);
if(slow.n>0) kick(clevel,sys2,slow, dt);
if(fast.n>0)
if(fast.n>0)
evolve_split_ppass_dkd(clevel+1,fast, join(slow,sys2), stime+dt/2, etime, dt/2,1);
else
else
drift(clevel,join(slow,sys2),etime,dt/2);
}

Expand Down Expand Up @@ -193,21 +193,21 @@ void evolve_sf_4m5(int clevel,struct sys s, DOUBLE stime, DOUBLE etime, DOUBLE d
CHECK_TIMESTEP(etime,stime,dt,clevel);
if(calc_timestep) timestep(clevel,s,s, SIGN(dt));
split((FLOAT) dt, s, &slow, &fast);
if(fast.n==0)
if(fast.n==0)
{
diag->deepsteps++;
diag->simtime+=dt;
diag->timetrack+=fabs(dt);
}
}
if(slow.n>0) kick(clevel,slow,join(fast,slow), K1*dt);
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K1*dt);

if(slow.n>0) drift(clevel,slow,stime+D1*dt,D1*dt);
if(fast.n>0)
if(fast.n>0)
for(i=0;i<N1;i++)
{
evolve_sf_4m5(clevel+1,fast,stime,stime+D1*dt/N1,D1*dt/N1,i==0?0:1);
stime+=D1*dt/N1;
stime+=D1*dt/N1;
}
if(slow.n>0) kick(clevel,slow,join(fast,slow), K2*dt);
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K2*dt);
Expand All @@ -220,7 +220,7 @@ void evolve_sf_4m5(int clevel,struct sys s, DOUBLE stime, DOUBLE etime, DOUBLE d
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K3*dt);

if(slow.n>0) drift(clevel,slow,stime+D3*dt,D3*dt);
if(fast.n>0)
if(fast.n>0)
for(i=0;i<N1;i++)
{
evolve_sf_4m5(clevel+1,fast,stime,stime+D3*dt/N1,D3*dt/N1,1);
Expand All @@ -237,14 +237,14 @@ void evolve_sf_4m5(int clevel,struct sys s, DOUBLE stime, DOUBLE etime, DOUBLE d
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K2*dt);

if(slow.n>0) drift(clevel,slow,etime,D1*dt);
if(fast.n>0)
if(fast.n>0)
for(i=0;i<N1;i++)
{
evolve_sf_4m5(clevel+1,fast,stime,i==N1-1?etime:stime+D1*dt/N1,D1*dt/N1,1);
stime+=D1*dt/N1;
stime+=D1*dt/N1;
}
if(slow.n>0) kick(clevel,slow,join(fast,slow), K1*dt);
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K1*dt);
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K1*dt);
}
#undef K1
#undef K2
Expand All @@ -258,7 +258,7 @@ void evolve_sf_4m5(int clevel,struct sys s, DOUBLE stime, DOUBLE etime, DOUBLE d
#define K2 ( 121*(12- sqrt( (DOUBLE) 471 ) )/3924 )
#define K3 ( 1-2*(K1+K2) )
#define D1 ( ((DOUBLE) 6)/11 )
#define D2 ( ((DOUBLE) 0.5)-D1 )
#define D2 ( ((DOUBLE) 0.5)-D1 )
#define N1 12
void evolve_sf_4m4(int clevel,struct sys s, DOUBLE stime, DOUBLE etime, DOUBLE dt, int calc_timestep)
{
Expand All @@ -267,21 +267,21 @@ void evolve_sf_4m4(int clevel,struct sys s, DOUBLE stime, DOUBLE etime, DOUBLE d
CHECK_TIMESTEP(etime,stime,dt,clevel);
if(calc_timestep) timestep(clevel,s,s, SIGN(dt));
split((FLOAT) dt, s, &slow, &fast);
if(fast.n==0)
if(fast.n==0)
{
diag->deepsteps++;
diag->simtime+=dt;
diag->timetrack+=fabs(dt);
}
}
if(slow.n>0) kick(clevel,slow,join(fast,slow), K1*dt);
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K1*dt);

if(slow.n>0) drift(clevel,slow,stime+D1*dt,D1*dt);
if(fast.n>0)
if(fast.n>0)
for(i=0;i<N1;i++)
{
evolve_sf_4m5(clevel+1,fast,stime,stime+D1*dt/N1,D1*dt/N1,i==0?0:1);
stime+=D1*dt/N1;
stime+=D1*dt/N1;
}
if(slow.n>0) kick(clevel,slow,join(fast,slow), K2*dt);
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K2*dt);
Expand All @@ -301,37 +301,38 @@ void evolve_sf_4m4(int clevel,struct sys s, DOUBLE stime, DOUBLE etime, DOUBLE d
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K2*dt);

if(slow.n>0) drift(clevel,slow,etime,D1*dt);
if(fast.n>0)
if(fast.n>0)
for(i=0;i<N1;i++)
{
evolve_sf_4m5(clevel+1,fast,stime,i==N1-1?etime:stime+D1*dt/N1,D1*dt/N1,1);
stime+=D1*dt/N1;
stime+=D1*dt/N1;
}
if(slow.n>0) kick(clevel,slow,join(fast,slow), K1*dt);
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K1*dt);
if(fast.n>0 && slow.n>0) kick(clevel,fast,slow, K1*dt);
}
#undef K1
#undef K2
#undef K3
#undef D1
#undef D2

// partitions a contiguous array bordered by left and right according to a pivot timestep dt
// partitions a contiguous array bordered by left and right according to a pivot timestep dt
static struct particle *partition(FLOAT dt, struct particle *left, struct particle *right)
{
UINT i,n;
dt=fabs(dt);
i=0;
n=right-left+1;
while(1)
{
if(i>=n) ENDRUN("partition error");
i++;
while(left->timestep<dt && left<right) left++;
while(right->timestep>=dt && left<right) right--;
if(left<right)
if(left<right)
{SWAP( *left, *right, struct particle);}
else
break;
else
break;
}
if(left->timestep<dt) left++;
return left;
Expand All @@ -340,8 +341,8 @@ static struct particle *partition(FLOAT dt, struct particle *left, struct partic
static void split(FLOAT dt, struct sys s, struct sys *slow, struct sys *fast)
{
struct particle *left, *right, *pivot;
slow->n=0;
fast->n=0;
slow->n=0;
fast->n=0;
if(s.n-s.nzero>0)
{
left=s.part;
Expand All @@ -350,24 +351,24 @@ static void split(FLOAT dt, struct sys s, struct sys *slow, struct sys *fast)
slow->n=right-pivot+1;
fast->n=(pivot-left);
}
slow->nzero=0;
fast->nzero=0;
slow->nzero=0;
fast->nzero=0;
if(s.nzero>0)
{
left=s.zeropart;
right=LASTZERO(s);
pivot=partition(dt, left, right);
slow->nzero=right-pivot+1;
fast->nzero=(pivot-left);
fast->nzero=(pivot-left);
slow->n+=slow->nzero;
fast->n+=fast->nzero;
fast->n+=fast->nzero;
}
if(fast->n<=1)
{
*fast=zerosys;
slow->n=s.n;
slow->nzero=s.nzero;
}
}
if(slow->n>0)
{
slow->part=s.part+fast->n-fast->nzero;
Expand Down
Loading