Mesh Mess

FEM, CFD, CAE, and all that.

Tag: coding

Store a polynomial in non-symbolic language

Sometimes one wants to store a polynomial in a non-symbolic language, such as Fotran or C. A easy way to achieve this is to take advantage of the isomorphism between polynomial space P(n) and space R^{n+1}. Namely, we can build an array with entries as the coefficients of the polynomial to be stored. Furthermore, considering these coefficients are just the coordinates of the polynomial in the space spanned by the canonical basis 1,x,x^2,\dots, we can express the polynomial using any basis expansion.

Check Fortran 77 line length

Another issue with F77 is its length limit: each line should be less than 72 char, otherwise the rest of the content will be ignored. Of course I can demand compiler work in free-form mode, but that would cause other compatibility problems. This happens occasionally after I’ve done some “sed s/” stuff over the variable names. So I need to remember checking line length, by adding an awk line in the Makefile:

awk '/^[^cC]/ && length > 72 {print FILENAME,FNR}' *.f


Common block in Domain Decomposition implementation

Fortran 77 essentially does not have global variables for subroutines, instead, common blocks are used to passing data across subroutines when arguments are not preferred. This is conceptually unsafe, though widely used in some legacy F77 codes. The code I’ve been working on adopts this “feature” extensively. The problem is, in Dirichlet-Neumann-like domain decomposition implementation, the solver will be called twice for each iteration, each time with different stiffness matrix setup(due to different subdomains) and boundary conditions. On the other hand, the common blocks make those two calls undistinguishable.

To reuse the legacy solver, my first try was to construct two copies of the solver by putting it into two modules, hoping the explicit interface of the modules would identify the common blocks in different copies. This turns out to be wrong: the subroutines from the two modules still share the same common blocks.

What I finally decided to do is to build a copy of the original solver by renaming all the common blocks. Sed & AWK make this  not to difficult. But still I don’t think that’s the most efficient way to tackle this. Consider this is a lesson that not all sequential solvers are easy to parallelize.

30 of the World’s Greatest Wedding Cakes

Following the link. And this one is my favorite.

Top 50 Programming Quotes of All Time

Smart, hilarious, insightful, whatever you want to call them. Here are my favorite:

50. “Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning.”
– Rick Cook
37. “In the one and only true way. The object-oriented version of ‘Spaghetti code’ is, of course, ‘Lasagna code’. (Too many layers).”
– Roberto Waltman.
36. “FORTRAN is not a flower but a weed — it is hardy, occasionally blooms, and grows in every computer.”
– Alan J. Perlis.
30. “Python’s a drop-in replacement for BASIC in the sense that Optimus Prime is a drop-in replacement for a truck.”
– Cory Dodt
22. “Perl – The only language that looks the same before and after RSA encryption.”
– Keith Bostic
13. “Sometimes it pays to stay in bed on Monday, rather than spending the rest of the week debugging Monday’s code.”
– Christopher Thompson
12. “Measuring programming progress by lines of code is like measuring aircraft building progress by weight.”
– Bill Gates
5. “To iterate is human, to recurse divine.”
– L. Peter Deutsch
2. “Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.”
– Martin Golding