コード例 #1
0
ファイル: test_examples.py プロジェクト: teeratornk/topy
def test_optimise(filename, benchmark):
    # type: (str) -> None
    """Optimise the file at `filename`."""
    print("Optimizing file '%s'..." % filename)
    # Set up ToPy:
    t = topy.Topology()
    t.load_tpd_file(filename)
    t.set_top_params()
    benchmark.pedantic(topy.optimise, args=(t,), rounds=1, iterations=1)
コード例 #2
0
ファイル: test_examples.py プロジェクト: Bassarey/app
def test_optimise(filename, benchmark):
    # тип: (str) -> None
    # Оптимизация файла по адресу "filename"
    print("Optimizing file '%s'..." % filename)
    # Настройка топологии:
    t = topy.Topology()
    t.load_tpd_file(filename)
    t.set_top_params()
    benchmark.pedantic(topy.optimise, args=(t,), rounds=1, iterations=1)
コード例 #3
0
ファイル: latticeEnv.py プロジェクト: prakhar0402/DeepLattice
 def solve_fea(self, config):
     '''
     Solves the ToPy FEA problem specified in TPD config
     '''
     t = topy.Topology()
     t.load_config_dict(config)
     t.set_top_params()
     
     t.update_desvars_oc()
     t.fea()
     t.sens_analysis()
     
     disp = t.d.reshape((self.domainSz[0]+1, self.domainSz[1]+1, 2, 1))
     
     self.dispX = disp[:, :, 0, :] # TODO: change displacement size
     self.dispY = disp[:, :, 1, :]
     
     self.comp = t.qkq.T
     self.comp = self.comp[:, :, np.newaxis]
コード例 #4
0
def main(dir_to_save, num_samples):

    if not os.path.exists(dir_to_save):
        os.mkdir(dir_to_save)
        print('Directory "{}" created'.format(dir_to_save))

    print('Generating the dataset...')
    samples_done = 0
    while samples_done < num_samples:
        try:
            topology = topy.Topology(config=random_config())
            topology.set_top_params()
            sample = optimize(topology)
            path = os.path.join(dir_to_save, str(samples_done))
            np.savez_compressed(path, sample)
            samples_done += 1
        except BaseException:  # For the incorrect constraints
            pass
        print('\rDone: {}/{}'.format(samples_done, num_samples), end='')
        sys.stdout.flush()
コード例 #5
0
 def load_topy(self, filename):
     t = topy.Topology()
     t.load_tpd_file(filename)
     return t
コード例 #6
0
def run_through_optimisations(tpd_file, print_all_images=False):

    # Set up ToPy:
    t = topy.Topology()
    t.load_tpd_file(tpd_file)
    t.set_top_params()


    # Optimising function:
    def optimise(print_all_images=False):
        t.fea()
        t.sens_analysis()
        t.filter_sens_sigmund()
        t.update_desvars_oc()

        # Added if to only print the end result
        if print_all_images == True or t.itercount == t.numiter:
            # Below this line we print and create images:
            if t.nelz:
                topy.create_3d_geom(t.desvars, prefix=t.probname, \
                iternum=t.itercount, time='none')
            else:
                topy.create_2d_imag(t.desvars, prefix=t.probname, \
                iternum=t.itercount, time='none')
        print '%4i  | %3.6e | %3.3f | %3.4e | %3.3f | %3.3f |  %1.3f  |  %3.3f '\
        % (t.itercount, t.objfval, t.desvars.sum()/(t.nelx * t.nely * nelz), \
        t.change, t.p, t.q, t.eta.mean(), t.svtfrac)
        # Build a list of average etas:
        etas_avg.append(t.eta.mean())



    # Create empty list for later use:
    etas_avg = []

    # Create (plot) initial design domain:
    if t.nelz:
        #create_3d_geom(t.desvars, prefix=t.probname, iternum=0, time='none')
        nelz = t.nelz
    else:
        #create_2d_imag(t.desvars, prefix=t.probname, iternum=0, time='none')
        nelz = 1 #  else we divide by zero

    # Start optimisation runs, create rest of design domains:
    print '%5s | %11s | %5s | %10s | %5s | %5s | %7s | %5s ' % ('Iter', \
    'Obj. func.  ', 'Vol. ', 'Change    ', 'P_FAC', 'Q_FAC', 'Ave ETA', 'S-V frac.')
    print ' ----:|-------------:|------:|-----------:|------:|------:|--------:|---------:'
    ti = time()

    # Try CHG_STOP criteria, if not defined (error), use NUM_ITER for iterations:
    try:
        while t.change > t.chgstop:
            optimise(print_all_images)
    except AttributeError:
        for i in range(t.numiter):
            optimise(print_all_images)
    te = time()

    # Print solid-void ratio info:
    print '\n- Solid plus void to total elements fraction = `%3.5f`' % (t.svtfrac)
    # Print iteration info:
    print '\n- `', t.itercount,'` iterations took `%3.3f minutes` (%3.3f min/iter or %3.3f sec/iter)'\
    %((te - ti) / 60, (te - ti) / 60 / t.itercount, (te - ti) / t.itercount)
    print '\n- Average of all ETA\'s = `%3.3f` (average of all a\'s = %3.3f)' \
    % (array(etas_avg).mean(), 1/array(etas_avg).mean() - 1)

    return t
コード例 #7
0
        # voxel center global coordinates
        x = x_v + x_c[i, j]
        y = y_v + y_c[i, j]
        # cell center coordinates
        xx = x_c[i, j] + cellSz[0] / 2
        yy = y_c[i, j] + cellSz[1] / 2
        holes[hh] = [xx, yy]
        hh += 1
        # calculate distance field
        cell = np.sqrt((x - xx)**2 + (y - yy)**2) - p
        field[i * numVoxels[0]:(i + 1) * numVoxels[0],
              j * numVoxels[1]:(j + 1) * numVoxels[1]] += cell

config = tpd.minimal_tpd_dict()
config['PROB_NAME'] = 'sph_lat_test'
config['NUM_ELEM_X'] = domainSz[0]
config['NUM_ELEM_Y'] = domainSz[1]
config['VOL_FRAC'] = np.count_nonzero(field >= 0) * 1. / field.size
config['NUM_ITER'] = 2
config['PASV_ELEM'] = tpd.passive_elems(field >= 0)
config['FXTR_NODE_Y'] = '1|81'
config['FXTR_NODE_X'] = '1|81'
config['LOAD_NODE_Y'] = '12961'
config['LOAD_VALU_Y'] = '-1'

t = topy.Topology()
t.load_config_dict(config)
t.set_top_params()

topy.optimise(t)
コード例 #8
0
ファイル: optimise.py プロジェクト: iitrabhi/topy-1
def optimise(fname):
    # Set up ToPy:
    t = topy.Topology()
    t.load_tpd_file(fname)
    t.set_top_params()
    topy.optimise(t)