Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Learning Programming for Structural Engineering 12

Status
Not open for further replies.

MegaStructures

Structural
Sep 26, 2019
366
0
0
US
I have recently become very interested in matrix structural analysis and finite element analysis and I have been creating my own "program" using excel. Of course I have quickly noticed that the basic operations available within excel without using VBA is somewhat limited and I cannot make the quality of the program I want. So naturally I have began learning VBA and in my journey around the internet learning VBA I have seen other recommendations for more powerful languages such as Python, Matlab, Fortran etc..

During this whole process I have been thinking a lot about the usefulness of coding in structural engineering and thought that it might be a fun conversation to have to see what other structural engineers have taught themselves to code, how useful they have found it, and what language might be the most helpful. So I would love to hear others opinions on the topic of coding for a structural engineer!

“Any idiot can build a bridge that stands, but it takes an engineer to build a bridge that barely stands.”
 
Replies continue below

Recommended for you

Hi Megastructures

I love programming, I started at a young age and was initially enrolled to study computer science with computational and applied mathematics, I eventually ended up doing Civil engineering.

I think it is a valuable skill that many engineers neglect and don't bother with, as you can develop some amazing solutions through programing.

For my work and personal FEA programming purposes I use Octave which is basically the same as Matlab just a freeware version, the syntax and file formats are exactly the same which makes it easy for trouble shooting as the Matlab help forums are amazing. I also have a freeware copy of Mathematic which runs from a Raspberry Pi which I normally use to test preliminary mathematical ideas which are mathematically intense, just to check the feasibility or troubleshoot before I take the concept to Octave to develop a full on program. I am currently writing a paper about a methodology I developed using a very unconventional method to assess the stability of barges, I implemented the methodology on Octave.

For my personal coding, making small games or messing around with AI, I normally use Python. The only reason I don't use Python in my professional life due to the lack of stability when it comes to updates. A colleague developed a monstrous piece of code for remotely assessing the life span on mechanical equipment and when he did an update of python and/or it's modules, all his code stopped working. After a huge amount of time debugging he couldn't get it to work and just reverted back to the older versions. You wouldn't have these type issues on stuff like Matlab and Octave.

 
I think coding is an excellent skill to have as a structural engineer. I personally enjoy working with C# and javascript, which are two main languages I used for building Tribby3d.

Coding is such a good tool for calcs, structural design and geometry. Aside from text based coding, I would also recommend checking out visual programming such as Grasshopper3d. It's great for generative design and parametric modelling.

Best of luck!
 
I saw your program tribby3d and I was immediately impressed with the graphical interface. I don't work with concrete often, but I do plan on trying the program. Funny you mention Grasshopper3d as another item I've been learning is Dynamo for Revit, which is another visual programming language and seems to make the process so easy it is hard to call it coding :).

It seems like VBA would be the most practical language to learn based on how often Microsoft and Auto-desk programs are used in engineering offices, but VBA doesn't seem to be a very "respected" coding language and it would be a bummer to take the time to learn a language that isn't as helpful as some others. The main reason I started trying to learn VBA for my own program is to try to learn how to make a graphical interface that shows element deflections like shown here.
I've also just always been extremely impressed by the functions that some companies have been able to automate with the help of a good programmer.



“Any idiot can build a bridge that stands, but it takes an engineer to build a bridge that barely stands.”
 
no issue learning VBA, in my experience most of the differences across programming languages are syntax related a logic statement is still a logic statement and a loop s still a loop. Check out IDS's site for some of the things you can do with VBA,
I'd say since you've already started VBA keep with it and see where it leads, Excel is ubiquitous in our industry so makes deployment of your sheet/program almost trivial vs making a web or GUI based program in another language.




My Personal Open Source Structural Applications:

Open Source Structural GitHub Group:
 
Years ago, I took a Visual Basic course as part of my continuing education. One lesson learned from that, is that if you don't regularly use the material, you tend to forget it before long, too. A lesson learned from Excel work primarily is that there is a substantial investment in time to confirm that the software is doing what you think it is.
 
It's been a few years since I last programmed, but used to program in half a dozen different languages... My language of preference was Embarcadero... this is the re-name of Borland's Delphi... extremely powerful with an incredibly easy user interface... The graphical interface and putting together a program is so fast and easy. It can be used for anything that C++ can do and a lot easier. The Pascal type language is strongly typed. Try it, you'll like it... it's incredibly easy to use. It has a built-in matrix operation 'toolkit'.



Rather than think climate change and the corona virus as science, think of it as the wrath of God. Feel any better?
-Dik
 
If you're not invested or interested in writing your own standalone programs, it may also be of interest to work with the APIs of existing programs to automate the more mind-numbing (and thus mistake-prone) tasks or checks. We've been using the little downtime we have now while things are a little slower to play around with creating tools for Revit and ETABS, for instance. I know RAM SS has an API as well, though we haven't touched that one yet since we don't use that program as much. Would love an API for RAM Concept, but don't think that exists yet. We're using Python for our tools, though C# is a pretty common language for APIs as well. Then Revit uses Dynamo as well, as you noted.
 
I'll suggest that what Mohanlal said is true. Using Matlab makes things a good bit easier on you. I don't personally use it. But, a number of "part time" programmers in graduate school swore by it.
 
When I first learned to program structural analysis, I took a huge mental leap in terms of problem solving ability and the process of distilling complex problems into logical steps. I owe my college professor (shout out to Dr. Bill Davids) a debt of gratitude for that, as that skill has probably had the most beneficial and significant impact on my career as an engineer.
 
Don't be ashamed of Excel and VBA but don't expect too much out of them either. I have created some VBA programs for helping me solve retaining wall designs or creating an interaction diagram for a reinforced concrete column design but its abilities for solving complex mathematical operations is limited. I typically write specialty programs nowadays to solve very specific mind numbing math operations that are pretty standardized but that end up saving me lots of time in the end. A thorough program that solves repetitive wood beam design, FRP strengthening, or a PT tendon profile layout can be really helpful. You can either create it just in the spreadsheet or utilize VBA to make the interface have a more professional feel.

Matlab and Fortran were great for me while in school when setting up stiffness matrices and finding forces in truss members but haven't used it since I've been practicing engineering. If you are going to undertake this in a very serious way then I am sure you will have some use for these languages but as a working professional, I know that it's hard to find free time to do this type of stuff if it's not making you money... As for FEA, we're talking a steep learning curve! My FEA professor in grad school created a program with some help from some of his RA's and I looked into it once and was astonished at the limited abilities of it compared to some of the commercially available programs. It makes you realize just how much effort and mindpower go into some of these programs.
 
Wow, I really didn't expect so many responses. It seems that maybe programming isn't as rare among the structural engineering ranks as I might have thought. I appreciate everyone's responses.

Celt83 that was my idea, that once I learned one language I had a better shot at being able to learn others down the road if the need arose.

MrHershey Becoming good at modifying existing commercial programs with API's seems like possibly the most beneficial thing to do with the lowest "cost of entry" in time spent learning. I definitely want to start writing some API's where I can.

Bones206 That is exactly my hope!

STrctPono I'm only making this program to learn. I have spent years kind've sort've knowing what my FEA solver was doing for me on a basic level, but I don't have a full grasp on mesh convergence etc. and I figured what better way to learn the program than build one myself! I am experienced in ANSYS, FEMAP, and SOLIDWORKS so I have no real need to create my own program, but it's sort of fun and teaching me quite a bit.

“Any idiot can build a bridge that stands, but it takes an engineer to build a bridge that barely stands.”
 
Thanks for the mention Celt83.

On the question of whether it is worth using VBA:

It is true that VBA is not well respected amongst full-time programmers, but as far as I have seen the people who make bad comments about it don't know what they are talking about. Not only do they not use the program regularly, they don't even know what the actual features are, or what its real strong points and weaknesses are. Their opinion seems to be based on inexpert users making programming mistakes, which of course there are plenty of examples of, since it remains by far the most widely used programming language for inexpert users.

It simply isn't true that VBA is a less powerful programming language than those used by full-time developers; you can do any computation in VBA that you can do in any other language, including linking to compiled routines if you need to speed up maths intensive operations. The only disadvantages I see with VBA are:

1) You are tied to the Office interface (which means Excel, as far as I'm concerned). This is also an advantage (see below), but it does make it difficult doing anything to work on-line, or do anything for pads or phones (although I don't see why anyone would choose to use a pad or a phone for general engineering work).

2) Passwords are easily cracked, so if code security is an important issue, VBA is not the program to use.

3) Microsoft are basically doing nothing with it these days, so the coding interface is looking pretty old fashioned. I don't find that a problem myself, in fact I still find it far easier and faster to code and debug in VBA than in alternatives, but people starting out may prefer a more modern interface.


Now the advantages:

1) The interface with Excel makes it (as far as I have seen) the easiest and most efficient way to set up programs using numerical calculations, and to display results efficiently. I simply don't agree that using Excel for complex calculations is particularly error prone. Of course it is easy to make mistakes, but it is at least equally easy in any other programming language. In my experience, checking for and fixing errors is much easier using Excel+VBA than it is in any other programming language/ graphical interface, including Python, which I have used quite extensively in recent years.

2) The ability to record and then edit a VBA macro makes the use of complex object models far easier.

3) There are numerous resources on-line available to help non-expert programmers.

For more discussion of what VBA is good for, including links to a number of engineering examples see:



Doug Jenkins
Interactive Design Services
 
IDS, awesome! You have inspired me to keep going with VBA. I opened up your "Frame4 file" and your plot of the frame deflections is exactly what I'm trying to learn right now! I will study your code and see if I can replicate it. I love the website!

“Any idiot can build a bridge that stands, but it takes an engineer to build a bridge that barely stands.”
 
@OP,

If you are a non-programmer and would like to learn programming AND you do not have any particular application/project in mind I would 100% recommend starting with Python. Python is a minimalistic language and so it is possibly the easiest environment to learn basic principles of programming without getting too bogged down in language-specific syntax and other funny bits that you get with some of the other languages. On top of this Python is a general purpose language that can perform on state-of-the-art level if used well and there will be very few instances where you cannot use it to meet your objectives.

Having said that if you work in a traditional style of structural consultancy and would like to learn programming with work-related applications in mind then your best bet is probably VBA. VBA is ugly, it is clunky, and it can be limiting...but it is very good at using Office applications programmatically and thus it is a clear winner. If you are fluent in Python people will find it cool but likely nothing will come of it, however if you are fluent in VBA your employer will potentially (big emphasis on this word) love it and you stand a good chance of firing it up for work every so often. I would say that great majority of work-related tasks can be performed with VBA and it's only with really complex math that you may have to venture out into Python/Java/C++/whatever to fill in the blanks.

There are many good things about MATLAB and in many ways it is similar to Python in the way that it has minimalistic syntax. MATLAB's big downside is that you have to pay a fair amount of money to use it as it comes inside of a proprietary application. MATLAB is also not a general purpose programming language and so it has its limitations - it's like JavaScript but for scientists and engineers.

Accessing application API's is a very useful feature that I think is going to become commonplace in the next 10 years or so. Being able to programmatically access something completely changes the way you look at it - the easiest analogy is to think of how your use of Excel is affected by becoming fluent in VBA. I personally don't even use convoluted nested Excel functions anymore because sometimes it is just way easier to write a custom function to do the job. Application API's change the situation in a similar manner, you can write your own tools to fill in the functionality blanks that are inevitably let over by the application designers.

 
IDS - Did you use the conjugate beam method found on your blog post here to model the appropriate deflected shape for your beam program, or is there a simpler/more effective technique you recommend?

That will be my only questions as I don't expect free help!

“Any idiot can build a bridge that stands, but it takes an engineer to build a bridge that barely stands.”
 
Conjugate beam is one method. I found once I had the end moments from either moment distribution or stiffness matrix solutions it was simpler to use the deflection formulas from direct integration for each load type directly and combine the results using super position. Assuming you've already got the formulas worked out for each loading type and a beam with constant cross section.

My Personal Open Source Structural Applications:

Open Source Structural GitHub Group:
 
MegaStructures said:
IDS - Did you use the conjugate beam method found on your blog post here to model the appropriate deflected shape for your beam program, or is there a simpler/more effective technique you recommend?

No, the procedure used in the ConBeam spreadsheet is:

1. Find the deflections and actions in the beam with all internal supports and end moment restraints removed, i.e. as a simply supported beam with only the end supports.

2. Find the deflections at each support due to unit loads at each support position (one loadcase for each support freedom).

3. Set up and solve the simultaneous equations to find the reaction forces required to reduce the combined deflection to zero at every support location.

4. Find the deflections and actions along the beam due to the combined reaction forces, and add to the results from 1.


That will be my only questions as I don't expect free help!

I like to get questions on anything posted in the blog and you are free to use the code from any of the download files. Feel free to ask as many questions as you like, and if it is too detailed or time consuming for me to answer (or if I'm just busy with other things) I'll let you know.

Doug Jenkins
Interactive Design Services
 
captain-slow - I'm tempted to leap to the defence of VBA, but since I doubt we'd agree on that, I'll just comment on why I am using Python (with Excel) these days.

Python has several features that I dislike, and lacks some VBA features that I find very useful, but what it does have that VBA lacks is easy access to a vast range of free libraries (such as Numpy and Scipy) that provide efficient compiled code for linear algebra, statistics, curve fitting, solver routines, and many others. These combined with Excel interface programs such as pyxll or xlwings allow maths intensive applications to be run efficiently from Excel with less hassle than preparing and accessing compiled code through VBA.

Doug Jenkins
Interactive Design Services
 
Status
Not open for further replies.
Back
Top