Skip to content

Commit

Permalink
Merge pull request #10 from ipelupessy/fractalcluster_nsmax_fix
Browse files Browse the repository at this point in the history
fix for nsmax problem 

closes #7 7
  • Loading branch information
ipelupessy committed Oct 20, 2015
2 parents 154414e + bc84494 commit 389f001
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/amuse/community/fractalcluster/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def clear_particle_set(self):
class MakeFractalCluster(object):

def __init__(self, N=None, convert_nbody=None, masses=None, do_scale=True,
random_seed=None, fractal_dimension=1.6, virial_ratio=0.5, verbose=False):
random_seed=None, fractal_dimension=1.6, virial_ratio=0.5, verbose=False, match_N=True):
if masses is None:
if N is None:
raise exceptions.AmuseException("Either keyword argument 'N' (number of particles) or "
Expand All @@ -231,6 +231,7 @@ def __init__(self, N=None, convert_nbody=None, masses=None, do_scale=True,
self.fractal_dimension=fractal_dimension
self.virial_ratio=virial_ratio
self.verbose=verbose
self.match_N=match_N

def new_model(self):
generator = FractalCluster(redirection=("none" if self.verbose else "null"))
Expand All @@ -239,6 +240,9 @@ def new_model(self):
if self.random_seed is not None:
generator.parameters.random_seed = self.random_seed
generator.generate_particles()
if self.match_N:
while len(generator.particles)<self.N:
generator.generate_particles()
result = generator.particles.copy()
generator.stop()
result.mass = self.masses
Expand Down
2 changes: 1 addition & 1 deletion src/amuse/community/fractalcluster/src/amuse_helpers.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function amuse_generator() result(err)
endif
if(allocated(r)) deallocate(r,v)
allocate(r(3,nstar),v(3,nstar))
call makefractal(nstar,r,v,fdim,iseed)
n_generated = nstar
call makefractal(n_generated,r,v,fdim,iseed)
end function

end module
7 changes: 5 additions & 2 deletions src/amuse/community/fractalcluster/src/makefractal.f90
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,20 @@ SUBROUTINE makefractal(nstar,rstar,vstar,fdim,idum)
IF (ndo==nsnow) EXIT
END DO
nsmax=ndo - 1
IF (nsmax<nstar) STOP 'nsmax<nstar - change random number seed'
IF (nsmax<nstar) THEN
WRITE(6,*) 'nsmax<nstar - change random number seed'
nstar=nsmax
ENDIF
!
! we now have a fractal of nsmax stars
! need to randomly remove stars until we get nstar
DO
! star to remove
IF (nsmax==nstar) EXIT
is=INT(ran2(idum)*REAL(nsmax)) + 1
r(1:3,is)=r(1:3,nsmax)
v(1:3,is)=v(1:3,nsmax)
nsmax=nsmax - 1
IF (nsmax==nstar) EXIT
END DO
WRITE(6,*) 'Cut to size', nsmax
!
Expand Down

0 comments on commit 389f001

Please sign in to comment.