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
Posted 23 feb 2010, 07:25 GMT-5 17 Replies
Please login with a confirmed email address before reporting spam
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)
Please login with a confirmed email address before reporting spam
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
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
"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
At least the small example is working fine now.
Best regards, Christian
Please login with a confirmed email address before reporting spam
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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
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
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
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
for automated interpolation function import in COMSOL.
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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
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.
Please login with a confirmed email address before reporting spam
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.