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 can I define a interpolation-based function f(t,x), which is time- and space-dependent
Posted 3 ott 2010, 00:13 GMT-4 7 Replies
Please login with a confirmed email address before reporting spam
In comsol, it seems that only f(x) is allowed. Any suggestions are highly appreciated. thanks.
Please login with a confirmed email address before reporting spam
f you have no more than 2 space dimension in your problem, a trick will be to use a "comsol space dimension" as the time of yout problem.. it just labeled y or z and not t... :-)
The shock tube example [ in the doc or in the model example section I dont remember[precisely] is a good example of using such a "comsol space dimension " in lieu of time.
JF
Please login with a confirmed email address before reporting spam
Thanks for your great help. Following your suggestion, I defined an interpolation-based function f(t,x), however, I encountered some fatal errors and comsol stopped working.
My problem is very simple so that I used the "PDE Coefficient Form" directly. My PDE (time-dependent, 1-D space dimension) is of the standard form: da*ut-c*uxx+a*u+be*ux=f, but I need to define "be" in front of ux using an interpolation-based function f(t,x) based on "BFile.txt": "t" is between 1 and 10, and "x" is between 0 and 1. The first few rows in the text file "BFile.txt" are the following:
1.0000000e+000 0.0000000e+000 9.8000000e-001
1.0000000e+000 5.0000000e-002 1.1000000e-001
1.0000000e+000 1.0000000e-001 2.2000000e-001
1.0000000e+000 1.5000000e-001 3.3000000e-001
1.0000000e+000 2.0000000e-001 4.4000000e-001
1.0000000e+000 2.5000000e-001 5.5000000e-001
1.0000000e+000 3.0000000e-001 6.6000000e-001
1.0000000e+000 3.5000000e-001 7.7000000e-001
Could you or someone else in this forum help me out? It's frustrating to be stuck here. Thanks a million.
P.S. I thought about using inline functions: f(t,x)=interp2(matT,matX,matZ,t,x). However, I don't know how to script it in matlab since I am not using GUI of comsol and prefer to do it all in matlab scripts. Do you know how I can do it? Thanks.
P.S. The error message is:
??? Java exception occurred:
Exception:
com.femlab.server.MlError: Error using ==> feval
Undefined command/function 'f'.
(rethrown as com.femlab.jni.FlNativeException)
Messages:
Error using ==> feval
Undefined command/function 'f'.
Please login with a confirmed email address before reporting spam
Please discard my previous post. I just figured it out. I used "fem1" but defined the function f(t,x) for "fem". Of course, it didn't work ...
But now I got a new problem: "Non monotonous interpolation grid", which I don't quite understand.
As you can see from my previous post, my data are sorted and stored in "BFile.txt" in the following way: I first sort "t" from 1 to 10, and then for each value of "t", I sorted "x" from 0 to 1. So why I got this message? Does anyone here know how to fix it? Thank you very much.
Hi JF
Thanks for your great help. Following your suggestion, I defined an interpolation-based function f(t,x), however, I encountered some fatal errors and comsol stopped working.
My problem is very simple so that I used the "PDE Coefficient Form" directly. My PDE (time-dependent, 1-D space dimension) is of the standard form: da*ut-c*uxx+a*u+be*ux=f, but I need to define "be" in front of ux using an interpolation-based function f(t,x) based on "BFile.txt": "t" is between 1 and 10, and "x" is between 0 and 1. The first few rows in the text file "BFile.txt" are the following:
1.0000000e+000 0.0000000e+000 9.8000000e-001
1.0000000e+000 5.0000000e-002 1.1000000e-001
1.0000000e+000 1.0000000e-001 2.2000000e-001
1.0000000e+000 1.5000000e-001 3.3000000e-001
1.0000000e+000 2.0000000e-001 4.4000000e-001
1.0000000e+000 2.5000000e-001 5.5000000e-001
1.0000000e+000 3.0000000e-001 6.6000000e-001
1.0000000e+000 3.5000000e-001 7.7000000e-001
Could you or someone else in this forum help me out? It's frustrating to be stuck here. Thanks a million.
P.S. I thought about using inline functions: f(t,x)=interp2(matT,matX,matZ,t,x). However, I don't know how to script it in matlab since I am not using GUI of comsol and prefer to do it all in matlab scripts. Do you know how I can do it? Thanks.
P.S. The error message is:
??? Java exception occurred:
Exception:
com.femlab.server.MlError: Error using ==> feval
Undefined command/function 'f'.
(rethrown as com.femlab.jni.FlNativeException)
Messages:
Error using ==> feval
Undefined command/function 'f'.
Please login with a confirmed email address before reporting spam
the first parameter must be strictly increasing or decreasing, in the worst case just add a "counter" 1:n variably and define it to a dummy variable you do not need to use anywhere else
--
Good luck
Ivar
Please login with a confirmed email address before reporting spam
Thank you so much for your great help. If I define another dummy variable "count" (1:n), shall I also include it into my function, which will become f(count,t,x)?
Maybe it is easier to use inline function: f(t,x)=interp2(matT,matX,matZ,t,x). However, I don't know in GUI, how can I import the Matlab matrices: "matT" and "matX" and "matZ", which are stored on my computer. If possible, can you give me some help about how I can define such an inline function and make these matrices accessible in comsol? Thank you very much.
Please login with a confirmed email address before reporting spam
Sorry, I was also confused here, my remark is related to parametric sweep multiple variable entries, where the first one must be strictly increasing and decresing. Your case is a bit more tricky, the error message is close and its more or less the same issue.
your text file has the first column set to 1, if this is used for the interpolation it is as if there are many settings for the same point. Either you have a coumn index error, or I have missed something also possible (I do not have access to matlab+3.5 from home)
--
Good luck
Ivar
Please login with a confirmed email address before reporting spam
Sorry for the confusion. My text file has three columns, for "t", "x", and "f(t,x)", respectively for all grid points. I put more entries below. The first column, "t", ranges from 1 to 10; the second, "x", from 0 to 1. As a beginner of comsol, I don't know how to successfully define an interpolation-based function f(t,x). Any help on this is highly appreciated. Thanks a lot.
code:
clear fcns
fcns{1}.type='interp';
fcns{1}.name='f';
fcns{1}.filename='.\BFile.txt';
fcns{1}.fileindex='1';
fcns{1}.method='linear';
fcns{1}.extmethod='const';
fcns{1}.defvars='true';
fem1.functions = fcns;
some entries of "BFile.txt".
1.0000000e+000 0.0000000e+000 9.8000000e-001
1.0000000e+000 5.0000000e-002 1.1000000e-001
1.0000000e+000 1.0000000e-001 2.2000000e-001
1.0000000e+000 1.5000000e-001 3.3000000e-001
1.0000000e+000 2.0000000e-001 4.4000000e-001
1.0000000e+000 2.5000000e-001 5.5000000e-001
1.0000000e+000 3.0000000e-001 6.6000000e-001
......
1.2000000e+000 0.0000000e+000 9.9100000e-001
1.2000000e+000 5.0000000e-002 1.3200000e-001
1.2000000e+000 1.0000000e-001 2.6400000e-001
1.2000000e+000 1.5000000e-001 3.9600000e-001
1.2000000e+000 2.0000000e-001 5.2800000e-001
1.2000000e+000 2.5000000e-001 6.6000000e-001
1.2000000e+000 3.0000000e-001 7.9200000e-001
1.2000000e+000 3.5000000e-001 9.2400000e-001
1.2000000e+000 4.0000000e-001 1.0560000e+000
......
1.3000000e+000 0.0000000e+000 9.9650000e-001
1.3000000e+000 5.0000000e-002 1.4300000e-001
1.3000000e+000 1.0000000e-001 2.8600000e-001
1.3000000e+000 1.5000000e-001 4.2900000e-001
1.3000000e+000 2.0000000e-001 5.7200000e-001
1.3000000e+000 2.5000000e-001 7.1500000e-001
1.3000000e+000 3.0000000e-001 8.5800000e-001
1.3000000e+000 3.5000000e-001 1.0010000e+000
.......
1.0000000e+001 0.0000000e+000 1.4750000e+000
1.0000000e+001 5.0000000e-002 1.1000000e+000
1.0000000e+001 1.0000000e-001 2.2000000e+000
1.0000000e+001 1.5000000e-001 3.3000000e+000
1.0000000e+001 2.0000000e-001 4.4000000e+000
1.0000000e+001 2.5000000e-001 5.5000000e+000
1.0000000e+001 3.0000000e-001 6.6000000e+000
1.0000000e+001 3.5000000e-001 7.7000000e+000
1.0000000e+001 4.0000000e-001 8.8000000e+000
1.0000000e+001 4.5000000e-001 9.9000000e+000
1.0000000e+001 5.0000000e-001 1.1000000e+001
1.0000000e+001 5.5000000e-001 1.2100000e+001
1.0000000e+001 6.0000000e-001 1.3200000e+001
1.0000000e+001 6.5000000e-001 1.4300000e+001
1.0000000e+001 7.0000000e-001 1.5400000e+001
1.0000000e+001 7.5000000e-001 1.6500000e+001
1.0000000e+001 8.0000000e-001 1.7600000e+001
1.0000000e+001 8.5000000e-001 1.8700000e+001
1.0000000e+001 9.0000000e-001 1.9800000e+001
1.0000000e+001 9.5000000e-001 2.0900000e+001
1.0000000e+001 1.0000000e+000 2.1425000e+001
Hi
Sorry, I was also confused here, my remark is related to parametric sweep multiple variable entries, where the first one must be strictly increasing and decresing. Your case is a bit more tricky, the error message is close and its more or less the same issue.
your text file has the first column set to 1, if this is used for the interpolation it is as if there are many settings for the same point. Either you have a coumn index error, or I have missed something also possible (I do not have access to matlab+3.5 from home)
--
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.