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.

Interpolation .txt-File Format Error: 9048

Please login with a confirmed email address before reporting spam

Hello everybody,
I’m trying to read a data file consisting of a matrix of measured data of an inhomogeneous refractive index (n).
But I’m always getting an error (# 9048) saying the format of the data file is not correct. When I try to use the data file from the rock structure example I still get the same error.

I also tried to handle the file with and without units but there is no difference.
The file test.txt looks like this:

% grid
0 1 2 3
0 1 2 3
% data
1.1 1.4 1.7 1.9
1.6 1.7 1.8 1.9
1.4 1.3 1.2 1.1
1.1 1.2 1.3 1.4

Did someone had a similar problem like me and www.comsol.com/community/forums/general/thread/2711/ or any suggestions?

Best Regards, Christian

Interpolation: Options-->Funcions... -->New... Name: test, interpolation from file.
Use in Rectangle: n=test(x,y)

17 Replies Last Post 2010年3月10日 GMT-5 01:38
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年2月23日 GMT-5 15:22
Hi

are you sure it is not your function name "test()", I beleive this is a reserved name for COMSOL "test" function for weak variables

Good luck
Ivar

Hi are you sure it is not your function name "test()", I beleive this is a reserved name for COMSOL "test" function for weak variables Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年2月24日 GMT-5 12:55
Thanks for your suggestion. I have allready tried it with other names as well. There must be an other problem.
I won't be able to work on it before monday, but will contact the forum then again.

Christian
Thanks for your suggestion. I have allready tried it with other names as well. There must be an other problem. I won't be able to work on it before monday, but will contact the forum then again. Christian

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月1日 GMT-5 03:46
I'm back at work on this topic and am still searching for a solution. I tried different names as well and still get the same error message when i press the "update model" button:
"Exception:
com.femlab.jni.FlNativeException: Format of data file is not correct
Messages:
Format of data file is not correct

Stack trace:
at interputil.cpp, row 636, ()
at com.femlab.xmesh.Xmesh.addElems(Native Method)
at com.femlab.xmesh.Xmesh.addElems(Unknown Source)
at com.femlab.commands.MeshExtendCommand.c(Unknown Source)
at com.femlab.commands.MeshExtendCommand.s(Unknown Source)
at com.femlab.commands.MeshExtendCommand.evalOnServer(Unknown Source)
at com.femlab.commands.FlCommand.runServerCode(Unknown Source)
at com.femlab.server.ServerProxy.eval(Unknown Source)
at com.femlab.commands.FlCommand.a(Unknown Source)
at com.femlab.commands.FlCommand.eval(Unknown Source)
at com.femlab.commands.a.a(Unknown Source)
at com.femlab.util.CoreUtil.meshExtend(Unknown Source)
at com.femlab.api.client.Solver.solve(Unknown Source)
at com.femlab.api.client.SolveModel.solveNow(Unknown Source)
at com.femlab.api.client.SolveModel.solveNow(Unknown Source)
at com.femlab.api.client.ah.a(Unknown Source)
at com.femlab.gui.FlProgressThread.run(Unknown Source)
at com.femlab.util.i.run(Unknown Source)
at com.femlab.util.aa.run(Unknown Source)
"
Is there a more easy way to test my data import?

Thanks, Christian
I'm back at work on this topic and am still searching for a solution. I tried different names as well and still get the same error message when i press the "update model" button: "Exception: com.femlab.jni.FlNativeException: Format of data file is not correct Messages: Format of data file is not correct Stack trace: at interputil.cpp, row 636, () at com.femlab.xmesh.Xmesh.addElems(Native Method) at com.femlab.xmesh.Xmesh.addElems(Unknown Source) at com.femlab.commands.MeshExtendCommand.c(Unknown Source) at com.femlab.commands.MeshExtendCommand.s(Unknown Source) at com.femlab.commands.MeshExtendCommand.evalOnServer(Unknown Source) at com.femlab.commands.FlCommand.runServerCode(Unknown Source) at com.femlab.server.ServerProxy.eval(Unknown Source) at com.femlab.commands.FlCommand.a(Unknown Source) at com.femlab.commands.FlCommand.eval(Unknown Source) at com.femlab.commands.a.a(Unknown Source) at com.femlab.util.CoreUtil.meshExtend(Unknown Source) at com.femlab.api.client.Solver.solve(Unknown Source) at com.femlab.api.client.SolveModel.solveNow(Unknown Source) at com.femlab.api.client.SolveModel.solveNow(Unknown Source) at com.femlab.api.client.ah.a(Unknown Source) at com.femlab.gui.FlProgressThread.run(Unknown Source) at com.femlab.util.i.run(Unknown Source) at com.femlab.util.aa.run(Unknown Source) " Is there a more easy way to test my data import? Thanks, Christian

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月1日 GMT-5 04:34
I have got it. I just didn't delete one older function and didn't recognised, that Comsol wants to analyse functions also if they aren't actually used. So I had it correct for quite a while.
At least the small example is working fine now.

Best regards, Christian
I have got it. I just didn't delete one older function and didn't recognised, that Comsol wants to analyse functions also if they aren't actually used. So I had it correct for quite a while. At least the small example is working fine now. Best regards, Christian

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月2日 GMT-5 17:36
Is there an easy way to generate a plot of a function defined in this way, to confirm that the data file is imported and interpretated correctly?
Is there an easy way to generate a plot of a function defined in this way, to confirm that the data file is imported and interpretated correctly?

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月3日 GMT-5 01:36
Hi

in Options Functions you have a "plot" button lower right

I believe that even more is coming in V4

Ivar
Hi in Options Functions you have a "plot" button lower right I believe that even more is coming in V4 Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月3日 GMT-5 04:13
The 'plot...' button exsists (at least in my version) only for analytic functions. But after solving you can plot it with: Postprocessing -> Domain plot parameters -> surface: functionname.
The 'plot...' button exsists (at least in my version) only for analytic functions. But after solving you can plot it with: Postprocessing -> Domain plot parameters -> surface: functionname.

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月3日 GMT-5 13:44
Hi
Then probably you do not need to solve fully, a "Solve get initial conditions" is enought to full the matrices to do most postprocessing, I use it very often to check my initial conditions, or to do gemetrical checks by allowing volume and inertia calculations based on the meshed volumes.

This is very handy when a normal solve can take an hour or more

Hope this options remains in to come V4 ;)

Good luck
Ivar
Hi Then probably you do not need to solve fully, a "Solve get initial conditions" is enought to full the matrices to do most postprocessing, I use it very often to check my initial conditions, or to do gemetrical checks by allowing volume and inertia calculations based on the meshed volumes. This is very handy when a normal solve can take an hour or more Hope this options remains in to come V4 ;) Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月5日 GMT-5 05:09
I would like to import many functions to COMSOL an easy way.


Therefore I made the following experiment
to create a function interpfun1(x,y)

export the fem structure to matlab.

Run the following code:

x=[0 1 2 3]
y=[0 1 2 3]
data=[1.1 1.4 1.7 1.9; 1.6 1.7 1.8 1.9; 1.4 1.3 1.2 1.1; 1.1 1.2 1.3 1.4]

fem.functions{1}.type = 'interp';
fem.functions{1}.name = 'interpfun1';
fem.functions{1}.method = ''linear';
fem.functions{1}.extmethod = 'linear';
fem.functions{1}.x = x
fem.functions{1}.y = y
fem.functions{1}.data = data

Then import the fem structure again.
Unfortunately I get the following error message:

"Not a cell array.
-Field: fem.functions{1}.x"

What is wrong?

Is this method generally the the right one?

(I am very new to Matlab and COMSOL)
I would like to import many functions to COMSOL an easy way. Therefore I made the following experiment to create a function interpfun1(x,y) export the fem structure to matlab. Run the following code: x=[0 1 2 3] y=[0 1 2 3] data=[1.1 1.4 1.7 1.9; 1.6 1.7 1.8 1.9; 1.4 1.3 1.2 1.1; 1.1 1.2 1.3 1.4] fem.functions{1}.type = 'interp'; fem.functions{1}.name = 'interpfun1'; fem.functions{1}.method = ''linear'; fem.functions{1}.extmethod = 'linear'; fem.functions{1}.x = x fem.functions{1}.y = y fem.functions{1}.data = data Then import the fem structure again. Unfortunately I get the following error message: "Not a cell array. -Field: fem.functions{1}.x" What is wrong? Is this method generally the the right one? (I am very new to Matlab and COMSOL)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月5日 GMT-5 05:25
I have tried it quite the same way first.
You just have to convert the matrizes the correct way: in matlab you can store them as normal numerical arrays or as cell arrays. You need to store the data as strings in cell arrays!
x={'0' '1' '2' '3'} would be correct.
There are some functions to convert the data:
have a look at the matlab help for cell(), mat2cell(), num2cell() ...

Christian
I have tried it quite the same way first. You just have to convert the matrizes the correct way: in matlab you can store them as normal numerical arrays or as cell arrays. You need to store the data as strings in cell arrays! x={'0' '1' '2' '3'} would be correct. There are some functions to convert the data: have a look at the matlab help for cell(), mat2cell(), num2cell() ... Christian

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月5日 GMT-5 08:01
Some help with this data conversion will be much appreciated.
Some help with this data conversion will be much appreciated.

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月5日 GMT-5 08:43
Hi

I do not have a direct answer, but dealing with the matlab structures is often confusing in the beginning, at least it is still for me ;)

if you do a search of "struct", "postinterp", posteval" on the forum you will find several examples, some answered other not, this could help you on the way.

A working example of another issue (not exactly what you are looking after) is towards the bottom of thread

www.comsol.com/community/forums/general/thread/287/

Good luck
Ivr
Hi I do not have a direct answer, but dealing with the matlab structures is often confusing in the beginning, at least it is still for me ;) if you do a search of "struct", "postinterp", posteval" on the forum you will find several examples, some answered other not, this could help you on the way. A working example of another issue (not exactly what you are looking after) is towards the bottom of thread http://www.comsol.com/community/forums/general/thread/287/ Good luck Ivr

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月5日 GMT-5 13:23
So it will be easier to create these data formats with Maple

for automated interpolation function import in COMSOL.
So it will be easier to create these data formats with Maple for automated interpolation function import in COMSOL.

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月5日 GMT-5 15:32
Hi

Maple is not really required, I still find it usefull for PDE verification.

Now to interface easily Matlab and Comsol, at a low level, one must master fully the structures and its rules and methods in Matlab (something I forget quickly if I'm not regularly using them). Tht's what I ment

Good luck
Ivar





Hi Maple is not really required, I still find it usefull for PDE verification. Now to interface easily Matlab and Comsol, at a low level, one must master fully the structures and its rules and methods in Matlab (something I forget quickly if I'm not regularly using them). Tht's what I ment Good luck Ivar

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月5日 GMT-5 16:22
Hi again

Now to come back to the example of the function defined in matlab: my way in these situations is always to generate an example in the Comsol GUI and then to look at it in Matlab, before I create anything the opposite way, then what I see is that (V3.5a):

the data in fem.functions.x .y and .data are structures with a cell for each number saved in an ascii representation and not an array of numbers, this is probably why COMSOL is not happy.

As ASCII values the expression can be evaluated further by COMSOL, in case it is a full expression with variable names an not just numbers

There are more in the "Variables and Expressions" section of the help file with a few matlab examples too

This is what I get for two simple function defined in the comsol GUI taken from the saved .m file:

% Functions
clear fcns
fcns{1}.type='interp';
fcns{1}.name='tst';
fcns{1}.method='piecewisecubic';
fcns{1}.extmethod='interior';
fcns{1}.x={'1','2','3','4'};
fcns{1}.data={'1','4','9','16'};

fcns{2}.type='piecewise';
fcns{2}.name='tstpcw(x)';
fcns{2}.extmethod='const';
fcns{2}.subtype='general';
fcns{2}.expr={'x^2','x^3'};
fcns{2}.intervals={'0','1','2'};
fcns{2}.complex='false';
fcns{2}.linear='false';
fem.functions = fcns;


for 2 variable functions the data must be sorted along the formatof a "meshgrid" call see help file:

here is an excerb of my help file, but I agree there is nothing stated about the special format of the .x, .y, .z not .data
-------------------------
To retrieve data from MATLAB, create a structure on the command line with the fields x, y (optional), z (optional), data, and elem (optional). For structured data, x, y, and z are vectors specifying the grid, and data is a multidimensional array of the same format as produced by the function call [xx,yy,zz] = meshgrid(x,y,z);. For example, to define the function f(x, y, z) = xysin(z) on a unit-cube grid and prepare it for export to COMSOL Multiphysics, type the following on the MATLAB command line:

x = 0:0.1:1; y = 0:0.1:1; z = 0:0.1:1;
[xx,yy,zz] = meshgrid(x,y,z);
data = xx.*yy.*sin(zz);
f.x = x; f.y = y; f.z = z; f.data = data;

----------------------------------------

Hope this helps further on the way

Good luck
Ivar
Hi again Now to come back to the example of the function defined in matlab: my way in these situations is always to generate an example in the Comsol GUI and then to look at it in Matlab, before I create anything the opposite way, then what I see is that (V3.5a): the data in fem.functions.x .y and .data are structures with a cell for each number saved in an ascii representation and not an array of numbers, this is probably why COMSOL is not happy. As ASCII values the expression can be evaluated further by COMSOL, in case it is a full expression with variable names an not just numbers There are more in the "Variables and Expressions" section of the help file with a few matlab examples too This is what I get for two simple function defined in the comsol GUI taken from the saved .m file: % Functions clear fcns fcns{1}.type='interp'; fcns{1}.name='tst'; fcns{1}.method='piecewisecubic'; fcns{1}.extmethod='interior'; fcns{1}.x={'1','2','3','4'}; fcns{1}.data={'1','4','9','16'}; fcns{2}.type='piecewise'; fcns{2}.name='tstpcw(x)'; fcns{2}.extmethod='const'; fcns{2}.subtype='general'; fcns{2}.expr={'x^2','x^3'}; fcns{2}.intervals={'0','1','2'}; fcns{2}.complex='false'; fcns{2}.linear='false'; fem.functions = fcns; for 2 variable functions the data must be sorted along the formatof a "meshgrid" call see help file: here is an excerb of my help file, but I agree there is nothing stated about the special format of the .x, .y, .z not .data ------------------------- To retrieve data from MATLAB, create a structure on the command line with the fields x, y (optional), z (optional), data, and elem (optional). For structured data, x, y, and z are vectors specifying the grid, and data is a multidimensional array of the same format as produced by the function call [xx,yy,zz] = meshgrid(x,y,z);. For example, to define the function f(x, y, z) = xysin(z) on a unit-cube grid and prepare it for export to COMSOL Multiphysics, type the following on the MATLAB command line: x = 0:0.1:1; y = 0:0.1:1; z = 0:0.1:1; [xx,yy,zz] = meshgrid(x,y,z); data = xx.*yy.*sin(zz); f.x = x; f.y = y; f.z = z; f.data = data; ---------------------------------------- Hope this helps further on the way Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月9日 GMT-5 15:31

For example, to define the function f(x, y, z) = xysin(z) on a unit-cube grid and prepare it for export to COMSOL Multiphysics, type the following on the MATLAB command line:

x = 0:0.1:1; y = 0:0.1:1; z = 0:0.1:1;
[xx,yy,zz] = meshgrid(x,y,z);
data = xx.*yy.*sin(zz);
f.x = x; f.y = y; f.z = z; f.data = data;

----------------------------------------



I would be usefull to have an automated method, to import functions prepared in this way, into Comsol.

To import functions one at a time from the comsol GUI is time consuming and mistake-prone.

Maybe the best way is to import from file constructed to contain the date for all the functions.

The command "postwriteinterpfile" creates the datafile for one function only, but thet can be joined.

[QUOTE] For example, to define the function f(x, y, z) = xysin(z) on a unit-cube grid and prepare it for export to COMSOL Multiphysics, type the following on the MATLAB command line: x = 0:0.1:1; y = 0:0.1:1; z = 0:0.1:1; [xx,yy,zz] = meshgrid(x,y,z); data = xx.*yy.*sin(zz); f.x = x; f.y = y; f.z = z; f.data = data; ---------------------------------------- [/QUOTE] I would be usefull to have an automated method, to import functions prepared in this way, into Comsol. To import functions one at a time from the comsol GUI is time consuming and mistake-prone. Maybe the best way is to import from file constructed to contain the date for all the functions. The command "postwriteinterpfile" creates the datafile for one function only, but thet can be joined.

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2010年3月10日 GMT-5 01:38
Hi

my only comment, when you have usefull suggestions, document them by explaining why etc and send them to Comsol Support so that they canbe introduced into the improvements for next version. I'm doing it regularly and it works :)

Good luck
Ivar
Hi my only comment, when you have usefull suggestions, document them by explaining why etc and send them to Comsol Support so that they canbe introduced into the improvements for next version. I'm doing it regularly and it works :) Good luck Ivar

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.