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.