Tuesday, March 11, 2025

What can AI do for engineers (2)

What can AI do for engineers? Beyond providing accurate and reliable information at lightning speed, it can also serve you as your personal computer programmer.


A Real-World Example: AI Writing a Gas Flow Calculation Program

I needed a program to calculate pipeline gas flow using a specific equation found in a three-page PDF. The first two pages contained nomenclature, while the third page had the actual formula.

I decided to use Grok to generate the program. Here’s how it went:
1. Uploading the PDFI visited Grok.com, uploaded the file, and asked: "Please make an HTML program based on AGA equations."
 
2. AI Generates the ProgramGrok quickly produced the program. Clicking "Preview," I saw that it had already prefilled some inputs. I hit the "Calculate Flow Rate" button, and the result was 182,000 cubic feet per day. However, based on experience, this number seemed incorrect.
 
3. Identifying and Fixing an ErrorUpon reviewing the formula, I noticed that Grok had missed the diameter term (d².⁵, where d = 12D). I informed Grok: "Please notice you are missing the term d².⁵. d = 12D." Grok apologized for the oversight and updated the program accordingly. After clicking "Preview" and recalculating, the flow rate was now 91 MMSCFD, which matched my verification with other tools.


Enhancing the Program: Solving for Multiple Variables

There are scenarios where the flow rate is known, but we need to determine diameter, pipeline length, inlet pressure, or other variables.

I instructed Grok to modify the program to allow solving for Q, E, D, P₁, P₂, S, Lₘ, Tₐᵥg, Zₐᵥg, and absolute roughness when any one of these variables is missing.

Grok responded by adding radio buttons to select which variable to solve for. However, I preferred a more intuitive approach, so I said: "Instead of radio buttons, I would like to leave it blank, so that I know this is the missing value to be calculated."

Grok adjusted the program accordingly.


Testing the Final Version

I tested different scenarios:

1. Changing the Diameter and Outlet Pressure. Setting diameter to 0.5 ft and outlet pressure to 500 psia, the program calculated the flow as 30 MMSCFD. 
 
2. Solving for Pipe Diameter. Entering the flow rate and asking Grok to determine the pipe diameter, it returned 6 inches, which was spot on!


AI: Your Personal Programmer

Ever dreamed of becoming a programmer? Now you don’t have to—AI can do it for you!


More Topics

Thanks for watching this video! It is brought to you by Guofu Chen. More interesting topics can be found at showcase.guofuchen.com.