Programming Hardcore Programming for Mechanical Engineers: Build Engineering Applications from Scratch

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Hardcore Programming for Mechanical Engineers is for intermediate programmers who want to write good applications that solve tough engineering problems – from scratch. What if you could solve challenging engineering problems with Python programming? With this book’s hardcore approach, you’ll learn how to code solutions from scratch using linear algebra, geometry, and physics to write custom libraries, draw primitives, and build applications. Ángel Sola Orbaiceta covers core programming techniques for mechanical engineers, with a focus on crafting high-quality code and leveraging automated unit testing for error-free implementations. You’ll develop a geometry toolbox, filling it with lines and shapes to diagram engineering problems; create vector graphics and animations for mechanical simulations; and code algorithms to perform complex calculations. As a capstone you’ll combine these lessons to build a complete structural analysis application to solve a 2D truss problem that you might encounter in the field. Learn how to: • Use regular expressions to elegantly parse file input • Refine your code with unit testing, encapsulation, and descriptive names • Draw images onscreen and create animations with Tkinter’s Canvas widget • Solve systems of linear equations using the Cholesky decomposition algorithm • Build an application that visualizes a truss structure’s stresses and strains Stop relying on third-party software—there are no shortcuts on the path to proficiency. With Hardcore Programming for Mechanical Engineers, you’ll hone your programming skills to get correct results every time.

Author(s): Angel Sola Orbaiceta
Edition: 1
Publisher: No Starch Press
Year: 2021

Language: English
Commentary: Vector PDF
Pages: 600
City: San Francisco, CA
Tags: Programming; GUI; Python; Functional Programming; Numerical Methods; Graphics; Animation; Object-Oriented Programming; Simulation; Tkinter; Linear Algebra; Unit Testing; Engineering; Geometry; Elementary

About the Author
Brief Contents
Contents in Detail
Acknowledgments
Introduction
Who This Book Is For
What You'll Learn
About This Book
What Is the "Hardcore" About?
Why Python?
Contents at a Glance
Setting Up Your Environment
Downloading the Book's Code
Installing Python
Installing and Configuring PyCharm
PyCharm Introduction
Creating Packages and Files
Creating Run Configurations
Debugging Python Code
Summary
Part I: Basics
1: A Short Python Primer
Python Packages and Modules
Modules
Packages
Running Files
Importing Code
Different Import Forms
Documenting the Code with Docstrings
Collections in Python
Sets
Tuples
Lists
Dictionaries
Destructuring
Summary
2: Two Python Paradigms
Functional Programming
Pure Functions
Immutability
Lambdas
Higher-Order Functions
Functions Inside Other Functions
Filter, Map, and Reduce
List Comprehensions
Object-Oriented Programming
Classes
Magic Methods
Type Hints
Summary
3: The Command Line
Unix and Windows
Finding Your Shell
Installing the Windows Subsystem for Linux
Taking a First Look at the Shell
Files and Directories
Moving Around
Creating Files and Directories
Deleting Files and Directories
Commands Summary
Using Windows Subsystem for Linux
Running Python Scripts
Passing Arguments to the Script
Standard Input and Output
Redirecting the Output to a File
Redirecting the Input from a File
Using PyCharm's Python Console
Summary
Part II: 2D Geometry
4: Points and Vectors
The Point Class
Calculating Distance Between Points
Addition and Subtraction Operators
The Vector Class
Addition and Subtraction Operators
Scaling Vectors
Displacing Points
Vector Norms
Immutable Design
Naming Convention
Dot Product
Projecting Vectors
Cross Product
Parallel and Perpendicular Vectors
Angles Between Vectors
Rotating Vectors
Sine and Cosine
Completing Our Classes
Checking Equality
String Representation
Vector Factories
Unit Testing
Testing Distances
Testing Vector Plus and Minus Operations
Testing Vector Product Operations
Testing Vector Parallelism and Perpendicularity
Three Golden Rules for Unit Testing
Summary
5: Lines and Segments
Segment Class
The Segment's Direction
The Segment's Length
The t Parameter and Middle Points
Closest Point
Distance to a Point
Segment Intersections
Equality and String Representation
Line Class
Line Intersections
Segment's Bisector
Summary
6: Polygons
Polygon Class
Sides
Centroid
Contains Point
Polygon Factory
Polygon Equality
Circle Class
Contains Point
Circle to Polygon
Equality and String Representation
Circle Factories
Rect Class
Contains Point
Intersections
Convert to Polygon
Equality
Rectangle Factories
Summary
7: Affine Transformations
Affine Transformations
Examples of Affine Transformations
The Affine Transformation Class
Testing the Transformation of Points
Transform Segments and Polygons
Concatenating Transformations
Inverting Affine Transformations
Scaling
Rotating
Interpolating Transformations
Motivating Interpolation
Implementing Interpolation
Geom2D Final Touches
Test Files
Running All Tests
Package Imports
Summary
Part III: Graphics and Simulations
8: Drawing Vector Images
Bitmaps and Vector Images
The SVG Format
The viewBox
Space Transformation
The svg Package
Templates
Loading Templates
Image Templates
Attributes
The SVG Primitives
Lines
Rectangles
Circles
Polygons
Polylines
Text
Groups
Arrows
Primitives Result
Package Imports
Summary
9: Building a Circle from Three Points
Application Architecture
Setup
Creating a Run Configuration
Why Use a Run Configuration?
Reading the Input and Configuration Files
Regular Expressions
Regular Expressions Cheat Sheet
Matching Points
The Configuration File
Problem Model and Resolution
Generating Output
Drawing the Output Circle
Drawing the Input Points
Result
Flip the Y-Axis
Distributing Our Application
Understanding the Problem
Finding a Solution
Running the App Without an Input File
Summary
10: Graphical User Interfaces and the Canvas
Tkinter
Our First GUI Program
The Canvas
Drawing Our Geometric Primitives
The Canvas Wrapper Class
Drawing Segments
Drawing Polygons
Drawing Arrows
Summary
11: Animations, Simulations, and the Time Loop
Defining Terms
What Is an Animation?
What Is a System?
What Is a Simulation?
What Is the Time Loop?
Our First Animation
Setup
Adding a Frame Count Label
Updating the System
Creating Motion
Abstracting the Main Loop Function
Refactoring Our Simulation
Playing with the Circle Divisions
Playing with the Affine Transformation
Cleaning Up the Module
Summary
12: Animating Affine Transformations
Application Architecture and Visibility Diagrams
Setting Up
Creating a Run Configuration
Creating a Bash Script
Reading the Configuration File
Reading Input
Formatting the Input
Adding Example Input
Parsing the Affine Transformation
Parsing the Geometric Primitives
Running the Simulation
Building the User Interface
Implementing the Simulation Logic
Drawing the Axes
Summary
Part IV: Systems of Equations
13: Matrices and Vectors
List Utils
Setup
Vectors
Implementing the Vector Class
Testing the Vector Class
Matrices
Setting Values
Getting Values
Scaling Values
Matrix Equality
Testing the Matrix Class
Summary
14: Linear Equations
Systems of Linear Equations
Numerical Methods
Cholesky Decomposition
LU Factorization Methods
Understanding Cholesky
A Factorization by Hand
A Resolution by Hand
Implementing Cholesky
Testing Cholesky: An Integration Test
Summary
Part V: Truss Structures
15: Structural Models
Solving Structural Problems
Structural Member Internal Forces
Elastic Bodies Subject to External Forces
Axial and Shear Forces
Bending and Torsional Moments
Tension and Compression
Hooke's Law
Stress-Strain Diagrams
Plane Trusses
Two-Force Members
Stiffness Matrices in Global Coordinates
Original Structure Model
The Node Class
The Bar Class
The Structure Class
Creating a Structure from the Python Shell
The Structure Solution Model
The Solution Nodes
The Solution Bars
The Structure Solution
Summary
16: Structure Resolution
Structure Resolution
Interpreting the Stiffness Matrix Terms
Structure Initialization
The Main Structure Resolution Algorithm
Numbering Degrees of Freedom
Assembling and Resolving the System of Equations
Creating the Solution
The Result
Advanced Unit Testing: Test Doubles
Test Doubles
The unittest.mock Package
Testing the Structure Solution Class
Testing the Structure Resolution Process
Summary
17: Reading Input from a File
Defining the Input Format
The Nodes Format
The Loads Format
The Bars Format
The File Format
Finding the Regular Expressions
The Nodes Regex
The Loads Regex
The Bars Regex
Setup
Parsing Nodes
Testing the Node Parser
Parsing Bars
Testing the Bar Parser
Parsing Loads
Testing the Load Parser
Parsing the Structure
Overview
Setup
Ignoring Blank Lines and Comments
Parsing the Lines
Splitting the Lines and Instantiating the Structure
The Result
Testing the Structure Parser
Summary
18: Producing an SVG Image and Text File
Setup
From Structure Solution to SVG
The Configuration File
The Settings
The Solution Drawing Function
Captions
The Bars
The Nodes
The Node Reactions
The Loads
Putting It All Together
The Final Result
From Structure Solution to Text
Structure Solution's String
The Nodes
The Bars
The Unicode Characters
Putting It All Together
Summary
19Assembling Our Application
A General Overview
Setup
Input Arguments
Generating the Output
The Main Script
Trying the App
Playing with the Arguments
Solving a Large Structure
Summary
Bibliography
Index
Bibliography
Index