COMSOL MeshImportExportGuide
COMSOL MeshImportExportGuide
Contact Information
Visit the Contact COMSOL page at www.comsol.com/contact to submit general inquiries
or search for an address and phone number. You can also visit the Worldwide Sales Offices
page at www.comsol.com/contact/offices for address and contact information.
If you need to contact Support, an online request form is located on the COMSOL Access
page at www.comsol.com/support/case. Other useful links include:
Index 69
CONTENTS |3
4 | CONTENTS
Importing and Exporting Mesh and Interpolation
Data
In COMSOL Multiphysics, you can import mesh and interpolation data created by other software for use in your
simulations. You can also export data created in COMSOL Multiphysics to use in other COMSOL models and
applications as well as other software. This document and accompanying example files give an overview of the
import and export functionality available in COMSOL Multiphysics and a detailed description of the import,
export, and native COMSOL formats. For more detailed information on how to use COMSOL Multiphysics for
import and export of data, see the COMSOL Multiphysics Reference Manual in the installed documentation set.
FILE FORMAT EXTENSION VOLUME SURFACE INTERPOLATION IMPORT AS IMPORT AS EXPORT SELECTIONS
MESH MESH DATA IMPORT GEOMETRY MESH TRANSFER
1
Can be imported as geometry curve objects
The COMSOL native binary and text file formats can also be used for storing CAD data, which is not covered by
this document. For a mesh data file, there will be exactly one mesh defined in the file. Mixing geometry and mesh
Note that Table 1 only includes file formats for mesh and interpolation data and that many other types of file
formats are supported by COMSOL Multiphysics as well as by various add-on products. For a complete list of file
formats, see Introduction to COMSOL Multiphysics or the COMSOL web page.
CONVERSIONS ON IMPORT
The import functionality includes the capability of partitioning the imported mesh data into multiple domains and
boundary entities, either automatically or by manual partition operations. Imported mesh data can be used in two
different ways: directly as a mesh used for analysis or indirectly as a geometry object. This is indicated in Table 1 in
the columns Import as Geometry and Import as Mesh. It is recommended to work with the mesh directly, using
the Operations for Editing Imported Meshes to repair, combine, and remesh the imported meshes. As an
alternative, when importing volumetric or surface mesh data, COMSOL Multiphysics can convert the surface part
of the data into a solid COMSOL geometry object that can further be used for generating a new mesh that is
different from the original mesh.
When importing volumetric mesh data directly, COMSOL Multiphysics can retain the original mesh, such as a
tetrahedral mesh, and use the mesh data in any type of physics analysis, regardless of the intent of the original
imported mesh. For example, a mesh generated by another software, originally intended for structural analysis, can
be imported into COMSOL Multiphysics and used for fluid flow, acoustics, electromagnetics, etc. The functionality
in COMSOL Multiphysics allows the user to change the element type, also called the shape function, defined on
an imported mesh. For example, the imported mesh may have originally been used for a structural analysis based
on so-called serendipity elements. After being imported to COMSOL Multiphysics, the same mesh can be used in
the RF Module for an electromagnetic wave propagation analysis, where a completely different type of element is
needed; so-called vector elements. The conversion of the element type, or shape function, is done automatically. In
addition, mixed elements can be used for a multiphysics analysis where each participating physics defines its own
type of element. See Second-Order Element Data for more information about how the element order is handled.
From the model tree Results>Export node, you can export the mesh, simulation, and other data in several ways,
including mesh data used for visualization that is not directly related to the mesh used for simulation, as described
in the section Exporting Data from the Results Node.
For the sectionwise (.txt) format, you specify one type of elements to export: domain, boundary, or edge mesh data.
The output NASTRAN file can be stored in the small field format (single precision), large field format (double
precision), or free field format (comma separated). These options are specific to the NASTRAN format. For more
information, see the various online resources for the NASTRAN format. By default, second-order elements are
exported. If the mesh to export is an imported linear mesh, the information about how to place the second-order
nodes will be estimated from the linear mesh. Exporting the linear, or first-order, element information is also
supported. Second-order information is then ignored.
The 3MF format supports two modes of export: the entire surface mesh as one 3MF object of Surface type, or
export of the surface mesh of each domain as a separate 3MF object of Model type and the remaining surface mesh,
corresponding to faces not adjacent to any domain, as a 3MF object of Surface type.
The following tutorial series showcases how imported STL data can be used in the software:
https://www.comsol.com/model/stl-import-tutorial-series-30951
https://www.comsol.com/model/eigenvalue-analysis-of-a-crankshaft-986.
Alternatively, you can import a surface mesh on any of the formats STL, PLY, 3MF, or VRML. The length unit
specified in 3MF files is used to scale the mesh during the import. Use Operations for Editing Imported Meshes to
improve the quality of the surface mesh, intersect the mesh, form domains, and fill the domains with a volume
mesh.
Mesh Partitioning
When a mesh is imported into COMSOL Multiphysics, it is automatically partitioned into geometric domains,
boundaries, edges, and points. If the automatically performed partitioning does not match the requirements, you
can modify the boundary partitioning options or perform manual partitioning using Operations for Editing
Imported Meshes. The additional domains and boundaries formed by this type of operation can be used, for
example, to define other material properties or boundary conditions (loads). See Mesh Elements for 1D, 2D, and
3D Meshes for more information.
• Adapt
• Boundary Layers
• Collapse Entities
https://www.comsol.com/blogs/editing-and-repairing-imported-meshes-in-comsol-multiphysics/
Selections
Selections are used for grouping geometric entities in order to organize the model setup better. They are used for
assigning material properties, volume forces and sources, boundary conditions, edge conditions, and point
conditions to domains, boundaries, edges, and points. See Table 1 for a list of file formats that support the import
and export of selections.
The example in this section is a modified version of the example in the document Introduction to COMSOL
Multiphysics, available in the installed documentation set.
https://www.comsol.com/model/72351
The filenames are:
busbar_box_fully_coupled_export_from_normal_mesh.mph
busbar_box_fully_coupled_compare.mph
busbar_box_T_data_grid.txt
busbar_box_T_data_spreadsheet.txt
busbar_box_T_data_sectionwise.txt
In this case, temperature data in the computational volume of a fluid flow with heat transfer simulation is being
imported. The data is computed on a coarser mesh than that of the current simulation.
Imported data can be visualized on an existing mesh, automatically applying data interpolation and extrapolation
where needed, or against a regular grid. Figure 1 shows the temperature data visualized on a regular grid.
Figure 2: Imported temperature data visualized on the tetrahedral mesh of the simulation.
Figure 3 shows a comparison between the temperature field of the current simulation, using a finer mesh, and the
imported data, previously simulated on a mesh with the default size.
Figure 3: Comparison between the computed temperature field and imported temperature data.
Note that the same type of comparison can be done by using two different meshes within the user interface without
using file export and import. This example illustrates the use of file export and import.
Figure 4 shows a similar comparison, but where the imported data is originally defined on a regular grid with 50-
by-50-by-50 grid points.
Figure 4: Comparison between the computed temperature field and imported temperature data defined on a regular
grid with 50-by-50-by-50 grid points.
In this case, the discrepancy is a bit higher due to the mismatch between the regular grid and the unstructured
mesh.
https://www.comsol.com/model/72351
The filenames are:
non_newtonian_flow_compare_surface.mph
non_newtonian_flow_export_from_normal_mesh_surface.mph
non_newtonian_flow_normal_sectionwise_w.txt
non_newtonian_flow_normal_spreadsheet_w.txt
This simulation uses a mesh with the default size. Figure 6 shows the same flow field in the z direction visualized
on the surface. In this visualization, the color range is set to a minimum value of 0 and a maximum value of 0.1
(m/s).
Figure 6: A surface plot showing the computed flow field in the z direction, using a mesh with a default size.
Figure 8 shows the simulation with a mesh with a finer size. The same manual color range is used.
Figure 8: Surface plot showing the z component of the computed velocity field, using a mesh with a finer size.
Figure 9: Mesh with a finer size, used for the second simulation.
Figure 10 shows the z-directional flow data imported as an interpolation function in the spreadsheet format. In this
example, the data is first exported from a simulation based on the mesh with the default size and then imported to
a model where a mesh with a finer size is used. The simulation data based on the coarser mesh is automatically
interpolated to the finer mesh and can be used, for example, as input to subsequent simulations. The same manual
color range is used.
Figure 10: Surface plot showing the z component of the velocity field, imported from file in the spreadsheet format.
It is difficult to see when comparing Figure 8 with Figure 10, but the interpolated data is not as smooth as the
original simulated data, which is expected, since some of the original information is lost due to interpolation error.
Figure 11: The absolute difference between the computed and the imported velocity field data (z direction).
The grid format is a structured format and contains only point coordinates and data values with no topological
information. The grid format allows for more extrapolation options than the other formats. Interpolation is faster
when using the grid data format than for the other formats.
The spreadsheet format may contain either structured or unstructured data and contains only point coordinates
and data values with no topological information. This means that extrapolated data in regions without point
coordinates will be extrapolated to a fixed, user-defined constant value. In order to perform interpolation of the
spreadsheet format, the software creates an auxiliary unstructured mesh (not visible to the user). For this reason,
using the sectionwise format generally results in faster interpolation than the spreadsheet format.
The sectionwise format is an unstructured format and contains detailed topological information that can be used
to carefully design both interpolation and extrapolation. For example, holes in the geometry could be filled with
data for the purpose of controlling the values for imported data that would otherwise be extrapolated to a constant
value.
For more details on the available interpolation and extrapolation options, see the COMSOL Multiphysics Reference
Manual.
Lines starting with % at the beginning of the file are ignored. Values can be separated by space, tab, comma, or
semicolon.
The grid coordinate section lists the unique coordinate values that form the grid. In the data section, each row
contains values for different x grid points for fixed values of y and z. In a particular column of the data section, the
data values in the rows correspond to grid points that first increase in the y-grid coordinate value and then the z-
grid coordinate value. The grid points do not have to be coordinates and can represent another independent
variable that the data values depend on. For example, the grid points can be temperature values and the data values
can be the thermal conductivity at these temperatures. It is possible to include more than one function in the file,
as long as the function data is separated by a line %Data. There is no limit to the number of functions defined in
this way. For grid points that are outside of the computational mesh, the data values will be NaN.
The example below shows interpolation data on the grid format with a 2-by-3-by-4 grid of temperature values for
x-, y-, and z-coordinates, respectively.
% Model: busbar_box.mph
% Version: COMSOL 6.2.0.266
The grid section lists the unique coordinate values for x (first row), y (second row), and z (third row).
The columns of the data section correspond to the two x-coordinate values 0.01875 and 0.07625, respectively.
The length of each column is 12=3*4, where the first 3 rows of a column correspond to the data associated with
the y-coordinate values -0.045, 0.045, 0.135, and the z-coordinate value 0.01. The next 3 rows correspond
to the y-coordinate values -0.045, 0.045, 0.135, the z-coordinate value 0.04, and so on.
An example file showcasing the grid data format can be downloaded from:
https://www.comsol.com/model/72351
The filename is:
busbar_box_T_data_grid.txt
Lines starting with % at the beginning of the file are ignored. Values can be separated by space, tab, comma, or
semicolon.
There is no limit to the number of function data columns, but the number of input variable data columns can be
at most 3. The number of input variable columns is implicit and needs to be specified by the user before import.
The example below shows the first few lines of a file containing interpolation data in the spreadsheet format for a
2D model with x- and y-coordinates, with two function data columns for the temperature and the temperature
gradient, respectively.
% Model: heat_convection_2d.mph
% Version: COMSOL 6.2.0.266
% Date: Oct 13 2023, 10:11
The following example shows the first few lines of a file containing interpolation data in the spreadsheet format for
a 3D model with x-, y-, and z-coordinates, with one function data column for the temperature.
% Model: busbar_box.mph
% Version: COMSOL 6.2.0.266
% Date: Oct 13 2023, 10:08
% Dimension: 3
% Nodes: 1861
% Expressions: 1
% Description: Temperature
% Length unit: m
% x y z T (K)
0.05621906254245827 0.1669952915832881 0.09803256635402077 293.1943545749328
0.04782791857244105 0.18000000000000002 0.09052024778162253 293.20080218975176
0.059 0.18000000000000005 0.11500000000000002 293.29372333205174
0.06685101713939509 0.18000000000000002 0.08907407172684315 293.4285639892069
0.10500000000000001 0.18000000000000002 0.067 305.7374583411461
...
Note that a function data column need not represent a continuous field, as in the example above, but can represent
discrete quantities. For example, if you export a set of streamlines, the first function data column will contain the
number of each streamline that the data belongs to.
Example files showcasing the spreadsheet data format can be downloaded from:
https://www.comsol.com/model/72351
The filenames are:
busbar_box_T_data_spreadsheet.txt
non_newtonian_flow_normal_spreadsheet_w.txt
The example below shows the first few lines of a coordinate file containing 3D point coordinate values.
% Coordinate values
-15.588426130362178 -8.999992011840579 3.000000000000001
-14.562300137244211 -10.580140343409553 3.000000000000001
-15.097478588358936 -9.80133359671242 4.64656422933223
-13.376581989138662 -12.044339345370581 3.000000000000001
-13.989436345998962 -11.326767885025419 4.646420660346455
...
Lines starting with % are ignored for interpolation data import. However, the length unit is taken into account if
the file is imported under the Mesh node. Values and indices can be separated by a space, tab, comma, or semicolon.
It is possible to include more than one function in the file as long as the function data is separated by a line %Data.
There is no limit to the number of functions defined in this way. However, the number of independent variables
can be at most 3, such as in the case of functions of space coordinates (x, y, z). Note that in the sectionwise format,
rows are indexed starting from 1.
The abbreviated example below shows temperature data from a 3D heat transfer model with tetrahedral elements.
The temperature values are defined for each coordinate; the number of coordinate lines is the same as the number
of temperature data lines.
% Model: busbar_box.mph
% Version: COMSOL 6.2.0.266
% Date: Oct 13 2023, 10:08
% Dimension: 3
% Nodes: 1861
% Elements: 9120
% Expressions: 1
% Description: Temperature
% Length unit: m
% Coordinates
0.05621906254245827 0.1669952915832881 0.09803256635402077
0.04782791857244105 0.18000000000000002 0.09052024778162253
0.059 0.18000000000000005 0.11500000000000002
0.06685101713939509 0.18000000000000002 0.08907407172684315
0.10500000000000001 0.18000000000000002 0.067
...
0.10500000000000001 -0.0230117893210171 0.056949328388214815
0.10499999999999998 -0.023506233446282956 0.053559015131106474
0.105 -0.026400036416763993 0.05663458881955498
0.10249999998293331 -0.02751267010274674 0.05306405946148493
0.105 -0.026933687000386404 0.05311865209250027
% Elements (tetrahedra)
4 3 2 1
8 7 6 5
12 11 10 9
13 9 12 10
11 14 9 12
...
1852 831 1854 1855
832 1852 1819 1855
831 1828 1854 1855
1856 625 1852 1859
1860 852 1859 1852
% Data (T (K))
293.1943545749328
293.20080218975176
293.29372333205174
293.4285639892069
305.7374583411461
...
The abbreviated example below shows fluid velocity data for a 3D fluid flow model with values defined on the
triangular surface elements.
The abbreviated example below, based on a MEMS model, shows voltage values for the edge elements of a 3D line
plot.
% Model: mems_pressure_sensor.mph
% Version: COMSOL 6.2.0.266
% Date: Oct 13 2023, 10:11
% Dimension: 3
% Nodes: 1756
% Elements: 1764
% Expressions: 1
% Description: Line
% Coordinates
-104.99999999999999 -50.714285714285715 0
-105 -48.80952380952381 0
-105 -46.904761904761905 0
-104.99999999999999 -44.99999999999999 0
-104.99999999999999 -56.42857142857143 0
...
104.99999999999999 49.285714285714285 0
105 47.38095238095238 0
Example files showcasing the sectionwise data format can be downloaded from:
https://www.comsol.com/model/72351
The filenames are:
busbar_box_T_data_sectionwise.txt
non_newtonian_flow_normal_sectionwise_w.txt
EVALUATION OPTIONS
When exporting to the sectionwise format as described in the section Exporting Data from the Results Node, the
entered expressions are evaluated at a number of points in each mesh element. For example, evaluating in Lagrange
points of order 1 means that the expressions are evaluated at the vertices of each mesh element. When more than
one mesh element share a vertex (as is typically the case), the expressions are evaluated several times at that
coordinate using the shape functions in the different mesh elements. The values of these evaluations at the same
point might not be equal, depending on the expression being evaluated. In particular, derivatives are commonly
discontinuous across mesh element boundaries and usually have different values. Once all the evaluations have been
made, the data is checked for duplicate values (that is, evaluations with the same coordinates and the same values
of the expressions). Such duplicates are removed before the data is exported to file. With smoothing, a smoothed
variant of the derivative is evaluated, which is continuous across mesh element boundaries; in such cases, there are
many duplicates. When evaluating at Gauss points, the evaluation points are always in the interior of mesh elements,
so there are never any duplicates.
This section gives an overview with examples of the COMSOL native file formats for mesh data. For a formal
specification, see the section Specification of COMSOL Formats for Mesh Data. See the section The Sectionwise
Interpolation Format for more information about the sectionwise format.
Figure 12: Mesh containing prism and tetrahedral elements, used to show how groups of mesh elements belong to different
geometric entities.
Figure 13: Distinguishing geometric entities by color using he example mesh in Figure 12.
https://www.comsol.com/model/72351
The filenames are:
mesh_example_intro.mphtxt
mesh_example_intro.mph
The file mesh_example_intro.mphtxt contains fewer mesh elements, but the entities corresponds to the example
shown in the images above.
In 1D meshes, the domains (intervals) are represented by edge elements. The endpoints of the mesh elements are
called mesh vertices. The boundaries (or vertices) defined in the geometry are represented in the mesh by boundary
elements (vertex elements).
In 2D meshes, the domains are represented by triangular or quadrilateral mesh elements. The sides of the triangle
and quadrilateral elements are called mesh edges, and their corners are mesh vertices. A mesh edge must not contain
mesh vertices in its interior. The boundaries defined are discretized into boundary elements (edge elements), which
In 3D meshes, the domains are represented by tetrahedral, hexahedral, prism, or pyramid elements whose faces,
edges, and corners are called mesh faces, mesh edges, and mesh vertices, respectively. The boundaries are discretized
into triangular or quadrilateral boundary elements. The geometric edges are discretized into edge elements. Similar
to 2D, the geometric vertices are represented by vertex elements.
The following table summarizes the terminology used for geometric and mesh entities in 3D:
TABLE 2: GEOMETRIC AND MESH ENTITIES (3D)
ENTITY GEOMETRIC ALTERNATIVE GEOMETRIC MESH ENTITY ALTERNATIVE MESH COMSOL NATIVE
DIMENSION ENTITY ENTITY NAME ENTITY NAME FORMAT
ENTRIES
The term node is used when the mesh data contains information about higher-order elements. The mesh data
formats used for import and export support, at most, second-order element information and is limited to certain
element types; see Element Types and Numbering Conventions. However, using higher-order elements for
simulations in COMSOL Multiphysics is not restricted to the order specified in the imported mesh file. See
Conversions on Import and Second-Order Element Data for more information.
A complete set of mesh data on the COMSOL native text or binary format contains information at all space
dimension levels for both mesh elements and geometric entities. If the contents of a file are incomplete — for
example, if it only contains information about mesh vertex coordinates and connectivity of tetrahedral elements —
the mesh import automatically generates the missing element data including partitioning into domains, boundaries,
and edges. This means that the structure of a COMSOL native text or binary file that is used for import can be
different depending on the level of completeness of the mesh data. For more information, see Importing
Incomplete Mesh Data in the COMSOL Native Format.
Geometric domain entity numbering typically starts at 1 (0 is reserved for empty domains or voids), whereas
geometric face, edge, and vertex entity numbering typically starts at 0. Mesh vertex numbering typically starts at
either 0 or 1. The lowest indices can be specified in the mesh data file.
A mesh of assembly type can either be conforming with a geometry where the Form an Assembly finalization action
has been used for the model tree Geometry node, or it defines its own geometric model with two or more
Mesh>Import nodes. It can also be one Mesh>Import node if the mesh file contains a mesh of assembly type.
Regardless of its origin, an assembly type of mesh defines several disconnected components with duplicated
boundaries, edges, and points where the components are touching. The boundary meshes at touching surfaces
between two parts do not need to define geometrically matching mesh vertices and elements. The image to the left
in Figure 14 shows a nonmatching assembly mesh with two disconnected components. The exploded view to the
right shows that the two components are indeed disconnected. The mesh contains 21 mesh vertices and 20 triangle
elements, 2 domains (indicated by yellow and green colors), 8 geometry edges, and 8 geometry points.
Figure 14: The left image shows a nonmatching assembly mesh. The right image shows the geometric model of the mesh
in an exploded view where the disconnected components and the duplicated boundaries (edges) are seen more clearly.
To connect the physics in disconnected components, add Identity Boundary Pairs nodes and add pair boundary
conditions in the physics interfaces. Alternatively, if you want to connect the meshes (and avoid setting up pairs),
use a Merge Entities operation (only supported in 3D) and merge the boundaries of the disconnected components.
When importing nonconforming mesh data, the Import operation will typically create edge and boundary elements
of the mesh edges and boundaries corresponding to each nonconformity in the mesh, since these mesh edges and
boundaries are typically only adjacent to one element each. In Figure 15, the image to the left shows the result after
importing nonconforming mesh data, with so-called hanging nodes. The mesh contains 18 mesh vertices and 20
triangle elements, compared to the assembly mesh in Figure 14 which contains 21 mesh vertices. The resulting
domains are connected in points 3, 4, and 6 with slit-like holes between the domains, as seen in the exploded view
in the right image. Note that the mesh gets 2 domains (indicated by color), 10 geometry edges, and 7 geometry
points.
Hanging nodes
Figure 15: Two “hanging nodes” in an imported mesh (left). The image to the right shows the geometric model of the
mesh in an exploded view where the slit-like holes and the duplicated boundaries (edges) are seen more clearly.
Figure 16: Imported nonconforming mesh data in 3D (left) and the mesh where the Merge Entities operation has been
used to merge the adjacent faces.
Import of nonconfoming mesh data with so called hanging edges results in an error. A hanging edge appears when
two triangles (yellow mesh faces to the right in Figure 17) coincide with a quad (blue mesh face) with which they
share mesh vertices.
Figure 17: A hanging edge appears when the mesh faces of two tetrahedral elements (yellow) coincide with the mesh face
of a hexahedral element (blue). The triangle and quad mesh faces (right image) share mesh vertices.
Figure 19: Triangular element (tri) as a first-order element (left) and a second-order element (right).
Figure 20: Quadrilateral element (quad) as a first-order element (left) and a second-order element (right).
Figure 22: Pyramid element (pyr) as a first-order element (left) and a second-order element (right).
Figure 23: Prism element (prism) as a first-order element (left) and a second-order element (right).
An entry of the type PSOLID is often the link between an element, such as CHEXA, and the corresponding
material, such as MAT1. In addition, entries of the type PSOLID are often used to define domain selections.
RBE2 and RBE3 elements are typically specifications of rigid body data. Selections will be created for the fixed
point in the RBE entry. If this point is not adjacent to any other mesh element, a vertex element will also be created
in this point. The rest of the RBE2 entry is used to set up selections that can, together with the selection for the
fixed point, be used to automatically set up Rigid Connectors for simulations using any of the Solid Mechanics,
Shell, and Beam physics interfaces in the software.
The NASTRAN bulk data format uses reduced second-order elements, so-called serendipity elements; that is, the
center node on quadrilateral mesh faces (quadNode) and the center node of hexahedral elements (hexNode) are not
included. When importing a NASTRAN mesh with second-order elements, the coordinates of these missing node
points are interpolated from the surrounding node points using the following formulas: quadNode =
0.5*quadEdgeNodes - 0.25*quadCornerNodes, where quadEdgeNodes is the sum of the coordinates of the
surrounding 4 edge nodes and quadCornerNodes is the sum of the coordinates of the surrounding 4 corner nodes,
and hexNode = 0.25*hexEdgeNodes-0.25*hexCornerNodes, where hexEdgeNodes is the sum of the
coordinates of the surrounding 12 edge nodes and hexCornerNodes is the sum of the coordinates of the
surrounding 8 corner nodes.
The vertex (node) numbering used in the NASTRAN format is different from that of the COMSOL native format.
The following table describes the relationship between the two formats by providing ordered lists of node numbers.
The table lists the NASTRAN format node numbering expressed in terms of the COMSOL native vertex (node)
numbering (see the images in section The COMSOL Native Format):
TABLE 4: VERTEX MAPPING BETWEEN COMSOL NATIVE FORMAT AND NASTRAN FORMAT
COMSOL ELEMENT COMSOL COMSOL NATIVE FORMAT NASTRAN ORDER NASTRAN FORMAT
ORDER
The NASTRAN format does not support Lagrange (nonserendipity) elements, such as a 27-node hex element. For
Lagrange elements, the corresponding serendipity element vertices (or nodes) are exported. This is indicated in the
table by a hyphen (-) for the “missing” vertex. To use serendipity elements in COMSOL Multiphysics, the setting
for the element order used by the physics needs to be changed as described in the next section.
After importing mesh data, you can change the element order used for the COMSOL Multiphysics simulation
regardless of whether the imported data contains first- or second-order element information. Note that element
order is sometimes also referred to as geometry shape function. See Conversions on Import for more information.
You change the element in order to curve mesh elements on boundaries. The second-order element information
in an imported mesh is used for representing curved boundaries and placing higher-order nodes. However, if
second-order information is not available in the imported mesh data file, this information will be estimated from
the linear mesh, curving the elements to adjust to the curvature of the face. This estimation is done for all orders
higher than two.
If you import a mesh containing second-order element information and then lower the geometric shape function
to linear, then the curvature of the boundary is no longer respected. If you import a mesh containing second-order
element information and increase the geometry shape function to cubic or higher, then the higher-order nodes are
inserted on the boundary based on interpolation using the second-order element data.
https://www.comsol.com/model/72351
File Listing
Domain elements only.
# Created by COMSOL Multiphysics.
0 0 1
4 Mesh # class
4 # version
3 # sdim
12 # number of mesh vertices
0 # lowest mesh vertex index
# Type #0
# Type #1
The mesh data is an object belonging to the mesh class. For more information, see Mesh Class.
The domain entity information in the file divides the mesh into two domains, numbered 1 for the tetrahedral
elements and 2 for the prism elements. Note that any grouping of elements, including elements of different types,
can be associated with a domain number or geometric entity. For example, each of the 7 elements can have their
respective domain number (from 1 to 7), or all of them have the domain number 1.
https://www.comsol.com/model/72351
The figure below shows a visualization of the domain information, where blue corresponds to domain 1 and red
corresponds to domain 2.
File Listing
Domain elements with geometric entity information.
0 0 1
4 Mesh # class
4 # version
3 # sdim
12 # number of mesh vertices
0 # lowest mesh vertex index
# Type #0
# Type #1
Replacing the element and domain entity information of the example above with the following data gives a domain
numbering from 1 to 7 for each element. The corresponding example file
mesh_example_with_domain_geom_info_1_7.mphtxt is available from:
https://www.comsol.com/model/72351
The figure below shows the corresponding domain numbering by color (using shrunk elements):
File Listing
# Created by COMSOL Multiphysics.
0 0 1
4 Mesh # class
4 # version
3 # sdim
12 # number of mesh vertices
0 # lowest mesh vertex index
# Type #0
# Type #1
Replacing the element and geometric entity information with the following data gives a domain numbering from
1 to 3. The corresponding example file mesh_example_with_domain_geom_info_1_3.mphtxt is available from:
https://www.comsol.com/model/72351
File Listing
# Created by COMSOL Multiphysics.
0 0 1
4 Mesh # class
4 # version
3 # sdim
12 # number of mesh vertices
0 # lowest mesh vertex index
# Type #0
# Type #1
If the import algorithm detects that a domain is not a connected component, it will split the domain until each
resulting domain is connected; similarly for faces and edges.
IMPORTING MESH DATA WITH ADDITIONAL BOUNDARY ELEMENTS AND FACE INDICES
The following example illustrates mesh data that contains:
To transfer boundary partitioning information, you need to include boundary elements with the corresponding
geometric entity information in the .mphtxt file. To illustrate this, import the file
mesh_example_with_domain_and_boundary_geom_info.mphtxt with minimal boundary partitioning. This file
contains the domain and boundary elements with geometric entity information defining 5 boundaries, as shown in
The imported mesh now has just 3 faces, because the minimal boundary partitioning generates the minimal possible
partitioning that is required by the topological criteria used by the import. Note that the interior face entity (index
2) between domains 1 and 2 is not visible in the figure.
https://www.comsol.com/model/72351
0 0 1
4 Mesh # class
4 # version
3 # sdim
12 # number of mesh vertices
0 # lowest mesh vertex index
# Type #0
# Type #1
# Type #2
# Type #3
https://www.comsol.com/model/72351
File Listing
Face elements with geometric entity information.
# Created by COMSOL Multiphysics.
0 0 1
4 Mesh # class
4 # version
3 # sdim
12 # number of mesh vertices
0 # lowest mesh vertex index
# Type #0
# Type #1
The boundary subdivision will be taken “as is” from the file unless a boundary does not form a connected
component. In that case, a further subdivision will be made during the import.
IMPORTING MESH DATA WITH EDGE AND VERTEX ELEMENTS AND INDICES
The following example illustrates mesh data that contains:
https://www.comsol.com/model/72351
0 0 1
4 Mesh # class
4 # version
3 # sdim
12 # number of mesh vertices
0 # lowest mesh vertex index
# Type #0
# Type #1
If a file is missing the vertex elements information, then the import will reconstruct vertex elements from the edge
intersection points.
Note that not all possible variants are illustrated in the examples above. It is also possible to import a file with other
combinations of element and index data.
https://www.comsol.com/model/72351
Note that you can get a file containing complete mesh data when exporting by first importing any of the incomplete
example data files above and then exporting using the default settings.
File Listing
Complete mesh and geometric entity information.
# Created by COMSOL Multiphysics.
0 0 1
4 Mesh # class
4 # version
3 # sdim
12 # number of mesh vertices
0 # lowest mesh vertex index
# Type #0
# Type #1
# Type #2
# Type #3
# Type #4
# Type #5
The abbreviated example below shows a mesh with second-order tetrahedral elements exported to the COMSOL
native (.mphtxt) format.
https://www.comsol.com/model/72351
# Type #0
# Type #1
# Type #2
# Type #3
As can be seen from the contents, the number of vertex elements is 12, whereas the number of mesh vertices is 113.
For version 5.4 and earlier, an exported file may contain additional sections.
The example below shows the header and the last part of a file containing three selections. Each selection is an
object with an individual tag.
https://www.comsol.com/model/72351
The filenames are:
busbar_with_selections.mph
busbar_with_selections.mphtxt
0 0 1
4 Mesh # class
4 # version
3 # sdim
232 # number of mesh vertices
0 # lowest mesh vertex index
0 0 1
9 Selection # class
0 # Version
8 Ti Bolts # Label
5 mesh1 # Geometry/mesh tag
3 # Dimension
6 # Number of entities
# Entities
2
3
4
5
6
7
0 0 1
9 Selection # class
0 # Version
12 Copper Piece # Label
5 mesh1 # Geometry/mesh tag
3 # Dimension
1 # Number of entities
# Entities
1
0 0 1
9 Selection # class
0 # Version
11 Single Bolt # Label
5 mesh1 # Geometry/mesh tag
3 # Dimension
2 # Number of entities
# Entities
2
3
The selections are objects belonging to the selection class. For more information, see Selection Class.
The section Mesh Data Formats includes specific examples of COMSOL native text files for mesh data. This section
gives a formal specification of the format, again for storing mesh data. For a more general description, including
information on how geometry data is stored, see the COMSOL Multiphysics Programming Reference Manual.
File Structure
VERSION NUMBER
The COMSOL native data format has a global version number so that it is possible to revise the whole structure in
the future if needed. The first entry in each file is the file format, indicated by two integers. The first integer is the
major file version and the second is referred to as the minor file version. For the current version, supported by
COMSOL Multiphysics version 6.2, the first two entries in a file are 0 1.
The example below shows the first few lines of a mesh data file.
# Created by COMSOL Multiphysics.
Comments, starting with the character #, are ignored. (These can all be removed and the file will still be imported.)
TAGS
The next data fields are the number of tags and the tags, as shown in the example below.
...
# Major & minor version
0 1
1 # number of tags
# Tags
5 mesh1
...
The tags are strings that function as identifiers so that objects can refer to each other. Tags are listed in the
subsequent lines. In this example, there is one tag, mesh1. The number 5 preceding the tag is the number of
characters in the string mesh1.
TYPES
The next data fields are the number of types and the types, as shown in the example below.
In the current version, 0 1, of the COMSOL native data format, only Object types (obj) are supported.
Note that references to type in the bulk of a COMSOL native data file, such as in the excerpt below:
1 # number of element types
# Type #0
are referring to element type and are not related to the type of the header.
OBJECTS
The objects represent the serialization (conversion to a file format) of the COMSOL data structures. Each object
starts with the header 0 0 1, followed by a string that defines which type of object follows. For mesh data, objects
are instances of the serializable classes Mesh Class or Selection Class.
The example below shows file export using the API command model.mesh(<tag>).export(<filename>) or
Mesh>Export to File in the user interface to save a COMSOL mesh. The tag equals the variable name mesh1; the
type is set to obj; and the file contains the serialization of the mesh object, including point coordinates and element
data of the mesh. In this example, the file also contains a selection object.
# Created by COMSOL Multiphysics.
0 0 1
4 Mesh # class
4 # version
3 # sdim
782 # number of mesh vertices
0 # lowest mesh vertex index
0 0 1
9 Selection # class
0 # Version
5 Fluid # Label
5 mesh1 # Geometry/mesh tag
3 # Dimension
1 # Number of entities
# Entities
1
Matrices are stored in row-major order. In this documentation, brackets are used to indicate a matrix. Hence,
integer[3][4] means that 12 integers representing a matrix are stored in the file. The first three entries
correspond to the integers in the first row of the matrix, and so on.
Lexical conventions:
• Strings are serialized as the length of the string followed by a space and then the characters of the string; for
example, “6 COMSOL”.
• The software ignores everything following a # on a line except when reading a string. This makes it possible to
store comments in the file.
In the Field sections for each class below, the fields appear in the table in the exact order they must
appear in the data files.
The Variable column lists the internal variables used in the descriptions of data types and in the
definitions of what the class implements.
For an example of the serialization format — specifically, of a file containing a 3D mesh with tetrahedral and prism
elements — see mesh_example_4.mphtxt in the installation folder
\applications\COMSOL_Multiphysics\Meshing_Tutorials.
Mesh Class
SUPPORTED VERSIONS
Up to 4. Version 4 is documented below.
SUBCLASS OF
Serializable Class
FIELDS
The class is defined by the following fields:
integer Version.
integer d Space dimension (if equal to 0 no more fields).
integer np Number of mesh points.
integer Lowest mesh point index.
double[d][np] p Mesh vertices.
integer nt Number of element types (equals the number of repeats of the following fields).
string Element type.
integer nep Number of nodes per element.
integer ne Number of elements.
integer[ne][nep] elem Matrix of point indices for each element.
integer ndom Number of geometric entity values.
integer[ndom] dom Vector of geometric entity labels for each element.
DESCRIPTION
The geometric entity numbering for points, edges, and boundaries typically starts from 0 and the geometric entity
numbering for domains normally starts from 1 when defining a mesh through a COMSOL Multiphysics mesh file.
EXAMPLE
The following displays a mesh with triangular elements on a unit square. Neither vertex nor edge elements are
present.
# Major & minor version
0 1
1 # number of tags
# Tags
5 mesh1
1 # number of types
# Types
3 obj
0 0 1
4 Mesh # class
4 # version
2 # sdim
4 # number of mesh vertices
0 # lowest mesh vertex index
# Type #0
Selection Class
SUPPORTED VERSIONS
0
SUBCLASS OF
Serializable Class
FIELDS
The class is defined by the following fields:
integer Version.
string Selection label. The string is encoded in UTF-8.
string Tag of corresponding object (mesh) in file.
integer Dimension of selection (0: vertex; 1: edge; 2: face; 3: domain in 3D).
integer Number of entities.
integer[] The indices of the entities for the selection. The integers specify the 0-based indices of the entities (1-
based for domains).
DESCRIPTION
Selections can appear in files containing a mesh. Each selection refers to a set of entities that needs to be defined by
the mesh in the file.
EXAMPLE
The following example displays a domain selection in 3D named Fluid, specifying domains 1 and 3.
0 # Version
5 Fluid # Label
5 mesh1 # Geometry/mesh tag
3 # Dimension
2 # Number of entities
# Entities
1
3
SUPPORTED VERSIONS
0
FIELDS
This is the abstract base class of all other classes. It has no fields.
DESCRIPTION
Serializable is the abstract base class. It is used to indicate that a field can contain all supported types.
assembly 8 edges 23
editing imported meshes 8
B binary data 57
electromagnetics 6
booleans and partitions for mesh 9
element 27
boundary conditions 9, 24
boundary 6, 23, 39, 43
boundary element 6, 23, 39, 43
changing order 32
boundary elements 24
domain 6, 23, 32
boundary layers generation 8
edge 6, 23, 44
boundary partitioning 39
first order 28, 32
C CAD hexahedral 27
mixing with mesh data 9 Lagrange 27, 31
class nodal-based isoparametric 27
mesh 58 prism 27
selection 59 quadrilateral 27
serializable 57, 60 second order 28, 32
clean up imported meshes 8 serendipity 31
collapse entities in mesh 8 shape 27
complete mesh data 46 specialized 27
COMSOL native binary format 5–6, 8, 23 tetrahedral 27
COMSOL native text format 5–6, 8, 23 triangular 27
convert mesh 9 type 6, 23
coordinate format 19 vertex 6, 44
create entities for mesh 9 export 6
curvature 32
F face 23
curve geometry objects 5, 9, 19
entity numbering 25
curve objects 17
indices 39, 43
curved mesh elements 32
field format 7
D data file format
export 6 3MF 6–8
flow 15 COMSOL native binary 5–6, 8, 23
import 8 COMSOL native text 5–6, 8, 23
temperature 10 coordinate 19
data extrapolation 10, 17 glTF 5, 8
data interpolation 10, 17 grid 5, 7, 9–10, 17
data type 57 NASTRAN 5, 7–8, 23, 30
delete entities for mesh 9 PLY 6–8
domain element 6, 23, 32 sectionwise 5, 7–10, 12, 17, 19
domain entity numbering 25 spreadsheet 5, 9–10, 12, 17–18
domain indices 34 STL 5–8
domains 23 VRML 5, 8
double precision 7 VTK 5, 7
duplicate values 22 first-order element 28, 32
INDEX| 69
fluid flow 6, 10 multiphysics analysis 6
free tetrahedral 9
N NASTRAN format 5, 7–8, 23, 30
G Gauss points 22 nodal-based isoparametric elements 27
geometric entity 23–25 node 25
indices 24 numbering 31
geometric entity information 7 numbering
Geometric entity information check box 6 node 31
geometric shape vertex 31
element 27 numbering conventions, meshes 27
geometry object 6
O operations
glTF format 5, 8
intersecting 9
grid 10
partitioning 8–9
regular 12
remeshing 9
grid format 5, 7, 9–10, 17
repairing 9
H heat transfer 10, 20
P partitioning 6, 8
hexahedral element 27, 30
plot
higher-order elements 25
exporting 7
higher-order nodes 25
PLY format 6–8
I image formats 8 point conditions 9
import 8 prism element 27
mesh 32 numbering 29
imprint operation 9 pyramid 27
incomplete mesh data 25 pyramid element 27
indices pyramid elements
domain 34 numbering 29
face 39, 43
Q quadrilateral element 27
interpolation function 15
numbering 28
J join entities for mesh 9
R refine mesh 9
L Lagrange element 27, 31 regular grid 10, 12
Lagrange points 22 remesh imported meshes 6, 8–9
linear element 7 remeshing 9
loads 8–9 repair imported meshes 8
70 | I N D E X
T temperature data 10
tetrahedral element 27
numbering 29
text data 57
triangular element 7, 27
numbering 28
V vector element 6
vertex element 6–7, 23, 44
vertex elements 24
vertex entity numbering 25
vertex numbering 31
vertices 23
volume forces 9
volumetric mesh 6
volumetric meshes 9
VRML format 5, 8
VTK format 5, 7
W wave propagation 6
INDEX| 71
72 | I N D E X