コード例 #1
0
ファイル: bdb_concurrent.py プロジェクト: kb3vwt/swarm
        def do_integration():
            cfg = swarmng.config(nsys=64,
                                 nbod=3,
                                 log_writer='bdb',
                                 log_output_db=output_file_name,
                                 log_interval=1,
                                 integrator='hermite_cpu_log',
                                 time_step=0.01,
                                 nogpu=1)
            ref = swarmng.generate_ensemble(cfg)
            ens = ref.clone()

            swarmng.init(cfg)

            integ = swarmng.Integrator.create(cfg)

            integ.ensemble = ens

            swarmng.sync
            for i in range(1, final_time + 1):
                integ.destination_time = i
                integ.integrate()
コード例 #2
0
ファイル: bdb_concurrent.py プロジェクト: AstroGPU/swarm
    def do_integration():
      cfg = swarmng.config(
	nsys=64,
	nbod=3,
	log_writer='bdb',
	log_output_db=output_file_name,
	log_interval=1,
	integrator='hermite_cpu_log',
	time_step=0.01,
	nogpu=1
      );
      ref = swarmng.generate_ensemble( cfg )
      ens = ref.clone()

      swarmng.init(cfg)

      integ = swarmng.Integrator.create( cfg )

      integ.ensemble = ens
    
      swarmng.sync
      for i in range(1,final_time+1):
	integ.destination_time = i
	integ.integrate()
コード例 #3
0
#
# Source code for this tutorial can be found at @ref py/tutorial.py
#
# First thing is to import swarmng package. It is located in `\<SOURCE DIRECTORY\>/py/swarmng/`
# It takes care of loading the libswarmng_ext.so; it also contains some Pythonified
# API on top of libswarmng_ext. But please run the scripts
# from your build directory so swarmng can find your libraries.
import swarmng
import os

# swarm functions cannot take hashes for config. So
# we have to create the special config object (a C++ std::map)
# using swarmng.config function
# This first line initializes Swarm-NG. 'nogpu' option
# allows us to run this script on a machine without GPU
swarmng.init(swarmng.config(nogpu=1))

# Now we can load an ensemble from a text file. The ensemble file is in the swarm source directory:
ensemble_filename = os.path.join(swarmng.SWARMDIR,
                                 'test/integrators/test.3.in.txt')
# We use a simple call that loads the file and returns the data structure
ref = swarmng.DefaultEnsemble.load_from_text(ensemble_filename)

# We can also look into the data structure and view the values
for s in ref:
    print("System {0}, time: {1}, state: {2} ".format(s.id, s.time, s.state))
    for i, b in enumerate(s):
        print("\tBody {0} pos: {1}\tvel:{2}".format(i, b.pos, b.vel))

# We can treat the data structure as an array. e.g to set the position
# of body 0 of system 3 you can write:
コード例 #4
0
#!/usr/bin/env python2
# -*- coding: utf8 -*-

import swarmng
import time

for c in range(0,2):
    swarmng.init(swarmng.config(CUDA_DEVICE=c,verbose=1))

    integ = swarmng.Integrator.create(swarmng.config(integrator="hermite",time_step=0.001))

    times = []

    for nb in range(3,7):
        integ.ensemble = swarmng.generate_ensemble(swarmng.config(nsys=8000,nbod=nb))
        integ.destination_time = 10.0

        start = time.clock()
        integ.integrate()
        times.append(time.clock() - start)

    print(times)




コード例 #5
0
ファイル: ejection_tutorial.py プロジェクト: AstroGPU/swarm
# The first step is to import the swarmng module. We also use make_test_case from the 
# @ref TutorialPythonEnsemble "Ensemble generation tutorial" to generate our test case.
import swarmng
import random
from ensemble_tutorial import make_test_case
# \subsection candi Configuration and initial conditions
# RMAX is the maximum radius of the planetary system. If the planets is farther than RMAX from
# the origin, we consider it ejected.
RMAX = 10
#
# Configuratino for the integration, we use CPU version of the PEC² Hermite integrator, it is
# by default checks for ejections when the planets get too far from the origin.
cfg = swarmng.config(
        integrator = "hermite_cpu",
        time_step  = 1e-3,
        nogpu      = 1,
        deactivate_on_ejection = 1,
        rmax       = RMAX
        )
# We have to set the destination_time directly on the integrator object
# and it cannot be included in the Config object.
destination_time = 100
#
# We create an ensemble with very close orbits. This ensures that the planets
# will come close at some point and the result would be an ejection.
ens = make_test_case(nsys=20, nbod = 6, spacing_factor=1.01);
#
# \section int Integration
# Same procedure as in @ref TutorialPython. Set-up the integrator parameters and
# call the method @ref swarmng.Integrator.integrate "integrate".
swarmng.init(cfg)
コード例 #6
0
import swarmng, argparse
import os

swarmng.init(swarmng.config(nogpu=0))

ensemble_file = os.path.join(swarmng.SWARMDIR,
                             'test/integrators/test.3.in.txt')

ref = swarmng.DefaultEnsemble.load_from_text(ensemble_file)

ens = ref.clone()

integrator_cfg = swarmng.config(integrator='irk2', time_step=.001, nbod=3)

integ = swarmng.Integrator.create(integrator_cfg)

integ.ensemble = ens
integ.destination_time = 100

integ.integrate()

ens.save_to_text("hermite_cpu_snapshot.txt")

max_deltaE = swarmng.find_max_energy_conservation_error(ens, ref)
print("Max energy conservation error %g" % max_deltaE)
コード例 #7
0
ファイル: ejection_tutorial.py プロジェクト: kb3vwt/swarm
#
# The first step is to import the swarmng module. We also use make_test_case from the
# @ref TutorialPythonEnsemble "Ensemble generation tutorial" to generate our test case.
import swarmng
import random
from ensemble_tutorial import make_test_case
# \subsection candi Configuration and initial conditions
# RMAX is the maximum radius of the planetary system. If the planets is farther than RMAX from
# the origin, we consider it ejected.
RMAX = 10
#
# Configuratino for the integration, we use CPU version of the PEC² Hermite integrator, it is
# by default checks for ejections when the planets get too far from the origin.
cfg = swarmng.config(integrator="hermite_cpu",
                     time_step=1e-3,
                     nogpu=1,
                     deactivate_on_ejection=1,
                     rmax=RMAX)
# We have to set the destination_time directly on the integrator object
# and it cannot be included in the Config object.
destination_time = 100
#
# We create an ensemble with very close orbits. This ensures that the planets
# will come close at some point and the result would be an ejection.
ens = make_test_case(nsys=20, nbod=6, spacing_factor=1.01)
#
# \section int Integration
# Same procedure as in @ref TutorialPython. Set-up the integrator parameters and
# call the method @ref swarmng.Integrator.integrate "integrate".
swarmng.init(cfg)
integ = swarmng.Integrator.create(cfg)
コード例 #8
0
ファイル: tutorial.py プロジェクト: AstroGPU/swarm
#
# Source code for this tutorial can be found at @ref py/tutorial.py
#
# First thing is to import swarmng package. It is located in `\<SOURCE DIRECTORY\>/py/swarmng/`
# It takes care of loading the libswarmng_ext.so; it also contains some Pythonified
# API on top of libswarmng_ext. But please run the scripts
# from your build directory so swarmng can find your libraries.
import swarmng
import os

# swarm functions cannot take hashes for config. So 
# we have to create the special config object (a C++ std::map)
# using swarmng.config function
# This first line initializes Swarm-NG. 'nogpu' option
# allows us to run this script on a machine without GPU
swarmng.init(swarmng.config(nogpu=1))

# Now we can load an ensemble from a text file. The ensemble file is in the swarm source directory:
ensemble_filename = os.path.join(swarmng.SWARMDIR , 'test/integrators/test.3.in.txt')
# We use a simple call that loads the file and returns the data structure
ref = swarmng.DefaultEnsemble.load_from_text( ensemble_filename )


# We can also look into the data structure and view the values
for s in ref:
  print("System {0}, time: {1}, state: {2} ".format(s.id, s.time, s.state))
  for i,b in enumerate(s):
    print("\tBody {0} pos: {1}\tvel:{2}".format(i,b.pos,b.vel))

# We can treat the data structure as an array. e.g to set the position
# of body 0 of system 3 you can write:
コード例 #9
0
ファイル: irk2_test.py プロジェクト: AstroGPU/swarm
import swarmng, argparse
import os

swarmng.init(swarmng.config(nogpu=0))

ensemble_file = os.path.join(swarmng.SWARMDIR,'test/integrators/test.3.in.txt')

ref = swarmng.DefaultEnsemble.load_from_text(ensemble_file)

ens = ref.clone()

integrator_cfg = swarmng.config(
	integrator = 'irk2',
	time_step = .001,
	nbod = 3
)

integ = swarmng.Integrator.create(integrator_cfg)

integ.ensemble = ens
integ.destination_time = 100

integ.integrate()

ens.save_to_text("hermite_cpu_snapshot.txt")

max_deltaE = swarmng.find_max_energy_conservation_error(ens,ref)
print("Max energy conservation error %g" % max_deltaE)