Engineering Programming and Five-Step Problem Solving

Methodological Approach to Engineering Programming

  • The problem-solving process consists of five distinct steps that must be completed before writing a single line of actual code. These steps are as vital as the code itself, serving as the foundation for complex engineering solutions.

  • The bridge between understanding a problem and writing software is the combination of English descriptions and mathematical notation, which forms the logic and algorithm design.

  • Skipping the initial thinking phase leads to structural errors; therefore, the pre-coding steps are categorized as "things to do before we code."

  • The final preparatory stage involves the creation of pseudocode, which act as a direct precursor to the development of the Python script.

  • The overarching workflow for engineering programming includes defined phases of preparation, implementation (Python), and verification of results.

The Engineering Scenario: Steel Bar Stress Analysis

  • A specific engineering problem is used to illustrate the five-step process: analyzing a steel bar subjected to mechanical stress.

  • The known parameters of the bar are:

    • Tensile Force (FF): 50kN50\,kN

    • Cross-Section Area (AA): 500mm2500\,mm^2

  • The two primary goals for the analysis are:

    • Goal 1: Determine the actual normal stress (σ\sigma) produced in the bar.

    • Goal 2: Determine if the bar is safe to use based on a specific safety limit.

  • Safety Limit (Allowable Stress, σallowable\sigma_{allowable}): 100MPa100\,MPa

Phase 1 and 2: Problem Comprehension and Decomposition

  • Understanding the goal requires identifying what needs to be determined—specifically, the magnitude of the stress and a binary safety assessment.

  • Information gathering involves identifying the physical relationship between force and area. The fundamental engineering formula for stress is:

    • σ=FA\sigma = \frac{F}{A}

  • Consistency in units is paramount for safety calculations. In this context, the relationship for Megapascals (MPaMPa) is defined as:

    • 1MPa=1N1mm21\,MPa = \frac{1\,N}{1\,mm^2}

  • The problem decomposition process highlights that we have sufficient information to solve for stress but must account for the specific units (kNkN vs NN) provided in the initial data.

Phase 3: Identification of Inputs and Outputs

  • Inputs: To reach the goals, the system requires specific variables:

    • Input 1: Tensile Force (FF)

    • Input 2: Cross-Section Area (AA)

    • Input 3: Maximum Allowable Stress (σallowable\sigma_{allowable})

  • Note: While area and force are calculation-specific, the allowable stress is included as an input to facilitate "what-if" scenarios or variable safety thresholds.

  • Outputs: The process must yield two distinct results:

    • Output 1: The calculated normal stress (σ\sigma).

    • Output 2: A safety status (Safe or Not Safe).

Phase 4: Logic and Algorithm Development

  • The algorithm must manage unit conversion to ensure the calculated stress is directly comparable to the allowable stress of 100MPa100\,MPa.

  • Algorithm Sequence:

    1. Obtain Force (FF) and Area (AA).

    2. Obtain Allowable Stress (σallowable\sigma_{allowable}).

    3. Convert Force from kilonewtons (kNkN) to Newtons (NN) to align with the MPaMPa unit definition (N/mm2N/mm^2).

    4. Calculate Stress: σ=FA\sigma = \frac{F}{A}.

    5. Compare the calculated stress (σ\sigma) to the allowable stress (σallowable\sigma_{allowable}).

    6. If σσallowable\sigma \leq \sigma_{allowable}, then the condition is deemed "Safe."

    7. If \sigma > \sigma_{allowable}, then the condition is deemed "Unsafe" or "Not Safe."

    8. Report both the stress value and the safety status.

  • This logic accounts for the two goals of the problem and involves the engineering knowledge of the field combined with programming logic.

Phase 5: Pseudocode, Implementation, and Verification

  • Pseudocode acts as the last step before working on actual code. It structured logically as follows:

    • START

    • Input the required values: Force, Area, Allowable Stress.

    • Perform specific conversions: Force in N=Force in kN×1000\text{Force in } N = \text{Force in } kN \times 1000.

    • Calculate: σ=ForceArea\sigma = \frac{\text{Force}}{Area}.

    • IF stressallowable_stressstress \leq allowable\_stress:

      • The system should report "Safe."

    • ELSE (or IF NOT):

      • The system should report "Not Safe."

    • Report the calculated σ\sigma.

    • END

  • Applying the bar data to the algorithm:

    • F=50,000NF = 50,000\,N

    • A=500mm2A = 500\,mm^2

    • σ=50,000500=100MPa\sigma = \frac{50,000}{500} = 100\,MPa

    • Since 100MPa100MPa100\,MPa \leq 100\,MPa, the condition is "Safe."

  • Once the logic is verified, the system is translated into Python, allowing for any numerical input for force, area, and allowable stress to yield a report.

Questions & Discussion

  • Question regarding Pseudocode Examples: A request was made for a specific example of pseudocode. Response: Handled immediately through the step-by-step steel bar analysis.

  • Question regarding Logical Operators/If Statements: Is there a requirement for a formal "else" statement or can an "if not" structure be used? Response: In logic-building, both "else" and "if not" represent the opposite condition; the goal is to prepare the logic before actual coding. Python will eventually handle these as formal conditional statements.

  • Question regarding Input Convention: Is there a specific convention for which value comes first when comparing a stress number and a safety limit? Response: There is no strict convention; either can be prioritized as long as the logical comparison (\leq or >) remains accurate.

  • Discussion on Implementation: Engineering programming requires a unique combination of domain knowledge (physics/mechanics) and computational logic. The lecture concluded by offering ten minutes of time back to the participants.