コード例 #1
0
ファイル: mpm.py プロジェクト: tranorrepository/taichi
    def __init__(self, **kwargs):
        res = kwargs['res']
        self.frame_dt = kwargs.get('frame_dt', 0.01)
        if 'frame_dt' not in kwargs:
            kwargs['frame_dt'] = self.frame_dt
        self.num_frames = kwargs.get('num_frames', 1000)
        if len(res) == 2:
            self.c = tc_core.create_simulation2('mpm')
            self.Vector = tc_core.Vector2f
            self.Vectori = tc_core.Vector2i
        else:
            self.c = tc.core.create_simulation3('mpm')
            self.Vector = tc_core.Vector3f
            self.Vectori = tc_core.Vector3i

        if 'task_id' in kwargs:
            self.task_id = kwargs['task_id']
        else:
            self.task_id = sys.argv[0].split('.')[0]
        if 'delta_x' not in kwargs:
            kwargs['delta_x'] = 1.0 / res[0]
        else:
            self.task_id = sys.argv[0].split('.')[0]

        print('delta_x = {}'.format(kwargs['delta_x']))
        print('task_id = {}'.format(self.task_id))

        self.directory = tc.get_output_path(self.task_id)
        self.video_manager = VideoManager(self.directory)
        kwargs['frame_directory'] = self.video_manager.get_frame_directory()
        self.c.initialize(P(**kwargs))
        try:
            os.mkdir(self.directory)
        except OSError as exc:
            if exc.errno != errno.EEXIST:
                raise
        vis_res = self.c.get_vis_resolution()
        self.video_manager.width = vis_res.x
        self.video_manager.height = vis_res.y
        self.particle_renderer = ParticleRenderer('shadow_map',
                                                  shadow_map_resolution=0.3,
                                                  alpha=0.7,
                                                  shadowing=2,
                                                  ambient_light=0.01,
                                                  light_direction=(1, 1, 0))
        self.res = kwargs['res']
        self.frame = 0

        dummy_levelset = self.create_levelset()

        def dummy_levelset_generator(_):
            return dummy_levelset

        self.levelset_generator = dummy_levelset_generator
        self.start_simulation_time = None
        self.simulation_total_time = None
        self.visualize_count = 0
        self.visualize_count_limit = 400000.0
コード例 #2
0
ファイル: simulation.py プロジェクト: MultiPath/taichi
 def __init__(self, name, **kwargs):
   res = kwargs['res']
   if len(res) == 2:
     self.c = tc_core.create_simulation2(name)
     self.Vector = tc_core.Vector2f
     self.Vectori = tc_core.Vector2i
   else:
     self.c = tc.core.create_simulation3(name)
     self.Vector = tc_core.Vector3f
     self.Vectori = tc_core.Vector3i
   self.c.initialize(config_from_dict(kwargs))
コード例 #3
0
ファイル: mpm.py プロジェクト: ckatrycz/Spray
    def __init__(self, snapshot_interval=20, **kwargs):
        res = kwargs['res']
        self.frame_dt = kwargs.get('frame_dt', 0.01)
        if 'frame_dt' not in kwargs:
            kwargs['frame_dt'] = self.frame_dt
        self.num_frames = kwargs.get('num_frames', 1000)
        if len(res) == 2:
            self.c = tc_core.create_simulation2('mpm')
            self.Vector = tc_core.Vector2f
            self.Vectori = tc_core.Vector2i
        else:
            self.c = tc.core.create_simulation3('mpm')
            self.Vector = tc_core.Vector3f
            self.Vectori = tc_core.Vector3i

        self.snapshot_interval = snapshot_interval

        if 'task_id' in kwargs:
            self.task_id = kwargs['task_id']
        else:
            self.task_id = sys.argv[0].split('.')[0]
        if 'delta_x' not in kwargs:
            kwargs['delta_x'] = 1.0 / res[0]

        print('delta_x = {}'.format(kwargs['delta_x']))
        print('task_id = {}'.format(self.task_id))

        self.directory = tc.get_output_path('mpm/' + self.task_id, True)
        self.snapshot_directory = os.path.join(self.directory, 'snapshots')
        self.video_manager = VideoManager(self.directory)
        kwargs['frame_directory'] = self.video_manager.get_frame_directory()

        try:
            opts, args = getopt.getopt(sys.argv[1:], 'c:d:',
                                       ['continue=', 'dt-multiplier='])
        except getopt.GetoptError as err:
            print(err)
            # TODO: output usage here
            sys.exit()
        self.continue_opt = False
        self.continue_frame = ''
        for o, a in opts:
            if o in ('--continue', '-c'):
                print('clear_output_directory is disabled with --continue.')
                self.continue_opt = True
                self.continue_frame = int(a)
            elif o in ('--dt-multiplier', '-d'):
                kwargs['dt-multiplier'] = float(a)

        self.c.initialize(P(**kwargs))
        self.check_directory(self.directory)
        self.check_directory(self.snapshot_directory)
        vis_res = self.c.get_vis_resolution()
        self.video_manager.width = vis_res.x
        self.video_manager.height = vis_res.y
        self.particle_renderer = ParticleRenderer('shadow_map',
                                                  shadow_map_resolution=0.3,
                                                  alpha=0.7,
                                                  shadowing=2,
                                                  ambient_light=0.01,
                                                  light_direction=(1, 1, 0))
        self.res = kwargs['res']
        self.c.frame = 0

        dummy_levelset = self.create_levelset()

        def dummy_levelset_generator(_):
            return dummy_levelset

        self.levelset_generator = dummy_levelset_generator
        self.start_simulation_time = None
        self.simulation_total_time = None
        self.visualize_count = 0
        self.visualize_count_limit = 400000.0