[函数] Interpolation

An Interpolation function ([函数] Interpolation插图) 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).


Definition

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. Then 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 reread the file.
    • 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.


An Example of Importing a File Data Source into a Parameter Table

The file named temp.txt contains temperature measurements in nine points in the plane:

10 3 310

20 3 309

30 3 314

10 6 302

20 6 307

30 6 311

10 9 307

20 9 308

30 9 314

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.
  5. Enter the Function name tempfun.
  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.
  7. If desired, adjust the interpolation and extrapolation settings in the Interpolation and Extrapolation section (see below).

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.


默认图片
bossliu
清醒 专注 努力
文章: 499

留下评论

Captcha Code