Creating Spatially and Time-Varying DNN Surrogate Models
Building upon Part 3 of this course, where a multiphysics-driven deep neural network (DNN) surrogate model was created, this part will demonstrate how to develop a surrogate model that accurately captures important features of the same thermal actuator model. Using efficient geometry sampling, a DNN surrogate model can be trained to predict voltage, temperature, displacement, and stress fields over a wide range of input parameters. Once trained, the surrogate model can replace the original finite element model, producing near-instantaneous results as input parameters change. We will also briefly discuss time- and frequency-domain sampling.
Note: This demonstration requires functionality in version 6.3 of COMSOL Multiphysics®.
Generating Space-Dependent Surrogate Model Training Data
In Part 1 of this course, we discussed the fact that we can, in an abstract fashion, view a parametric COMSOL model as a series of functions:
...,
and
where are the input parameters, which could be length, width, material conductivity, coordinate, etc., and
are various output quantities that we are interested in, such as temperature, mechanical stress, or electric potential.
To use a DNN model to reconstruct a field throughout a computational domain, we need to allow some inputs, , to represent spatial coordinates. One approach to generate this data is to treat the spatial coordinates as parameters and let design of experiments (DOE) algorithms sample randomly in space during data generation. However, this approach is inefficient, as each sampled point requires solving the entire model, and only the field values at those specific points are retained, while all other computed field values are discarded.
Let's explore further why this method is inefficient. Suppose we are constructing a surrogate model for a thermal actuator where, just as in Part 3, the actuator length and applied voltage
are input parameters. Additionally, assume we want the surrogate model to reconstruct the full temperature field
inside the actuator. In other words, our goal is to build the following surrogate model:
In order to train such a surrogate model, we need to sample a large number of, say, , values. The full finite element model needs to be solved
times, once for each parameter combination. This generates the following table:
Sample Number | Outputs | T | Inputs | L | DV | x | y | z |
---|---|---|---|---|---|---|---|---|
1 | ||||||||
2 | ||||||||
3 | ||||||||
... | ... | ... | ... | ... | ... | ... | ||
... | ... | ... | ... | ... | ... | ... | ||
In this approach, each row is generated by the DOE algorithm combined with a finite element solution. The issue is that to obtain a single temperature value , we must solve the entire finite element model, a step that cannot be bypassed. While the finite element results provide temperature values throughout the actuator volume, a direct DOE method that includes spatial coordinates in the sampling will retain only one temperature value per sampling point,
. A more efficient approach would be to allow only the parameters driving the model, such as
and
, to be set by the DOE sampling and, for each finite element solution, store all the resulting temperature values:
...,
and
where is the number of finite element mesh vertices (or sampling grid points).
With this revised method, we can represent the data in the following table format:
Sample Number | Outputs | T | Inputs | L | DV | x | y | z |
---|---|---|---|---|---|---|---|---|
1 | ||||||||
2 | ||||||||
3 | ||||||||
... | ... | ... | ... | |||||
... | ... | ... | ... | |||||
Each row in this table compactly represents rows of detailed data, corresponding to each mesh vertex. Thus, the full table will contain
rows of data, where
is the number of finite element model computations. In this revised approach,
(the number of sample points) can be much smaller than
(from the previous method) while still achieving the same surrogate model accuracy. Generally, a similar sample set can be achieved as before if
.
For instance, if the mesh has vertices and we run
simulations, we would generate a table with
rows. A DNN surrogate model can easily handle this amount of data. In contrast, allowing the DOE algorithm to control all input parameters, including coordinates, would require solving the full finite element model 8 million times — an impractical computation.
Efficient Geometry Sampling: Thermal Actuator Surrogate Model App Overview
In the Application Libraries, under the COMSOL Multiphysics > the Applications section, the Thermal Actuator Surrogate Model appdemonstrates the Geometry Sampling feature. The figure below shows the app's user interface, where you can adjust four geometric parameters and the applied voltage. A DNN surrogate model retrieves field values near-instantaneously within the entire actuator geometry, with an option to compute the full finite element model for comparison. Note that the parametric CAD geometry and finite element mesh are necessary for displaying the field.

The Thermal Actuator Surrogate Model app demonstrating the use of a DNN surrogate model to reconstruct spatially varying field quantities.
The settings for geometry sampling are specified under the Definitions node in the Geometry Sampling feature, as shown in the figure below. You can choose to sample within one or more domains, boundaries, edges, or points. In this case, only one domain is available, and it is selected for sampling.

The Geometry Sampling feature used by the Surrogate Model Training study for efficient data generation.
The figure below shows the Surrogate Model Training study Settings window, where each quantity of interest references the Geometry Sampling feature. Selecting a row in the Quantities of Interest table displays the sampling properties for that specific quantity. Computed data is stored either within the model as an embedded file or externally on the file system. The input parameters are uniformly sampled, and 4000 computations (input points) are specified. Note that, in the Application Libraries model file, Number of input points is arbitrarily set to 1, as the data file is not included in the model (to save disk space). The generated file will contain approximately 8 million rows, totaling over 1 GB in size.

The Surrogate Model Training study settings for the thermal actuator model.
The figure below shows the first rows of the data file generated by the Surrogate Model Training study.

The first few rows of the data file generated by the Surrogate Model Training study.
The DNN surrogate model has 8 input features, 6 output features, and 4 hidden layers, which schematically can be represented as . Each layer uses the
activation function, as shown in the figure below. In the Data Column Settings section, the Quantities of Interest and Input Parameters from the Surrogate Model Training study are displayed. The first three columns, originating from the Geometry Sampling feature, represent the (x,y,z) coordinates of the mesh. Overall, the DNN surrogate model defines 6 DNN functions with 8 input arguments. Referring back to the previous notation, the temperature function is the second DNN function and can be represented as:
However, in the model settings, the temperature DNN function is named dnn1_T().

The DNN surrogate model settings with six functions in eight input arguments.
To generate a temperature plot from the surrogate model function, simply call it from the Expression field in the plot settings, as shown in the figure below. In this example, the expression dnn1_T(x,y,z,dw,gap,wv,L,DV2) is used, where the results parameter DV2 is specified instead of DV to accelerate the field plot when the geometry remains unchanged.

Generating a plot using a call to a surrogate model function.
Similarly, surrogate model function calls can be used for numerical result evaluations. For example, in the app, the maximum temperature is displayed by calling the same function in a Volume Maximum evaluation under Derived Values, as shown in the figure below. A method is used to toggle between the DNN function call and a direct reference to the finite element variable T, depending on whether the full solution is computed and visualized.
Generating numerical output using a call to a surrogate model function.
Note that spatially varying surrogate model functions, trained on geometry sampling data, need to be evaluated and visualized within the context of the parametric CAD geometry and finite element mesh. Visualizing these surrogate model functions as response surfaces (or volumes) alone would lack the appropriate context, as the extent and boundaries of the geometry are not well defined using a simple Cartesian grid. In this case, the complete surrogate model consists of both the surrogate model function and the finite element mesh on which it was trained.
Efficient Time-Domain Sampling: Battery Test Cycle Surrogate Model App Overview
Similar to efficient geometry sampling, the Surrogate Model Training study can also be used to generate time-domain, frequency-domain, or parametric data. Efficient time sampling is demonstrated in the Battery Test Cycle app, which is available in the Application Libraries of the Battery Design Module. This app demonstrates the usage of a surrogate model function for predicting the cell voltage, cell open-circuit voltage, and internal resistance of an NMC111/graphite battery cell undergoing a battery test cycle. The DNN surrogate function is fitted to a subset of the possible input data values. Five input data values can be set: the current in four segments of the cycle and the initial state of charge of the battery cell. The low computational cost of evaluating the surrogate function allows knobs to be used to interactively combine the input values and predict the cell voltage and internal resistance. Once a combination of values has been selected, the prediction of the surrogate model can be verified by computing the actual physical Li-ion battery model.

The Battery Test Cycle app demonstrating the use of a DNN surrogate model to reconstruct time-varying physical quantities.
In the Surrogate Model Training study, the time steps from the Time Dependent study are referenced by a vector. Similar to geometry sampling, the entire range of output values corresponding to this time vector is saved in batches to the data file. These settings are shown in the figure below.

The Surrogate Model Training study settings for efficient time-domain sampling.
The DNN surrogate model includes 6 input features, 2 output features, and 2 hidden layers, with a layer configuration of and
activation functions, as shown in the figure below. The Data Column Settings section reflects the quantities of interest and input parameters from the Surrogate Model Training study, with the last column originating from the time sampling vector. The DNN surrogate model defines 2 DNN functions with 6 input arguments.

The DNN surrogate model settings with two functions in six input arguments.
The surrogate model reconstructs time-varying data using a method known as time-series stitching. For a detailed explanation of this method, refer to the documentation for the app. Additionally, the sampling method described here can be applied to any parametric data by treating the parameter space similarly to how time data is managed in the Battery Test Cycle app.
Submit feedback about this page or contact support here.