-
Filter by Topic
Most Popular
All Topics
- List all discussions
Interpolation .txt-File Format Error: 9048
|
Thread index | Previous thread | Next thread | Start a new discussion |
February 23, 2010 12:25pm UTC
Interpolation .txt-File Format Error: 9048
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 http://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)
Reply | Reply with Quote | Send private message | Report Abuse
February 23, 2010 8:22pm UTC in response to Christian Renneke
Re: Interpolation .txt-File Format Error: 9048
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
Reply | Reply with Quote | Send private message | Report Abuse
February 24, 2010 5:55pm UTC in response to Ivar K
Re: Interpolation .txt-File Format Error: 9048
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
Reply | Reply with Quote | Send private message | Report Abuse
March 1, 2010 8:46am UTC in response to Christian Renneke
Re: Interpolation .txt-File Format Error: 9048
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
Reply | Reply with Quote | Send private message | Report Abuse
March 1, 2010 9:34am UTC in response to Christian Renneke
Re: Interpolation .txt-File Format Error: 9048
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
Reply | Reply with Quote | Send private message | Report Abuse
March 2, 2010 10:36pm UTC in response to Christian Renneke
Re: Interpolation .txt-File Format Error: 9048
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?
Reply | Reply with Quote | Send private message | Report Abuse
March 3, 2010 6:36am UTC in response to Jens Jensen
Re: Interpolation .txt-File Format Error: 9048
Hi
in Options Functions you have a "plot" button lower right
I believe that even more is coming in V4
Ivar
Reply | Reply with Quote | Send private message | Report Abuse
March 3, 2010 9:13am UTC in response to Ivar K
Re: Interpolation .txt-File Format Error: 9048
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.
Reply | Reply with Quote | Send private message | Report Abuse
March 3, 2010 6:44pm UTC in response to Christian Renneke
Re: Interpolation .txt-File Format Error: 9048
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
Reply | Reply with Quote | Send private message | Report Abuse
March 5, 2010 10:09am UTC in response to Ivar K
Re: Interpolation .txt-File Format Error: 9048
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)
Reply | Reply with Quote | Send private message | Report Abuse
March 5, 2010 10:25am UTC in response to Jens Jensen
Re: Interpolation .txt-File Format Error: 9048
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
Reply | Reply with Quote | Send private message | Report Abuse
March 5, 2010 1:01pm UTC in response to Christian Renneke
Re: Interpolation .txt-File Format Error: 9048
Some help with this data conversion will be much appreciated.
Reply | Reply with Quote | Send private message | Report Abuse
March 5, 2010 1:43pm UTC in response to Jens Jensen
Re: Interpolation .txt-File Format Error: 9048
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
Reply | Reply with Quote | Send private message | Report Abuse
March 5, 2010 6:23pm UTC in response to Ivar K
Re: Interpolation .txt-File Format Error: 9048
So it will be easier to create these data formats with Maple
for automated interpolation function import in COMSOL.
Reply | Reply with Quote | Send private message | Report Abuse
March 5, 2010 8:32pm UTC in response to Jens Jensen
Re: Interpolation .txt-File Format Error: 9048
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
Reply | Reply with Quote | Send private message | Report Abuse
March 5, 2010 9:22pm UTC in response to Ivar K
Re: Interpolation .txt-File Format Error: 9048
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
Reply | Reply with Quote | Send private message | Report Abuse
March 9, 2010 8:31pm UTC in response to Ivar K
Re: Interpolation .txt-File Format Error: 9048
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.
Reply | Reply with Quote | Send private message | Report Abuse
March 10, 2010 6:38am UTC in response to Jens Jensen
Re: Interpolation .txt-File Format Error: 9048
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
Reply | Reply with Quote | Send private message | Report Abuse
Rules and guidelines
