Skip to content

Latest commit

 

History

History
459 lines (295 loc) · 11.2 KB

how_to_use.md

File metadata and controls

459 lines (295 loc) · 11.2 KB

Quick start

Basic example

The following is the example code.

  • You could decide to either just type all the data about the truss in .py file or read the data in .json file. As for .json file, we will discuss it later.
  • If you want to do structural analysis on 2D truss, just switch the dimension of truss by changing the value of variable TRUSS_DIMENSION (Only can be 2 or 3).
  • By the way, you could use slientruss3d.plot.TrussPlotter to plot the result of structural analysis for your truss. We will discuss its details in Here !
from slientruss3d.truss import Truss
from slientruss3d.type  import SupportType, MemberType


def TestExample():
    # -------------------- Global variables --------------------
    TEST_OUTPUT_FILE    = f"./test_output.json"
    TRUSS_DIMENSION     = 3
    # ----------------------------------------------------------

    # Truss object:
    truss = Truss(dim=TRUSS_DIMENSION)

    # Truss settings:
    joints     = [(0, 0, 0), (360, 0, 0), (360, 180, 0), (0, 200, 0), (120, 100, 180)]
    supports   = [SupportType.PIN, SupportType.ROLLER_Z, SupportType.PIN, SupportType.PIN, SupportType.NO]
    forces     = [(1, (0, -10000, 5000))]
    members    = [(0, 4), (1, 4), (2, 4), (3, 4), (1, 2), (1, 3)]
    memberType = MemberType(1, 1e7, 1)

    # Read data in this [.py]:
    for joint, support in zip(joints, supports):
        truss.AddNewJoint(joint, support)
        
    for jointID, force in forces:
        truss.AddExternalForce(jointID, force)
    
    for jointID0, jointID1 in members:
        truss.AddNewMember(jointID0, jointID1, memberType)

    # Do direct stiffness method:
    truss.Solve()

    # Dump all the structural analysis results into a .json file:
    truss.DumpIntoJSON(TEST_OUTPUT_FILE)
    
    # Get result of structural analysis:
    displace, stress, resistance = truss.GetDisplacements(), truss.GetInternalStresses(), truss.GetResistances()
    return displace, stress, resistance

Truss

(Not every method or property is listed here)

Constructor

Truss(dim) -> None
  • dim : Dimension of the truss (only can be 2 or 3).

Define a new joint

Truss.AddNewJoint(vector, supportType=SupportType.NO) -> None
  • vector : Position of each joints in the truss.

  • supportType : Support type of the joint. The following is the options of support type in slientruss3d:

    • SupportType.NO      (not a support)
    • SupportType.PIN
    • SupportType.ROLLER_X
    • SupportType.ROLLER_Y
    • SupportType.ROLLER_Z(only in 3d truss)

Define a new load

Truss.AddExternalForce(jointID, vector) -> None
  • jointID : ID number of the joint.
  • vector : Force vector of each joints in the truss.

Define a new member

Truss.AddNewMember(jointID0, jointID1, memberType=MemberType()) -> None
  • jointID0 : ID number of the first joint of this member.
  • jointID1 : ID number of the second joint of this member.
  • memberType : Member type which contain the information about cross-sectional area, Young's modulus, density of this member.

Here is the detail of class MemberType:

class MemberType:
    def __init__(self, a=1., e=1., density=1.):
        self.a       = float(a)
        self.e       = float(e)
        self.density = float(density)
    
    def __repr__(self):
        return f"MemberType(a={self.a}, e={self.e}, density={self.density})"
    
    def __eq__(self, other):
        return IsZero(self.a - other.a) and IsZero(self.e - other.e) and IsZero(self.density - other.density)
    
    def __hash__(self):
        return (self.a, self.e, self.density).__hash__()
    
    def Set(self, other):
        self.a, self.e, self.density = other.a, other.e, other.density
    
    def Serialize(self):
        return [self.a, self.e, self.density]
    
    def Copy(self):
        return MemberType(self.a, self.e, self.density)

Get assembled stiffness matrix (K)

Truss.GetKMatrix() -> numpy.array
  • It will return a numpy array which is the assembled K matrix.

Do structural analysis

Truss.Solve() -> None
  • Do the structral analysis of your truss by direct stiffness method. After that, all the internal force (not stress!) of each member, displacement and total force at each joint will solved and stored in the Truss object. You could get them with some getters defined in Truss.

       As said in Description, slientruss3d is made for stable truss analysis. So once you call the method Truss.Solve(), it will check whether your truss is stable or not with the property Truss.isStable. If your truss is not stable, an exception TrussNotStableError will be raised.


Get internal stress

Truss.GetInternalStresses() -> dict[int, float]
  • Get inetrnal stress at each member. It returns a dictionary whose key is member ID and value is stress.

    Note that if you haven't done structural analysis yet, this method will return None.


Get internal force

Truss.GetInternalForces(isProtect=True) -> dict[int, float]
  • Get inetrnal force at each member. It returns a dictionary whose key is member ID and value is force magnitude.

    Note that if you haven't done structural analysis yet, this method will return None.

  • isProtect : If it's True, then return a deep-copy of the result of internal forces stored in Truss object. Otherwise, return its reference directly, but remember not to change any value in this reference.


Get joint displacement

Truss.GetDisplacements(isProtect=True) -> dict[int, numpy.array]
  • Get displacement at each joint. It returns a dictionary whose key is joint ID and value is displacement vector.

    Note that if you haven't done structural analysis yet, this method will return None.

  • isProtect : If it's True, then return a deep-copy of the result of joint displacements stored in Truss object. Otherwise, return its reference directly, but remember not to change any value in this reference.


Get support resistance

Truss.GetResistances() -> dict[int, numpy.array]
  • Get resistance at each support. It returns a dictionary whose key is joint ID and value is resistance vector.

    Note that if you haven't done structural analysis yet, this method will return None.


Load truss data from JSON file

Truss.LoadFromJSON(path=None, isOutputFile=False, data=None) -> Truss
  • path : Filename of the JSON file.
  • isOutputFile : Whether the JSON file or dictionary data contains the result of structural analysis.
  • data : Directly assign a dictionary whose format is the same as Format of JSON. If it's not none, do not assgin any value to the argument path.

Save the structural analysis result in a JSON file

Truss.DumpIntoJSON(path) -> None
  • path : Filename of the JSON in which you want to store the result of structural analysis.

    More about the utility of JSON will be introduced in Combine with JSON !


Serialize the truss

Truss.Serialize() -> dict
  • Return a dictionary which contains all the information about the truss.

    The format is the same as Format of JSON.


Check whether every stress is allowable

Truss.IsInternalStressAllowed(limit, isGetSumViolation=False, isGetSumNonViolation=False) -> tuple[bool, dict | float] | tuple[bool, dict | float, float]
  • limit : Allowable stress.
  • isGetSumViolation : Sum of the exceeding quantities of members that violate allowable stress.
  • isGetSumNonViolation : Sum of differences between allowable stress and the stresses of members that don't violate allowable stress. If it's True, then the length of return is 3, otherwise 2.

  If the parameter isGetSumViolation is True, then the method returns

  1. boolean : indicates whether the truss violates the allowable limit or not.
  2. float    : sum of absolute values of exceeding stresses or displacements.

Check whether every displacement is allowable

Truss.IsDisplacementAllowed(limit, isGetSumViolation=False, isGetSumNonViolation=False) -> tuple[bool, dict | float] | tuple[bool, dict | float, float]
  • limit : Allowable displacement.
  • isGetSumViolation : Sum of the exceeding quantities of joints that violate allowable displacement.
  • isGetSumNonViolation : Sum of differences between allowable displacement and the displacements of joints that don't violate allowable displacement. If it's True, then the length of return is 3, otherwise 2.

  If the parameter isGetSumViolation is True, then the method returns

  1. boolean : indicates whether the truss violates the allowable limit or not.
  2. float    : sum of absolute values of exceeding stresses or displacements.

Copy the truss

Truss.Copy() -> Truss

Some useful properties

  • Weight of the truss.
Truss.weight : float
  • Whether the truss is stable or not ?
Truss.isStable : bool
  • Whether the truss has been done structral analysis or not ?
Truss.isSolved : bool
  • Number of joints.
Truss.nJoint : int
  • Number of members.
Truss.nMember : int
  • Number of loads.
Truss.nForce : int
  • Number of supports (support type is not SupportType.NO).
Truss.nSupport : int
  • Number of resistances.
Truss.nResistance : int
  • Dimension of the truss
Truss.dim : int


Member

Constructor

Member(joint0, joint1, dim=3, memberType=MemberType()) -> None

Check whether the member is tension stress or not

Member.IsTension(forceVec) -> bool
  • forceVec : The internal force vector on joint1.

Serialize the member

Member.Serialize() -> dict
  • Return a dictionary which contains all the information about the member. The following is its format:
{
    "joint0"    : list[float],  # Position of joint0
    "joint1"    : list[float],  # Position of joint1
    "memberType": list[float]   # Cross-sectional area, Young's modulus, density
} 

Copy the member

Member.Copy() -> Member

Some useful properties

  • Weight of the member.
Member.weight : float
  • Length of the member.
Member.length : float
  • Cross-sectional area.
Member.a : float
  • Young's modulus.
Member.e : float
  • Density.
Member.density : float
  • Member type. (Has both getter and setter)
Member.memberType : MemberType
  • Cosine values of every axis.
Member.cosines : list[float]
  • E * A / L.
Member.k : float
  • Stiffness matrix (K).
Member.matK : numpy.array
  • Dimension of the member.
Member.dim : int