示例#1
0
class UnitTest(unittest.TestCase):

    # Load the structure for testing
    material_models_js = readFile('.\\materials\\material_models.json')
    load_material_models(material_models_js)
    structure_js = readFile('.\\structures\\testStructure.json')
    structure = Structure(structure_js)

    def test_section(self):
        element0 = self.structure.elements[0]
        section0 = element0.sections[0]
        section0.analyze([0, 0])

        expected = np.round(np.array([[4.55056806e+06, -2.18278728e-11],
                                      [-2.18278728e-11, 9.76568675e+04]]),
                            decimals=2)

        actual = np.round(section0.k_section, decimals=2)
        nptest.assert_array_equal(expected, actual,
                                  'Section stiffness miscalculation')

    def test_element(self):
        element0 = self.structure.elements[0]
        k = element0.calInitialElement_K()
        actual = np.round(element0.analyze(0.1), decimals=1)

        expected = np.round(np.array(
            [[
                1.30016230e+06, 7.66579609e-28, -6.23653510e-12,
                -1.30016230e+06, -7.66579609e-28, 6.23653510e-12
            ],
             [
                 -6.05845175e-28, 2.73325103e+04, 4.78318929e+04,
                 6.05845175e-28, -2.73325103e+04, 4.78318929e+04
             ],
             [
                 -6.23653510e-12, 4.78318929e+04, 1.11607775e+05,
                 6.23653510e-12, -4.78318929e+04, 5.58038505e+04
             ],
             [
                 -1.30016230e+06, -7.66579609e-28, 6.23653510e-12,
                 1.30016230e+06, 7.66579609e-28, -6.23653510e-12
             ],
             [
                 6.05845175e-28, -2.73325103e+04, -4.78318929e+04,
                 -6.05845175e-28, 2.73325103e+04, -4.78318929e+04
             ],
             [
                 6.23653510e-12, 4.78318929e+04, 5.58038505e+04,
                 -6.23653510e-12, -4.78318929e+04, 1.11607775e+05
             ]]),
                            decimals=1)

        nptest.assert_array_equal(expected, actual,
                                  'Element stiffness miscalculation')
示例#2
0
文件: Main.py 项目: imsuneth/FEM
def main():
    material_models_js = readFile('.\\materials\\material_models.json')
    load_material_models(material_models_js)

    # structure_js = readFile('.\\structures\\testStructure.json')
    # structure_js = readFile('.\\structures\\testStructure2.json')
    structure_js = readFile('.\\structures\\hipoStructure.json')

    structure = Structure(structure_js)
    structure.visualize()
    structure.analyze_structure()
    def test_main(self):
        self.maxDiff = None
        struct_files = ['structure00.json', 'structure01.json']
        out_files = ['output00.json', 'output01.json']

        for x, y in zip(struct_files, out_files):
            structure = readFile('Structures/' + x)
            truss = Truss(structure)
            d, fr = truss.main_func()
            out = truss.gen_output(d, fr)

            deeptest.assertDeepAlmostEqual(self,
                                           readFile('Expected_output/' + y),
                                           out)
 def test_write(self):
     js = {
         "no_of_crosssection_types":
         2,
         "no_of_nodes":
         4,
         "no_of_elements":
         3,
         "no_of_loads":
         1,
         "no_of_fixed_points":
         3,
         "nodes": [{
             "id": 0,
             "x": 1,
             "y": 0,
             "z": 0
         }, {
             "id": 1,
             "x": 3,
             "y": 3,
             "z": 0
         }, {
             "id": 2,
             "x": 5,
             "y": 4,
             "z": 0
         }, {
             "id": 3,
             "x": 5,
             "y": 0,
             "z": 0
         }],
         "element_type": [{
             "id": 0,
             "shape": "rectangle",
             "youngs_mod": 150,
             "density": 0,
             "dimensions": {
                 "y": 0.10,
                 "z": 0.20
             }
         }, {
             "id": 1,
             "shape": "circle",
             "youngs_mod": 150,
             "density": 0,
             "dimensions": {
                 "radius": 0.07
             }
         }],
         "elements": [{
             "id": 0,
             "start_node_id": 0,
             "end_node_id": 1,
             "element_type": 0,
             "local_x_dir": {
                 "x": 2.0,
                 "y": 3.0,
                 "z": 1.0
             },
             "local_y_dir": {
                 "x": 0.0,
                 "y": 0.0,
                 "z": -1.0
             },
             "local_z_dir": {
                 "x": -3.0,
                 "y": 2.0,
                 "z": 0.0
             }
         }, {
             "id": 1,
             "start_node_id": 1,
             "end_node_id": 3,
             "element_type": 0,
             "local_x_dir": {
                 "x": 2.0,
                 "y": -3.0,
                 "z": 0.0
             },
             "local_y_dir": {
                 "x": 0.0,
                 "y": 0.0,
                 "z": -1.0
             },
             "local_z_dir": {
                 "x": 3.0,
                 "y": 2.0,
                 "z": 0.0
             }
         }, {
             "id": 2,
             "start_node_id": 1,
             "end_node_id": 2,
             "element_type": 1,
             "local_x_dir": {
                 "x": 2.0,
                 "y": 1.0,
                 "z": 0.0
             },
             "local_y_dir": {
                 "x": 0.0,
                 "y": 0.0,
                 "z": 1.0
             },
             "local_z_dir": {
                 "x": -1.0,
                 "y": 2.0,
                 "z": 0.0
             }
         }],
         "loads": [{
             "id": 0,
             "point_id": 1,
             "force": {
                 "x": 10,
                 "y": 0,
                 "z": 0
             },
             "torque": {
                 "x": 0,
                 "y": 0,
                 "z": 0
             }
         }],
         "fixed_points": [{
             "id": 0,
             "point_id": 0,
             "translation": {
                 "x": True,
                 "y": True,
                 "z": True
             },
             "rotation": {
                 "x": True,
                 "y": True,
                 "z": False
             }
         }, {
             "id": 1,
             "point_id": 2,
             "translation": {
                 "x": True,
                 "y": False,
                 "z": True
             },
             "rotation": {
                 "x": True,
                 "y": True,
                 "z": False
             }
         }, {
             "id": 2,
             "point_id": 3,
             "translation": {
                 "x": True,
                 "y": True,
                 "z": True
             },
             "rotation": {
                 "x": True,
                 "y": True,
                 "z": True
             }
         }]
     }
     file = "Actual_output/test.json"
     writeFile(js, file)
     js_ = readFile(file)
     self.assertDictEqual(js_, js)
from JsonRead import readFile, writeFile
from Truss_class import Truss
import sys

if __name__ == "__main__":
    structure = readFile(sys.argv[1])
    truss = Truss(structure)

    # nodal deformation and Internal Forces
    d, fr = truss.main_func()

    out = truss.gen_output(d, fr)
    writeFile(out, sys.argv[2])
        K = self.get_K(k_local)
        Kf = K.copy()

        K = self.apply_BC(K)
        K_inv = self.inv(K)

        F = self.get_force_vect()
        d = np.dot(K_inv, F)

        fr = np.dot(Kf, d)

        # print("d", d)
        # print('fr', fr)
        # input()

        # self.todo()

        return d, fr

    def todo(self, td="NOT YET COMPLETE"):
        raise ValueError("TO DO : " + td)


if __name__ == '__main__':
    from JsonRead import readFile, writeFile
    structure = readFile('structure00.json')
    truss = Truss(structure)
    d, fr = truss.main_func()
    out = truss.gen_output(d, fr)
    writeFile(out, 'temp.json')