Some things I learnt during my thesis

Libmesh convert errors at runtime

On MAC OS X, the bundled C and C++ compilers are not all equal when it comes to typecasting. Libmesh has thrown me many convert errors on previously working programs (e.g. all my numerical work, but also simple examples of the library...). The typical error states: "Failed to convert N7libMesh13NumericVectorIdEE pointer to PN7libMesh11PetscVectorIdEE".

Solution: add the CC=clang CXX=clang++ to your configure line, and recompile the library.

Other (questionable) solution: never try to update a working library...

XCode : Frameworks that don't link correctly during copy files

When you're bundling an app to release it on Mac OS X, you have two choices to include frameworks correctly. You can have users install them on their machine, but that has some drawbacks (updating local copies for example), or you can include the frameworks directly in your app. This I think is the preferred solution, it usually doesn't make your app that much bigger.

Now, how do you make sure that the copy files step went on correctly ? It happens that your computer will rather use installed copies than bundled ones, so your app will always work on your machine. But what about others ? A quick'n'dirty solution to make sure is to rename your local copies (in /Library/Frameworks), if the app still runs, it worked.

Protip: make sure all the frameworks you bundle are actually in use. The ones that are not will never link correctly...

Handling file exportation in libmesh

Libmesh lets you export its mesh and solutions data to both XDA and XDR (eXternal Data Representation) file types. Although the exportation to the XDA file format never worked out for me (quickly got a bug iirc, I didn't wait long before using XDR), XDR file export and import actions worked like a charm immediately.

That was true until recently, when importing some files started getting me errors. It took time before I (Basile actually) found out what the issue was. The istream function threw an exception (assertion of in->good() failed) for numbers smaller than e-300. Yes, that's pretty small. So files without any of those smallish numbers imported alright, and others got me a nice error. (Btw, libmesh takes a desperate attempt to find out if some elements are infinite before crashing).

The nice solution is to use the libMeshEnums::XdrMODE ENCODE. Then your XDR files are written in binary format, and if you use the DECODE mode at read, you won't experience any crash, great ! Of course, reading binary files is not very funny, so don't hesitate to duplicate your writing if you want an ASCII file to read your data in clear text.

Compiling the libmesh library and its components

The Libmesh library provides a framework for finite elements simulations. It was developped for spacecraft engineering simulations, and is now a very fast, very versatile, open source finite elements library. Libmesh is a C++ written library.

It uses several external libraries to compute the results of the simualtions quicker, in particular petsc (linear systems solving) and slepc (for solving eigenvalue problems). The combination of these efficient external libraries makes libmesh a very powerful tool.

Libmesh is not a very heavy framework, but it can be tricky to get working for someone who is not used to compiling libraries, and linking them together. Practically, the programs you are going to write for libmesh, are C++ programs that are going to use the specific functions (classes, methods) provided by the libmesh environment. When you download libmesh, you get its source code. It's the same for the external libraries like petsc. You should put these where you keep your programs. That's gonna be the root folder, where libmesh is "installed". First, you have to compile this source code into a working "program". That's going to create binaries, link the whole thing together, and actually create the framework you're going to be using. That was the library's compilation part.

As I said earlier, this framework contains a lot of classes and tools, and to find those, the program you are now writing (somewhere else, your very own C++ written problem) must know where libmesh is located. It needs to be linked to the correct libraries.

These installation steps are described here (libmesh), here (petsc), and here (slepc)

And now for the tips :