def __init__(self, **kwargs): fn_in = kwargs['fn_model'] fn_out = kwargs['fn_out'] restart = kwargs['restart'] self.__draw_graph = kwargs.pop('draw_graph', False) self.__rooted = kwargs.pop('rooted', False) self.__pullback = kwargs.pop('pullback', False) if self.__pullback: self.__pullback_radius = kwargs['pullback_radius'] self.__pullback_r = np.zeros((3, )) if fn_in is not None: config = yamlio.read(fn_in) self.create_mbs(config['bodies'], config['joints']) if restart: self.__fh_out = h5py.File(fn_out, 'a') if 'ts' in self.__fh_out: self.__h5cntr = len(self.__fh_out['ts']) else: self.__h5cntr = 0 else: self.__fh_out = h5py.File(fn_out, 'w') self.__h5cntr = 0 self.tofile(kwargs['time_start'])
def from_file(cls, fn): ''' Read options from a file. ''' raise NotImplementedError options = yamlio.read(fn) sop = cls() sop.options.update(options) return sop
def modeltraj_from_mbstraj(fn_mbstraj, fn_modeltraj, fn_model): fh_traj = open(fn_modeltraj, 'wb') modelspec = yamlio.read(fn_model) mbstraj = MbsTrajectory(fn_mbstraj, fn_model) nframes = len(mbstraj) for k in range(nframes): df_mbs = mbstraj.get_frame(k) ec = EllipsoidChain.from_df_mbs(df_mbs, modelspec) df_traj = ec.to_df_traj() fh_traj.write(df_traj.tobytes()) mbstraj.close() fh_traj.close()
def run(fn_options): ''' options : dict ''' options = yamlio.read(fn_options) model = mbs.Mbs(**options['model']) ffield = flowfield.create(**options['flowfield']) hydrodyn = hydrodynamics.create(model, ffield, options['hydrodynamics']) ts = timestepper.Timestepper(model, hydrodyn, ffield, **options['timestepper']) ts.run()
def create(cls, fn_traj, fn_model): modelspec = yamlio.read(fn_model) fh_traj = h5py.File(fn_traj, 'r+') for key in fh_traj['ts']: grp = fh_traj['ts/' + key] if 'vertices' not in grp: body_coms = grp['body_coms'][...] body_oris = grp['body_orientations'][...] df_mbs = { 'body_coms': body_coms, 'body_orientations': body_oris } ms = MiuraSheet.from_df_mbs(df_mbs, modelspec) verts = grp.create_dataset('vertices', data=ms.verts) grid_shape = np.array([ms.nverts_x, 1, ms.nverts_z], dtype=np.int32) verts.attrs['grid_shape'] = grid_shape com = grp.create_dataset('com', data=ms.com) fh_traj.close() mst = cls(fn_traj, fn_model) return mst
def __init__(self, fn_traj, fn_model): self._modelspec = yamlio.read(fn_model) self.nel = len(self._modelspec['bodies']) dtype = np.dtype([('time', 'f8'), ('com', 'f8', (self.nel, 3)), ('ori', 'f8', (self.nel, 4))]) super(EllipsoidChainTrajectory, self).__init__(fn_traj, dtype)
def __init__(self, fn_traj, fn_model): self._fh_traj = h5py.File(fn_traj, 'r') self._modelspec = yamlio.read(fn_model)