Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

How does COMSOL read data from text file?

Please login with a confirmed email address before reporting spam

I set up a 3D COMSOL model, and several coefficients (Assume they are "A", "B", "C" and "D") are stored in a text file and should be evaluated at each node in each simulation step. Hence an interpolation function is used.

In COMSOL 3.5, I organize the text file in the following way:

% x y z A B C D
...

And when build a new interpolation function in COMSOL, A,B,C,D are automatically listed. The data type is "Unstructured".

However, in COMSOL 4.2, I have to choose a data type from "Grid", "Section Wise" and "Spreadsheet" before importing a text file. I think I should use "Grid". But when I import the same text file, COMSOL just cannot find those "A","B","C","D" parameters.

I check the rock_fracture_flow_aperture.mhp in the help document. And its text file is organized as follow:
% Grid
...
% Data
...

Question:
1) What type of data format should I use?
2) How to organize my text file?


Thanks

Dan

6 Replies Last Post Mar 6, 2012, 1:12 p.m. EST

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 5, 2012, 4:06 p.m. EST
I'm using version 3.5a. Maybe the grid format is different in two versions.

For 3.5a, the grid format looks like:

% grid
x1 x2 x3
y1 y2

% data
f1 f2 f3 f4 f5 f6

where f1 = f(x1, y1), f2 = f(x1, y2), f3 = f(x2, y1), f4 = f(x2, y2), f5 = f(x3, y1), f6 = f(x3, y2).
I'm using version 3.5a. Maybe the grid format is different in two versions. For 3.5a, the grid format looks like: % grid x1 x2 x3 y1 y2 % data f1 f2 f3 f4 f5 f6 where f1 = f(x1, y1), f2 = f(x1, y2), f3 = f(x2, y1), f4 = f(x2, y2), f5 = f(x3, y1), f6 = f(x3, y2).

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 6, 2012, 10:07 a.m. EST

I'm using version 3.5a. Maybe the grid format is different in two versions.

For 3.5a, the grid format looks like:

% grid
x1 x2 x3
y1 y2

% data
f1 f2 f3 f4 f5 f6

where f1 = f(x1, y1), f2 = f(x1, y2), f3 = f(x2, y1), f4 = f(x2, y2), f5 = f(x3, y1), f6 = f(x3, y2).


Thanks a lot.
Then what about "sectionwise" and "spreadsheet"?
In my text file, the (x,y,z) is not in a grid pattern, it's the coordinate of each node. Can I set up a format in COMSOL 4.2 like:
% x y z A B C D
just like what I did in COMSOL 3.5?
[QUOTE] I'm using version 3.5a. Maybe the grid format is different in two versions. For 3.5a, the grid format looks like: % grid x1 x2 x3 y1 y2 % data f1 f2 f3 f4 f5 f6 where f1 = f(x1, y1), f2 = f(x1, y2), f3 = f(x2, y1), f4 = f(x2, y2), f5 = f(x3, y1), f6 = f(x3, y2). [/QUOTE] Thanks a lot. Then what about "sectionwise" and "spreadsheet"? In my text file, the (x,y,z) is not in a grid pattern, it's the coordinate of each node. Can I set up a format in COMSOL 4.2 like: % x y z A B C D just like what I did in COMSOL 3.5?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 6, 2012, 10:50 a.m. EST
Hi, the "spreadsheet" reads the data in the unstructed format you are asking for. Not the "grid" format.

I'm trying to do this myself, but no luck yet. What I really want is a grid format defined like Excel

x1 x2 x3
y1 f11 f12 f13
y2 f21 f22 f23

which I could do with the grid command except I have hundreds of rows and columns. I don't want to type those in as one infinitely long row, so I'm heading down the path of

x1 y1 f11
x2 y1 f12

etc, which is the spreadsheet format. This set-up loads trivially as an interpolation function....

Haven't been able to actually plot the data yet...

Regards, John
Hi, the "spreadsheet" reads the data in the unstructed format you are asking for. Not the "grid" format. I'm trying to do this myself, but no luck yet. What I really want is a grid format defined like Excel x1 x2 x3 y1 f11 f12 f13 y2 f21 f22 f23 which I could do with the grid command except I have hundreds of rows and columns. I don't want to type those in as one infinitely long row, so I'm heading down the path of x1 y1 f11 x2 y1 f12 etc, which is the spreadsheet format. This set-up loads trivially as an interpolation function.... Haven't been able to actually plot the data yet... Regards, John

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 6, 2012, 11:36 a.m. EST

Hi, the "spreadsheet" reads the data in the unstructed format you are asking for. Not the "grid" format.

I'm trying to do this myself, but no luck yet. What I really want is a grid format defined like Excel

x1 x2 x3
y1 f11 f12 f13
y2 f21 f22 f23

which I could do with the grid command except I have hundreds of rows and columns. I don't want to type those in as one infinitely long row, so I'm heading down the path of

x1 y1 f11
x2 y1 f12

etc, which is the spreadsheet format. If/when I get it working I'll post.

Regards, John


OK, I think I should put my coordinates and parameters as follow:
x1 y1 z1 A1 B1 C1 D1
x2 y2 z2 A2 B2 C2 D2
...

But for the spreadsheet, we also need to set "Number of arguments". It should be an integer between 1 and 3.
What's the meaning of "Arguments" , the dimension of my model or the number of parameters?

Thank you and Have a nice day

Dan
[QUOTE] Hi, the "spreadsheet" reads the data in the unstructed format you are asking for. Not the "grid" format. I'm trying to do this myself, but no luck yet. What I really want is a grid format defined like Excel x1 x2 x3 y1 f11 f12 f13 y2 f21 f22 f23 which I could do with the grid command except I have hundreds of rows and columns. I don't want to type those in as one infinitely long row, so I'm heading down the path of x1 y1 f11 x2 y1 f12 etc, which is the spreadsheet format. If/when I get it working I'll post. Regards, John [/QUOTE] OK, I think I should put my coordinates and parameters as follow: x1 y1 z1 A1 B1 C1 D1 x2 y2 z2 A2 B2 C2 D2 ... But for the spreadsheet, we also need to set "Number of arguments". It should be an integer between 1 and 3. What's the meaning of "Arguments" , the dimension of my model or the number of parameters? Thank you and Have a nice day Dan

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 6, 2012, 11:42 a.m. EST

Hi, the "spreadsheet" reads the data in the unstructed format you are asking for. Not the "grid" format.

I'm trying to do this myself, but no luck yet. What I really want is a grid format defined like Excel

x1 x2 x3
y1 f11 f12 f13
y2 f21 f22 f23

which I could do with the grid command except I have hundreds of rows and columns. I don't want to type those in as one infinitely long row, so I'm heading down the path of

x1 y1 f11
x2 y1 f12

etc, which is the spreadsheet format. This set-up loads trivially as an interpolation function....

Haven't been able to actually plot the data yet...

Regards, John



I find the box before "Use space Coordinates as arguments", I think number of arguments equals to the dimension of my model. (x,y,z) means 2.
But what about the "Position in file"
% x y z A B C D
what is the the position of parameter A tnen, 1, 4 or something else?
[QUOTE] Hi, the "spreadsheet" reads the data in the unstructed format you are asking for. Not the "grid" format. I'm trying to do this myself, but no luck yet. What I really want is a grid format defined like Excel x1 x2 x3 y1 f11 f12 f13 y2 f21 f22 f23 which I could do with the grid command except I have hundreds of rows and columns. I don't want to type those in as one infinitely long row, so I'm heading down the path of x1 y1 f11 x2 y1 f12 etc, which is the spreadsheet format. This set-up loads trivially as an interpolation function.... Haven't been able to actually plot the data yet... Regards, John [/QUOTE] I find the box before "Use space Coordinates as arguments", I think number of arguments equals to the dimension of my model. (x,y,z) means 2. But what about the "Position in file" % x y z A B C D what is the the position of parameter A tnen, 1, 4 or something else?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 6, 2012, 1:12 p.m. EST

Hi, the "spreadsheet" reads the data in the unstructed format you are asking for. Not the "grid" format.

I'm trying to do this myself, but no luck yet. What I really want is a grid format defined like Excel

x1 x2 x3
y1 f11 f12 f13
y2 f21 f22 f23

which I could do with the grid command except I have hundreds of rows and columns. I don't want to type those in as one infinitely long row, so I'm heading down the path of

x1 y1 f11
x2 y1 f12

etc, which is the spreadsheet format. This set-up loads trivially as an interpolation function....

Haven't been able to actually plot the data yet...

Regards, John






I've successfully define the interpolation function! Thanks a lot.
The text file is like:
%x y z A B C D
...
I can plot this function right in COMSOL now.
Another problem:
When I want to call this interpolation function in COMSOL 4.2, it seems that I should write as " A(x,y,z) " instead of "A", and if Ais a matlab function, the input should be dimentionless: A(x[1/m],y[1/m],z[1/m]). Is this correct?
[QUOTE] Hi, the "spreadsheet" reads the data in the unstructed format you are asking for. Not the "grid" format. I'm trying to do this myself, but no luck yet. What I really want is a grid format defined like Excel x1 x2 x3 y1 f11 f12 f13 y2 f21 f22 f23 which I could do with the grid command except I have hundreds of rows and columns. I don't want to type those in as one infinitely long row, so I'm heading down the path of x1 y1 f11 x2 y1 f12 etc, which is the spreadsheet format. This set-up loads trivially as an interpolation function.... Haven't been able to actually plot the data yet... Regards, John [/QUOTE] I've successfully define the interpolation function! Thanks a lot. The text file is like: %x y z A B C D ... I can plot this function right in COMSOL now. Another problem: When I want to call this interpolation function in COMSOL 4.2, it seems that I should write as " A(x,y,z) " instead of "A", and if Ais a matlab function, the input should be dimentionless: A(x[1/m],y[1/m],z[1/m]). Is this correct?

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.