Code Monkey home page Code Monkey logo

Comments (2)

adtzlr avatar adtzlr commented on June 24, 2024

Okay, here is a tutorial how to achieve this with the current code of TrussPy (please update TrussPy via pip first):

Create a Model

In a first step we have to create the Model and set the maximum allowed increments to 1 (0 is not possible in TrussPy). We call this function create_model.

import trusspy as tp

def create_model():
    '''Create a TrussPy-Model and return the Model instance.'''
    M = tp.Model(log=0)
    
    with M.Nodes as MN:
        MN.add_node( 1, coord=( 0, 0, 0))
        MN.add_node( 2, coord=( 1, 0, 1))
        MN.add_node( 3, coord=( 2, 0, 0))
    
    with M.Elements as ME:
        ME.add_element( 1, conn=(1,2), gprop=[1] )
        ME.add_element( 2 ,conn=(2,3), gprop=[1] )
        ME.assign_material( 'all', [1])
    
    with M.Boundaries as MB:
        MB.add_bound_U( 1, (0,0,0) )
        MB.add_bound_U( 2, (0,0,1) )
        MB.add_bound_U( 3, (0,0,0) )
    
    with M.ExtForces as MF:
        MF.add_force( 2, ( 0, 0,-1) )
        
    M.Settings.incs = 1
    return M

Function for stiffness evaluation

In a second step we create a function which uses a list of elemental areas as its argument, runs the model and returns the stiffness matrix for the initial increment of zero deformation (may be adapted to your needs). Finally a reduced stiffness matrix for all active degree of freedoms (Kred) is returned. This may also be changed to the whole system stiffness matrix (K) or the one which is used by TrussPy (Kmod). See the documentation for further informations about Kmod.

def stiffness(list_of_areas):
    '''Calculate the stiffness matrix as a function of elemental
    cross-section areas (passed as list).'''
    
    M = create_model()
    M.Elements.assign_geometries('all', list_of_areas)
    
    M.build()
    M.run()
    
    R0 = M.Results.R[0]
    # return K (full system), Kred (only active DOF) 
    # or Kmod (see Documentation)
    return R0.Kred

Now we have a function which evaluates the stiffness matrix based on a list of elemental areas.

Code snippet inside a script

list_of_areas = [2,3]
K = stiffness(list_of_areas)

Have fun!

from trusspy.

adtzlr avatar adtzlr commented on June 24, 2024

@Giannis1993 please have a look - hope that helps!

from trusspy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.