Python calling C++ calling Fortran
I got it working a while ago, but I haven’t had a chance to update my eager audience. I built a simple simple simulation tool using this crazy combination of languages. It’s a library written in C++ that uses the finite volume method to simulate diffusion in one dimenstion. What’s cool is that it’s designed to be called from Python using Boost. Furthermore, it then uses Boost Bindings (not officially part of Boost) to call LAPACK (a Fortran library) to solve linear equations (as shown in a previous post). It’s pretty cool that all this stuff actually works together. Why did I do this? Python is my favorite very-high-level language for doing scientific programming. Compared to C++ or Fortran, it’s just so easy to do things in Python, like making plots or reading in an xml file. I chose C++ for the numerical codes because it’s faster than Python and the Boost library connects the two. I could have used Fortran, but the Python interfaces doesn’t seem to be as clean, probably because Fortran isn’t object-oriented. Finally, since the reference implementation of LAPACK is still in Fortran, I just used the Boost bindings to call it. I might switch to a native C++ linear algebra library if a clear leader emerges from the confusing alternatives that are available today. More complaints on that later…
Subtle aspects of using Boost and LAPACK
I spent part of the afternoon wrestling with LAPACK integration in a C++ program, using the unofficial Boost bindings. I learned a couple of interesting things. test.C is a file that demonstrates them. 1. You need to create column-major matrices to pass to LAPACK. The subtle part about this is that the matrices are internally stored as column-major (like Fortran) but are accessed like row-major matrices (like C). In other words, even when you declare A as column-major, A(3,5) refers to the third row and fifth column of A. This was not obvious to me. 2. The LAPACK routines may modify the matrices that are passed to them. For example, when using gesv(A,B) to solve a system of linear equations, the matrix B is modified to contain the solution values–this is obvious. It is not obvious, at first, that the matrix A is also modified (and I don’t know what useful information it contains). 3. There does not seem to be any binding to the specialized LAPACK solvers for banded and tri-diagonal matrices. I would like to know why, since my matrix is tri-diagonal and it can probably be solved considerable more quickly.
The need for 3D technical drawing software
Today I was reminded again of the need for a new kind of technical drawing software. Here is the problem I am facing: I want to create a vector drawing of a three dimensional structure. Right now, I can either create it in CAD and export a bitmap, or I can manually draw a 3-D representation using 2-D vector software such as Dia or Xfig. For publication-quality graphics, the first approach is usually out. The second approach works, but what if I spend an hour drawing, only to realize that I should have chosen a different perspective or viewpoint to show a critical feature of the drawing? I have to modify the entire drawing just to change the viewpoint. Or, what if I need to show two views to capture all the details? I have to create both from scratch. I envion a new type of tool, or CATD (Computer Aided Technical Drawing). My vision starts with a 3-D CAD tool, which could be built around lines, points, and surfaces (like AutoCAD) or a solid modeling kernel (like SolidWorks). The user should have the ability to choose surfaces to be transparent or solid, and create cut planes to show internal features. However, the 3-D model is only the first step. Once the user has created the model and chosen a viewpoint that shows its important features, the 3-D model is projected onto a 2D surface to create a vector drawing that can be further manipulated. Ideally, the 2-D vectors created from each “object” in the CAD model would remain grouped together for easy manipulation. The final output would be a publication-quality PostScript, PDF, or SVG file. I don’t know if this is commercially available, but it certainly isn’t available as open source. As a starting point, I propose creating a plugin for Blender that fulfills this purpose. It would take the 3-D model, as displayed on the screen, and create a vector 2-D representation that can be imported into other software for manipulation. Ultimately, the tool should allow users to import different types of CAD models. The text should be somehow integrated with LaTeX for seamless typesetting of equations and numbers.
LISP is cool but annoying
I spent today organizing my personal finances in GnuCash. I also spent a few hours customizing a report, which unfortunately means hacking in Scheme, a “dialect” of LISP. Don’t get me wrong, I actually like LISP/Scheme quite a bit. What I don’t like is writing code in “normal” languages, like C++ and Python, all week long and then switching to Scheme. Scheme has a totally different syntax and requires a different way of thinking about a problem. Normal language: result = myfunction (argument1, argument2) Scheme code: (myfunction (argument1 argument2)) If you have never seen a LISP language, find one and check it out. Here are the links I always use: