Main Street, OpenSees

Every C++ executable has a main() function and OpenSees.exe, the standalone Tcl executable, is no exception. You can find the main() function in SRC/tcl/tclAppInit.cpp, where nothing much happens besides calling g3TclMain(), which is defined in SRC/tcl/tclMain.cpp, home of more familiar content like the banner and copyright statement.

Prior to the conveniences provided by scripting languages–running parametric studies, dealing with convergence issues, and managing memory–OpenSees, or rather G3, models were built and analyzed by writing a main() function.

The analyses in Frank’s Ph.D. dissertation are all main() functions. Fortunately, I never had to deal with G3 main() functions–when I got involved, the Tcl interpreter had just been implemented, as brought forth by the aforementioned g3TclMain().

The interpreter commands allocate objects, add those objects to the domain, set pointers, perform analyses, record results, and clean up memory–all behind the scenes, hidden from the user. With a main() function, you have to do all that “behind the scenes” work yourself.

Still, despite the convenience of scripting languages, building and analyzing OpenSees models by writing a C++ main() function will always be useful, particularly for very specific types of models, like SDF or simple MDF systems, continuous beams, and linear-elastic frames.

Compared to OpenSees.exe (Tcl) and OpenSeesPy, analyses performed via main() will run faster due to the absence of scripting overhead. But how much faster depends on the size of the model, the number of analysis steps, the amount of scripting, and several other factors.

You also have to know what you’re doing with memory management in order to conduct an OpenSees analysis from main(). Garbage collection is not built into C++, i.e., you are the garbage collector. You can quickly run out of memory if, for example, your main() function performs a parametric analysis and you do not delete objects that were dynamically allocated inside the loop.

With great power comes great responsibility. So, if you are not familiar with C++ objects, references, and pointers and if the axiom “for every new you need a delete” doesn’t resonate with you, it’s best to stick with the scripting languages when using OpenSees.

If, despite my cautionary tone, you are still interested in building an OpenSees main() function for Windows, check out the quickMain project in the Visual Studio workspace. This project builds an executable for Example1.1.tcl, the canonical three member truss analysis that inspired this modeling challenge. The source code for the main() function is in EXAMPLES/Example1/main.cpp. In that directory, Linux users will also find a Makefile that works with everything set up in your OpenSees/Makefile.def, i.e., if you can compile OpenSees, you can compile this main() function. Eventually, all of this will work with CMake.

If you need any help getting an application built via an OpenSees main() function, get in touch.


Because it is a dynamically loaded library (dll), OpenSeesPy does not have a main() function.

3 thoughts on “Main Street, OpenSees

  1. Dear Professor Michael,

    Thanks for these minute details, hitherto unknown as a user for me over these years. Joining the recent Bootcamp was a great experience for me, which boosted up my confidence, as I am not a great c++ programer.

    We are working on implementing Scaled Boundary FEM in OS and I think, we are making reasonably satisfactory progress, particularly keeping in view my weak cpp background (I think).

    Thanks for your posts here as well as in FB and the OSG videos. Another great decision I was expecting for years now, is to shift to cmake..

    Now, there are good resources and more active community help is available, compared to the period when I started to play with OS, out of my interest in DSSI, after my PhD, probably around 2005 or so..

    Best regards Sukumar

    Liked by 1 person

    1. Hello Sukumar,
      Thank you for the kind feedback! I think there will be some major growing pains for the OpenSees community to make the change to CMake. Also, you are right, the resources available for OpenSees have come a long way since 2005 🙂
      Michael

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.