There is sometimes a need to include data from other simulation packages into a COMSOL Multiphysics model. There are a variety of ways in which this can be done, but one of the easiest approaches is to read in the point cloud data via a spreadsheet format text file. In this blog post, we walk through the steps of reading in such data, and using it in a COMSOL model.
Reading in Point Cloud Data as a Spreadsheet Text File
Let us start by looking at some data that was generated in another analysis package:
%X | Y | Z | VectorX | VectorY | VectorZ |
-0.03041 | 0.013353 | 0.138253 | 0.001493 | 0.003518 | -0.00302 |
-0.03862 | 0.01627 | 0.137537 | 0.001332 | 0.003296 | -0.00329 |
-0.0355 . . . |
0.010981 | 0.132823 | 9.60E-04 | 0.00287 | -0.00287 |
The first line you see is a header for the columnar data. We have XYZ data, and at each of these points we have the x-, y-, and z-components of a vector, which is a force that we will want to read into COMSOL Multiphysics. The remaining rows of the file are the point cloud data.
To read in this data, go to Model > Definitions > Functions and define a new Interpolation function. Like this:
Next you want to fill in the form as shown below:
Set the Data Source to File, and use the Browse button to locate the text file on your disk. The Spreadsheet data format is the default setting, and other formats are described in the documentation. Set the Number of Arguments to 3, since we are reading in XYZ data here, and toggle on the Use space coordinates as arguments check-box since the data we are reading in is a function of position. Switch the Frame drop-down menu to Material. Why? Because we are going to be applying loads to a structural problem, and by setting the Frame to Material, we specify that the loads are applied in the original, undeformed, configuration rather than the deformed, or Spatial, frame.
Finally, you want to enter a Function name. Here we can use Fx, Fy, and Fz for the components of a force vector. The Position in file column specifies that these data are in the three columns after the space coordinates. Note that COMSOL automatically detects that there are three arguments and sets the Number of arguments field to 3 automatically.
Also note the Interpolation and Extrapolation settings. A linear interpolation method means that the spreadsheet data is mapped linearly from the source mesh points in the data file onto the destination mesh in COMSOL Multiphysics. If the COMSOL mesh lies outside of the space defined by the external data, then a constant extrapolation is used. These defaults are reasonable in most cases, and more details about the mapping are given in the documentation.
After you click the Import button, the form will look like this:
Wish to read in a new data file instead? You also have the option to Discard the data.
Using the Point Cloud Data in a Model
Now let us see how to use this point cloud data in a model. Let’s suppose we wish to compute stresses in an impeller. The loads in the data file we have just read in represent the fluid loads on the surface of the vanes. (We could just as easily have read in volumetric data, but in this example we have read in surface data.) The impeller model, and loads, are shown below:
Simulating loads on an impeller.
The blue arrows represent the loads read in from the file. Let’s take a look at how the boundary condition is defined here:
And that’s it! Just by calling Fx, Fy, and Fz we have used the loads defined in our text file. Here are the results, showing the stresses as well:
Stresses in an impeller.
Comments (8)
Din-Chih Hwang
January 15, 2014Hi,
How about import a scalar function of (x,y,z,t) as spreadsheet/txt file? Thanks
Hugo Cabrera
December 18, 2015Fantastic.
Shirin Moradi
August 29, 2017Could we create geometry from the interpolation function?
for example I have created a surface (x,y,z) in the interpolation function and I want to create the same surface for my geometry.
Walter Frei
August 29, 2017 COMSOL EmployeeHello Shirin,
Yes, you can. You can call interpolation functions within the parametric surface geometry primitive.
For a related example, see:
https://www.comsol.com/blogs/how-to-generate-random-surfaces-in-comsol-multiphysics/
Entirely separately from that, you may also find this article interesting:
https://www.comsol.com/blogs/using-radial-basis-functions-for-surface-interpolation/
Alexandros Daniilidis
February 22, 2018Hello,
I have imported some permeability data from an external software into COMSOL. I tick ‘use spatial coordinates as arguments’ and ‘Geometry’ as frame. I would like to assign the material property ‘permeability’ from this dataset.
When visualizing the data, they seem to not honor the XYZ coordinates. Rather, they appear stretched throughout the whole domain.
Could you please indicate what the reason for this could be?
Caty Fairclough
March 1, 2018Hi Alexandros,
Thanks for your comment!
For your question, please contact our Support team.
Online Support Center: https://www.comsol.com/support
Email: support@comsol.com
Shirin Moradi
August 8, 2019Hi,
Is it possible to specify different properties for each point we have imported? e.g., each coordinate has a specific conductivity?
Mohammad Abdullah
September 18, 2021Hello Walter,
you said “There are a variety of ways in which this can be done”, I’d like to know what are other techniques to fed external data to comsol, how can it be done in Matlab livelink?
Sincerely,
Mohammed Abdullah