Giter VIP home page Giter VIP logo

leglib's Introduction

LegLib

Leglib is just a bunch of utility modules that I wrote and like to use. One very handy one is a rounding function that rounds to significant digits: leglib.fmt.sigdig.

Source: https://github.com/joelegner/leglib

Installation

$ pipenv install leglib

Using

>>> from leglib.fmt import sigdig
>>> sigdig(3.843718473821748732184732)
'3.84'
>>> sigdig(3.843718473821748732184732, 5)
'3.84372'

Testing

$ make test

UnitVal

The UnitVal class represents an engineering quantity with units of either force, distance, or both. It is primarily intended for use in structural engineering applications but could later be extended to other knowledge areas.

Important: Default units are inches for length and pounds for force.

Here are some usage examples. Let's initialize two variables: a distance and a force.

>>> L = 42.0*inches
>>> P = 21.4*kips
>>> print(L)
42.000 in
>>> print(P)
21.400 k

Now we can calculate the moment which is the force applied over the distance.

>>> print(P*L)
898.80 k-in

When units are inconsistent between two variables, UnitVal resolves the conflict by retaining the units of the left-hand side of the expression. So if we reverse P*L to L*P, we get a different result.

>>> print(L*P)
898800 lb-in

The fact that UnitVal converted the result to inches may not seem intuitive unless you understand that the default units are pounds and inches. Thus, when we assigned P = 21.4*kips the UnitVal instance P had its units set to kips explicitly and inches by default.

You can multiply a UnitVal by a float, integer, or Decimal scalar.

>>> print(L*P*0.5)
449400 lb-in

UnitVal keeps track of the exponents of its two unit types (distance and force) so that we can calculate areas, for example.

>>> print(L*L)
1764.0 in^2

UnitVal will substitute psf, psi, ksi, Pa, kPa, MPa, etc. for the appropriate combination of units. For example, it replaces lb/ft^2 with psf, which means "pounds per square foot." Division works as expected.

>>> B = 17.5*feet
>>> A = B*L
>>> Q = P/A
>>> print(Q)
349.39 psf

You can also change the units of a UnitVal instance by passing the units you want to change to.

>>> L = 24.5*feet
>>> L.change_units(inches)
>>> print(L)
294.00 in

Units can be changed to the special aggregate units too (psi, ksi, kPa, etc.).

>>> pressure = 1000.0*psi
>>> print(pressure)
1000.0 psi
>>> pressure.change_units(kilonewtons)
>>> print(pressure)
6894.6 kPa
>>> stress = 60*ksi
>>> print(stress)
60.000 ksi
>>> stress.change_units(megapascals)
>>> print(stress)
413.68 MPa
"""

leglib's People

Contributors

joelegner avatar

Watchers

 avatar

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.