How to Export Plot Data in COMSOL Multiphysics

Post processing is the last of the five primary steps of simulation development. This step represents the payoff from all the hard work of the previous steps, and it drives the deeper understanding of the design that engineers obtain though simulation. A simulation engineer can significantly improve their understanding, and better communicate that understanding, when they have mastered the skills of post processing. Many plots that simulation engineers develop contain multiple curves, e.g Figure 1, and there is a need to export the data forming the curves to text files. Exported data can then be used in third party software, e.g., MATLAB® or Excel®. These data can also be compared to data in another COMSOL Multiphysics analysis.

June 2021 p1

Figure 1. Example of multiple curves on the same plot.

To export the data behind the curves, right-click Global 1 plot sub-node and select Add Plot Data to Export. This will add a Plot 1 sub-node under the Export node, as shown in Figure 2. In the Settings window, click Browse… this defines the location and name of the file. Then click the Export button in the Settings window. The Messages window confirms where the file is exported as specified in the File section. The structure of the exported text file is shown in Figure 3.

June 2021 p2

Figure 2. Settings window for exporting plot.

June 2021 p3

Figure 3. Default data text file structure for export of multiple curves.

By default, the data are written into a file using the double precision option. To limit the precision to six significant figures, expand the Advanced section in the Settings window and clear the Full precision check box as shown in Figure 4.

Also, to output multiple curves using a separate column for each curve, choose the Append as columns, as shown in Figure 4. This will create a data file where all the curves’ coordinates appear in columns; the first one for the common x-coordinate values and subsequent columns, and one for each curve’s y-coordinate values, as shown in Figure 5. This format can be more convenient for use as input to interpolation functions and for further processing in external software products such as MATLAB® and Excel®.

June 2021 p4

Figure 4. Adjusting Settings to write data in a single precision format and append multiple curves as columns.

June 2021 p5

Figure 5. Data file format written using single precision option and append data as columns.

By default, the file type for the exported data is text file (*.txt). Other formats, such as CSV (Comma-Separated-Values) files (*.csv), data files (*.dat), or Microsoft Excel® workbook (*.xlsx) are also available.

Figures 6 and 7 show the settings and the format of the CSV data file.

June 2021 p6

Figure 6. Selecting file type to write data for the curves.

June 2021 p7

Figure 7. Data for curves saved in the Excel data file format.

AltaSim Technologies combines consulting and training to help our clients be as independent from us as they choose to be. Our introductory training class on COMSOL Multiphysics is taught as seven (7) separate sessions. Engineers can take all seven sessions for an excellent introduction to solving problems with COMSOL Multiphysics. Another option is for engineers to attend only the sessions of interest. Session 7 covers post-processing. Click here for more information and to register.