Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ruimaciel committed Jun 21, 2020
2 parents f3a1aae + c3092f1 commit 05fe8b3
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 35 deletions.
8 changes: 4 additions & 4 deletions barman/dofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class Parameter(Enum):
class CoordinateSystem:
"""A coordinate system"""

def __init__(self, angle: float = 0):
def __init__(self, angle: float = 0) -> None:
self.set_angle(angle)


def set_angle(self, angle: float):
def set_angle(self, angle: float) -> None:
"""Sets the rotation angle (in radians)"""

self._angle = angle
Expand Down Expand Up @@ -119,12 +119,12 @@ def __init__(self, node: Node, parameter):
self._node: Node = node
self._parameter = parameter

def __eq__(self, other):
def __eq__(self, other) -> bool:
if isinstance(other, self.__class__):
return self._node == other._node and self._parameter == other._parameter
return False

def __ne__(self, other):
def __ne__(self, other) -> bool:
return not self.__eq__(other)

def __str__(self) -> str:
Expand Down
28 changes: 14 additions & 14 deletions barman/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from abc import ABCMeta, abstractmethod

from typing import List
from typing import List, Tuple
import numpy
from math import sin, cos
from numpy.linalg import norm
Expand Down Expand Up @@ -54,22 +54,22 @@ def get_length(self) -> float:
pass

@abstractmethod
def get_global_dofs(self):
def get_global_dofs(self) -> List[GlobalDoF]:
"""Returns a list with the element's global degrees of freedom (DoF)"""
pass

@abstractmethod
def get_transformation_matrix(self):
def get_transformation_matrix(self) -> numpy.array:
"""Returns the transformation matrix that transforms local coordinates into global coordinates"""
pass

@abstractmethod
def get_local_stiffness_matrix(self):
def get_local_stiffness_matrix(self) -> numpy.array:
"""Returns the element's stiffness matrix represented in the local coordinate system"""
pass


def get_global_stiffness_matrix(self):
def get_global_stiffness_matrix(self) -> numpy.array:
"""Returns the element's stiffness matrix represented in the global coordinate system"""

T = self.get_transformation_matrix();
Expand All @@ -83,7 +83,7 @@ def get_global_stiffness_matrix(self):
class Bar2(BarElement):
"""Bar2 beam element"""

def get_global_dofs(self):
def get_global_dofs(self) -> List[GlobalDoF]:
"""Returns a list with the element's global degrees of freedom (DoF)"""

parameters = [ Parameter.dx, Parameter.dy]
Expand All @@ -109,7 +109,7 @@ def get_shape_functions(self, x: float):
return N


def get_local_stiffness_matrix(self):
def get_local_stiffness_matrix(self) -> numpy.array:
"""Returns the element's stiffness matrix represented in the local coordinate system"""

E: float = self.material.young_modulus
Expand All @@ -124,7 +124,7 @@ def get_local_stiffness_matrix(self):
return k


def get_local_mass_matrix(self):
def get_local_mass_matrix(self) -> numpy.array:
"""Returns the element's mass matrix represented in the local coordinate system"""

A: float = self.section.area
Expand All @@ -141,10 +141,10 @@ def get_local_mass_matrix(self):
return m


def get_transformation_matrix(self):
def get_transformation_matrix(self) -> numpy.array:
"""Returns the transformation matrix that transforms local coordinates into global coordinates"""

nodes: Node = self.nodes
nodes: List[Node] = self.nodes
nf = numpy.array(nodes[-1].position)
ni = numpy.array(nodes[0].position)
r = nf-ni
Expand All @@ -164,7 +164,7 @@ def get_transformation_matrix(self):
class EulerBernoulli(BarElement):
"""Euler-Bernoulli (engineering) beam element"""

def get_global_dofs(self):
def get_global_dofs(self) -> List[GlobalDoF]:
"""Returns a list with the element's global degrees of freedom (DoF)"""

parameters = [ Parameter.dx, Parameter.dy, Parameter.rz ]
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_shape_functions(self, x: float) -> numpy.array:
return N


def get_local_stiffness_matrix(self):
def get_local_stiffness_matrix(self) -> numpy.array:
"""Returns the element's stiffness matrix represented in the local coordinate system"""

E = self.material.young_modulus
Expand All @@ -218,7 +218,7 @@ def get_local_stiffness_matrix(self):
return k


def get_local_mass_matrix(self):
def get_local_mass_matrix(self) -> numpy.array:
"""Returns the element's mass matrix represented in the local coordinate system"""

A = self.section.area
Expand All @@ -241,7 +241,7 @@ def get_local_mass_matrix(self):



def get_transformation_matrix(self):
def get_transformation_matrix(self) -> numpy.array:
"""Returns the transformation matrix that transforms local coordinates into global coordinates"""

nodes = self.nodes
Expand Down
2 changes: 1 addition & 1 deletion barman/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LinearElastic:
"""Represents a linear elastic material"""


def __init__(self, name, young_modulus, poisson_ratio):
def __init__(self, name: str, young_modulus: float, poisson_ratio: float):
self._name: str = name
self._young_modulus: float = young_modulus
self._poisson_ratio: float = poisson_ratio
Expand Down
20 changes: 10 additions & 10 deletions barman/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
along with Barman. If not, see <http://www.gnu.org/licenses/>.
"""

from typing import List
from typing import List, Tuple
from barman.dofs import GlobalDoFLink
from barman.elements import BarElement
from barman.prescribed_displacements import PrescribedDisplacement
Expand All @@ -31,16 +31,16 @@ def __init__(self):
self.clear()


def clear(self):
def clear(self) -> None:
"""Clears all attributes."""

self._elements = []
self._prescribed_displacements = []
self._prescribed_forces = []
self._global_dof_links = [] # links between GlobalDoFs
self._elements: List[BarElement] = []
self._prescribed_displacements: List[PrescribedDisplacement] = []
self._prescribed_forces: List[PrescribedForce] = []
self._global_dof_links: List[GlobalDoFLink] = [] # links between GlobalDoFs


def append_element(self, element: BarElement):
def append_element(self, element: BarElement) -> None:
"""Appends an element to the element list"""

self._elements.append(element)
Expand All @@ -53,7 +53,7 @@ def elements(self) -> List[BarElement]:
return self._elements


def append_prescribed_displacement(self, prescribed_displacement: PrescribedDisplacement):
def append_prescribed_displacement(self, prescribed_displacement: PrescribedDisplacement) -> None:
"""Appends a prescribed displacement to the element list"""

if not isinstance(prescribed_displacement, PrescribedDisplacement):
Expand All @@ -62,7 +62,7 @@ def append_prescribed_displacement(self, prescribed_displacement: PrescribedDisp
self._prescribed_displacements.append(prescribed_displacement)


def append_prescribed_force(self, prescribed_force: PrescribedForce):
def append_prescribed_force(self, prescribed_force: PrescribedForce) -> None:
"""Appends an element to the element list"""

if not isinstance(prescribed_force, PrescribedForce):
Expand All @@ -85,7 +85,7 @@ def prescribed_forces(self) -> List[PrescribedForce]:
return self._prescribed_forces


def append_global_dof_link(self, global_dof_link: GlobalDoFLink):
def append_global_dof_link(self, global_dof_link: GlobalDoFLink) -> None:
"""Appends a link between global degrees of freedom (DoF)"""

self._global_dof_links.append(global_dof_link)
Expand Down
7 changes: 4 additions & 3 deletions barman/prescribed_displacements.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
along with Barman. If not, see <http://www.gnu.org/licenses/>.
"""

from typing import List, Tuple
from barman.dofs import GlobalDoF

class PrescribedDisplacement:
"""Prescribes the displacement of a global degree of freedom (DoF)"""

def __init__(self, global_dof: GlobalDoF, value):
def __init__(self, global_dof: GlobalDoF, value: float):
self._global_dof: GlobalDoF = global_dof
self._value = value
self._value: float = value

@property
def global_dof(self) -> GlobalDoF:
Expand All @@ -34,5 +35,5 @@ def global_dof(self) -> GlobalDoF:
def value(self):
return self._value

def get_values(self):
def get_values(self) -> List[Tuple[GlobalDoF, float]]:
return [(self._global_dof, self._value)]
5 changes: 3 additions & 2 deletions barman/prescribed_forces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
along with Barman. If not, see <http://www.gnu.org/licenses/>.
"""

from typing import List, Tuple
from barman.dofs import GlobalDoF

class PrescribedForce:
"""Prescribes the force associated with a global degree of freedom (DoF)"""

def __init__(self, global_dof: GlobalDoF, value):
def __init__(self, global_dof: GlobalDoF, value: float):
self._global_dof: GlobalDoF = global_dof
self._value = value

Expand All @@ -34,5 +35,5 @@ def global_dof(self) -> GlobalDoF:
def value(self):
return self._value

def get_values(self):
def get_values(self) -> List[Tuple[GlobalDoF, float]]:
return [(self._global_dof, self._value)]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='barman',
version='1.0.2dev',
version='1.0.2',
description='A 2D engineering beam theory model implemente in Python 3',
packages=['barman'],
author='Rui Maciel',
Expand Down

0 comments on commit 05fe8b3

Please sign in to comment.