Mechanics research codes are typically written by graduate students who aim
to get their work done as quickly as possible. These codes are not meant
to last beyond the publication of a few related papers.
These files have the advantage that they can be read in quickly using an input
file stream and the code for doing that can be written in minutes.
The problem
But sometimes these code last beyond the tenure of the student, and some other
person (or the student her/himself) has to try to understand the format of the
input file. That process can take hours and sometimes days, especially if the
format has not been docsumented and the next person has to dig into the code to
understand what each of the numbers means.
The XML Approach
One potential approach is to use XML to mark-up the input file which
can be transformed into:
Though this file is more verbose that the original, the user does not have to read the
source code to understand the format of the file and what the various numbers mean.
The challenge for mechanics researchers is parsing and reading that sort of format.
Below I’ll show you how that’s done quickly and easily with modern C++.
Reading XML
For production codes such as Vaango we use full featured libraries such as Xerces or LibXml2. However, for research codes, there are a number of simpler alternatives. I prefer the header-only style provided by ZenXml.
The reader code is quite straightforward. Let’s encapsulate it in the class
BoundaryReader.
First, the header BoundaryReader.h
and then the implementation BoundaryReader.cc
Of course, if you want to use the data that you have read, you will have to
save them. That’s left as an exercise for the reader. As you can see, reading
a XML file can be quite straightforward and you have checks on the validity of
your file along each step of the reading process.
Conclusion
I recommend shifting the XML or some other similar structured format for
the input files in your research codes. However, you may think that the
XML format is too verbose. In that case I’d suggest using JSON
and in a future post I’ll show you how to read JSON in C++.
If you have questions/comments/corrections, please contact banerjee at parresianz dot com dot zen (without the dot zen).
We have been translating a few Code-Aster verification test manuals into English.
The process is not just a straightforward translation of the text in the Fr...
The Code-Aster cooling tower modal analysis validation test
FORMA11c comes with a quadrilateral mesh provided by Code-Aster.
Tips on quadrilateral meshing wi...
In this article, I will discuss how elements can be selected from deep inside a 3D mesh
in the Salome-Meca environment and manipulated with Python scripts.
Introduction
One of the reasons I switched to cmake for my builds was the need to compile my
Vaango code on a BlueGene/Q system. The code was previously co...