Esempio n. 1
0
    def setUp(self):
        class DummyConstraint:
            def __init__(self):
                self.no_of_constrained_dofs = 2

            def unconstrain_u(self, u_constr):
                return np.array([0, 0, 0])

            def constrain_matrix(self, K_unconstr):
                return K_unconstr[0:2, 0:2]

        class DummyAssembly:
            def __init__(self):
                pass

            def assemble_k_and_f(self, u, t):
                K_unconstr = np.array([[10, -5, 0], [-5, 10, -5], [0, -5, 10]])
                f_unsonstr = np.array([2, 0, 0])
                return K_unconstr, f_unsonstr

        class DummyMesh:
            def __init__(self, dimension):
                self.dimension = dimension
                self.nodes = np.empty((0, dimension), dtype=float)
                self.connectivity = None
                self.el_df = pd.DataFrame(
                    columns=['shape', 'is_boundary', 'connectivity'])
                self.no_of_nodes = 0

            @property
            def no_of_elements(self):
                return 0

        class DummyLeaf:
            def __init__(self):
                pass

            def get_local_component_id(self, leaf_id, composite_layer):
                return leaf_id

        self.mesh = DummyMesh(2)
        self.assembly = DummyAssembly()
        self.constraints = DummyConstraint()
        self.leaf_paths = DummyLeaf()

        comp = StructuralComponent(self.mesh)
        comp._constraints = self.constraints
        comp._assembly = self.assembly

        self.TestComponent = comp
        self.CompComposite = ComponentComposite(self.TestComponent)
Esempio n. 2
0
    def setUp(self):
        class DummyConstraint:
            def __init__(self):
                self.no_of_constrained_dofs = 2

            def unconstrain_vector(self, u_free, u_constr=None):
                return np.array([0, 0, 0])

            def constrain_matrix(self, K_unconstr, t=0):
                return K_unconstr[0:2, 0:2]

        class DummyAssembly:
            def __init__(self):
                pass

            def assemble_k_and_f(self,
                                 nodes,
                                 ele_objects,
                                 connectivities,
                                 elements2dofs,
                                 dofvalues=None,
                                 t=0.,
                                 C_csr=None,
                                 f_glob=None):
                if C_csr is None:
                    C_csr = np.array([[10, -5, 0], [-5, 10, -5], [0, -5, 10]])
                else:
                    C_csr[:, :] = np.array([[10, -5, 0], [-5, 10, -5],
                                            [0, -5, 10]])
                if f_glob is None:
                    f_glob = np.array([2, 0, 0])
                else:
                    f_glob[:] = np.array([2, 0, 0])
                return C_csr, f_glob

            def preallocate(self, no_of_dofs, elements2dof):
                return np.zeros((3, 3))

        class DummyMesh:
            def __init__(self, dimension):
                self.dimension = dimension
                self.nodes_df = pd.DataFrame({
                    'x': [0.0, 1.0, 0.0],
                    'y': [0.0, 0.0, 1.0]
                })
                self.connectivity = None
                self.el_df = pd.DataFrame({
                    'shape': ['Tri3'],
                    'is_boundary': [False],
                    'connectivity': [np.array([1, 2, 3], dtype=int)]
                })
                self.no_of_nodes = 3

            @property
            def no_of_elements(self):
                return 0

            @property
            def nodes(self):
                return np.zeros(3)

            def get_nodeidxs_by_all(self):
                return np.arange(0, 3)

            def get_nodeids_by_nodeidxs(self, nodeidxs):
                return np.arange(0, 3)

            def get_iconnectivity_by_elementids(self, elementids):
                return None

        class DummyMapping:
            def __init__(self):
                pass

            @property
            def no_of_dofs(self):
                return 3

            def get_dofs_by_nodeids(self, nodeids):
                return np.arange(0, 3)

            def get_dofs_by_ids(self, ids):
                return None

        self.mesh = DummyMesh(2)
        self.assembly = DummyAssembly()

        self.structComp = []
        comp = StructuralComponent(self.mesh)
        comp._mapping = DummyMapping()
        comp._constraints = DummyConstraint()
        comp._assembly = DummyAssembly()
        comp._C_csr = comp._assembly.preallocate(2, None)
        comp._f_glob_int = np.zeros(comp._C_csr.shape[0])
        self.structComp.append(comp)