Пример #1
0
class Test(unittest.TestCase):




#==============================================================================
#     def setUp(self):
#         self.airLogger = AirLogger()
#         self.airServer = AirServer(self.airLogger)
#         self.airClient = AirClient(client)
# 
#     def tearDown(self):
#         self.airClient.disconnect()
#         self.airServer.stop(reactor_stop =  False)
#         pass
#==============================================================================


    def test_init(self):                
        self.opt = Optimizer('test', 0.15, Optimizer.prob_types.comp)
        self.opt.set_problem_dimensions(20, 20, 40)
        self.opt.fix_nodes(np.arange(441), directions=['x', 'y', 'z'])
        self.opt.load_nodes([17860], 1, direction = 'x')
        
    def load_topy(self, filename):
        t = topy.Topology()
        t.load_tpd_file(filename)
        return t
        
    def test_compare(self):
        self.test_init()
        t = self.load_topy('test_optimizer.tpd')
        assert np.all(self.opt.topy_dict['FIX_DOF'] == t.topydict['FIX_DOF'])
        assert list(self.opt.loaded_dof) == list(t.topydict['LOAD_DOF'])
        assert list(self.opt.loads) == list(t.topydict['LOAD_VAL'])
        
        assert set(t.topydict.keys()) - set(self.opt.topy_dict.keys()) - set(allowed_missing) == set([])
        
        for key in self.opt.topy_dict.keys():
            if type(t.topydict[key]) == np.ndarray:
                assert np.all(self.opt.topy_dict[key] == t.topydict[key])
            else:
                print key, type(self.opt.topy_dict[key]), type(t.topydict[key])
                assert self.opt.topy_dict[key] == t.topydict[key], (self.opt.topy_dict[key], t.topydict[key])
Пример #2
0
class Test(unittest.TestCase):

    #==============================================================================
    #     def setUp(self):
    #         self.airLogger = AirLogger()
    #         self.airServer = AirServer(self.airLogger)
    #         self.airClient = AirClient(client)
    #
    #     def tearDown(self):
    #         self.airClient.disconnect()
    #         self.airServer.stop(reactor_stop =  False)
    #         pass
    #==============================================================================

    def test_init(self):
        self.opt = Optimizer('test', 0.15, Optimizer.prob_types.comp)
        self.opt.set_problem_dimensions(20, 20, 40)
        self.opt.fix_nodes(np.arange(441), directions=['x', 'y', 'z'])
        self.opt.load_nodes([17860], 1, direction='x')

    def load_topy(self, filename):
        t = topy.Topology()
        t.load_tpd_file(filename)
        return t

    def test_compare(self):
        self.test_init()
        t = self.load_topy('test_optimizer.tpd')
        assert np.all(self.opt.topy_dict['FIX_DOF'] == t.topydict['FIX_DOF'])
        assert list(self.opt.loaded_dof) == list(t.topydict['LOAD_DOF'])
        assert list(self.opt.loads) == list(t.topydict['LOAD_VAL'])

        assert set(t.topydict.keys()) - set(
            self.opt.topy_dict.keys()) - set(allowed_missing) == set([])

        for key in self.opt.topy_dict.keys():
            if type(t.topydict[key]) == np.ndarray:
                assert np.all(self.opt.topy_dict[key] == t.topydict[key])
            else:
                print key, type(self.opt.topy_dict[key]), type(t.topydict[key])
                assert self.opt.topy_dict[key] == t.topydict[key], (
                    self.opt.topy_dict[key], t.topydict[key])
Пример #3
0
r1 = r0/3
mask = opt.elements[(x-x0)**2+(y-y0)**2<=r1**2]
opt.add_passive_elements(mask)


# Fix points in center
bearing1 = opt.nodes[x0+r1+1,y0+1-1:y0+1+2,z0+1-1:z0+1+2]
bearing2 = opt.nodes[x0-r1+1,y0+1-1:y0+1+2,z0+1-1:z0+1+2]

opt.fix_nodes(bearing1, directions = ['x', 'y', 'z'])
opt.fix_nodes(bearing2, directions = ['x', 'y', 'z'])

de = 1
left = opt.nodes[x0-r0+de+1,y0+1,z0]
top = opt.nodes[x0+1,y0+r0-de+1,z0]
right = opt.nodes[x0+r0-de+1,y0+1,z0]
bottom = opt.nodes[x0+1,y0-r0+de+1,z0]

load_points = [left, right, top, bottom]


opt.load_nodes(load_points, 1, direction = 'x')


opt.add_load_case('y')
opt.load_nodes(load_points, 1, direction = 'y')

opt.add_load_case('z')
opt.load_nodes(load_points, 1, direction = 'z')

opt.run_optimization()
Пример #4
0
"""

Example demonstrating optimization with multiple load cases. This enables the
ability to optimize the structure with respect to loads in different directions.

"""

from topy.optimizer import Optimizer

# Initialize problem
opt = Optimizer('multi_load', 0.10, load_case='vertical')
opt.set_problem_dimensions(10, 10, 20)

# Define fixed nodes (entire z = 0 plane)
left_face = opt.nodes[:, :, 0]
opt.fix_nodes(left_face, directions=['x', 'y', 'z'])  # Fixed in all directions

# Apply a load in -y direction at a single node in the center of the z = 20 plane
right_center = opt.nodes[(opt.num_nodes[0]) / 2, (opt.num_nodes[1]) / 2, -1]
opt.load_nodes([right_center], -1, direction='y')
""" Create a second load case to also optimize for horizontal loads. Note that
this is very different than applying loads in both directions to the same load
case, try to comment out the line below and observe the difference in the
output """
opt.add_load_case('horizontal')

# Apply a load in -x direction
opt.load_nodes([right_center], -1, direction='x')

opt.run_optimization()
Пример #5
0
"""

Example demonstrating basic use of the Optimizer class.

Note that by defining fixed and loaded nodes by reference to the node array
the number of elements can easily be changed for increased resolution

"""

from topy.optimizer import Optimizer

# Initialize problem
opt = Optimizer('basic', 0.15)
opt.set_problem_dimensions(10, 10, 20)

# Define fixed nodes (entire z = 0 plane)
left_face = opt.nodes[:,:,0]
opt.fix_nodes(left_face, directions = ['x', 'y', 'z']) # Fixed in all directions

# Apply a load in -y direction at a single node in the center of the z = 20 plane
right_center = opt.nodes[(opt.num_nodes[0])/2,(opt.num_nodes[1])/2,-1]
opt.load_nodes([right_center], -1, direction = 'y')

opt.run_optimization()