An Interpolation function (
) is defined by a table or file containing the values of the function in discrete points. The interpolation data can be structured (defined on a grid) or unstructured (defined on a generic point cloud).
Select a Data source —
File,
Local table (the default), or
Result table to define the interpolation function by entering values in a table or by importing interpolation data from a file or from a table under
Results, respectively.
•
|
If Local table is selected, enter a Function name and enter coordinates t and function values f(t) into the table cells. A function of one variable can be defined in this way. For functions of two or more variables, such as space-dependent data in 2D and 3D, use a file with the function data. The default Function name is int1. You can move rows up and down in the table, remove a row from the table, and clear the table using the buttons underneath the table.
|
-
|
Optional: Save the parameters to a text file to reuse in other models. Click the Save to File button ( ) and enter a File name, including the extension .txt. Click to Save the text file. The information is saved in space-separated columns in the same order as displayed on screen.
|
-
|
Optional: Import or Load data from a spreadsheet program or other format by saving the file with a .txt extension. Data must be separated by tabs or colons. Click the Load from File button ( ) and navigate to the text (.txt) file to load and click Open. If the license includes LiveLink™ for Excel® you can also load interpolation data from a Microsoft Excel Workbook spreadsheet. The data loads to the table. If there is other data already in the table, it adds it after the last row. Move or edit as needed.
|
•
|
If File is selected to import interpolation data from a file, select a Data format: Spreadsheet, Grid, or Sectionwise. If the license includes LiveLink™ for Excel®, you can also import interpolation data from a Microsoft ® Excel Workbook spreadsheet. COMSOL Multiphysics then uses the spreadsheet format and the Data format list is not available.
|
-
|
When the data format is specified, enter the complete network path and name of the interpolation data file in the Filename field, or click Browse to select a text or data file with interpolation data in the Interpolation Data dialog box. You can also click the downward arrow beside the Browse button and choose Browse From ( ) to open the fullscreen Select File window. Click the downward arrow for the File Location Actions menu ( ) to choose Show in Auxiliary Data ( ) to move to the row for this file in the Auxiliary Data window, Copy File Location ( ), and (if you have copied a file location) Paste File Location ( ). Also choose a decimal separator from the Decimal separator list: Point (the default) or Comma. Click Import ( ) to import the interpolation data into the model; otherwise COMSOL Multiphysics references the interpolation data on your file system. When you have imported the interpolation data, the Parameters section, under Data imported into model, contains information about the filename, data type, and dimension for the data. Click Export to save the interpolation data to a file and reference from there instead of including it in the model. Click the Discard button to delete the imported interpolation data from the model. Click the Refresh button to ensure that the file is reread when needed.
|
-
|
From the Data format list select Spreadsheet, Grid, or Sectionwise. The spreadsheet format is the default format, and that format is the easiest to use for functions defined on an unstructured grid or for general tabulated function values with one or more arguments.
|
•
|
If Result table is selected, interpolation data evaluated or imported into a table under Results>Tables or belonging to an Evaluation Group under Results is treated in the same way as a file using the spreadsheet format.
|
If the interpolation data is given on spreadsheet format and when using a result table, enter a Number of arguments (1–3). For all data formats and table sources, enter information about the functions into the table. Add a
Function name and its
Position in file. The first function in the file has position 1, the following has position 2, and so on. For spreadsheet data, the first columns contain the arguments (typically spatial coordinates); the following columns can contain one or more functions, and the positions entered are the relative position for each function’s data column.
For unstructured interpolation data, COMSOL Multiphysics may internally apply a scaling of the coordinates of the data points to simplify the process of creating an interpolation mesh. Use the Internal scaling of data points list to control this functionality. Select
Automatic (the default) to apply the scaling if the bounding box of the interpolation points has a bad aspect ratio,
On to always apply the scaling, or
Off to turn off scaling altogether. Changing the scaling strategy may affect the generated interpolation mesh. The
Internal scaling of data points list is only available when unstructured interpolation data can be entered (that is, when
Spreadsheet or
Result table is the data source).
For the common case where the data source contains function values that are functions of the spatial coordinates, select the Use spatial coordinates as arguments check box. Then select the frame to which the spatial coordinates are attached from the
Frame list (the default is
Spatial for the spatial frame). Then the function can be called without arguments when used in the model; the spatial coordinates are added as function arguments automatically. The
Use spatial coordinates as arguments check box is available for
Interpolation nodes in a
Component branch when the
Data source is
File or when using a
Table in 1D models.
The file named temp.txt contains temperature measurements in nine points in the plane:
The data columns contain x-coordinates,
y-coordinates, and temperature values, respectively. To use this file as an interpolation function called
tempfun, perform the following steps.
1
|
Select File from the Data source list.
|
2
|
Enter a Filename (the complete network path) or Browse to locate a file to import.
|
3
|
From the Data format list select Spreadsheet.
|
4
|
Enter a Number of arguments. In this example, enter 2.
|
6
|
Enter its Position in file as 1. The first function in the file has position 1, the following has position 2, and so on. The position in file for a function is the column after the spatial coordinates (or other function arguments) where it is defined. In this example with two arguments (spatial coordinates), the third column is Position 1 in the file.
|
Use the function tempfun with
x and
y as input arguments in a 2D model to get the interpolated value for the temperature at any position. If the
Use spatial coordinates as arguments check box is selected, use
tempfun without adding the input arguments.
In all file formats, use a % (percent) sign to indicate a comment line. Values and indices can be separated by space, comma, semicolon, or tab characters.
A spreadsheet file contains function data for space-dependent functions or general input variables and function values for functions of one or more variables (that is, the functions do not need to be functions of space coordinates but can also be functions of something else, such as temperature).
Columns containing x, y (optional), and z (optional), or any other arguments, followed by function data columns.
A sectionwise file has coordinates and function values. The sectionwise format can be used for exporting results and for importing numerical data defined on an unstructured first-order tetrahedral mesh (triangular mesh in 2D) as interpolation table data. It is also possible to use this format in 1D and can then, contrary to the spreadsheet format, be used for 1D geometries with disconnected intervals. It cannot be used directly for defining a geometry or mesh. A sectionwise file contains unstructured mesh and function data for space-dependent functions. The functions need not be functions of space coordinates (
x,
y, and
z) but can also be functions of some other quantities, such as deformation or temperature. The row indices in the format below are 1-based indices.
One to three columns containing x
, y
(optional), and z
(optional) coordinate values
or other input variable values
Triangulation where each row contains the row indices of the points in the Coordinates
Column of data values for each point
A grid file contains data values on a grid. You supply the grid points as
x coordinate values (in 1D),
x and
y coordinate values in 2D, and
x,
y, and
z coordinate values in 3D.
x grid points separated by spaces, commas, semicolons, or tab characters
y grid points separated by spaces,commas, semicolons, or tab characters (optional)
z grid points separated by spaces,commas, semicolons, or tab characters (optional)
Data values separated by spaces, commas, semicolons, or tab characters
The grid coordinate section lists the unique coordinate values. Each data row contains values for different x grid points for fixed values of
y and
z (in 3D). The rows first increase the
y grid value and then the
z grid value. The grid points can also represent another independent variable that the data values depend on. For example, the “grid points” can be temperature values and the data values the thermal conductivity at these temperatures.
It is possible to include more than one function in the file as long as a %Data header separates them one from the other. For grid points that are outside of the computational mesh, the data values will be
NaN.
Select an Interpolation method:
-
|
Nearest neighbor interpolation selects the value of the nearest point where the function is defined.
|
-
|
Linear interpolation uses a linear polynomial to interpolate the function between the points where it is defined.
|
-
|
Piecewise cubic interpolation uses a piecewise-cubic Hermite polynomial with continuous first derivatives. It preserves the shape of the data and respects monotonicity.
|
-
|
The Cubic spline method also performs interpolation with a piecewise cubic polynomial. Here, even second derivatives are continuous; however, the method does not necessarily respect monotonicity.
|
Select an Extrapolation method to specify how to treat arguments outside the grid or mesh of points.
•
|
None. No extrapolation outside the defined interpolation range.
|
•
|
Constant. Uses the value from the closest point inside the grid (for structured interpolation) or the value from the closest mesh element (for unstructured interpolation). The function evaluates the polynomial from the closest grid point at the actual point where a value is requested. This is the default extrapolation method.
|
•
|
Linear. The function is linear outside the grid with a continuous function value and continuous first derivative at the boundary of the grid. Piecewise cubic or Cubic spline must be selected from the Interpolation list.
|
•
|
Nearest function. Evaluates the polynomial from the closest grid point at the actual point where a value is requested.
|
•
|
Specific value. Uses a single value, such as zero or NaN (Not-a-Number), everywhere outside the grid or mesh. Enter the value in the Values outside range field.
|
If you have selected to define the inverse function (see below), this section becomes available. Select the Plot the inverse function check box to plot the inverse function instead of the interpolation function itself when you click the
Plot button (
) to generate a preview plot.
The inverse function is available for interpolation functions defined by a local table only. If you want to define the inverse function f −1 for the interpolation function
f, select the
Define inverse function check box and enter a function name for the inverse function in the
Inverse function name field (the default is the name of the interpolation function with a suffix
_inv). If you want to plot the inverse function instead of the interpolation function itself, first select the
Plot the inverse function check box in the
Plot Parameters sections, which is only available when you have chosen to define the inverse function.
If you want to define the primitive function F for the interpolation function
f, select the
Define primitive function check box and enter a function name for the primitive function in the
Primitive function name field (the default is the name of the interpolation function with a suffix
_prim). You can use the primitive function to sample from the interpolation function. The primitive function is the integral of the interpolation function. The integration constant is such that the value of the primitive function is zero at the first data point. In other words, if the interpolation function is
f(
x), then the primitive function is
where x0 is the
x-coordinate of the first data point.
To define a random function, select the Define random function check box with a name that you specify in the
Random function name field (the default for an interpolation function
int1 is
rn_int1). You can use this function to sample from the interpolation function. Random functions can be useful in particle tracing, for example. Suppose, for example, that you want to specify an arbitrary energy distribution function for the initial energy of a bunch of particles. In order to do this, you need to randomly sample from an interpolation function, not merely call it. The random function makes this possible. To use a random function for this purpose, select the
Define random function check box, and then call it in an Inlet feature, for example, using
rn_int1(cpt.pidx), where
cpt.pidx is a variable that is uniquely valued for each particle.
You specify the range of the random function using the Range list. The default is
Automatic. Choose
Manual to provide limits in the
Lower limit and
Upper limit fields.
|
•
|
Acoustics Module, see Muffler with Perforates: Application Library path Acoustics_Module/Automotive/perforated_muffler.
|
•
|
CFD Module, see Transonic Flow in a Sajben Diffuser: Application Library path CFD_Module/High_Mach_Number_Flow/sajben_diffuser.
|
•
|
Corrosion Module, see Cathodic Protection of Steel in Reinforced Concrete: Application Library path Corrosion_Module/Cathodic_Protection/cathodic_protection_in_concrete.
|
•
|
Heat Transfer Module, see Temperature Field in a Cooling Flange: Application Library path Heat_Transfer_Module/Thermal_Processing/cooling_flange.
|
•
|
Pipe Flow Module, see Geothermal Heating from a Pond Loop: Application Library path Pipe_Flow_Module/Heat_Transfer/geothermal_heating.
|
|