Biswajit Banerjee

### XML format for particle input files

##### Introduction

Let us now change tack slightly and return to an issue I had talked about earlier in Input files: reading XML. Typical input files in research simulation codes cannot be easily deciphered. But in some cases headers are included to make the reading process easier.

An example is a particle input file for a DEM code, called particle_distribution.csv, that looks like the following:

 12
id           type       radius_a       radius_b       radius_c     position_x     position_y     position_z       axle_a_x       axle_a_y       axle_a_z       axle_b_x       axle_b_y       axle_b_z       axle_c_x       axle_c_y       axle_c_z     velocity_x     velocity_y     velocity_z         omga_x         omga_y         omga_z        force_x        force_y        force_z       moment_x       moment_y       moment_z
1              0   1.150000e+00   5.000000e-01   6.900000e-01   4.973174e+01   0.000000e+00   9.936725e-01   2.250054e+00   1.570796e+00   6.792575e-01   1.570796e+00   4.619360e-07   1.570796e+00   2.462335e+00   1.570796e+00   2.250054e+00   2.008031e-02   0.000000e+00   5.505538e-02   0.000000e+00   2.781917e-02   0.000000e+00  -4.916840e+05   0.000000e+00  -1.269380e+05   1.688596e-01  -1.187120e+05  -3.092984e-01
187              0   1.150000e+00   5.000000e-01   6.900000e-01   5.090096e+01   0.000000e+00   5.320529e+00   2.536687e+00   1.570796e+00   9.658907e-01   1.570797e+00   1.803533e-06   1.570798e+00   2.175704e+00   1.570796e+00   2.536685e+00  -3.014865e-01   0.000000e+00  -1.031938e-01   0.000000e+00  -7.066198e-02   0.000000e+00  -4.413702e+03   0.000000e+00  -1.080548e+04  -1.174683e-01  -3.673358e+04  -5.749536e-02
........................
5
1.000000e+00   1.400000e+00
8.000000e-01   1.300000e+00
6.000000e-01   1.200000e+00
3.000000e-01   1.150000e+00
1.000000e-01   1.000000e+00

8.000000e-01   6.000000e-01


There are 12 particles in this file and at the end there are some sieve sizes and passing percentages, and also a radius ratio. We would like to automatically convert this file into a form that’s more easily read and which also contains information about units. R provides an excellent set of tools for that type of automation.

We would like to convert this data into a form that’s easier to understand, e.g.,

##### R script converter from CSV to XML

Here’s a script called convertParDistToBinXML.R that does the conversion:

You can run this script in R by first loading it using source("convertPartDistToBinXML.R") and then running doConversion("file_name.csv", "ascii") or doConversion("file_name.csv", "base64").

##### The output ASCII XML file

The ASCII XML file produced by this script is particle_distribution.ascii.xml and contains

##### The output compressed base64 XML file

The compressed base64 XML file produced by this script is particle_distribution.base64.xml and contains

For a file containing 412 particles, the original CSV file was of size 177K, the ASCII XML version was 85K, and the compressed base64 XML file was 39. The compressed ASCII XML file was also smaller than the compressed base64 XML file.

#### Remarks

In general it is better to use structured files for input data, provided the size of the data is not too large. If the input files are large, a compressed binary format is better and should be used if possible.